netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Palethorpe <rpalethorpe@suse.com>
To: linux-can@vger.kernel.org
Cc: Richard Palethorpe <rpalethorpe@suse.com>,
	Kees Cook <keescook@chromium.org>,
	netdev@vger.kernel.org, security@kernel.org, wg@grandegger.com,
	mkl@pengutronix.de, davem@davemloft.net
Subject: [PATCH v2] slcan: Don't transmit uninitialized stack data in padding
Date: Wed,  1 Apr 2020 12:06:39 +0200	[thread overview]
Message-ID: <20200401100639.20199-1-rpalethorpe@suse.com> (raw)

struct can_frame contains some padding which is not explicitly zeroed in
slc_bump. This uninitialized data will then be transmitted if the stack
initialization hardening feature is not enabled (CONFIG_INIT_STACK_ALL).

This commit just zeroes the whole struct including the padding.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
Fixes: a1044e36e457 ("can: add slcan driver for serial/USB-serial CAN adapters")
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: linux-can@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: security@kernel.org
Cc: wg@grandegger.com
Cc: mkl@pengutronix.de
Cc: davem@davemloft.net
---

V2: Reviewed by Kees and Fixes tag added.

As mentioned in V1; The following unfinished test can reproduce the bug:
https://github.com/richiejp/ltp/blob/pty-slcan/testcases/kernel/pty/pty04.c


 drivers/net/can/slcan.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c
index a3664281a33f..4dfa459ef5c7 100644
--- a/drivers/net/can/slcan.c
+++ b/drivers/net/can/slcan.c
@@ -148,7 +148,7 @@ static void slc_bump(struct slcan *sl)
 	u32 tmpid;
 	char *cmd = sl->rbuff;
 
-	cf.can_id = 0;
+	memset(&cf, 0, sizeof(cf));
 
 	switch (*cmd) {
 	case 'r':
@@ -187,8 +187,6 @@ static void slc_bump(struct slcan *sl)
 	else
 		return;
 
-	*(u64 *) (&cf.data) = 0; /* clear payload */
-
 	/* RTR frames may have a dlc > 0 but they never have any data bytes */
 	if (!(cf.can_id & CAN_RTR_FLAG)) {
 		for (i = 0; i < cf.can_dlc; i++) {
-- 
2.24.0


             reply	other threads:[~2020-04-01 10:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-01 10:06 Richard Palethorpe [this message]
2020-04-01 10:08 ` [PATCH v2] slcan: Don't transmit uninitialized stack data in padding Marc Kleine-Budde
2020-04-01 18:23 ` David Miller
2020-04-01 19:41 ` Oliver Hartkopp

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=20200401100639.20199-1-rpalethorpe@suse.com \
    --to=rpalethorpe@suse.com \
    --cc=davem@davemloft.net \
    --cc=keescook@chromium.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=security@kernel.org \
    --cc=wg@grandegger.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;
as well as URLs for NNTP newsgroup(s).