Received: by 2002:a17:90a:2044:0:0:0:0 with SMTP id n62csp529184pjc; Mon, 20 May 2019 11:18:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFKWrAR4q0aowIVcvmPzxjXiLyoinr7LUO4cNcLZi1QTG5P40cqXYrHXxH7Xc3pfrDHGVm X-Received: by 2002:a17:902:7002:: with SMTP id y2mr77361047plk.75.1558376310582; Mon, 20 May 2019 11:18:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558376310; cv=none; d=google.com; s=arc-20160816; b=JCeeISLmIVfbI1DK2PhbJAobU0ZqvTpgTVWcJmdTrzJOOgtNZhcISom8bRIyYwuoko FJyGl0GOdX7FwjOIkGDCHtNSZH4lhuU8SGtk3CEyDvoq7K4wrxruaNIhkC+aIIHUu3Ji F6xHeQj/i7F+o9SV2cqVuZgod5Qnod4LQAUV6BRfaqrH4EXOnBaNiva9mt2YQxuPODAU JQ9ORdpLXsXdMANTSwMSXft6eORQBb8Hq77CfakMcviCUOnP4LpCwzi0P8jDkYe3Bkuc 9lJISFkj4uoH5TJKs7wpCzYxuVKGrfSqEPi/TOyc41bDUcFKjV2t90zTS5F22wpVWSBc igHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=FVKmNQJMqTAQAcsz/9SSssbO/SW9TTP8CoLZIOoi9yQ=; b=SBWRd8o5pxV2cfIba9DsLimK4Oi3pBgGgttov/xam4z3lYfwgW4wL6wZDohXPmYOxl PnTUKF7DXyo+30Jp/5+R93YCe/Egq2xKgdiquHyTLiu9FBF0uD7g4/moMBEzLNhwBZCQ FU3uVBhrJAIYnXgtC5VZ7O8lHoBOTfIgtV8mDT8TsmKzegKMus0a/rdzz/KTIeh5Atm6 zIxeghaJbAU389h8N0HlMqyQEcRk3e7tQl0FmbL1to9w9n8ZL7/nYBoxqwrxTdBvTWzz 22lSiAY+/EQn+Kz7w9DMCdCZiSi6FDo2LLGlqF7GygMBcu+icccS2oYdIPY1742Di03Q aGTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gJpyToqR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a98si19106568pla.282.2019.05.20.11.18.15; Mon, 20 May 2019 11:18:30 -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; dkim=pass header.i=@chromium.org header.s=google header.b=gJpyToqR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389479AbfETQaI (ORCPT + 99 others); Mon, 20 May 2019 12:30:08 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:33923 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730795AbfETQaI (ORCPT ); Mon, 20 May 2019 12:30:08 -0400 Received: by mail-pg1-f193.google.com with SMTP id c13so7043612pgt.1 for ; Mon, 20 May 2019 09:30:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=FVKmNQJMqTAQAcsz/9SSssbO/SW9TTP8CoLZIOoi9yQ=; b=gJpyToqRVPXO+ltYTK4Lky5OkAaw69Mrtrad5aCa7yGfK4El/0DXFkagU8tetuVEYZ FNuq5yCeUJLwscIO7jFNskEvfjsv0z13hPpROg4VNeSVpMdiT7xEx8vop6Hyzv4xl8Ad PyzdjtAoIZ60HpyLZmSOm6nzlppl5UquAwBes= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=FVKmNQJMqTAQAcsz/9SSssbO/SW9TTP8CoLZIOoi9yQ=; b=KLE8Upb8EgR+B97LrnrrfrKO8ikpcyy7qammg3vMi3LMEANueZb1aEV/vU9ceTwaKx 9HIMFhG+bQAt6zOxuQYPgHk7psbgaI3pg7w6yvtyhuHPEhXaGhjUb2o/GUDvYB7YUr3s XirRSkEiSbp0h+fdKR+ZDeDXmKH/Wkn51zYyMQPeRSR1guQ8n2FaqXiLdonvaAsx/HSo Dhqrdz3izTJ51EsppsYCajrbb7wMmjVDXMuWuqfEf33PwV/bwbkEkKRRuINA+qzWrpvM WwSQhAn7NpHe4TLMmvfdH8y02DLenMtPL9OsWoDh07r64b1OJu0l2B+Q9MOfMAG9uc1M VliA== X-Gm-Message-State: APjAAAVZGUiTjSigUwkEvoO7UdR/KY3DSdEkVN+RVMALP45ygT3GTwCZ x13xSgt/qlSxMpl1yOG4x6OZkA== X-Received: by 2002:a62:1ec1:: with SMTP id e184mr14275504pfe.185.1558369807924; Mon, 20 May 2019 09:30:07 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id e184sm23783506pfa.169.2019.05.20.09.30.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 May 2019 09:30:07 -0700 (PDT) Date: Mon, 20 May 2019 09:30:06 -0700 From: Kees Cook To: Pi-Hsun Shih Cc: Anton Vorontsov , Colin Cross , Tony Luck , open list Subject: Re: [PATCH] pstore: Set tfm to NULL on free_buf_for_compression. Message-ID: <201905200928.08FE9977F3@keescook> References: <20190520065120.245811-1-pihsun@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190520065120.245811-1-pihsun@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 20, 2019 at 02:51:19PM +0800, Pi-Hsun Shih wrote: > Set tfm to NULL on free_buf_for_compression after crypto_free_comp. > > This avoid a use-after-free when allocate_buf_for_compression and > free_buf_for_compression are called twice. Although > free_buf_for_compression freed the tfm, allocate_buf_for_compression > won't reinitialize the tfm since the tfm pointer is not NULL. > > Fixes: 95047b0519c1 ("pstore: Refactor compression initialization") > Signed-off-by: Pi-Hsun Shih Thank you! Yes, without this, reloading pstore backend modules would cause bad behavior. :) Applied; will send to Linus shortly. -Kees > --- > fs/pstore/platform.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c > index 75887a269b64..8355a46638d0 100644 > --- a/fs/pstore/platform.c > +++ b/fs/pstore/platform.c > @@ -347,8 +347,10 @@ static void allocate_buf_for_compression(void) > > static void free_buf_for_compression(void) > { > - if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && tfm) > + if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && tfm) { > crypto_free_comp(tfm); > + tfm = NULL; > + } > kfree(big_oops_buf); > big_oops_buf = NULL; > big_oops_buf_sz = 0; > -- > 2.21.0.1020.gf2820cf01a-goog > -- Kees Cook