Received: by 10.213.65.68 with SMTP id h4csp1743730imn; Mon, 19 Mar 2018 12:03:14 -0700 (PDT) X-Google-Smtp-Source: AG47ELtZrErTrIH2wN4PMCmMqIshptycKHirIAe9tGDnJYumHkFVijgZJMCz7n0yhtG17EO7x/+d X-Received: by 10.98.189.24 with SMTP id a24mr11205050pff.125.1521486194732; Mon, 19 Mar 2018 12:03:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521486194; cv=none; d=google.com; s=arc-20160816; b=R+IP0Y9USSNvsABPQ4StKEa0yTOPU8Z3vZokzPth8LiSjePLaASRosptzYS2zTvC7L P9KKFri50X7f5K6JSiglu15ODVdKEP4n1crzbGQDDsB4RHUm5M/caXT0XrH8fd1OEfEc ++b0yO1W7KnfAzrkZAtDNhrIt7udGPrfSgf18hVuykLJ2wmY5KfUCllwwxwP0h5SBndh p8DlwI0DYQ3s4czqVWZd9pKsIbjFLSF7TNXpTXOIjWL7WofZ9n0WePts2EMFr2JhDjOk O6e4PousarTGx1HMhLd5YkLR/HX45QhW3Clj55aFmQNw2j/8sAi8OSnzP1X+e5lPsISM yNGQ== 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=/QlQ73X4PdHtCuSG6ZEfsDHZLSIp6gT0a7fNnsW/WG0=; b=YPRCgJ8MIZ13gj91Jp0m4ziELo2NnQrWYCdNxHg9WONu6IALoSf+UbNitATBvcQyYL WDn8HTOeWG1jyOFRFYS0jd2vpRWreNZV4d9phRL56Oa9QBeMvS/MJ95ihLFTzGCAmCgL 5+c6AcN9huJorxZjtW1PuBiAepXkfg82f0+xrp/taEzSX4ENpR7fzYS/4moFA9N9wrKK iDVX7Im7mH9fMWMLahts7l0IpDSetgT/Jld+vmWZWFljucEILQI2aS+iRLgHMy1M3BPz zjeTVGMeewlirL6U06wftAeIp4LFjW7jYzDo0JKZfGPiGtls/Gll5yH+WZmsB24T6oJe fD1A== 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 y12-v6si492605plr.42.2018.03.19.12.02.59; Mon, 19 Mar 2018 12:03:14 -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 S970684AbeCSTAQ (ORCPT + 99 others); Mon, 19 Mar 2018 15:00:16 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:52556 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S970146AbeCSS3C (ORCPT ); Mon, 19 Mar 2018 14:29:02 -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 99E3E1110; Mon, 19 Mar 2018 18:29:01 +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.9 222/241] ALSA: pcm: Fix UAF in snd_pcm_oss_get_formats() Date: Mon, 19 Mar 2018 19:08:07 +0100 Message-Id: <20180319180800.357441733@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@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.9-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 @@ -1814,10 +1814,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(params, SNDRV_PCM_HW_PARAM_FORMAT); - kfree(params); if (err < 0) - return err; + goto error; + format_mask = *hw_param_mask(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); @@ -1825,7 +1824,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)