From: Luis Henriques <luis.henriques@linux.dev>
To: Alex Markuze <amarkuze@redhat.com>
Cc: Goldwyn Rodrigues <rgoldwyn@suse.de>,
Xiubo Li <xiubli@redhat.com>, Ilya Dryomov <idryomov@gmail.com>,
ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v2] ceph: ceph: fix out-of-bound array access when doing a file read
Date: Thu, 28 Nov 2024 18:52:45 +0000 [thread overview]
Message-ID: <87zflj6via.fsf@orpheu.olymp> (raw)
In-Reply-To: <CAO8a2SjHq0hi22QdmaTH2E_c1vP2qHvy7JWE3E1+y3VhEWbDaw@mail.gmail.com> (Alex Markuze's message of "Thu, 28 Nov 2024 20:19:31 +0200")
Hi!
On Thu, Nov 28 2024, Alex Markuze wrote:
> On Thu, Nov 28, 2024 at 7:43 PM Luis Henriques <luis.henriques@linux.dev> wrote:
>>
>> Hi Alex,
>>
>> [ Thank you for looking into this. ]
>>
>> On Wed, Nov 27 2024, Alex Markuze wrote:
>>
>> > Hi, Folks.
>> > AFAIK there is no side effect that can affect MDS with this fix.
>> > This crash happens following this patch
>> > "1065da21e5df9d843d2c5165d5d576be000142a6" "ceph: stop copying to iter
>> > at EOF on sync reads".
>> >
>> > Per your fix Luis, it seems to address only the cases when i_size goes
>> > to zero but can happen anytime the `i_size` goes below `off`.
>> > I propose fixing it this way:
>>
>> Hmm... you're probably right. I didn't see this happening, but I guess it
>> could indeed happen.
>>
>> > diff --git a/fs/ceph/file.c b/fs/ceph/file.c
>> > index 4b8d59ebda00..19b084212fee 100644
>> > --- a/fs/ceph/file.c
>> > +++ b/fs/ceph/file.c
>> > @@ -1066,7 +1066,7 @@ ssize_t __ceph_sync_read(struct inode *inode,
>> > loff_t *ki_pos,
>> > if (ceph_inode_is_shutdown(inode))
>> > return -EIO;
>> >
>> > - if (!len)
>> > + if (!len || !i_size)
>> > return 0;
>> > /*
>> > * flush any page cache pages in this range. this
>> > @@ -1200,12 +1200,11 @@ ssize_t __ceph_sync_read(struct inode *inode,
>> > loff_t *ki_pos,
>> > }
>> >
>> > idx = 0;
>> > - if (ret <= 0)
>> > - left = 0;
>>
>> Right now I don't have any means for testing this patch. However, I don't
>> think this is completely correct. By removing the above condition you're
>> discarding cases where an error has occurred (i.e. where ret is negative).
>
> I didn't discard it though :).
> I folded it into the `if` statement. I find the if else construct
> overly verbose and cumbersome.
>
> + left = (ret > 0) ? ret : 0;
>
Right, but with your patch, if 'ret < 0', we could still hit the first
branch instead of that one:
if (off + ret > i_size)
left = (i_size > off) ? i_size - off : 0;
else
left = (ret > 0) ? ret : 0;
Cheers,
--
Luís
next prev parent reply other threads:[~2024-11-28 18:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-05 13:57 [RFC PATCH v2] ceph: ceph: fix out-of-bound array access when doing a file read Luis Henriques (SUSE)
2024-09-06 11:17 ` Xiubo Li
2024-09-06 11:30 ` Luis Henriques
2024-09-06 12:48 ` Xiubo Li
2024-09-30 15:30 ` Luis Henriques
2024-11-04 14:34 ` Luis Henriques
2024-11-05 1:10 ` Xiubo Li
2024-11-05 9:21 ` Luis Henriques
2024-11-06 20:40 ` Goldwyn Rodrigues
2024-11-07 11:09 ` Luis Henriques
2024-11-27 13:47 ` Alex Markuze
2024-11-28 17:42 ` Luis Henriques
2024-11-28 18:19 ` Alex Markuze
2024-11-28 18:52 ` Luis Henriques [this message]
2024-11-28 19:09 ` Alex Markuze
2024-11-28 19:31 ` Alex Markuze
2024-12-11 10:36 ` Alex Markuze
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zflj6via.fsf@orpheu.olymp \
--to=luis.henriques@linux.dev \
--cc=amarkuze@redhat.com \
--cc=ceph-devel@vger.kernel.org \
--cc=idryomov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rgoldwyn@suse.de \
--cc=xiubli@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox