Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3241061rwb; Mon, 15 Aug 2022 22:04:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR42KsFaFARz5bpaydQkKJBEu+WlwZUEogNJ/X8IUBWrj6DtFJf15ZDQyWObiJlqk3buuowK X-Received: by 2002:a05:6402:4024:b0:43d:2067:f068 with SMTP id d36-20020a056402402400b0043d2067f068mr17712688eda.258.1660626271015; Mon, 15 Aug 2022 22:04:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660626271; cv=none; d=google.com; s=arc-20160816; b=0JEFfsXaj2KhSCizKtvYOIwLF6iuJouUxGhzfNwwu2IjzGReO43iaUwPnvazwQg79L Ct2q7wNZxWS5FW9PnCPaV+bw9CgKYSdRVv/GKZqqqRzTfAnuRh0WIwGzr8LpNPKSm5SK z6mAna/VQCnG+8ljA6BlMHe2cr6day5AAroub/cznMDCg+K8VDUR0jw9t+J86NfRl7xf H/aG5ra2idgKMhcvyZcq0TuP3IJNWgVwr/v+Zgh7jVTARyUzcfv76JVCHje45yyeo1Xm CtBwQM+4sUheJxJax1oepuuIaVDN5ys8g3Vf6GZa8mOSVM7AOLNBEqDJvCOr+k/pjbDd CKKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=misfArid8HGvXXewiSkqQhKyU4R4arPsIGHYaxcc14g=; b=S6DBO5L/x5QM0/a31MRiPdd8M4LxxxN6yZ3VxurMOv9vpc2lpR80o9U3EzxB2HpTFj WIcmwEWIuAMZIqLvFoQoHTzZHDxUU0SCM0Lq06LAg1G9DTO70lyXshe/FEjgF4H67dbr A/iR36BHHDBFj9bza1rI7jadKr2gxRIH3DqU94Hhq1ZHsCR6A9rSv0vTxQnkpJ/DoFfV xvenbsg/p6nq8X2Ut0JjGgLlDCRRTikmJaGrsO3WJb7TZynKkGvXo2huK6uDDd2yT0dp LGf8PX2lkCNTtVB94IW8bySAXMSWRCbBE0kNSCdZa/n/fo7T2pWql9QsxqhVWjoAMQwr j7Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hC0f5u5P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c1-20020aa7c741000000b0044048190aa4si7671016eds.333.2022.08.15.22.04.03; Mon, 15 Aug 2022 22:04:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hC0f5u5P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232181AbiHPErT (ORCPT + 99 others); Tue, 16 Aug 2022 00:47:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231906AbiHPEoe (ORCPT ); Tue, 16 Aug 2022 00:44:34 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78B5DD475B; Mon, 15 Aug 2022 13:40:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C9E51B8114A; Mon, 15 Aug 2022 20:40:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32E60C433C1; Mon, 15 Aug 2022 20:40:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596043; bh=t5ImEyorQ3i44pNr0mQgsCc6Po4wNQF3sy5vCvr2iNU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hC0f5u5PlGhIiLdMUWk8HbIIaqTdvo95czelstBMbEtqRwUSTsI62AGfNGXRc1Y5H B+HpdTJ/omdJBvgPw8tSTZxO8v7isTrMJdU0B2NfZD9QqVAJ7elTIqpCqPnGItgBVr Q2NrPWBq5E5OXyQI2zxnzHI5mTzGoFjf5SyZVmP4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Mark Brown , Sasha Levin Subject: [PATCH 5.19 0955/1157] ASoC: SOF: ipc-msg-injector: fix copy in sof_msg_inject_ipc4_dfs_write() Date: Mon, 15 Aug 2022 20:05:11 +0200 Message-Id: <20220815180517.825168254@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit fa9b878ff86f4adccddf62492a5894fbdb04f97d ] There are two bugs that have to do with when we copy the payload: size = simple_write_to_buffer(ipc4_msg->data_ptr, priv->max_msg_size, ppos, buffer, count); The value of "*ppos" was supposed to be zero but it is sizeof(ipc4_msg->header_u64) so it will copy the data into the middle of the "ipc4_msg->data_ptr" buffer instead of to the start. The second problem is "buffer" should be "buffer + sizeof(ipc4_msg->header_u64)". This function is used for fuzz testing so the data is normally random and this bug likely does not affect anyone very much. In this context, it's simpler and more appropriate to use copy_from_user() instead of simple_write_to_buffer() so I have re-written the function. Fixes: 066c67624d8c ("ASoC: SOF: ipc-msg-injector: Add support for IPC4 messages") Signed-off-by: Dan Carpenter Link: https://lore.kernel.org/r/Ysg1tB2FKLnRMsel@kili Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/sof/sof-client-ipc-msg-injector.c | 29 +++++++++------------ 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/sound/soc/sof/sof-client-ipc-msg-injector.c b/sound/soc/sof/sof-client-ipc-msg-injector.c index 6bdfa527b7f7..752d5320680f 100644 --- a/sound/soc/sof/sof-client-ipc-msg-injector.c +++ b/sound/soc/sof/sof-client-ipc-msg-injector.c @@ -181,7 +181,7 @@ static ssize_t sof_msg_inject_ipc4_dfs_write(struct file *file, struct sof_client_dev *cdev = file->private_data; struct sof_msg_inject_priv *priv = cdev->data; struct sof_ipc4_msg *ipc4_msg = priv->tx_buffer; - ssize_t size; + size_t data_size; int ret; if (*ppos) @@ -191,25 +191,20 @@ static ssize_t sof_msg_inject_ipc4_dfs_write(struct file *file, return -EINVAL; /* copy the header first */ - size = simple_write_to_buffer(&ipc4_msg->header_u64, - sizeof(ipc4_msg->header_u64), - ppos, buffer, count); - if (size < 0) - return size; - if (size != sizeof(ipc4_msg->header_u64)) + if (copy_from_user(&ipc4_msg->header_u64, buffer, + sizeof(ipc4_msg->header_u64))) return -EFAULT; - count -= size; + data_size = count - sizeof(ipc4_msg->header_u64); + if (data_size > priv->max_msg_size) + return -EINVAL; + /* Copy the payload */ - size = simple_write_to_buffer(ipc4_msg->data_ptr, - priv->max_msg_size, ppos, buffer, - count); - if (size < 0) - return size; - if (size != count) + if (copy_from_user(ipc4_msg->data_ptr, + buffer + sizeof(ipc4_msg->header_u64), data_size)) return -EFAULT; - ipc4_msg->data_size = count; + ipc4_msg->data_size = data_size; /* Initialize the reply storage */ ipc4_msg = priv->rx_buffer; @@ -221,9 +216,9 @@ static ssize_t sof_msg_inject_ipc4_dfs_write(struct file *file, /* return the error code if test failed */ if (ret < 0) - size = ret; + return ret; - return size; + return count; }; static int sof_msg_inject_dfs_release(struct inode *inode, struct file *file) -- 2.35.1