* [PATCH v2] slcan: Don't transmit uninitialized stack data in padding
@ 2020-04-01 10:06 Richard Palethorpe
2020-04-01 10:08 ` Marc Kleine-Budde
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Richard Palethorpe @ 2020-04-01 10:06 UTC (permalink / raw)
To: linux-can; +Cc: Richard Palethorpe, Kees Cook, netdev, security, wg, mkl, davem
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] slcan: Don't transmit uninitialized stack data in padding
2020-04-01 10:06 [PATCH v2] slcan: Don't transmit uninitialized stack data in padding Richard Palethorpe
@ 2020-04-01 10:08 ` Marc Kleine-Budde
2020-04-01 18:23 ` David Miller
2020-04-01 19:41 ` Oliver Hartkopp
2 siblings, 0 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2020-04-01 10:08 UTC (permalink / raw)
To: Richard Palethorpe, linux-can; +Cc: Kees Cook, netdev, security, wg, davem
On 4/1/20 12:06 PM, Richard Palethorpe wrote:
> 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
Acked-by: Marc Kleine-Budde <mkl@pengutronix.de>
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] slcan: Don't transmit uninitialized stack data in padding
2020-04-01 10:06 [PATCH v2] slcan: Don't transmit uninitialized stack data in padding Richard Palethorpe
2020-04-01 10:08 ` Marc Kleine-Budde
@ 2020-04-01 18:23 ` David Miller
2020-04-01 19:41 ` Oliver Hartkopp
2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2020-04-01 18:23 UTC (permalink / raw)
To: rpalethorpe; +Cc: linux-can, keescook, netdev, security, wg, mkl
From: Richard Palethorpe <rpalethorpe@suse.com>
Date: Wed, 1 Apr 2020 12:06:39 +0200
> 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>
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] slcan: Don't transmit uninitialized stack data in padding
2020-04-01 10:06 [PATCH v2] slcan: Don't transmit uninitialized stack data in padding Richard Palethorpe
2020-04-01 10:08 ` Marc Kleine-Budde
2020-04-01 18:23 ` David Miller
@ 2020-04-01 19:41 ` Oliver Hartkopp
2 siblings, 0 replies; 4+ messages in thread
From: Oliver Hartkopp @ 2020-04-01 19:41 UTC (permalink / raw)
To: Richard Palethorpe, linux-can; +Cc: Kees Cook, netdev, security, wg, mkl, davem
On 01/04/2020 12.06, Richard Palethorpe wrote:
> 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
Acked-by: Oliver Hartkopp <socketcan@hartkopp.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++) {
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-04-01 19:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-01 10:06 [PATCH v2] slcan: Don't transmit uninitialized stack data in padding Richard Palethorpe
2020-04-01 10:08 ` Marc Kleine-Budde
2020-04-01 18:23 ` David Miller
2020-04-01 19:41 ` Oliver Hartkopp
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).