Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp61302pxj; Thu, 20 May 2021 04:36:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3AS4/wSTmfk+n6MGxxQ4k3uymFFr7FL1Q1CYpmfQhhZY+0lU2S22bPNoBrA3YANY66JUr X-Received: by 2002:a05:6402:42cd:: with SMTP id i13mr4487995edc.34.1621510561791; Thu, 20 May 2021 04:36:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621510561; cv=none; d=google.com; s=arc-20160816; b=I89Ed0q3YViMwC9bkcB+OChklOky8HtdH/VZOe3kxgR+8yBY+XB5QNdbsmtAKFsS6g 0hX5MXPM4PXtXLJwd6weuT892Q92ly5NihF2m2x/ytgEVEFh+2uYGAO9FZvm7yVHnHdz zP/XfSQZCEJFt3TnFC83/h5oyNDKej69U8WUqhDfIgVXJgNRlH1tIW4dNfdbQr2NcFUz oUIEHvxXFiZBxhf5Jwgpo+fnFylPhusN5wXGYCUpLl1Nt7DGOZ6WHzyIifYlPKurekJk nFcX4MXZU/VunPwZf4niwOnK/u0wSoa3rgujroE+BQGD67y/lT0r+ZZtoLDgtuBD9iWv J3RQ== 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=SlscUe2fqDV8GglQsSynf71SQMRHqNRoVWfV6UXG6kk=; b=WCyM0tPOTzmDVlD66f6B25myzP92f4oeVEg/nuXttnJLAzr+xkYD+gL5KbmUOsucby b9EqGDsax8RA0sPuTMVAB6DQn1ZSe6KNbzNMtxPy1Ow6jpvZEYAFz1Mqllb0GV72QIPA WWAn3vA3vuyJAjAxq9/7NPt9DTGi4MqIqsM/jT5KpRSF1tLG5u8dKKFp5eGuT2BPazAf 4rI39zCqscPVKyh9gWUVk+ESX4A+CbdYxcferH27DYLPuOaZHCDjw9Shf2nKY75kbAqC d+ikHQu1R9D0TQwhYf6ghV4YhOXAL7mpmqadSIfDEkGrgIbGQ/uzqAPI6t/1A1RA3C0I PaYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dTMWsUk9; 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 jz8si75733ejc.34.2021.05.20.04.35.38; Thu, 20 May 2021 04:36:01 -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=dTMWsUk9; 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 S242145AbhETLeh (ORCPT + 99 others); Thu, 20 May 2021 07:34:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:56532 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239249AbhETLNr (ORCPT ); Thu, 20 May 2021 07:13:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 613AC61947; Thu, 20 May 2021 10:08:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505306; bh=/CncAhzPTjBPbmdbXKkNiHClkxizzGCCXUoVLQh2+CA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dTMWsUk9fvlixuFMI8Tvux9CN2jm9ubutqwf+qUaj/PiAV70Hle4ZKYB5bb3xMVlG q/dXLpPwtTeBiUfpZ8UlO4JMOKMiNUClH2/hbRIR7kKARGD91ioUZYswbrlZ7MPBS4 eeFM4Ttu3JOCU+0X7Ve5cXUzg3e7apnUMrV8VPUU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lv Yunlong , Takashi Iwai Subject: [PATCH 4.4 040/190] ALSA: sb: Fix two use after free in snd_sb_qsound_build Date: Thu, 20 May 2021 11:21:44 +0200 Message-Id: <20210520092103.499831732@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@linuxfoundation.org> User-Agent: quilt/0.66 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: Lv Yunlong commit 4fb44dd2c1dda18606348acdfdb97e8759dde9df upstream. In snd_sb_qsound_build, snd_ctl_add(..,p->qsound_switch...) and snd_ctl_add(..,p->qsound_space..) are called. But the second arguments of snd_ctl_add() could be freed via snd_ctl_add_replace() ->snd_ctl_free_one(). After the error code is returned, snd_sb_qsound_destroy(p) is called in __error branch. But in snd_sb_qsound_destroy(), the freed p->qsound_switch and p->qsound_space are still used by snd_ctl_remove(). My patch set p->qsound_switch and p->qsound_space to NULL if snd_ctl_add() failed to avoid the uaf bugs. But these codes need to further be improved with the code style. Signed-off-by: Lv Yunlong Cc: Link: https://lore.kernel.org/r/20210426145541.8070-1-lyl2019@mail.ustc.edu.cn Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/isa/sb/sb16_csp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/sound/isa/sb/sb16_csp.c +++ b/sound/isa/sb/sb16_csp.c @@ -1059,10 +1059,14 @@ static int snd_sb_qsound_build(struct sn spin_lock_init(&p->q_lock); - if ((err = snd_ctl_add(card, p->qsound_switch = snd_ctl_new1(&snd_sb_qsound_switch, p))) < 0) + if ((err = snd_ctl_add(card, p->qsound_switch = snd_ctl_new1(&snd_sb_qsound_switch, p))) < 0) { + p->qsound_switch = NULL; goto __error; - if ((err = snd_ctl_add(card, p->qsound_space = snd_ctl_new1(&snd_sb_qsound_space, p))) < 0) + } + if ((err = snd_ctl_add(card, p->qsound_space = snd_ctl_new1(&snd_sb_qsound_space, p))) < 0) { + p->qsound_space = NULL; goto __error; + } return 0;