linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: bsauce <bsauce00@gmail.com>
To: alexander.h.duyck@intel.com
Cc: vbabka@suse.cz, mgorman@suse.de, l.stach@pengutronix.de,
	vdavydov.dev@gmail.com, akpm@linux-foundation.org, alex@ghiti.fr,
	adobriyan@gmail.com, mike.kravetz@oracle.com,
	rientjes@google.com, rppt@linux.vnet.ibm.com, mhocko@suse.com,
	ksspiers@google.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, bsauce <bsauce00@gmail.com>
Subject: [PATCH] fs/seq_file.c: Fix a UAF vulnerability in seq_release()
Date: Wed, 10 Jul 2019 18:26:29 +0800	[thread overview]
Message-ID: <1562754389-29217-1-git-send-email-bsauce00@gmail.com> (raw)

In seq_release(), 'm->buf' points to a chunk. It is freed but not cleared to null right away. It can be reused by seq_read() or srm_env_proc_write().
For example, /arch/alpha/kernel/srm_env.c provide several interfaces to userspace, like 'single_release', 'seq_read' and 'srm_env_proc_write'.
Thus in userspace, one can exploit this UAF vulnerability to escape privilege.
Even if 'm->buf' is cleared by kmem_cache_free(), one can still create several threads to exploit this vulnerability.
And 'm->buf' should be cleared right after being freed.

Signed-off-by: bsauce <bsauce00@gmail.com>
---
 fs/seq_file.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/seq_file.c b/fs/seq_file.c
index abe27ec..de5e266 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -358,6 +358,7 @@ int seq_release(struct inode *inode, struct file *file)
 {
 	struct seq_file *m = file->private_data;
 	kvfree(m->buf);
+	m->buf = NULL;
 	kmem_cache_free(seq_file_cache, m);
 	return 0;
 }
-- 
2.7.4


             reply	other threads:[~2019-07-10 10:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-10 10:26 bsauce [this message]
2019-07-10 10:58 ` Eric Dumazet
2019-07-10 12:25 ` Matthew Wilcox
2019-07-10 15:01 ` Alexander Duyck

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=1562754389-29217-1-git-send-email-bsauce00@gmail.com \
    --to=bsauce00@gmail.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=alexander.h.duyck@intel.com \
    --cc=ksspiers@google.com \
    --cc=l.stach@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mhocko@suse.com \
    --cc=mike.kravetz@oracle.com \
    --cc=rientjes@google.com \
    --cc=rppt@linux.vnet.ibm.com \
    --cc=vbabka@suse.cz \
    --cc=vdavydov.dev@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox