* [PATCH] xfs: check for negatives in xfs_exchange_range_checks()
@ 2024-05-04 11:27 Dan Carpenter
2024-05-04 16:46 ` Markus Elfring
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Dan Carpenter @ 2024-05-04 11:27 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: Chandan Babu R, linux-xfs, linux-kernel, kernel-janitors
The fxr->file1_offset and fxr->file2_offset variables come from the user
in xfs_ioc_exchange_range(). They are size loff_t which is an s64.
Check the they aren't negative.
Fixes: 9a64d9b3109d ("xfs: introduce new file range exchange ioctl")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
From static analysis. Untested. Sorry!
fs/xfs/xfs_exchrange.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/xfs/xfs_exchrange.c b/fs/xfs/xfs_exchrange.c
index c8a655c92c92..3465e152d928 100644
--- a/fs/xfs/xfs_exchrange.c
+++ b/fs/xfs/xfs_exchrange.c
@@ -337,6 +337,9 @@ xfs_exchange_range_checks(
if (IS_SWAPFILE(inode1) || IS_SWAPFILE(inode2))
return -ETXTBSY;
+ if (fxr->file1_offset < 0 || fxr->file2_offset < 0)
+ return -EINVAL;
+
size1 = i_size_read(inode1);
size2 = i_size_read(inode2);
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] xfs: check for negatives in xfs_exchange_range_checks()
2024-05-04 11:27 [PATCH] xfs: check for negatives in xfs_exchange_range_checks() Dan Carpenter
@ 2024-05-04 16:46 ` Markus Elfring
2024-05-07 6:06 ` Christoph Hellwig
` (2 subsequent siblings)
3 siblings, 0 replies; 10+ messages in thread
From: Markus Elfring @ 2024-05-04 16:46 UTC (permalink / raw)
To: Dan Carpenter, linux-xfs, kernel-janitors, Darrick J. Wong
Cc: LKML, Chandan Babu R
…
> Check the they aren't negative.
Would you like to use the word “that” (instead of “the”) in this sentence?
Regards,
Markus
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] xfs: check for negatives in xfs_exchange_range_checks()
2024-05-04 11:27 [PATCH] xfs: check for negatives in xfs_exchange_range_checks() Dan Carpenter
2024-05-04 16:46 ` Markus Elfring
@ 2024-05-07 6:06 ` Christoph Hellwig
2024-05-07 6:33 ` Dan Carpenter
2024-05-07 23:33 ` Darrick J. Wong
2024-05-08 1:29 ` Dave Chinner
3 siblings, 1 reply; 10+ messages in thread
From: Christoph Hellwig @ 2024-05-07 6:06 UTC (permalink / raw)
To: Dan Carpenter
Cc: Darrick J. Wong, Chandan Babu R, linux-xfs, linux-kernel,
kernel-janitors
On Sat, May 04, 2024 at 02:27:36PM +0300, Dan Carpenter wrote:
> The fxr->file1_offset and fxr->file2_offset variables come from the user
> in xfs_ioc_exchange_range(). They are size loff_t which is an s64.
> Check the they aren't negative.
>
> Fixes: 9a64d9b3109d ("xfs: introduce new file range exchange ioctl")
In this commit file1_offset and file2_offset are u64. They used to
be u64 in the initial submission, but we changed that as part of the
review process.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] xfs: check for negatives in xfs_exchange_range_checks()
2024-05-07 6:06 ` Christoph Hellwig
@ 2024-05-07 6:33 ` Dan Carpenter
2024-05-07 6:40 ` Christoph Hellwig
0 siblings, 1 reply; 10+ messages in thread
From: Dan Carpenter @ 2024-05-07 6:33 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Darrick J. Wong, Chandan Babu R, linux-xfs, linux-kernel,
kernel-janitors
On Mon, May 06, 2024 at 11:06:17PM -0700, Christoph Hellwig wrote:
> On Sat, May 04, 2024 at 02:27:36PM +0300, Dan Carpenter wrote:
> > The fxr->file1_offset and fxr->file2_offset variables come from the user
> > in xfs_ioc_exchange_range(). They are size loff_t which is an s64.
> > Check the they aren't negative.
> >
> > Fixes: 9a64d9b3109d ("xfs: introduce new file range exchange ioctl")
>
> In this commit file1_offset and file2_offset are u64. They used to
> be u64 in the initial submission, but we changed that as part of the
> review process.
I've just checked again, and I think it was loff_t in that commit.
There are two related structs, the one that's userspace API and the
one that's internal. The userspace API is u64 but internally it's
loff_t.
fs/xfs/libxfs/xfs_fs.h
818 struct xfs_exchange_range {
819 __s32 file1_fd;
820 __u32 pad; /* must be zeroes */
821 __u64 file1_offset; /* file1 offset, bytes */
822 __u64 file2_offset; /* file2 offset, bytes */
823 __u64 length; /* bytes to exchange */
824
825 __u64 flags; /* see XFS_EXCHANGE_RANGE_* below */
826 };
fs/xfs/xfs_exchrange.h
16 struct xfs_exchrange {
17 struct file *file1;
18 struct file *file2;
19
20 loff_t file1_offset;
21 loff_t file2_offset;
22 u64 length;
23
24 u64 flags; /* XFS_EXCHANGE_RANGE flags */
25 };
regards,
dan carpenter
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] xfs: check for negatives in xfs_exchange_range_checks()
2024-05-07 6:33 ` Dan Carpenter
@ 2024-05-07 6:40 ` Christoph Hellwig
2024-05-07 23:36 ` Darrick J. Wong
0 siblings, 1 reply; 10+ messages in thread
From: Christoph Hellwig @ 2024-05-07 6:40 UTC (permalink / raw)
To: Dan Carpenter
Cc: Christoph Hellwig, Darrick J. Wong, Chandan Babu R, linux-xfs,
linux-kernel, kernel-janitors
On Tue, May 07, 2024 at 09:33:40AM +0300, Dan Carpenter wrote:
> On Mon, May 06, 2024 at 11:06:17PM -0700, Christoph Hellwig wrote:
> > On Sat, May 04, 2024 at 02:27:36PM +0300, Dan Carpenter wrote:
> > > The fxr->file1_offset and fxr->file2_offset variables come from the user
> > > in xfs_ioc_exchange_range(). They are size loff_t which is an s64.
> > > Check the they aren't negative.
> > >
> > > Fixes: 9a64d9b3109d ("xfs: introduce new file range exchange ioctl")
> >
> > In this commit file1_offset and file2_offset are u64. They used to
> > be u64 in the initial submission, but we changed that as part of the
> > review process.
>
> I've just checked again, and I think it was loff_t in that commit.
> There are two related structs, the one that's userspace API and the
> one that's internal. The userspace API is u64 but internally it's
> loff_t.
Ah, yes. The in-kernel ones probably just needs to move to use u64
as well.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] xfs: check for negatives in xfs_exchange_range_checks()
2024-05-04 11:27 [PATCH] xfs: check for negatives in xfs_exchange_range_checks() Dan Carpenter
2024-05-04 16:46 ` Markus Elfring
2024-05-07 6:06 ` Christoph Hellwig
@ 2024-05-07 23:33 ` Darrick J. Wong
2024-05-08 1:29 ` Dave Chinner
3 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2024-05-07 23:33 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Chandan Babu R, linux-xfs, linux-kernel, kernel-janitors
On Sat, May 04, 2024 at 02:27:36PM +0300, Dan Carpenter wrote:
> The fxr->file1_offset and fxr->file2_offset variables come from the user
> in xfs_ioc_exchange_range(). They are size loff_t which is an s64.
> Check the they aren't negative.
>
> Fixes: 9a64d9b3109d ("xfs: introduce new file range exchange ioctl")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> From static analysis. Untested. Sorry!
Not a fan of this ^^^^^^^^
>
> fs/xfs/xfs_exchrange.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fs/xfs/xfs_exchrange.c b/fs/xfs/xfs_exchrange.c
> index c8a655c92c92..3465e152d928 100644
> --- a/fs/xfs/xfs_exchrange.c
> +++ b/fs/xfs/xfs_exchrange.c
> @@ -337,6 +337,9 @@ xfs_exchange_range_checks(
> if (IS_SWAPFILE(inode1) || IS_SWAPFILE(inode2))
> return -ETXTBSY;
>
> + if (fxr->file1_offset < 0 || fxr->file2_offset < 0)
> + return -EINVAL;
but this looks right to me.
If you actually test your changes, then
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
--D
> +
> size1 = i_size_read(inode1);
> size2 = i_size_read(inode2);
>
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] xfs: check for negatives in xfs_exchange_range_checks()
2024-05-07 6:40 ` Christoph Hellwig
@ 2024-05-07 23:36 ` Darrick J. Wong
0 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2024-05-07 23:36 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Dan Carpenter, Chandan Babu R, linux-xfs, linux-kernel, kernel-janitors
On Mon, May 06, 2024 at 11:40:25PM -0700, Christoph Hellwig wrote:
> On Tue, May 07, 2024 at 09:33:40AM +0300, Dan Carpenter wrote:
> > On Mon, May 06, 2024 at 11:06:17PM -0700, Christoph Hellwig wrote:
> > > On Sat, May 04, 2024 at 02:27:36PM +0300, Dan Carpenter wrote:
> > > > The fxr->file1_offset and fxr->file2_offset variables come from the user
> > > > in xfs_ioc_exchange_range(). They are size loff_t which is an s64.
> > > > Check the they aren't negative.
> > > >
> > > > Fixes: 9a64d9b3109d ("xfs: introduce new file range exchange ioctl")
> > >
> > > In this commit file1_offset and file2_offset are u64. They used to
> > > be u64 in the initial submission, but we changed that as part of the
> > > review process.
> >
> > I've just checked again, and I think it was loff_t in that commit.
> > There are two related structs, the one that's userspace API and the
> > one that's internal. The userspace API is u64 but internally it's
> > loff_t.
>
> Ah, yes. The in-kernel ones probably just needs to move to use u64
> as well.
I don't think we want userspace to be able to exchangerange data at file
positions that they can't read or write with a standard fs syscall.
--D
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] xfs: check for negatives in xfs_exchange_range_checks()
2024-05-04 11:27 [PATCH] xfs: check for negatives in xfs_exchange_range_checks() Dan Carpenter
` (2 preceding siblings ...)
2024-05-07 23:33 ` Darrick J. Wong
@ 2024-05-08 1:29 ` Dave Chinner
2024-05-08 2:26 ` Darrick J. Wong
2024-05-08 9:20 ` Dan Carpenter
3 siblings, 2 replies; 10+ messages in thread
From: Dave Chinner @ 2024-05-08 1:29 UTC (permalink / raw)
To: Dan Carpenter
Cc: Darrick J. Wong, Chandan Babu R, linux-xfs, linux-kernel,
kernel-janitors
On Sat, May 04, 2024 at 02:27:36PM +0300, Dan Carpenter wrote:
> The fxr->file1_offset and fxr->file2_offset variables come from the user
> in xfs_ioc_exchange_range(). They are size loff_t which is an s64.
> Check the they aren't negative.
>
> Fixes: 9a64d9b3109d ("xfs: introduce new file range exchange ioctl")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> From static analysis. Untested. Sorry!
>
> fs/xfs/xfs_exchrange.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fs/xfs/xfs_exchrange.c b/fs/xfs/xfs_exchrange.c
> index c8a655c92c92..3465e152d928 100644
> --- a/fs/xfs/xfs_exchrange.c
> +++ b/fs/xfs/xfs_exchrange.c
> @@ -337,6 +337,9 @@ xfs_exchange_range_checks(
> if (IS_SWAPFILE(inode1) || IS_SWAPFILE(inode2))
> return -ETXTBSY;
>
> + if (fxr->file1_offset < 0 || fxr->file2_offset < 0)
> + return -EINVAL;
Aren't the operational offset/lengths already checked for underflow
and overflow via xfs_exchange_range_verify_area()?
-Dave.
--
Dave Chinner
david@fromorbit.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] xfs: check for negatives in xfs_exchange_range_checks()
2024-05-08 1:29 ` Dave Chinner
@ 2024-05-08 2:26 ` Darrick J. Wong
2024-05-08 9:20 ` Dan Carpenter
1 sibling, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2024-05-08 2:26 UTC (permalink / raw)
To: Dave Chinner
Cc: Dan Carpenter, Chandan Babu R, linux-xfs, linux-kernel, kernel-janitors
On Wed, May 08, 2024 at 11:29:15AM +1000, Dave Chinner wrote:
> On Sat, May 04, 2024 at 02:27:36PM +0300, Dan Carpenter wrote:
> > The fxr->file1_offset and fxr->file2_offset variables come from the user
> > in xfs_ioc_exchange_range(). They are size loff_t which is an s64.
> > Check the they aren't negative.
> >
> > Fixes: 9a64d9b3109d ("xfs: introduce new file range exchange ioctl")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > ---
> > From static analysis. Untested. Sorry!
> >
> > fs/xfs/xfs_exchrange.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/fs/xfs/xfs_exchrange.c b/fs/xfs/xfs_exchrange.c
> > index c8a655c92c92..3465e152d928 100644
> > --- a/fs/xfs/xfs_exchrange.c
> > +++ b/fs/xfs/xfs_exchrange.c
> > @@ -337,6 +337,9 @@ xfs_exchange_range_checks(
> > if (IS_SWAPFILE(inode1) || IS_SWAPFILE(inode2))
> > return -ETXTBSY;
> >
> > + if (fxr->file1_offset < 0 || fxr->file2_offset < 0)
> > + return -EINVAL;
>
> Aren't the operational offset/lengths already checked for underflow
> and overflow via xfs_exchange_range_verify_area()?
Oh, yeah, they are. I was just thinking surely I wrote some tests to
pass in garbage offsets and bounce back out...
--D
> -Dave.
> --
> Dave Chinner
> david@fromorbit.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] xfs: check for negatives in xfs_exchange_range_checks()
2024-05-08 1:29 ` Dave Chinner
2024-05-08 2:26 ` Darrick J. Wong
@ 2024-05-08 9:20 ` Dan Carpenter
1 sibling, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2024-05-08 9:20 UTC (permalink / raw)
To: Dave Chinner
Cc: Darrick J. Wong, Chandan Babu R, linux-xfs, linux-kernel,
kernel-janitors
On Wed, May 08, 2024 at 11:29:15AM +1000, Dave Chinner wrote:
> On Sat, May 04, 2024 at 02:27:36PM +0300, Dan Carpenter wrote:
> > The fxr->file1_offset and fxr->file2_offset variables come from the user
> > in xfs_ioc_exchange_range(). They are size loff_t which is an s64.
> > Check the they aren't negative.
> >
> > Fixes: 9a64d9b3109d ("xfs: introduce new file range exchange ioctl")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > ---
> > From static analysis. Untested. Sorry!
> >
> > fs/xfs/xfs_exchrange.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/fs/xfs/xfs_exchrange.c b/fs/xfs/xfs_exchrange.c
> > index c8a655c92c92..3465e152d928 100644
> > --- a/fs/xfs/xfs_exchrange.c
> > +++ b/fs/xfs/xfs_exchrange.c
> > @@ -337,6 +337,9 @@ xfs_exchange_range_checks(
> > if (IS_SWAPFILE(inode1) || IS_SWAPFILE(inode2))
> > return -ETXTBSY;
> >
> > + if (fxr->file1_offset < 0 || fxr->file2_offset < 0)
> > + return -EINVAL;
>
> Aren't the operational offset/lengths already checked for underflow
> and overflow via xfs_exchange_range_verify_area()?
Ah right. Smatch complains in the middle of the two calls to
xfs_exchange_range_verify_area(). (It get's called in different places
depending on if the XFS_EXCHANGE_RANGE_TO_EOF flag is set).
regards,
dan carpenter
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-05-08 9:20 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-04 11:27 [PATCH] xfs: check for negatives in xfs_exchange_range_checks() Dan Carpenter
2024-05-04 16:46 ` Markus Elfring
2024-05-07 6:06 ` Christoph Hellwig
2024-05-07 6:33 ` Dan Carpenter
2024-05-07 6:40 ` Christoph Hellwig
2024-05-07 23:36 ` Darrick J. Wong
2024-05-07 23:33 ` Darrick J. Wong
2024-05-08 1:29 ` Dave Chinner
2024-05-08 2:26 ` Darrick J. Wong
2024-05-08 9:20 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).