All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Wysochanski <dwysocha@redhat.com>
To: David Howells <dhowells@redhat.com>
Cc: linux-cachefs <linux-cachefs@redhat.com>,
	Jeff Layton <jlayton@kernel.org>,
	Steve French <smfrench@gmail.com>,
	linux-cifs <linux-cifs@vger.kernel.org>
Subject: Re: [PATCH] cachefiles: Fix KASAN slab-out-of-bounds in cachefiles_set_volume_xattr
Date: Tue, 5 Apr 2022 11:54:33 -0400	[thread overview]
Message-ID: <CALF+zOksePcvCzY4kTrkZeEJOxxNkxu2f=PTM_3SSoYtYo_1PA@mail.gmail.com> (raw)
In-Reply-To: <CALF+zOn+JEB7F30wMEcs3Zm=2HFMXS+8vfiQP9HW26OtwXUHGg@mail.gmail.com>

On Tue, Apr 5, 2022 at 10:24 AM David Wysochanski <dwysocha@redhat.com> wrote:
>
> On Tue, Apr 5, 2022 at 10:14 AM David Howells <dhowells@redhat.com> wrote:
> >
> > Dave Wysochanski <dwysocha@redhat.com> wrote:
> >
> > > @@ -203,7 +203,7 @@ bool cachefiles_set_volume_xattr(struct cachefiles_volume *volume)
> > >       if (!buf)
> > >               return false;
> > >       buf->reserved = cpu_to_be32(0);
> > > -     memcpy(buf->data, p, len);
> > > +     memcpy(buf->data, p, volume->vcookie->coherency_len);
> >
> > Good catch.  However, I think it's probably better to change things a bit
> > further up, eg.:
> >
> >         -       len += sizeof(*buf);
> >         -       buf = kmalloc(len, GFP_KERNEL);
> >         +       buf = kmalloc(sizeof(*buf) + len, GFP_KERNEL);
> >
> > David
> >
>
> Agree with the above.  I'll send a v2.  Thanks!

After I looked at this again I realized 'len' is used in
vfs_setxattr() and needs to be the size of the kmalloc'd memory.
So we need another adjustment there or the v1 patch.

    191 bool cachefiles_set_volume_xattr(struct cachefiles_volume *volume)
    192 {
    193         struct cachefiles_vol_xattr *buf;
    194         unsigned int len = volume->vcookie->coherency_len;
    195         const void *p = volume->vcookie->coherency;
    196         struct dentry *dentry = volume->dentry;
    197         int ret;
    198
    199         _enter("%x,#%d", volume->vcookie->debug_id, len);
    200
    201         buf = kmalloc(sizeof(*buf) + len, GFP_KERNEL);
    202         if (!buf)
    203                 return false;
    204         buf->reserved = cpu_to_be32(0);
    205         memcpy(buf->data, p, len);
    206
    207         ret = cachefiles_inject_write_error();
    208         if (ret == 0)
    209                 ret = vfs_setxattr(&init_user_ns, dentry,
cachefiles_xattr_cache,
    210                                    buf, len, 0);


      reply	other threads:[~2022-04-05 23:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-05 13:46 [PATCH] cachefiles: Fix KASAN slab-out-of-bounds in cachefiles_set_volume_xattr Dave Wysochanski
2022-04-05 14:14 ` David Howells
2022-04-05 14:24   ` David Wysochanski
2022-04-05 15:54     ` David Wysochanski [this message]

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='CALF+zOksePcvCzY4kTrkZeEJOxxNkxu2f=PTM_3SSoYtYo_1PA@mail.gmail.com' \
    --to=dwysocha@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=jlayton@kernel.org \
    --cc=linux-cachefs@redhat.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=smfrench@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.