Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp811641imu; Tue, 11 Dec 2018 07:58:41 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xlh3/BQ9GwcYSeJBrD9ndaAUK+SauhyoLRT9dxlCsbiaxMMXDSjdwBsZ7a0vo985rGySDo X-Received: by 2002:a63:5346:: with SMTP id t6mr15394389pgl.40.1544543921879; Tue, 11 Dec 2018 07:58:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544543921; cv=none; d=google.com; s=arc-20160816; b=fE86k9vNJKd0Oyc7G4kV5X1D/3xcpp40s1gZPYaaj0cmfiLE8Bu4TkBNcI8xmGEkrK xgWmFrOjDzX9nzficP/k1yFTjOxn6A3ZaC5l9D9DsqA1JqqThUDuB05kQc5N1uvfxEZ7 QsP411oAnLOt299xkkP8RqN7sYlzyH7uuPi9R+Q1fqp1+hQocw13UqKvCLSAaZIXxF9b rVhHYNmjrWltAeSEMKO8ZIJVXYeezXgIrEb5ZfhS3DfPczsDRoi32VazqnDBYn/iTeDD 6z34D31pY/EBCvPExpIs8F8X77q9rqw7LZU/VA+vFnA/XIkJKLFmETGGDpGEr8rZAlpn u9fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5V8uxdtnaXZNpAlqSjrTJ+kfO0v+0l3X6D43lenY6eA=; b=yZnDmkUcZLD7PDwF8l+ziX2+z+xWEaXUgXaWo/oWDQFfn/T74QxvMpOfcx7PvnwE8n 6lXLy6y7VlzhsmnPdt6Qch1uM5BzJ2Y1QS0h1sFNcaonYEY4sM6GsAMDK/KRha1sHyQ3 T2z+uLG5NTMvCsyfoDYjaButSGcrlAUNv5DUocEgdp9MaL74lRoNpJvCe6d8NuR6ehXn Y5rnSzttVr5oER/IhsuL6Yq8uta0pSq+RosmovdHgQeuvgLLp3aoN4Cgeu0deggVuRId xzGeqckVPa9l+feM0aB1BEaBuWeYjheqaEITqlmQDGT6BDDI5YqoD0Z8Vlzgu+1ajWCU 0Ing== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="j+AX+A/z"; 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 n4si2689676pgv.512.2018.12.11.07.58.03; Tue, 11 Dec 2018 07:58:41 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b="j+AX+A/z"; 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 S1730569AbeLKP4Z (ORCPT + 99 others); Tue, 11 Dec 2018 10:56:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:45144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730561AbeLKP4V (ORCPT ); Tue, 11 Dec 2018 10:56:21 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8139A2086D; Tue, 11 Dec 2018 15:56:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543781; bh=5KFRpNovaCOr16lwarSTSNjAPc+H2JwKjgTZzamUb5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j+AX+A/zC/Zj9FnIsqAELgEnGsDHvSCGywLTG9oh5ij9TdwSNE5qYCxTfn8WJvaRi VJEYYobisMqBMy5dCAIroqUkpjZoPkR3EGTPBI1+k9Hjiy51C9m0Zo4FH1vz+X/t+A Z6sko/9Rt2V4biKLjGPUrV+xmu/3OmCPP+VhwMl8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hui Peng , Mathias Payer , Takashi Iwai Subject: [PATCH 4.19 061/118] ALSA: usb-audio: Fix UAF decrement if card has no live interfaces in card.c Date: Tue, 11 Dec 2018 16:41:20 +0100 Message-Id: <20181211151646.701378689@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151644.216668863@linuxfoundation.org> References: <20181211151644.216668863@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hui Peng commit 5f8cf712582617d523120df67d392059eaf2fc4b upstream. If a USB sound card reports 0 interfaces, an error condition is triggered and the function usb_audio_probe errors out. In the error path, there was a use-after-free vulnerability where the memory object of the card was first freed, followed by a decrement of the number of active chips. Moving the decrement above the atomic_dec fixes the UAF. [ The original problem was introduced in 3.1 kernel, while it was developed in a different form. The Fixes tag below indicates the original commit but it doesn't mean that the patch is applicable cleanly. -- tiwai ] Fixes: 362e4e49abe5 ("ALSA: usb-audio - clear chip->probing on error exit") Reported-by: Hui Peng Reported-by: Mathias Payer Signed-off-by: Hui Peng Signed-off-by: Mathias Payer Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/usb/card.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -682,9 +682,12 @@ static int usb_audio_probe(struct usb_in __error: if (chip) { + /* chip->active is inside the chip->card object, + * decrement before memory is possibly returned. + */ + atomic_dec(&chip->active); if (!chip->num_interfaces) snd_card_free(chip->card); - atomic_dec(&chip->active); } mutex_unlock(®ister_mutex); return err;