From nobody Sun May 24 20:33:33 2026 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F03BD18BBAE for ; Sat, 23 May 2026 01:18:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779499090; cv=none; b=O/mLDtoRoYjGa4VEBOyQZcqm5Rw24M3U9R4jjQpwSbyr9FqM93+bOMS0UvAPBV/9U5YgWJFIIxiFweW+M6zbaGU4Fr0KK/+6H/GjooEoyH8hcz7hA3qgt6DtnMxAcXBSWH3OFFznwXrMpLzjYAWbIu6sa1fMZLkn1yXzh1EE/9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779499090; c=relaxed/simple; bh=EE1tcyn1jHAVW4AZjBS03dCHEHJ6qNChOXmFcU9svNI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=CdKbSuYAX0i+Zav9sug1vjnB0dJAbrLGfFX6P/oS1AQiAuJSVxQHf1QVETp9iE+j0vOPpR+OuiMuBys2Yl1L57wxOeVo+PiEmVYn1cPCAJyyXMWj9FLL4p3prJ3v6WVhdSXP5+dJeHBEmFFPHuopHR+VbCs3TW2PzHQPht6I80U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RTLozvtq; arc=none smtp.client-ip=209.85.215.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RTLozvtq" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-c6dd5b01e14so3698237a12.0 for ; Fri, 22 May 2026 18:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779499088; x=1780103888; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=czoVXPIPzuLk/t99nJVJxuYO5649Md10TI8uUG61Ujo=; b=RTLozvtqAU/umcF9Bh5ENqOZMh5IiAXx2RG7i/mZq0qnLSdMWLIVE3ODHBWosAu4m0 eBLIJGA5ITR2tZ++tNIMc8pb+V0oakGx4uIx4sgN+Ncni9PYXZJfstTtqAcJ38c8W17b gHiLIj1I0i68UkWnygJZuGWw6WyX9rxMNirD6BYNeOZDX4Fk/VDsVr5RGeEAqTdR2EbS mR3oeWkxKIpxkxMlcBBZ8TzAtytmMPFYQ/csqOEuh5R+63IOZNtIfMqu0Q9vjLBstpCq TALYC8uz6pgCKY+t0Udqa13HU2XuG1KuvE71uMQ7xK5U39EOO1kdoqjScyVY0wqTcx7j GOtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779499088; x=1780103888; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=czoVXPIPzuLk/t99nJVJxuYO5649Md10TI8uUG61Ujo=; b=ZMhIWh2noHKM0no1Si6gFkeR1XUw7nMq8rShiNixvQd284ozJtZRpK+nSh66STC9Kr UByPWm+gn+nYlXMxlJnb5IfdaF4r9ielCp0BNX4cnuTcVqM6CUmGF+ky/yzLcWYKWme1 oEF7v9MRENkpMybZ31gr6Y9i4jxuPSmVMK38Hc7XYVVjPUY5ST7ynZdcBXgPyePQqyw0 IbXlk0VmjjJPJ+HaJSb5r3ZoNbhUTL9slHl018hU1djYUP7d8/aVm6JyQDcz0SZnQ3lP e6s2C0XbjmFhnBoYEboNpQp20gv0OiBtytVI3H/+84hErPGtuM1j4p/vA518ZJkADjh3 amwA== X-Forwarded-Encrypted: i=1; AFNElJ926/iGXh7Sj5T+dhMzd33tWFWanZMyYBx4Tvt1GVhHhDS4LPpMHhRyAHBLXXn7JqjLt9HYEDj3X7ANo9U=@vger.kernel.org X-Gm-Message-State: AOJu0YwHn3YiLbFC9Y5KWRSNiT+aoiAh4exYN+5KWep+/T/ucpQGGTE7 cvWIsl6Y+xvUzfgl480qZEricoJErHZ2T+z9I5q/X3AWyZd2RPiBmOm9 X-Gm-Gg: Acq92OFLiSkgNjYSi5thmmz0/Y6Ac4aPCz9Tw3w6QwT8ucINu3qC4bEaqR80dLW1xvV kdCUY9up37ICoS25UlkgY8X1v+ljJIm2WFUYCk6DPdzMF8MV06S5q+ojnmAWrTjRGKKB5deJTaK U4NxyYd95bi/Dnru1yIiLvs2JDFdUyJs6sKV2/p0zIGaVo7fk3meUY9o7hl+7MMROJtAeCBuKsO jLS3fCvCx8Ni2Eo21cMO1m25lByV1bZ5BE7dOI+FglcYRqJVF7TLmtLFJFLzcjFIj/rEUVOHZZK z0HLQnpKI4R9oQymN4p1kKZ/eRkQLQlBQMFDJh0T5exdkN13rYaO/fCH3BrzMblTW5F4cAT0Nix ckURHM5FyEp1h11hmj0W0cJvYp9cVz9XqOxA+uRi76ZzieJi6bEgz7T4+dNgnmScgGdFKaDETpU L0DNLrBOa57vX2uDPe11WlahmuduB/t7Byg9pkIT5kZZkn4GlJnoaizCoK59qn+ovK404ixwEVd FXbKsfuX37nATNENlLiX12NLjPnxYyyqMGlSXoeVj889A== X-Received: by 2002:a05:6a21:594:b0:3aa:f9cb:d438 with SMTP id adf61e73a8af0-3b328cbfcaemr5718353637.21.1779499087982; Fri, 22 May 2026 18:18:07 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d:7285:c2ff:fe45:8a32]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84164fb00b6sm3774034b3a.40.2026.05.22.18.18.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 18:18:07 -0700 (PDT) From: Rosen Penev To: linux-sound@vger.kernel.org Cc: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be|_ptr)?\b) Subject: [PATCH] ASoC: aw88395: use struct_size() and __counted_by() for aw_container Date: Fri, 22 May 2026 18:17:49 -0700 Message-ID: <20260523011749.101555-1-rosenp@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The firmware container allocations passed cont->size + sizeof(int) to kzalloc(), which was wrong: the struct contains an int len followed by a u8 data[] flexible array. It ended up being the same as the struct's size is only the int member but still wrong. Use the modern struct_size helper for this. Add __counted_by for extra runtime analysis. Assisted-by: Claude:Opus-4.7 Signed-off-by: Rosen Penev --- sound/soc/codecs/aw88081.c | 12 ++++++++---- sound/soc/codecs/aw88261.c | 11 +++++++---- sound/soc/codecs/aw88395/aw88395.c | 11 +++++++---- sound/soc/codecs/aw88395/aw88395_device.h | 2 +- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/sound/soc/codecs/aw88081.c b/sound/soc/codecs/aw88081.c index a5ba177a48df..d5e886a8f106 100644 --- a/sound/soc/codecs/aw88081.c +++ b/sound/soc/codecs/aw88081.c @@ -1137,6 +1137,7 @@ static int aw88081_dev_init(struct aw88081 *aw88081, = struct aw_container *aw_cfg static int aw88081_request_firmware_file(struct aw88081 *aw88081) { const struct firmware *cont =3D NULL; + struct aw_container *aw_cfg; int ret; =20 aw88081->aw_pa->fw_status =3D AW88081_DEV_FW_FAILED; @@ -1148,13 +1149,16 @@ static int aw88081_request_firmware_file(struct aw8= 8081 *aw88081) dev_dbg(aw88081->aw_pa->dev, "loaded %s - size: %zu\n", AW88081_ACF_FILE, cont ? cont->size : 0); =20 - aw88081->aw_cfg =3D devm_kzalloc(aw88081->aw_pa->dev, cont->size + sizeof= (int), GFP_KERNEL); - if (!aw88081->aw_cfg) { + aw_cfg =3D devm_kzalloc(aw88081->aw_pa->dev, struct_size(aw_cfg, data, co= nt->size), GFP_KERNEL); + if (!aw_cfg) { release_firmware(cont); return -ENOMEM; } - aw88081->aw_cfg->len =3D (int)cont->size; - memcpy(aw88081->aw_cfg->data, cont->data, cont->size); + aw_cfg->len =3D (int)cont->size; + memcpy(aw_cfg->data, cont->data, cont->size); + + aw88081->aw_cfg =3D aw_cfg; + release_firmware(cont); =20 ret =3D aw88395_dev_load_acf_check(aw88081->aw_pa, aw88081->aw_cfg); diff --git a/sound/soc/codecs/aw88261.c b/sound/soc/codecs/aw88261.c index 50521dd2ebb1..02e5cb8fc909 100644 --- a/sound/soc/codecs/aw88261.c +++ b/sound/soc/codecs/aw88261.c @@ -1094,6 +1094,7 @@ static int aw88261_dev_init(struct aw88261 *aw88261, = struct aw_container *aw_cfg static int aw88261_request_firmware_file(struct aw88261 *aw88261) { const struct firmware *cont =3D NULL; + struct aw_container *aw_cfg; const char *fw_name; int ret; =20 @@ -1111,15 +1112,17 @@ static int aw88261_request_firmware_file(struct aw8= 8261 *aw88261) dev_info(aw88261->aw_pa->dev, "loaded %s - size: %zu\n", fw_name, cont ? cont->size : 0); =20 - aw88261->aw_cfg =3D devm_kzalloc(aw88261->aw_pa->dev, cont->size + sizeof= (int), GFP_KERNEL); - if (!aw88261->aw_cfg) { + aw_cfg =3D devm_kzalloc(aw88261->aw_pa->dev, struct_size(aw_cfg, data, co= nt->size), GFP_KERNEL); + if (!aw_cfg) { release_firmware(cont); return -ENOMEM; } - aw88261->aw_cfg->len =3D (int)cont->size; - memcpy(aw88261->aw_cfg->data, cont->data, cont->size); + aw_cfg->len =3D (int)cont->size; + memcpy(aw_cfg->data, cont->data, cont->size); release_firmware(cont); =20 + aw88261->aw_cfg =3D aw_cfg; + ret =3D aw88395_dev_load_acf_check(aw88261->aw_pa, aw88261->aw_cfg); if (ret) { dev_err(aw88261->aw_pa->dev, "load [%s] failed !", fw_name); diff --git a/sound/soc/codecs/aw88395/aw88395.c b/sound/soc/codecs/aw88395/= aw88395.c index 982d54f2f8a3..ee0e8bd8c54c 100644 --- a/sound/soc/codecs/aw88395/aw88395.c +++ b/sound/soc/codecs/aw88395/aw88395.c @@ -462,6 +462,7 @@ static void aw88395_hw_reset(struct aw88395 *aw88395) static int aw88395_request_firmware_file(struct aw88395 *aw88395) { const struct firmware *cont =3D NULL; + struct aw_container *aw_cfg; int ret; =20 aw88395->aw_pa->fw_status =3D AW88395_DEV_FW_FAILED; @@ -475,15 +476,17 @@ static int aw88395_request_firmware_file(struct aw883= 95 *aw88395) dev_info(aw88395->aw_pa->dev, "loaded %s - size: %zu\n", AW88395_ACF_FILE, cont ? cont->size : 0); =20 - aw88395->aw_cfg =3D devm_kzalloc(aw88395->aw_pa->dev, cont->size + sizeof= (int), GFP_KERNEL); - if (!aw88395->aw_cfg) { + aw_cfg =3D devm_kzalloc(aw88395->aw_pa->dev, struct_size(aw_cfg, data, co= nt->size), GFP_KERNEL); + if (!aw_cfg) { release_firmware(cont); return -ENOMEM; } - aw88395->aw_cfg->len =3D (int)cont->size; - memcpy(aw88395->aw_cfg->data, cont->data, cont->size); + aw_cfg->len =3D (int)cont->size; + memcpy(aw_cfg->data, cont->data, cont->size); release_firmware(cont); =20 + aw88395->aw_cfg =3D aw_cfg; + ret =3D aw88395_dev_load_acf_check(aw88395->aw_pa, aw88395->aw_cfg); if (ret < 0) { dev_err(aw88395->aw_pa->dev, "Load [%s] failed ....!", AW88395_ACF_FILE); diff --git a/sound/soc/codecs/aw88395/aw88395_device.h b/sound/soc/codecs/a= w88395/aw88395_device.h index 3626f222899d..7b74eeb84c43 100644 --- a/sound/soc/codecs/aw88395/aw88395_device.h +++ b/sound/soc/codecs/aw88395/aw88395_device.h @@ -152,7 +152,7 @@ struct aw_cali_desc { =20 struct aw_container { int len; - u8 data[]; + u8 data[] __counted_by(len); }; =20 struct aw_device { --=20 2.54.0