Skip to contentSkip to conversation

pipe: Fix bogus dereference in iov_iter_alignment()

PATCH Applied Jan Kara 3 participants 3 messages Dec 16, 2019 – Dec 17, 2019

Subsystems (3)
lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

PATCH 1/1 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 8cefc107ca54 ("pipe: Use head and tail pointers for the ring, not cursor and length")
---
 lib/iov_iter.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Al, David, not sure who's going to merge this so sending to both :).

Honza

lib/iov_iter.c +2 -1
index fb29c02c6a3c..51595bf3af85 100644
@@ -1222,11 +1222,12 @@ EXPORT_SYMBOL(iov_iter_discard);
 
 unsigned long iov_iter_alignment(const struct iov_iter *i)
 {
-	unsigned int p_mask = i->pipe->ring_size - 1;
 	unsigned long res = 0;
 	size_t size = i->count;
 
 	if (unlikely(iov_iter_is_pipe(i))) {
+		unsigned int p_mask = i->pipe->ring_size - 1;
+
 		if (size && i->iov_offset && allocated(&i->pipe->bufs[i->head & p_mask]))
 			return size | i->iov_offset;
 		return size;
Signature · 1 line
2.16.4
maintainer Applied
#1 lore raw
Quoted 4 lines · Jan Kara

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.

Quoted 8 lines
Reported-by [email protected]
Fixes 8cefc107ca54 ("pipe: Use head and tail pointers for the ring, not cursor and length")
---
 lib/iov_iter.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Al, David, not sure who's going to merge this so sending to both :).

Applied, will push tonight.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Jan Kara
Quoted 7 lines · Jan Kara

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 8cefc107ca54 ("pipe: Use head and tail pointers for the ring, not cursor and length")