Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5580854ybi; Sun, 7 Jul 2019 08:04:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqykzTW+Wa+zew2w4Rwb5H054WaQNB0gOTgx5TrDY7vnv2YAxpAnX/6zrTkLNzuBfPp+2HSw X-Received: by 2002:a17:90a:36e4:: with SMTP id t91mr18094097pjb.22.1562511885561; Sun, 07 Jul 2019 08:04:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562511885; cv=none; d=google.com; s=arc-20160816; b=dMkdj7kQhQK+klREN+3T82KoPxi7czXYdZXYk0EbFIfNC/Tj+BUoWzX4RJlj8iNGl+ s91W9gng56okex5jlLmExnAAxA9dN/jlcKrcYMFFT0mz+jvZG5wc0XcbMOJIzi4abLEp pihhpb/YLc5a6t/rbDT+DW5F846HuXHTTgDoUYD8X1WGnTW1pHw1xiZnT4wSgAjSH0O1 2jgrqfvhA3u+yb5HjjXz87uKMtJ7sO5E/JqVJWPYZy4LRx3OV9HkTZg5TweEVKFx69r9 R7OV8VT/KijrUhGYfgByOIAR5phDe2bUMmo39nWnXhfXEhER5sLs2cayZe7/x7VlBQD5 c5AA== 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=hg+2F4CQEXTPGuzXZHgWpeWud+WKMzNK6Pc5pT307kM=; b=uJEdltYApCBO/LehA5FW8/DQbNancXBjkqzlgcuuhfVoM7iipnfy925dVRScr+bSqE IcNJB/UQEPB6D0IwwsZy22tjcXxL0MC6/ECfGSxXElvT4D6f7b6d5s3TIAK20YShzhZA D0UE6fdZGq0kYsqJWTd6zpDN/0Koc5L5L/n7259tPTwgUidUbG00CAqzuUEpaCRnvn8v QaVU1KfHdX0fAkkckXhwfZEmJsn1LPqsSqTp4NTEFWtZWExfjaohFmQ1HmdtNS9jVcYA VOBx3z512spyhotUaIRs5a57EyTGb/7s3RkdeS8F+Ox+xQHaXNRJSYg+HnWqlTf6HGkF txow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JJGOHMK2; 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 c9si15732721pfi.143.2019.07.07.08.04.01; Sun, 07 Jul 2019 08:04:45 -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=JJGOHMK2; 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 S1726613AbfGGOlM (ORCPT + 99 others); Sun, 7 Jul 2019 10:41:12 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34829 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725928AbfGGOlL (ORCPT ); Sun, 7 Jul 2019 10:41:11 -0400 Received: by mail-pg1-f195.google.com with SMTP id s27so6358350pgl.2 for ; Sun, 07 Jul 2019 07:41:11 -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=hg+2F4CQEXTPGuzXZHgWpeWud+WKMzNK6Pc5pT307kM=; b=JJGOHMK2ecBPtywHW+pwEEByqzswqKCHObyjZWXEVxFiTcAEhRTBI1Aaso+HqQNaYf w77emYzzGqa8xlvmUTTPz2E/T5pNla2Q9nZVIY2keM65vyK7548yvj4UhvRui34hsNof uaUFHKvBdztXLVaQc9cc3BwuhFxbTwmu+1EL4= 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=hg+2F4CQEXTPGuzXZHgWpeWud+WKMzNK6Pc5pT307kM=; b=LkDriMzPVKxN+A4ETXYx9LO85tzpctGKhbIA9JYKspAFWIJA4HpmS7l7WZ1GRuKwx6 uzRpG8b4GJWe2lzJss/NuWuF3VJwlc1foSwGLPjlnxAtBgcIZMxGuhZ7HIz7nFabOZ/B StjAg6bhjKtB0MUdX3uW24kZNUknEPoTtsJ0kGmErtTAtrItaAr77QMvlCynsZKF+lsx bR3zQrpOP1LtWoR61AfQ7SDtGbVOUEsXiMrMoa4tLUS8c23jt1CqxdbbrKRfMDIMc0Qg 5T50AHCwQsu2poGNDoZAlavvNtgXtf2E2aDuzpqniFx+ReQTy+8/pSrDPZVoLP5sbBlM B6JQ== X-Gm-Message-State: APjAAAXk/y4CNwF1vnakPc3suhqqkvgk4Kl+gu/V+yd2KR5U1LRqYC+1 JyzWAPPjgn8PoC0eWIl439KRNA== X-Received: by 2002:a17:90a:f98a:: with SMTP id cq10mr18462409pjb.43.1562510471215; Sun, 07 Jul 2019 07:41:11 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id i74sm16400681pje.16.2019.07.07.07.41.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Jul 2019 07:41:10 -0700 (PDT) Date: Sun, 7 Jul 2019 07:41:09 -0700 From: Kees Cook To: Norbert Manthey Cc: linux-kernel@vger.kernel.org, David Woodhouse , Anton Vorontsov , Colin Cross , Tony Luck Subject: Re: [PATCH pstore fix v1] pstore: fix use after free Message-ID: <201907070734.86DE450@keescook> References: <1562331960-26198-1-git-send-email-nmanthey@amazon.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1562331960-26198-1-git-send-email-nmanthey@amazon.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 05, 2019 at 03:06:00PM +0200, Norbert Manthey wrote: > The pstore_mkfile() function is passed a pointer to a struct > pstore_record. On success it consumes this 'record' pointer and > references it from the created inode. > > On failure, however, it may or may not free the record. There are even > two different code paths which return -ENOMEM -- one of which does and > the other doesn't free the record. > > Make the behaviour deterministic by never consuming and freeing the > record when returning failure, allowing the caller to do the cleanup > consistently. Yup, good catch. Looks like a double-free in the one failure case. > Signed-off-by: Norbert Manthey Fixes: 83f70f0769ddd ("pstore: Do not duplicate record metadata") Fixes: 1dfff7dd67d1a ("pstore: Pass record contents instead of copying") Cc: stable@vger.kernel.org Applied to my pstore tree. :) -Kees > --- > fs/pstore/inode.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c > --- a/fs/pstore/inode.c > +++ b/fs/pstore/inode.c > @@ -333,7 +333,6 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) > private = kzalloc(sizeof(*private), GFP_KERNEL); > if (!private) > goto fail_alloc; > - private->record = record; > > switch (record->type) { > case PSTORE_TYPE_DMESG: > @@ -387,6 +386,8 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) > if (!dentry) > goto fail_private; > > + private->record = record; > + > inode->i_size = private->total_size = size; > > inode->i_private = private; > -- > 2.7.4 > > > > > Amazon Development Center Germany GmbH > Krausenstr. 38 > 10117 Berlin > Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich > Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B > Sitz: Berlin > Ust-ID: DE 289 237 879 > > > -- Kees Cook