From patchwork Fri Sep 15 19:09:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 140635 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1269039vqi; Fri, 15 Sep 2023 12:21:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFM/dR0kQ8D01hRBZbq8lIqOEGdxlRpnwbeuHpp1z3kY9OWDoV3zYsw1t14OwX0aqYR6LYD X-Received: by 2002:a05:6358:3398:b0:134:d78f:67bc with SMTP id i24-20020a056358339800b00134d78f67bcmr2374030rwd.14.1694805676866; Fri, 15 Sep 2023 12:21:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694805676; cv=none; d=google.com; s=arc-20160816; b=PUE96LPkO9ABccn0h6+JbeU2r55a3ARTWS8fCx86KdPIbqz98kyhZKW3/IaSwWup0B BIRz0fz0cQlczxYW5Y61GPUFek988s3vBkr51FwvGTKq50kqu4Xm8ciwnziM1wsjVN/P J1eLd2/hkA8UqYLr4f6x/b5fVozK4APupKfhmQyxqciszI7HW993A3f+NEp3FZ/ebtfy vTnjLNXL4XeX/5fcm0VFbL6X6cIVoGFRFkDw5v21TchoPjnIoIhZYlAa3RYS4IfoaNbH c2Z5guxg4aE67AIyGi7LfT+/7cxLrDSo2TqsOkthaCWeXI4EBvPFy39sjKOPt8dfdPUg 6X/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=3mpTwQ0qDfY1S3hp7cZeYaNJzygwbpisyv4fM5hAHf0=; fh=ggHRXwYsmVRnlJJHySxHbJXzje9llUQuM0pl2FBjKqY=; b=NjfPQnHoZK1Xiaqo5Qqc0XE1MGvNvsIB7qr8tIafXPjm7OgvzyFUhwu56xzcBize5K P8at3HN1gx+vwv+PduF6Set+vfyNO+I+AJ/V8pCEQRDEFSjiDiCIYah3xSagePbTJDKl xt3HDTjzHOgcZlzbUpKQll5AvYcGGudP+KA3iKMzQPtSzKerISdfO0JP1SJ4iW4qelUn rOcU1WaOIQMiGiElYa1GkQAtqFx9gVkf5Ya1jKnfZqHSc2WtDKk9etMWgl5jRRndugGa j8fVWo2VViHM/0dKLZA+K2VLN+Zs9ARjyq1USF4QpQjbLIyCoqb0YMol9+0nFoZQ+EcO 0y+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gYy38NgD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id x15-20020a63170f000000b005774aba519dsi3582099pgl.298.2023.09.15.12.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 12:21:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gYy38NgD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id EA6FA8345672; Fri, 15 Sep 2023 12:09:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236983AbjIOTIu (ORCPT + 30 others); Fri, 15 Sep 2023 15:08:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236990AbjIOTIW (ORCPT ); Fri, 15 Sep 2023 15:08:22 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFE7BB2; Fri, 15 Sep 2023 12:08:17 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E4FFC433C9; Fri, 15 Sep 2023 19:08:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694804897; bh=MyIJinpQ9MRMn81ExQ9ajAd6WI7sU/Hkeyd+BcDwjgM=; h=Date:From:To:Cc:Subject:From; b=gYy38NgDEaxdxsygoAP+2/quW8rTNMyRpJP9ZV8TtK+g5Y5u0QXK1UTwRMjbwk8Gz XANgzlbvILid7tntD8XrkILDhzG8La55yDL8I9VW2nMh0CAvBxKoCC72EJZlWuDfbS R6P/JlkAL+PZbhxiQFlm3lBN/9NXAGye5UD+DJ1n0hdLE/CPGjDxAl6I1wNBmYwraW Knm0vmboBjTLurGoatMl48Nr1+bWEfcPBBUw5Y5D6rLzt+U4fWGs8HzKHBzyvbUhU2 5IlYhZPOSckqWgsP3grA4OJE/G+1aO6xdYnq+rrEzHBEd/6WqK0AU5zPhLHxgr/8TJ RNEs8sBPAwZGg== Date: Fri, 15 Sep 2023 13:09:11 -0600 From: "Gustavo A. R. Silva" To: Pierre-Louis Bossart , Liam Girdwood , Peter Ujfalusi , Bard Liao , Ranjani Sridharan , Daniel Baluta , Kai Vehmanen , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: sound-open-firmware@alsa-project.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] ASoC: SOF: ipc4-topology: Use size_add() in call to struct_size() Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 15 Sep 2023 12:09:31 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777132557589290084 X-GMAIL-MSGID: 1777132557589290084 If, for any reason, the open-coded arithmetic causes a wraparound, the protection that `struct_size()` adds against potential integer overflows is defeated. Fix this by hardening call to `struct_size()` with `size_add()`. Fixes: f9efae954905 ("ASoC: SOF: ipc4-topology: Add support for base config extension") Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- sound/soc/sof/ipc4-topology.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sound/soc/sof/ipc4-topology.c b/sound/soc/sof/ipc4-topology.c index f2a30cd31378..2a19dd022aaf 100644 --- a/sound/soc/sof/ipc4-topology.c +++ b/sound/soc/sof/ipc4-topology.c @@ -895,7 +895,8 @@ static int sof_ipc4_widget_setup_comp_process(struct snd_sof_widget *swidget) if (process->init_config == SOF_IPC4_MODULE_INIT_CONFIG_TYPE_BASE_CFG_WITH_EXT) { struct sof_ipc4_base_module_cfg_ext *base_cfg_ext; u32 ext_size = struct_size(base_cfg_ext, pin_formats, - swidget->num_input_pins + swidget->num_output_pins); + size_add(swidget->num_input_pins, + swidget->num_output_pins)); base_cfg_ext = kzalloc(ext_size, GFP_KERNEL); if (!base_cfg_ext) {