Skip to content

Commit e0ff126

Browse files
jankaraAl Viro
authored andcommitted
pipe: Fix bogus dereference in iov_iter_alignment()
We cannot look at 'i->pipe' unless we know the iter is a pipe. Move the ring_size load to a branch in iov_iter_alignment() where we've already checked the iter is a pipe to avoid bogus dereference. Reported-by: [email protected] Fixes: 8cefc10 ("pipe: Use head and tail pointers for the ring, not cursor and length") Signed-off-by: Jan Kara <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent e42617b commit e0ff126

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/iov_iter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,11 +1222,12 @@ EXPORT_SYMBOL(iov_iter_discard);
12221222

12231223
unsigned long iov_iter_alignment(const struct iov_iter *i)
12241224
{
1225-
unsigned int p_mask = i->pipe->ring_size - 1;
12261225
unsigned long res = 0;
12271226
size_t size = i->count;
12281227

12291228
if (unlikely(iov_iter_is_pipe(i))) {
1229+
unsigned int p_mask = i->pipe->ring_size - 1;
1230+
12301231
if (size && i->iov_offset && allocated(&i->pipe->bufs[i->head & p_mask]))
12311232
return size | i->iov_offset;
12321233
return size;

0 commit comments

Comments
 (0)