mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fsi:fsi-sbefifo: Fix possible concurrency use-after-free bugs in sbefifo_user_release
@ 2018-12-26 13:56 Jia-Ju Bai
  2019-01-02  9:34 ` David Howells
  2019-01-04  0:47 ` Benjamin Herrenschmidt
  0 siblings, 2 replies; 7+ messages in thread
From: Jia-Ju Bai @ 2018-12-26 13:56 UTC (permalink / raw)
  To: benh, dhowells, joel, eajames, andrew; +Cc: linux-kernel, Jia-Ju Bai

In drivers/fsi/fsi-sbefifo.c, the functions sbefifo_user_release(), 
sbefifo_user_read() and sbefifo_user_write() may be concurrently executed.

sbefifo_user_release()
  sbefifo_release_command()
    vfree(user->pending_cmd);

sbefifo_user_read()
  mutex_lock();
  rc = __sbefifo_submit(sbefifo, user->pending_cmd, ...);

sbefifo_user_write()
  mutex_lock();
  user->pending_cmd = user->cmd_page;
  user->pending_cmd = vmalloc(len);

Thus, possible concurrency use-after-free bugs may occur in
sbefifo_user_release().

To fix these bugs, the calls to mutex_lock() and mutex_unlock() are
added in sbefifo_user_release().


Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/fsi/fsi-sbefifo.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/fsi/fsi-sbefifo.c b/drivers/fsi/fsi-sbefifo.c
index d92f5b87c251..e278a9014b8f 100644
--- a/drivers/fsi/fsi-sbefifo.c
+++ b/drivers/fsi/fsi-sbefifo.c
@@ -900,8 +900,10 @@ static int sbefifo_user_release(struct inode *inode, struct file *file)
 	if (!user)
 		return -EINVAL;
 
+	mutex_lock(&user->file_lock);
 	sbefifo_release_command(user);
 	free_page((unsigned long)user->cmd_page);
+	mutex_unlock(&user->file_lock);
 	kfree(user);
 
 	return 0;
-- 
2.17.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-01-04  3:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-26 13:56 [PATCH] fsi:fsi-sbefifo: Fix possible concurrency use-after-free bugs in sbefifo_user_release Jia-Ju Bai
2019-01-02  9:34 ` David Howells
2019-01-03  3:27   ` Benjamin Herrenschmidt
2019-01-03  4:26     ` Benjamin Herrenschmidt
2019-01-04  0:47 ` Benjamin Herrenschmidt
2019-01-04  2:26   ` Jia-Ju Bai
2019-01-04  3:26     ` Benjamin Herrenschmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®