* [PATCH] cifs: Fix cifs_limit_bvec_subset() to correctly check the maxmimum size
@ 2023-05-22 14:40 David Howells
2023-05-22 17:28 ` Shyam Prasad N
0 siblings, 1 reply; 4+ messages in thread
From: David Howells @ 2023-05-22 14:40 UTC (permalink / raw)
To: Shyam Prasad N
Cc: dhowells, Steve French, Rohith Surabattula, Paulo Alcantara,
Tom Talpey, Jeff Layton, linux-cifs, linux-fsdevel, linux-kernel
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")
Reported-by: Shyam Prasad N <sprasad@microsoft.com>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Steve French <smfrench@gmail.com>
cc: Rohith Surabattula <rohiths.msft@gmail.com>
cc: Paulo Alcantara <pc@manguebit.com>
cc: Tom Talpey <tom@talpey.com>
cc: Jeff Layton <jlayton@kernel.org>
cc: linux-cifs@vger.kernel.org
cc: linux-fsdevel@vger.kernel.org
---
fs/cifs/file.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index ba7f2e09d6c8..4778614cfccf 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -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)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] cifs: Fix cifs_limit_bvec_subset() to correctly check the maxmimum size
2023-05-22 14:40 [PATCH] cifs: Fix cifs_limit_bvec_subset() to correctly check the maxmimum size David Howells
@ 2023-05-22 17:28 ` Shyam Prasad N
2023-05-22 18:11 ` David Howells
0 siblings, 1 reply; 4+ messages in thread
From: Shyam Prasad N @ 2023-05-22 17:28 UTC (permalink / raw)
To: David Howells
Cc: Shyam Prasad N, Steve French, Rohith Surabattula, Paulo Alcantara,
Tom Talpey, Jeff Layton, linux-cifs, linux-fsdevel, linux-kernel
On Mon, May 22, 2023 at 8:22 PM David Howells <dhowells@redhat.com> wrote:
>
> 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")
> Reported-by: Shyam Prasad N <sprasad@microsoft.com>
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Steve French <smfrench@gmail.com>
> cc: Rohith Surabattula <rohiths.msft@gmail.com>
> cc: Paulo Alcantara <pc@manguebit.com>
> cc: Tom Talpey <tom@talpey.com>
> cc: Jeff Layton <jlayton@kernel.org>
> cc: linux-cifs@vger.kernel.org
> cc: linux-fsdevel@vger.kernel.org
> ---
> fs/cifs/file.c | 1 +
> 1 file changed, 1 insertion(+)
>
>
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index ba7f2e09d6c8..4778614cfccf 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -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?
> nsegs++;
> ix++;
> if (span >= max_size || nsegs >= max_segs)
>
--
Regards,
Shyam
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cifs: Fix cifs_limit_bvec_subset() to correctly check the maxmimum size
2023-05-22 17:28 ` Shyam Prasad N
@ 2023-05-22 18:11 ` David Howells
2023-05-23 6:45 ` Steve French
0 siblings, 1 reply; 4+ messages in thread
From: David Howells @ 2023-05-22 18:11 UTC (permalink / raw)
To: Shyam Prasad N
Cc: dhowells, Shyam Prasad N, Steve French, Rohith Surabattula,
Paulo Alcantara, Tom Talpey, Jeff Layton, linux-cifs,
linux-fsdevel, linux-kernel
Shyam Prasad N <nspmangalore@gmail.com> wrote:
> > + 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cifs: Fix cifs_limit_bvec_subset() to correctly check the maxmimum size
2023-05-22 18:11 ` David Howells
@ 2023-05-23 6:45 ` Steve French
0 siblings, 0 replies; 4+ messages in thread
From: Steve French @ 2023-05-23 6:45 UTC (permalink / raw)
To: David Howells
Cc: Shyam Prasad N, Shyam Prasad N, Rohith Surabattula,
Paulo Alcantara, Tom Talpey, Jeff Layton, linux-cifs,
linux-fsdevel, linux-kernel
On Mon, May 22, 2023 at 1:11 PM David Howells <dhowells@redhat.com> wrote:
>
> Shyam Prasad N <nspmangalore@gmail.com> wrote:
>
> > > + 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
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-23 6:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-22 14:40 [PATCH] cifs: Fix cifs_limit_bvec_subset() to correctly check the maxmimum size David Howells
2023-05-22 17:28 ` Shyam Prasad N
2023-05-22 18:11 ` David Howells
2023-05-23 6:45 ` Steve French
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox