Received: by 10.213.65.68 with SMTP id h4csp836485imn; Tue, 27 Mar 2018 09:40:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx48y7ydqHPoWXDyfS4aQR9Jjvu8R+aXweGzlonoPSyRtkxYGVmavZxp39gW0Aq/n/fW2RfU5 X-Received: by 10.99.103.197 with SMTP id b188mr51815pgc.108.1522168833953; Tue, 27 Mar 2018 09:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522168833; cv=none; d=google.com; s=arc-20160816; b=nuaSSCXDGg4TlOTWEzoRFV7TUSU7KJdBwwh9yHvoGxe/32fKrOWrFlzSyRT0/bSwsR ihuipNYZUxlMfXWdPqz1r0khWq2WRaXuNuU9BSOwTXpfbQesx/TGe3HzCMuP913Bgijm 0z2XlVCIVpV4T8LIek8Zscw3HHZ8Qs71rp8qORXesdQStQxzec/IxLwE9xp20B+AKkUT 1p6UlND7EmmZsrj/VtVKZOHsa1aWO/cExu+F0BTH8Yw8bAjCtWMo+c8UTvp93tNmB43C 5Z0dOT45aQ3oHyDLSflx4ZXfvTP/HvN+Ap+PQ4oLogFwup45GLj/bYz0BRgnEKjqduRh Ho6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=5Lo36IER1d9Q4qIV1YkojUCwRRfSaVDz91xLDGw/+2U=; b=iMgcOpABj7dU7+eZgWZG/2tnkZr6EEdU9yNy4nQFSsJPSx6/tng2BQriYZsBSpt1AU YIdx+WYkczvpGHljPsdcdwuAjxVKgzEg6IXQAUUdqckphwcwh/PqvtDZu6zloo9wLsbp 6Yn9jBpzjj96Yb6sMQD9ClbBzUrWMl5bhKSbIiuVuaLtz61gCqCvXwmjDalLzQJa837F X2rWTt3O6gR/1EPo+qYqrpUH4TXIZbWQTFKfMfZZvhwkF0Av9tXWr4rtXdHYv2uVi01x quFG/MA6vGTHJMNAGz0Gmr+P/dEXkqewiNJ1wYh8dtSGKC6lbf03bFtWS/B7Sz67hD7H RRqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k2-v6si1661653plt.413.2018.03.27.09.40.19; Tue, 27 Mar 2018 09:40:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755308AbeC0Qiv (ORCPT + 99 others); Tue, 27 Mar 2018 12:38:51 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46924 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755249AbeC0Qis (ORCPT ); Tue, 27 Mar 2018 12:38:48 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D0C221034; Tue, 27 Mar 2018 16:38:47 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai Subject: [PATCH 4.15 011/105] ALSA: aloop: Fix access to not-yet-ready substream via cable Date: Tue, 27 Mar 2018 18:26:51 +0200 Message-Id: <20180327162758.316467864@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162757.813009222@linuxfoundation.org> References: <20180327162757.813009222@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai commit 8e6b1a72a75bb5067ccb6b56d8ca4aa3a300a64e upstream. In loopback_open() and loopback_close(), we assign and release the substream object to the corresponding cable in a racy way. It's neither locked nor done in the right position. The open callback assigns the substream before its preparation finishes, hence the other side of the cable may pick it up, which may lead to the invalid memory access. This patch addresses these: move the assignment to the end of the open callback, and wrap with cable->lock for avoiding concurrent accesses. Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/drivers/aloop.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/sound/drivers/aloop.c +++ b/sound/drivers/aloop.c @@ -666,7 +666,9 @@ static void free_cable(struct snd_pcm_su return; if (cable->streams[!substream->stream]) { /* other stream is still alive */ + spin_lock_irq(&cable->lock); cable->streams[substream->stream] = NULL; + spin_unlock_irq(&cable->lock); } else { /* free the cable */ loopback->cables[substream->number][dev] = NULL; @@ -705,7 +707,6 @@ static int loopback_open(struct snd_pcm_ loopback->cables[substream->number][dev] = cable; } dpcm->cable = cable; - cable->streams[substream->stream] = dpcm; snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); @@ -737,6 +738,11 @@ static int loopback_open(struct snd_pcm_ runtime->hw = loopback_pcm_hardware; else runtime->hw = cable->hw; + + spin_lock_irq(&cable->lock); + cable->streams[substream->stream] = dpcm; + spin_unlock_irq(&cable->lock); + unlock: if (err < 0) { free_cable(substream);