Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp853596pxk; Thu, 17 Sep 2020 19:08:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUzLPOSka9wASa73dBYpcAszJSXSahUMaSqfa/lCxnSyMisgVhCkg1nP96QWGa/4e7GVWi X-Received: by 2002:a50:dec9:: with SMTP id d9mr36332474edl.145.1600394928630; Thu, 17 Sep 2020 19:08:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600394928; cv=none; d=google.com; s=arc-20160816; b=BFO3Fg/TmW5SodI/K+V/dBOg/bHH4llPpHdgv8XssXrU9Kqcbr0l8c0iLPMYDq+Ijz TEWd8AC//uXenc+o0pRGAe8kgpr8QkJLlMPZj+WW2k2aANXxUux02JgMjkg1lllJglag lcfkeH3d+2PzrW2yRkulCP+uLuX98g7C/MKfEt1FqB9w+klfjpM9zoDjzfiAor3zyQcA Spk5yXAIjUikIa8PiJ94gvLtkMf06g4qzxQbqBbFuIZwSAsy5O7bUViFU7my+gh7fPoe pc4P+81FE2qTVt10xiZns+L+NYDoenMt9YnftHN6GEX7eBJD+jeXs903Hk+n3ajAdWQp a1nQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LPv2kLUCMUVpIuk6ZOIRTu1DPLF/RZ9yNV3VIYNlRC8=; b=ys9HMwDrh8I6CxwJMifE1yvt7H7RnNUl4bQqOMY2a3DO15ES+i4nMY7dUGJTNkmoQ9 gCMnEEXWgPFHi1M3xzZELsh4q6Fhnm3lhtsopw4TivKtKgWQwdeVYjXcxzLyqNgKTPWm zQpAerApTT1ILMLBY0sw50zLo5r7uNCb8+Bd6HCqWC9AvSJDqGyW1kPt8nAzAJv9pwJa whEf73rWnU1OiBOmAo906MfG7UZAKE4yfFW5IekBDoC4hqnq8NxdhB1okj7eAlbC39A5 bQdQEeTeXs+rO2jDFRzQiJYwfk/2YWC/KOCB5i617ovjhhJpk5ax+ABge3kYbwK5PLZG LNNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uK8PWcIn; 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 pv21si1286143ejb.44.2020.09.17.19.08.25; Thu, 17 Sep 2020 19:08:48 -0700 (PDT) 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=default header.b=uK8PWcIn; 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 S1727299AbgIRCEX (ORCPT + 99 others); Thu, 17 Sep 2020 22:04:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:51525 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727267AbgIRCET (ORCPT ); Thu, 17 Sep 2020 22:04:19 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D3E1723600; Fri, 18 Sep 2020 02:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394652; bh=K8YFbiPi9jArRe8RYEmaRUiNBfLLK+iMBy+K9lLk7ok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uK8PWcInO1WMeNq4wtmczq5BxJY/IVrRnyjZz+qD6f5qJYQL2EY/erK6eU+GpFmHL oF5TurkOxi8Lu1Zoritgc995r0Tzxw1tOSQEyKMfgvi0Ajr0CHLhX7wozWA8ZPM1E5 tm4RyvKhKgDPbqGIHoGoCt8B3PkYvt/d9+lIZSoc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jaska Uimonen , Pierre-Louis Bossart , Mark Brown , Sasha Levin , alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 5.4 149/330] ASoC: SOF: ipc: check ipc return value before data copy Date: Thu, 17 Sep 2020 21:58:09 -0400 Message-Id: <20200918020110.2063155-149-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jaska Uimonen [ Upstream commit 1919b42ca4ad75a2397081164661af3ce5a7b8f4 ] In tx_wait_done the ipc payload is copied before the DSP transaction error code is checked. This might lead to corrupted data in kernel side even though the error would be handled later. It is also pointless to copy the data in case of error. So change the order of error check and copy. Signed-off-by: Pierre-Louis Bossart Signed-off-by: Jaska Uimonen Link: https://lore.kernel.org/r/20200228231850.9226-3-pierre-louis.bossart@linux.intel.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/sof/ipc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sound/soc/sof/ipc.c b/sound/soc/sof/ipc.c index e7b1a80e2a14c..f38f651da2246 100644 --- a/sound/soc/sof/ipc.c +++ b/sound/soc/sof/ipc.c @@ -215,15 +215,17 @@ static int tx_wait_done(struct snd_sof_ipc *ipc, struct snd_sof_ipc_msg *msg, snd_sof_trace_notify_for_error(ipc->sdev); ret = -ETIMEDOUT; } else { - /* copy the data returned from DSP */ ret = msg->reply_error; - if (msg->reply_size) - memcpy(reply_data, msg->reply_data, msg->reply_size); - if (ret < 0) + if (ret < 0) { dev_err(sdev->dev, "error: ipc error for 0x%x size %zu\n", hdr->cmd, msg->reply_size); - else + } else { ipc_log_header(sdev->dev, "ipc tx succeeded", hdr->cmd); + if (msg->reply_size) + /* copy the data returned from DSP */ + memcpy(reply_data, msg->reply_data, + msg->reply_size); + } } return ret; -- 2.25.1