Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp304588pxj; Thu, 20 May 2021 09:42:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0DmjDLO1iXrD/K2/BdMy3P+Z7BhqXVLaYQoXW62FfsyuKGy7qI6qGHMFljc5snYEF55Ue X-Received: by 2002:a05:6402:1a:: with SMTP id d26mr5961868edu.99.1621528929891; Thu, 20 May 2021 09:42:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621528929; cv=none; d=google.com; s=arc-20160816; b=P/m54TRg3EXf1isFHMLIgGgWAzbDo80qm7BGnrlcOjku6lQY/E/ent25T3CSs1UXpT nxnLFtB0/aULWYrEpBRa9TXUVJXogarXQDbm0BWXXiEgGrsHJvu7vKBbv2vhYc85/fnR 3LGUzCT882twRPM9cklPBvGREEdpQcOzwHSmTZbmjKuo+x7dSLzcUM66Ml5fHi2CjStQ IJOg7AYX0/9I4OQ/3uKdtlmj55o47okCUIl7H0q9MEXD+1yVRxFCf11WZY+g8xq/Co9A iRc+5tla8x1JHawS3kevf0xjIBXLw7BJEFFVt6M2Rrue8hMmudMO5GYxWtQtIE00YbsB dikw== 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=PAEB93krq4SdNXElvPWnWdrP2ZcDSwMClxnCAOhJS1f8Y/QW9m3Fli8lq/wzCADvWH Qpye40Ck4M1+FLjl7ktepetopfZ3PQqjXUWYiIYP/W/nRLlatmaDZBhJDnwUyKKzzAZb LjO/u63h0FT4Uil3kKsdq0XRCPk1BQ9hBbsfSmp++UBRxBYkOBG7ElIeRzhlzA9tYBhb JLae6qDxsf1e4QdmOi2XAEb7zkyTvGuwRMvbAWKtakIir3g28XIMU9tobWsh7bOqCOCe D4NjyJAS6fP6LwpxXWfemJOH2xiRct8HkI3fPmis6Cx+Zl7thOcKvoIaBB60QUjBq5cK 11jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MSewxJmu; 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 k25si3206695ejg.471.2021.05.20.09.41.46; Thu, 20 May 2021 09:42:09 -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=MSewxJmu; 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 S233184AbhETJrN (ORCPT + 99 others); Thu, 20 May 2021 05:47:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:47556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233716AbhETJoJ (ORCPT ); Thu, 20 May 2021 05:44:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C2E00613F1; Thu, 20 May 2021 09:33:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503186; bh=AL7u/WMym1lYfDxy4MVtqLMV/bv2ffPUd+7yZssaMYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MSewxJmuwKO2gVxFJxwAgGycw7HTL68EmENDvzR2Thb72pZVuIDAVlMKKjCxbcooL VLXxtAiYAB5YPv6xpR6Zg18B78zqThigf37PEtOFjJcKwUcSwBccfgSHRGGcqWRdAy 7sUyvsa/Px8bTEuaYmj7KX2UqyvdoJIM3cP9xEJ0= 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.19 074/425] ALSA: emu8000: Fix a use after free in snd_emu8000_create_mixer Date: Thu, 20 May 2021 11:17:23 +0200 Message-Id: <20210520092133.883131794@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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;