From: Dmitry Vyukov <dvyukov@google.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: "linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Hugh Dickins <hughd@google.com>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
syzkaller <syzkaller@googlegroups.com>,
Kostya Serebryany <kcc@google.com>,
Alexander Potapenko <glider@google.com>,
Sasha Levin <sasha.levin@oracle.com>,
Eric Dumazet <edumazet@google.com>
Subject: Re: fs: use-after-free in link_path_walk
Date: Fri, 5 Feb 2016 14:33:08 +0100 [thread overview]
Message-ID: <CACT4Y+Y4e2gLbJAnNtaid3R_j_vM_e_1e6YuW0gRWPG2zA+w3Q@mail.gmail.com> (raw)
In-Reply-To: <20160122230823.GI17997@ZenIV.linux.org.uk>
On Sat, Jan 23, 2016 at 12:08 AM, Al Viro <viro@zeniv.linux.org.uk> wrote:
> On Fri, Jan 22, 2016 at 11:33:09PM +0100, Dmitry Vyukov wrote:
>> Hello,
>>
>> The following program triggers a use-after-free in link_path_walk:
>> https://gist.githubusercontent.com/dvyukov/fc0da4b914d607ba8129/raw/b761243c44106d74f2173745132c82d179cbdc58/gistfile1.txt
>
> Hmm... Actually, I wonder if that had been triggerable since May. What
> happens is that unlike struct inode itself, shmem info->symlink is
> freed immediately, without an RCU delay. Easy to fix, fortunately...
>
> Could you check if the patch below fixes that for you?
Yes, it fixes the crash for me.
Thanks
> diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h
> index a43f41c..4d4780c 100644
> --- a/include/linux/shmem_fs.h
> +++ b/include/linux/shmem_fs.h
> @@ -15,10 +15,7 @@ struct shmem_inode_info {
> unsigned int seals; /* shmem seals */
> unsigned long flags;
> unsigned long alloced; /* data pages alloced to file */
> - union {
> - unsigned long swapped; /* subtotal assigned to swap */
> - char *symlink; /* unswappable short symlink */
> - };
> + unsigned long swapped; /* subtotal assigned to swap */
> struct shared_policy policy; /* NUMA memory alloc policy */
> struct list_head swaplist; /* chain of maybes on swap */
> struct simple_xattrs xattrs; /* list of xattrs */
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 38c5e72..440e2a7 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -701,8 +701,7 @@ static void shmem_evict_inode(struct inode *inode)
> list_del_init(&info->swaplist);
> mutex_unlock(&shmem_swaplist_mutex);
> }
> - } else
> - kfree(info->symlink);
> + }
>
> simple_xattrs_free(&info->xattrs);
> WARN_ON(inode->i_blocks);
> @@ -2549,13 +2548,12 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s
> info = SHMEM_I(inode);
> inode->i_size = len-1;
> if (len <= SHORT_SYMLINK_LEN) {
> - info->symlink = kmemdup(symname, len, GFP_KERNEL);
> - if (!info->symlink) {
> + inode->i_link = kmemdup(symname, len, GFP_KERNEL);
> + if (!inode->i_link) {
> iput(inode);
> return -ENOMEM;
> }
> inode->i_op = &shmem_short_symlink_operations;
> - inode->i_link = info->symlink;
> } else {
> inode_nohighmem(inode);
> error = shmem_getpage(inode, 0, &page, SGP_WRITE, NULL);
> @@ -3132,6 +3130,7 @@ static struct inode *shmem_alloc_inode(struct super_block *sb)
> static void shmem_destroy_callback(struct rcu_head *head)
> {
> struct inode *inode = container_of(head, struct inode, i_rcu);
> + kfree(inode->i_link);
> kmem_cache_free(shmem_inode_cachep, SHMEM_I(inode));
> }
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
prev parent reply other threads:[~2016-02-05 13:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-22 22:33 Dmitry Vyukov
2016-01-22 23:08 ` Al Viro
2016-02-05 13:33 ` Dmitry Vyukov [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=CACT4Y+Y4e2gLbJAnNtaid3R_j_vM_e_1e6YuW0gRWPG2zA+w3Q@mail.gmail.com \
--to=dvyukov@google.com \
--cc=edumazet@google.com \
--cc=glider@google.com \
--cc=hughd@google.com \
--cc=kcc@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sasha.levin@oracle.com \
--cc=syzkaller@googlegroups.com \
--cc=viro@zeniv.linux.org.uk \
/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