Skip to contentSkip to conversation

cifs: Fix cifs_limit_bvec_subset() to correctly check the maxmimum size

PATCH Superseded David Howells 3 participants 4 messages May 22, 2023 – May 23, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: Fix cifs_limit_bvec_subset() to correctly check the maxmimum size

Fix cifs_limit_bvec_subset() so that it limits the span to the maximum specified and won't return with a size greater than max_size.

Fixes d08089f649a0 ("cifs: Change the I/O paths to use an iterator rather than a page list")
cc Steve French <[email protected]>
cc Rohith Surabattula <[email protected]>
cc Paulo Alcantara <[email protected]>
cc Tom Talpey <[email protected]>
cc Jeff Layton <[email protected]>
---
 fs/cifs/file.c |    1 +
 1 file changed, 1 insertion(+)
fs/cifs/file.c +1 -0
index ba7f2e09d6c8..4778614cfccf 100644
@@ -3353,6 +3353,7 @@ static size_t cifs_limit_bvec_subset(const struct iov_iter *iter, size_t max_siz
 	while (n && ix < nbv) {
 		len = min3(n, bvecs[ix].bv_len - skip, max_size);
 		span += len;
+		max_size -= len;
 		nsegs++;
 		ix++;
 		if (span >= max_size || nsegs >= max_segs)
#1 lore raw
Quoted 24 lines · David Howells

Fix cifs_limit_bvec_subset() so that it limits the span to the maximum specified and won't return with a size greater than max_size.

Fixes d08089f649a0 ("cifs: Change the I/O paths to use an iterator rather than a page list")
cc Steve French <[email protected]>
cc Rohith Surabattula <[email protected]>
cc Paulo Alcantara <[email protected]>
cc Tom Talpey <[email protected]>
cc Jeff Layton <[email protected]>
---
 fs/cifs/file.c |    1 +
 1 file changed, 1 insertion(+)
fs/cifs/file.c +0 -0
index ba7f2e09d6c8..4778614cfccf 100644

fs/cifs/file.c static size_t cifs_limit_bvec_subset(const struct iov_iter *iter, size_t max_siz · line 3356

Quoted 4 lines
fs/cifs/file.c +1 -0
@@ -3353,6 +3353,7 @@ static size_t cifs_limit_bvec_subset(const struct iov_iter *iter, size_t max_siz
        while (n && ix < nbv) {
                len = min3(n, bvecs[ix].bv_len - skip, max_size);
                span += len;
+               max_size -= len;

Shouldn't this decrement happen below, after the span has been compared with max_size?

Quoted 4 lines
fs/cifs/file.c +0 -0
                nsegs++;
                ix++;
                if (span >= max_size || nsegs >= max_segs)
Signature · 2 lines
Regards,
Shyam
#2 lore raw
Quoted 4 lines · Shyam Prasad N
Quoted 1 line

+ max_size -= len;

Shouldn't this decrement happen below, after the span has been compared with max_size?

It probably doesn't matter. The compiler is free to move it around, but yes that and ix++ can both be moved down.

David

#3 lore raw
Quoted 10 lines · David Howells
Quoted 4 lines · Shyam Prasad N
Quoted 1 line

+ max_size -= len;

Shouldn't this decrement happen below, after the span has been compared with max_size?

It probably doesn't matter. The compiler is free to move it around, but yes that and ix++ can both be moved down.

I am not sure I follow - can you explain? It looks like moving it up vs. down would change behavior

Signature · 3 lines
Thanks,

Steve