Re: [PATCH v2] fs: fix unintentional arithmetic wraparound in offset calculation

Kees Cook
2024-05-13T23:29:57Z

On Mon, May 13, 2024 at 10:06:59PM +0000, Justin Stitt wrote:
> On Mon, May 13, 2024 at 01:01:57PM -0700, Kees Cook wrote:
> > On Thu, May 09, 2024 at 11:42:07PM +0000, Justin Stitt wrote:
> > > fs/read_write.c | 18 +++++++++++-------
> > > fs/remap_range.c | 12 ++++++------
> > > 2 files changed, 17 insertions(+), 13 deletions(-)
> > >
> > > diff --git a/fs/read_write.c b/fs/read_write.c
> > > index d4c036e82b6c..d116e6e3eb3d 100644
> > > --- a/fs/read_write.c
> > > +++ b/fs/read_write.c
> > > @@ -88,7 +88,7 @@ generic_file_llseek_size(struct file *file, loff_t offset, int whence,
> > > {
> > > switch (whence) {
> > > case SEEK_END:
> > > - offset += eof;
> > > + offset = min(offset, maxsize - eof) + eof;
> >
> > This seems effectively unchanged compared to v1?
> >
> > https://lore.kernel.org/all/CAFhGd8qbUYXmgiFuLGQ7dWXFUtZacvT82wD4jSS-xNTvtzXKGQ@mail.gmail.com/
> >
>
> Right, please note the timestamps of Jan's review of v1 and when I sent
> v2. Essentially, I sent v2 before Jan's review of v1 and as such v2 does
> not fix the problem pointed out by Jan (the behavior of seek is
> technically different for VERY LARGE offsets).

Oh! Heh. I was tricked by versioning! ;)

--
Kees Cook