All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kernel-janitors@vger.kernel.org
Subject: [PATCH v2] fs/coda: potential buffer overflow in coda_psdev_write()
Date: Fri, 13 Jul 2018 15:10:17 +0000	[thread overview]
Message-ID: <20180713151017.lxbv4eljvd6olziq@kili.mountain> (raw)

"dcbuf" is a union that is "size" bytes large.  We ensure that "nbytes"
is large enough to hold the smallest member of the union, but the
problem is that we might try to use a larger member.  If "nbytes" is
set to sizeof(struct coda_out_hdr) that would cause a problem in
coda_downcall() when we try to access &out->coda_zapdir.CodaFid;

The union is quite small so we can allocate enough space so everything
fits.  The CODA_ALLOC() macro calls kzalloc() which means the extra
memory is just zeroed and it's fine.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: I forgot to update CODA_FREE() in my first patch.

diff --git a/fs/coda/psdev.c b/fs/coda/psdev.c
index c5234c21b539..7ed698bc5f73 100644
--- a/fs/coda/psdev.c
+++ b/fs/coda/psdev.c
@@ -124,7 +124,7 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf,
 				hdr.opcode, hdr.unique);
 		        nbytes = size;
 		}
-		CODA_ALLOC(dcbuf, union outputArgs *, nbytes);
+		CODA_ALLOC(dcbuf, union outputArgs *, size);
 		if (copy_from_user(dcbuf, buf, nbytes)) {
 			CODA_FREE(dcbuf, nbytes);
 			retval = -EFAULT;
@@ -134,7 +134,7 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf,
 		/* what downcall errors does Venus handle ? */
 		error = coda_downcall(vcp, hdr.opcode, dcbuf);
 
-		CODA_FREE(dcbuf, nbytes);
+		CODA_FREE(dcbuf, size);
 		if (error) {
 			pr_warn("%s: coda_downcall error: %d\n",
 				__func__, error);

         reply	other threads:[~2018-07-13 15:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-12 12:32 [PATCH] fs/coda: potential buffer overflow in coda_psdev_write() Dan Carpenter
2018-07-12 12:32 ` Dan Carpenter
2018-07-12 15:31 ` Jan Harkes
2018-07-12 15:31   ` Jan Harkes
2018-07-12 15:50   ` Dan Carpenter
2018-07-12 15:50     ` Dan Carpenter
2018-07-13 15:10 ` Dan Carpenter [this message]
2018-07-13 16:16   ` [PATCH v2] " Jan Harkes
2018-07-13 19:05     ` Dan Carpenter
2018-07-13 19:05       ` Dan Carpenter
2018-07-13 19:08       ` Jan Harkes
2018-07-13 19:08         ` Jan Harkes
2018-07-14  2:24       ` [PATCH v3] " Jan Harkes
2018-07-14  2:24         ` Jan Harkes

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=20180713151017.lxbv4eljvd6olziq@kili.mountain \
    --to=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    /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.