Skip to contentSkip to conversation

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

PATCH In review David Howells 2 participants 2 messages May 23, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 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 |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/cifs/file.c +2 -1
index ba7f2e09d6c8..df88b8c04d03 100644
@@ -3353,9 +3353,10 @@ 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)
+		if (max_size == 0 || nsegs >= max_segs)
 			break;
 		skip = 0;
 		n -= len;
#1 lore raw
Quoted 25 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 |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/cifs/file.c +0 -0
index ba7f2e09d6c8..df88b8c04d03 100644
@@ -3353,9 +3353,10 @@ static size_t cifs_limit_bvec_subset(const struct iov_iter *iter, size_t max_siz
        while (n && ix < nbv) {

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

Quoted 10 lines
fs/cifs/file.c +2 -1
                len = min3(n, bvecs[ix].bv_len - skip, max_size);
                span += len;
+               max_size -= len;
                nsegs++;
                ix++;
-               if (span >= max_size || nsegs >= max_segs)
+               if (max_size == 0 || nsegs >= max_segs)
                        break;
                skip = 0;
                n -= len;

Looks good to me.

Signature · 2 lines
Regards,
Shyam