linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [v2] ASoC: cros_ec_codec: fix uninitialized memory read
@ 2020-12-04  8:36 Arnd Bergmann
  2020-12-04  8:57 ` Tzung-Bi Shih
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2020-12-04  8:36 UTC (permalink / raw)
  To: Cheng-Yi Chiang, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Benson Leung, Enric Balletbo i Serra,
	Tzung-Bi Shih
  Cc: Arnd Bergmann, Guenter Roeck, Herbert Xu, Ard Biesheuvel,
	Eric Biggers, Yu-Hsuan Hsu, Pierre-Louis Bossart, alsa-devel,
	linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

gcc points out a memory area that is copied to a device
but not initialized:

sound/soc/codecs/cros_ec_codec.c: In function 'i2s_rx_event':
arch/x86/include/asm/string_32.h:83:20: error: '*((void *)&p+4)' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   83 |   *((int *)to + 1) = *((int *)from + 1);

Change the length of the command to only pass down the
part of the structure that has been initialized, as
Tzung-Bi Shih explains that only that member is meant to
be used.

Cc: Tzung-Bi Shih <tzungbi@google.com>
Fixes: 727f1c71c780 ("ASoC: cros_ec_codec: refactor I2S RX")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 sound/soc/codecs/cros_ec_codec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/cros_ec_codec.c b/sound/soc/codecs/cros_ec_codec.c
index 58894bf47514..6ec673573c70 100644
--- a/sound/soc/codecs/cros_ec_codec.c
+++ b/sound/soc/codecs/cros_ec_codec.c
@@ -348,7 +348,7 @@ static int i2s_rx_event(struct snd_soc_dapm_widget *w,
 	}
 
 	return send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_I2S_RX,
-				    (uint8_t *)&p, sizeof(p), NULL, 0);
+				    &p.cmd, sizeof(p.cmd), NULL, 0);
 }
 
 static struct snd_soc_dapm_widget i2s_rx_dapm_widgets[] = {
-- 
2.27.0


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

* Re: [PATCH] [v2] ASoC: cros_ec_codec: fix uninitialized memory read
  2020-12-04  8:36 [PATCH] [v2] ASoC: cros_ec_codec: fix uninitialized memory read Arnd Bergmann
@ 2020-12-04  8:57 ` Tzung-Bi Shih
  2020-12-04  9:11   ` Arnd Bergmann
  0 siblings, 1 reply; 3+ messages in thread
From: Tzung-Bi Shih @ 2020-12-04  8:57 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Cheng-Yi Chiang, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Benson Leung, Enric Balletbo i Serra,
	Arnd Bergmann, Guenter Roeck, Herbert Xu, Ard Biesheuvel,
	Eric Biggers, Yu-Hsuan Hsu, Pierre-Louis Bossart,
	ALSA development, Linux Kernel Mailing List

On Fri, Dec 4, 2020 at 4:36 PM Arnd Bergmann <arnd@kernel.org> wrote:
> diff --git a/sound/soc/codecs/cros_ec_codec.c b/sound/soc/codecs/cros_ec_codec.c
> index 58894bf47514..6ec673573c70 100644
> --- a/sound/soc/codecs/cros_ec_codec.c
> +++ b/sound/soc/codecs/cros_ec_codec.c
> @@ -348,7 +348,7 @@ static int i2s_rx_event(struct snd_soc_dapm_widget *w,
>         }
>
>         return send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_I2S_RX,
> -                                   (uint8_t *)&p, sizeof(p), NULL, 0);
> +                                   &p.cmd, sizeof(p.cmd), NULL, 0);
>  }

I would prefer your v1.

Reasons:
1. The change is not just kernel related.
There is a EC (embedded controller) firmware to collaborate with the
code.  The firmware doesn't know the kernel only copies the first byte
of the packet (at least for now).  See
https://chromium.googlesource.com/chromiumos/platform/ec/+/refs/heads/master/common/audio_codec_i2s_rx.c#120.

2. We don't copy partial packets in a EC host command.
IMHO, it is also not a big deal if copying a few unused bytes in the packet.

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

* Re: [PATCH] [v2] ASoC: cros_ec_codec: fix uninitialized memory read
  2020-12-04  8:57 ` Tzung-Bi Shih
@ 2020-12-04  9:11   ` Arnd Bergmann
  0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2020-12-04  9:11 UTC (permalink / raw)
  To: Tzung-Bi Shih
  Cc: Cheng-Yi Chiang, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Benson Leung, Enric Balletbo i Serra,
	Arnd Bergmann, Guenter Roeck, Herbert Xu, Ard Biesheuvel,
	Eric Biggers, Yu-Hsuan Hsu, Pierre-Louis Bossart,
	ALSA development, Linux Kernel Mailing List

On Fri, Dec 4, 2020 at 9:57 AM Tzung-Bi Shih <tzungbi@google.com> wrote:
>
> On Fri, Dec 4, 2020 at 4:36 PM Arnd Bergmann <arnd@kernel.org> wrote:
> > diff --git a/sound/soc/codecs/cros_ec_codec.c b/sound/soc/codecs/cros_ec_codec.c
> > index 58894bf47514..6ec673573c70 100644
> > --- a/sound/soc/codecs/cros_ec_codec.c
> > +++ b/sound/soc/codecs/cros_ec_codec.c
> > @@ -348,7 +348,7 @@ static int i2s_rx_event(struct snd_soc_dapm_widget *w,
> >         }
> >
> >         return send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_I2S_RX,
> > -                                   (uint8_t *)&p, sizeof(p), NULL, 0);
> > +                                   &p.cmd, sizeof(p.cmd), NULL, 0);
> >  }
>
> I would prefer your v1.
>
> Reasons:
> 1. The change is not just kernel related.
> There is a EC (embedded controller) firmware to collaborate with the
> code.  The firmware doesn't know the kernel only copies the first byte
> of the packet (at least for now).  See
> https://chromium.googlesource.com/chromiumos/platform/ec/+/refs/heads/master/common/audio_codec_i2s_rx.c#120.
>
> 2. We don't copy partial packets in a EC host command.
> IMHO, it is also not a big deal if copying a few unused bytes in the packet.

Ok, so if the EC does access the uninitialized data, then it is indeed
better to initialize it to zero as I first thought.

      Arnd

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

end of thread, other threads:[~2020-12-04  9:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-04  8:36 [PATCH] [v2] ASoC: cros_ec_codec: fix uninitialized memory read Arnd Bergmann
2020-12-04  8:57 ` Tzung-Bi Shih
2020-12-04  9:11   ` Arnd Bergmann

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).