Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp61303pxj; Thu, 20 May 2021 04:36:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytHizXx1P4vdmBj+FUvTVhE+MknP6nP/GPhCZ5Ypx4M7989Eqnv3pr/PYgFrcoyRdrrJNh X-Received: by 2002:a17:906:6ad0:: with SMTP id q16mr4360685ejs.286.1621510561862; 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=r3I/aO1h8RoiKmqDv1BWOZzdJz56Qq294EslUQPbFRNTGNoS2hYCEudkYTGvITe5+c uEpIHaGvT4FA+Nvoq3mTHHyBzOwKGsXN7GJNFuy5g5IQxpcvHvqHpchW9KdyDKFhzmtI izB7pTfN98qyQasoLp8+HxS7gTYifG/wsU5bJKCD5VUrby/3CrYgeAclo1Fu1hjD4HqY lIaA3h0Efl9vJkbs/7ITcUqbUfF+VCAoeFhPREj6mgQ7LE2NVOcRpi9HmjgNqBV2Gghc i1NJHPglDuzOhZJybjuVLB2mSLhui9qGBJw+mEfcxKL96DivZ+yfeFjLez+0oWF5LWwA uf3w== 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=rmkNeZErbIuNx3iHhNadWsLwJ7xnVcWCxc6ik1uq5a0=; b=FryGk0uK/G4EiuLK9kmR2m4sI9D/i+VnvJOHn/ihIXHSiZQM3NBB2DMZjoUjuY6KI4 Jt/WutoRQM5oM+8gCRI2KzGwkZzBSnSgFDHcYQYSME6FY46YA8C7APvQcN1i32NsIgNK 7esjGkaiEir8g+Rrgvp+8osS5GZL+pqUIy/jE6rxRFy+zY/UjbTnqz3Yi9Mk/10Ey9KJ yruHceM9ZsdIAkd38z99pf4SLYq2tMj1c1vK0LmgKu7bdPTWJ6R9hQ7NiGGRMfKJj2wG VePy8AlzljiTfdRLi3NXFnHMyR3oPFyIvtamwhsm4dGZan+4GEWyHV49oMfwZrdnVZHw AujA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pBuyxkZn; 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 os10si2237692ejb.60.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=pBuyxkZn; 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 S242108AbhETLe3 (ORCPT + 99 others); Thu, 20 May 2021 07:34:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:56448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240167AbhETLNo (ORCPT ); Thu, 20 May 2021 07:13:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2F58361946; Thu, 20 May 2021 10:08:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505304; bh=AL7u/WMym1lYfDxy4MVtqLMV/bv2ffPUd+7yZssaMYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pBuyxkZnYLrwgTJshLdHgAx2tR2wGXLBjqdg6i9PUNywF3GKIRtVcVKZEqUVlvDn7 dnvxojAz2iEKew8wsNWpl9cPTyv8W5YiYpR5RDpOOFiz/2/v+UvDAnCBaltc2zY9/l nwk4BGLmILzOHNTkQoKET0w7C6qGj7kHj4iD+dXs= 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 039/190] ALSA: emu8000: Fix a use after free in snd_emu8000_create_mixer Date: Thu, 20 May 2021 11:21:43 +0200 Message-Id: <20210520092103.458645098@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 1c98f574403dbcf2eb832d5535a10d967333ef2d upstream. Our code analyzer reported a uaf. In snd_emu8000_create_mixer, the callee snd_ctl_add(..,emu->controls[i]) calls snd_ctl_add_replace(.., kcontrol,..). Inside snd_ctl_add_replace(), if error happens, kcontrol will be freed by snd_ctl_free_one(kcontrol). Then emu->controls[i] points to a freed memory, and the execution comes to __error branch of snd_emu8000_create_mixer. The freed emu->controls[i] is used in snd_ctl_remove(card, emu->controls[i]). My patch set emu->controls[i] to NULL if snd_ctl_add() failed to avoid the uaf. Signed-off-by: Lv Yunlong Cc: Link: https://lore.kernel.org/r/20210426131129.4796-1-lyl2019@mail.ustc.edu.cn Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/isa/sb/emu8000.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/sound/isa/sb/emu8000.c +++ b/sound/isa/sb/emu8000.c @@ -1042,8 +1042,10 @@ snd_emu8000_create_mixer(struct snd_card memset(emu->controls, 0, sizeof(emu->controls)); for (i = 0; i < EMU8000_NUM_CONTROLS; i++) { - if ((err = snd_ctl_add(card, emu->controls[i] = snd_ctl_new1(mixer_defs[i], emu))) < 0) + if ((err = snd_ctl_add(card, emu->controls[i] = snd_ctl_new1(mixer_defs[i], emu))) < 0) { + emu->controls[i] = NULL; goto __error; + } } return 0;