Received: by 10.213.65.68 with SMTP id h4csp1742645imn; Mon, 19 Mar 2018 12:01:57 -0700 (PDT) X-Google-Smtp-Source: AG47ELtrDUh7zPvxaDeGnerx2aQrUmEopnjTwDpk07W0GeVkODR+Uyy2F4/7+xAUCCr9IoUQjx3s X-Received: by 10.99.109.203 with SMTP id i194mr10140803pgc.314.1521486117678; Mon, 19 Mar 2018 12:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521486117; cv=none; d=google.com; s=arc-20160816; b=eHsYdCCdGpcQM6SdO260fZQ59OVHsvnQ8sIOsIXzQllc78O+yUtBHkw+y4c6AZTg5N lTQqY96T14F1jQGKS7juBcQc8ywAzX0bY/0IOYoPdXPCMgzJendc82q12ahpkQSup7v4 hUvKrHvGZBdLxTbVUA30Y9rDnTDo6MyBR8cdD4TFFR7KzoTaUcu+jE2Lo1YnSGu6II4z f+oHQ0EJSBoY/WC9D/KpEWL9o1h0nq1lLHA9nxN3zeQndMsBODPYAkdzZVLL/CSLL1Ch fk8XVY87e8QPRyjokkpIU9XIJ5YYi2j5jKY4+z9zvh0i4/wD9jLkKUxQ8+UBE9eJd23V HN5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=0jGjX/TxaCCk8QD/P8XsOysdk8MAJ/F2v9LUGfvW4So=; b=tdRgnUHMy6dMTZoNudbK+Jwq8P8upqE1mu2BR8jxyalnqzrzU2ztQ2JKSU2nO5z1dw AmYI+jG0g9iw8NgpLl73WhY1KSh0G1A6zS/tGa3o+3RwCpUg+BcVQgCzSGoEfOYyAMK/ FtGHewwa2bOIeZKrq6hKxfTWbB/fBUpS6ESGokoLLrrc2D3AIKjlIIzEthz0GKBJ7cUy 6FJpLetF4oH5rGhYunqce4F9VCeV5UxrIHkxn17gB59bBrfxh/LakfkPxsjhSOBygx1g rLCVbEPadcQivpeieyt1Oyumolr9XJy+DSQ/6VuV75uyY5Pm2PFh7478zFEWy5R1P0sX dOGg== ARC-Authentication-Results: i=1; mx.google.com; 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 m10si365424pgt.292.2018.03.19.12.01.43; Mon, 19 Mar 2018 12:01:57 -0700 (PDT) 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; 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 S970663AbeCSS67 (ORCPT + 99 others); Mon, 19 Mar 2018 14:58:59 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:52706 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031813AbeCSS3W (ORCPT ); Mon, 19 Mar 2018 14:29:22 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7929E111B; Mon, 19 Mar 2018 18:29:21 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+4090700a4f13fccaf648@syzkaller.appspotmail.com, Takashi Iwai Subject: [PATCH 4.14 13/41] ALSA: pcm: Fix UAF in snd_pcm_oss_get_formats() Date: Mon, 19 Mar 2018 19:08:13 +0100 Message-Id: <20180319180733.068995288@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180732.195217948@linuxfoundation.org> References: <20180319180732.195217948@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai commit 01c0b4265cc16bc1f43f475c5944c55c10d5768f upstream. snd_pcm_oss_get_formats() has an obvious use-after-free around snd_mask_test() calls, as spotted by syzbot. The passed format_mask argument is a pointer to the hw_params object that is freed before the loop. What a surprise that it has been present since the original code of decades ago... Reported-by: syzbot+4090700a4f13fccaf648@syzkaller.appspotmail.com Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/oss/pcm_oss.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/sound/core/oss/pcm_oss.c +++ b/sound/core/oss/pcm_oss.c @@ -1762,10 +1762,9 @@ static int snd_pcm_oss_get_formats(struc return -ENOMEM; _snd_pcm_hw_params_any(params); err = snd_pcm_hw_refine(substream, params); - format_mask = hw_param_mask_c(params, SNDRV_PCM_HW_PARAM_FORMAT); - kfree(params); if (err < 0) - return err; + goto error; + format_mask = hw_param_mask_c(params, SNDRV_PCM_HW_PARAM_FORMAT); for (fmt = 0; fmt < 32; ++fmt) { if (snd_mask_test(format_mask, fmt)) { int f = snd_pcm_oss_format_to(fmt); @@ -1773,7 +1772,10 @@ static int snd_pcm_oss_get_formats(struc formats |= f; } } - return formats; + + error: + kfree(params); + return err < 0 ? err : formats; } static int snd_pcm_oss_set_format(struct snd_pcm_oss_file *pcm_oss_file, int format)