Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3009102pxb; Mon, 18 Oct 2021 06:31:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQDMB+5qpurc8hrEUsIy74PTXPuqy72VDXBsrYlLvEZ3BKxwbIsIq5vciStAcnsbdKfkNn X-Received: by 2002:a17:902:c410:b0:13e:cfac:45ad with SMTP id k16-20020a170902c41000b0013ecfac45admr27796525plk.68.1634563904333; Mon, 18 Oct 2021 06:31:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634563904; cv=none; d=google.com; s=arc-20160816; b=b7EAuHkzra8j9vfpjE+woU9RI/wRrzLbHHnaz8VKppnjTp9+E4Ewyr+ddbbYEOAZDG eel7Q4VbA2V2EklRVu0nXaDNm2C4tjHCYr0+TVvhYWWUKRLnSeeJw/3IF6KAvc10B20B IW8bRiQRaxwKQdoXS8rsxMy7UJ0eXv7Ore030gUu896mnTfYwjh5/rdELBM/1AHDTLtx e2JOJ8lE4m/VrvUn8wGfHX24uFH4VPVNAb8B/6eGzABi5Q6lewsTJe23SjE3pm9Zqaw0 2Nd4cm6LHQH5VmHJDlTsfcmAnUPS8T9IQi3M9Dh/zP6nBl3BIzr8p+LtDtHHtq9PNPUR tSQA== 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=NhzDE/JD6n205tD0Cfzew/TTfBhiUJiw8RMVjGUL3L8=; b=JYed2p3kMllJud1LACt/HbWvK/O4DIy+kSx5ChwDRgRYogYmc+qdyuNHFxN5yIlYB8 ICUbM9ozYW+Sy/fEE5J3eOl8FUUtr8arheL2KcszDL5HeBi7kWlWE5ctcGVq33YAX60+ p3iMWP7AkGy60PnsdZ81mcxZC5BITPKKQwp3GT3MNtLbi93n5sX8BcGsoz8pA8g3wE0E 34GTk/FfZJHyIX5QI02y9vr/7HWjf4nMkAbTygY0o4KRtKjPbI/6L4zGM7d8vrY9cx9y dLbOMVFcvdhPMJe7jud3b9M5NHQR/ueYInEf4H1SSy5pqQpIBIYXi4lAEHBWzYDGhi1w efWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MsBiPbHu; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e129si822930pgc.461.2021.10.18.06.31.31; Mon, 18 Oct 2021 06:31:44 -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=@linuxfoundation.org header.s=korg header.b=MsBiPbHu; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231961AbhJRNb1 (ORCPT + 99 others); Mon, 18 Oct 2021 09:31:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:42612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232191AbhJRN3i (ORCPT ); Mon, 18 Oct 2021 09:29:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CC52E6135E; Mon, 18 Oct 2021 13:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634563647; bh=XUV2F7QPq6I0CrJayOW5sCUAAwA4qldj1kvMCO92C68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MsBiPbHuEI/BT3cDsJAzWDGkA9CcVs7y+vopf0FHgkVW9Jsc3jRmK0aTF4nhWPrzd V1rqnI3NNmXQ/o1sgdwRRkpkvlm8UG2N1Wgnvw7D0mVz9/fdauiXSdM+QBZClUhMMe grj+uSGmyGEU6IkfZaDiN4VoV0jDfzph9E2m5KRo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , John Keeping Subject: [PATCH 4.19 01/50] ALSA: seq: Fix a potential UAF by wrong private_free call order Date: Mon, 18 Oct 2021 15:24:08 +0200 Message-Id: <20211018132326.576347595@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132326.529486647@linuxfoundation.org> References: <20211018132326.529486647@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai commit 1f8763c59c4ec6254d629fe77c0a52220bd907aa upstream. John Keeping reported and posted a patch for a potential UAF in rawmidi sequencer destruction: the snd_rawmidi_dev_seq_free() may be called after the associated rawmidi object got already freed. After a deeper look, it turned out that the bug is rather the incorrect private_free call order for a snd_seq_device. The snd_seq_device private_free gets called at the release callback of the sequencer device object, while this was rather expected to be executed at the snd_device call chains that runs at the beginning of the whole card-free procedure. It's been broken since the rewrite of sequencer-device binding (although it hasn't surfaced because the sequencer device release happens usually right along with the card device release). This patch corrects the private_free call to be done in the right place, at snd_seq_device_dev_free(). Fixes: 7c37ae5c625a ("ALSA: seq: Rewrite sequencer device binding with standard bus") Reported-and-tested-by: John Keeping Cc: Link: https://lore.kernel.org/r/20210930114114.8645-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/seq_device.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) --- a/sound/core/seq_device.c +++ b/sound/core/seq_device.c @@ -162,6 +162,8 @@ static int snd_seq_device_dev_free(struc struct snd_seq_device *dev = device->device_data; cancel_autoload_drivers(); + if (dev->private_free) + dev->private_free(dev); put_device(&dev->dev); return 0; } @@ -189,11 +191,7 @@ static int snd_seq_device_dev_disconnect static void snd_seq_dev_release(struct device *dev) { - struct snd_seq_device *sdev = to_seq_dev(dev); - - if (sdev->private_free) - sdev->private_free(sdev); - kfree(sdev); + kfree(to_seq_dev(dev)); } /*