Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp196394pxu; Fri, 4 Dec 2020 00:34:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNSWiHz52yzihrjAPzXp3avGfMu9Zox2mxOEo8eKVNuy45SkoW6f0PTh3Q+SfNNwvP9diq X-Received: by 2002:a17:906:348b:: with SMTP id g11mr3543346ejb.12.1607070842792; Fri, 04 Dec 2020 00:34:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607070842; cv=none; d=google.com; s=arc-20160816; b=BaGYoMnPOZl0Tb9MFIqwXfN4BznWUV0pwlR5jyXhzQ5ZJKnan/qN6n5SLU7iLV+wtZ 20BMAlx70+81RJKSSepo4cO5Tg/8F9JDnHYpi7bHAOhzWXB5wmT8RKmLbSRR0o+QQA8m wq4FTJ/1soZvnzevs+RLgGwfAlPFacMp51ljV0W2oe1uPhwli1YGkILAT/8BS0SyXH9k XOCrBvAUiG86ic7XXwQX6shnUvrjnGVtClstXGgF72swpyn+ScEI7VkgApXeP0C6vVsi G2FKW5C2CTvEKkvcd6qnoB4B8uoFjGlfmcpC6sXoMuwcCkjQ2oHmt17Hq0ol8Nn+dRI0 NjFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Bv+6OPP5SQoiO47eHKLhOXDvFKnjS7MBcf7iBVbuvts=; b=pkc3P+Y+P2tkye+UKNxJOzGVRAZU7xHOBInaI39oxMiqcSTW+ZTvf17JT4u/jeujSw VvV/huy0NAVEaItG4D28lvRJEjanqIE6GMEtwlZBBmFa+0cF7p2LWBtU2dDHx7QMBA+t PhrlsxJJiQk/S/vfWZSviHlZcm1ITq6UWQ/ZoYbywTQN/k5b2vAFE7HEubtgbz3+tDW0 Qx+AnPHq5Rs9kTF1/gQ7sH563YFo8EezcoEDZZBAjvN1ZWCodfzEpxIc3MT8dHiJTnR7 J5n7SSgxdbQa7Ua64hvsZzco8semwPcPngnCaA35msrFxx6iuOynYBSM4/hVvu3F7bzB 8THw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sMUOuwpM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si835718ejz.308.2020.12.04.00.33.39; Fri, 04 Dec 2020 00:34:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sMUOuwpM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729120AbgLDI3J (ORCPT + 99 others); Fri, 4 Dec 2020 03:29:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:35436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728067AbgLDI3J (ORCPT ); Fri, 4 Dec 2020 03:29:09 -0500 X-Gm-Message-State: AOAM530pPy1UhylqktQmBvlFwA1raLdYzVhHE07EUZgdMYDUS2PPqdDU CFaYahFwDhgdYyK7dbnuOjPtJJboE4u2dNVcsuQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1607070508; bh=BFz3wtlydRdBCLt2TC7R8FQN/cjuYB3BQdmcqZcvaC8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=sMUOuwpM1mjcyB7jBZde6GKfioq7mpVZo5v2qaWgUQtGD59LKTyMibetZjT1GsYuX 4EZLfWSZOn5qjOPyHIEuLcJafyb6qkJs7df/PlKByeJb0je+jekrRBAgLF1YiOU5ox lbccItDj6OuOoJ2qZxVymeUSrf/1tBw1MFeHHFAmBx/RS3ytoXjPtUXoBDsdsY9/HD LsrEAKc38CQ3mQM2lYlDcafO0jmukrpx4dURW9sXQ4xIfPKvNpE9KsmE1sVEqX7MQ/ xEen1CaZcc0793EA789I3/O2/dgt/hN5OQrjdTXjEK6rHzEzP3NsD1P9Ak+0VfdlxB GlpAdWZCQAHLQ== X-Received: by 2002:a9d:6317:: with SMTP id q23mr2769894otk.251.1607070508028; Fri, 04 Dec 2020 00:28:28 -0800 (PST) MIME-Version: 1.0 References: <20201203225458.1477830-1-arnd@kernel.org> In-Reply-To: From: Arnd Bergmann Date: Fri, 4 Dec 2020 09:28:11 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] ASoC: cros_ec_codec: fix uninitialized memory read 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 , ALSA development , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 4, 2020 at 3:56 AM Tzung-Bi Shih wrote: > > On Fri, Dec 4, 2020 at 6:55 AM Arnd Bergmann wrote: > > > > From: Arnd Bergmann > > > > 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); > > > > Initialize all the unused fields to zero. > > > > Fixes: 727f1c71c780 ("ASoC: cros_ec_codec: refactor I2S RX") > > Signed-off-by: Arnd Bergmann > > Acked-by: Tzung-Bi Shih > > In the case in i2s_rx_event(), only the "cmd" member is used. But it > is fine to please the compiler. I wouldn't do it just to please the compiler. I sent this patch since the code clearly copies the uninitialized data here. If only one byte is meant to be copied, then we should change the function call to not pass the entire structure. I'll send a new patch for that. > struct __ec_align4 ec_param_ec_codec_i2s_rx { > uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */ > uint8_t reserved[3]; > > union { > ... > }; > }; > > I am a bit curious about, in other use cases of > ec_param_ec_codec_i2s_rx, why the compiler doesn't complain about > uninitialization of the "reserved" member? The -Wmaybe-uninitialized warning is fundamentally unreliable. In this case, the __constant_memcpy() function accesses the members one at a time, and the warning is for the first 'int' array member that is completely uninitialized, while the 'reserved' part of the structure is still in the first 'int' that is partially initialized. Arnd