Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1152902ybl; Wed, 8 Jan 2020 11:58:51 -0800 (PST) X-Google-Smtp-Source: APXvYqyxYKST6Sg26ffoWfhgEYmpZ4r4TKjozgxIN+nKkv7vRypEKE3Lsa44jkZ/u9Gu47YrAsre X-Received: by 2002:a05:6808:486:: with SMTP id z6mr229409oid.117.1578513530896; Wed, 08 Jan 2020 11:58:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578513530; cv=none; d=google.com; s=arc-20160816; b=vlPiLQWFskCd+sTKx59qLX7HSRJtpmHwaxPOjlNFdxGP+cwsTC027B9Adplth1JJcO jMPSYsmHlshV0S4fXtZ+RdAMQ9UoXt52TWs3qD29xvnLN5+fCzViLQrmx6ZE9GrMuIjL X2gTRsvlbfwslVAdUiZ2nSsXNOQuUvGK1Q0Cxydo0+6zg3nvpSxGEhWZyhJ2oQLHul8x aNOxsGA1PH9FXDKRBPqUnAT16GTdZAKpVzHotr+rCnzJEdf9Mw47DS+/lkqrRQ0OUqBe Qw1gVWRdP5dJD7OBtLl88X/u0uujU9iYj91OZkG5uVMoFBBPmwQJxTFwdSzRhYo4f181 dxxw== 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=XR36J4mDpO4U+TRkIgyEQycFtRJlUupvMB+eBkNGJTE=; b=i2nbzGrWSs4BK+5EG4voYCvfzW1KEWDyeb19c6ucrnVHmHgA2mXzcEo9migA/uKkht V/DBqXT63gsY2FB08XEb+lQc5XA6h2JCQynn3Rchf9ed6tiFBrd30eUlxrctbQad04ko foGYXukgj3ggoC6f9b3HCwcq3J+gvEEB9QfHjamlS89EweChhVIEEIflRm83wYokRZzE qD+N01K57RYsXoXHdYFdXbyUK8+L4wIW+5ff99BST8iS32UVj189l0xUxfT/8oOjwuaA qoX1abOHMc8aZK7WgktVPQFzjY6DZ9sACcBEv1AOhqGNWSZqmup0khAm5kSghbm8+x6S ZPhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Bdoq5YxM; 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 c21si2533504oto.176.2020.01.08.11.58.39; Wed, 08 Jan 2020 11:58:50 -0800 (PST) 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=Bdoq5YxM; 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 S1730016AbgAHSBJ (ORCPT + 99 others); Wed, 8 Jan 2020 13:01:09 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:36913 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727090AbgAHSBI (ORCPT ); Wed, 8 Jan 2020 13:01:08 -0500 Received: by mail-pj1-f65.google.com with SMTP id m13so1407809pjb.2 for ; Wed, 08 Jan 2020 10:01:07 -0800 (PST) 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=XR36J4mDpO4U+TRkIgyEQycFtRJlUupvMB+eBkNGJTE=; b=Bdoq5YxMvQOdYiIJhMG/ucGPOj3k1HoZkdOzfa+bHUJY5Zh4vUvC+BSAk/4sG6X+1P lSYDFD1vuyO+jt4fEyhq6lnafPHwPjzqLRLzyMhe9Cwczepfe82gE/GKmy+cge/wzG7K 47sx3BWKj/njxj+qt0AzxrkIWZVKmWuqyYsEI= 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=XR36J4mDpO4U+TRkIgyEQycFtRJlUupvMB+eBkNGJTE=; b=WI+uA2ZOWsVMl6cGsfVKpdth5M1euq6yHVJJfr0VIfFeunxJ5C/a+5RfDEogOWV2EV 7Hap11idBVaV2ilcp1wT5DXvbrRujcapq+7Qsown1Acfq7B/aGjdsIY2Gdar1ggDs7Nr o7u88UjVjcGtcczpGImQ1ZtMhsVYhJ7spQoganjvixfvRMn2oSgdMaFHMHQflw38kAn6 kUweSFsKxp+OyRurPuYg3rSS5PIMeVf3K/xUmLxSpaKgSIwC9G0iN5km5/kwMjvD1d/m 5yAe/XxcQGRI4bPRx56pt+xt/YlOyK4U9anv+F8DbSLHu214bslhK3Wjs/lZJ3rhlwQQ HUPg== X-Gm-Message-State: APjAAAUEiIAqQvuGWOHADpLWcPAHMo+jd8JTtjrQC0N3FZ8h/LDXD9df pc8Zu8EhOioQxiFaNjwIjLmEtQ== X-Received: by 2002:a17:90a:d582:: with SMTP id v2mr5761263pju.59.1578506466462; Wed, 08 Jan 2020 10:01:06 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 20sm4386671pfn.175.2020.01.08.10.01.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2020 10:01:05 -0800 (PST) Date: Wed, 8 Jan 2020 10:01:04 -0800 From: Kees Cook To: Cengiz Can Cc: linux-kernel@vger.kernel.org, Anton Vorontsov , Colin Cross , Tony Luck Subject: Re: [PATCH] fs: pstore: fix double-free on ramoops_init_przs Message-ID: <202001081000.88F20E5@keescook> References: <20200107110445.162404-1-cengiz@kernel.wtf> <202001071002.A236EBCA0@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 07, 2020 at 10:40:58PM +0300, Cengiz Can wrote: > Hello Kees! > > It's a pleasure to hear from you! > > On 2020-01-07 21:05, Kees Cook wrote: > > > > I think this is a false positive (have you actually hit the > > double-free?). The logic in this area is: > > No I did not actually hit the double-free. I'm just following > the indicators from static analyzer. > > > nothing was freeing the label on the failed prz, but all the other prz > > labels were free (i.e. there is a "i--" that skips the failed prz > > alloc). > > I have noticed that. Thanks for clearing it up though. > > The `kfree` I was referring to is in `err:` label of function > `persistent_ram_new` in `ram_core.c#595` of `for-next/pstore` tree: > > https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/tree/fs/pstore/ram_core.c?h=for-next/pstore#n595 > > Here are the relevant bits: > > ``` > struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t > size, > u32 sig, struct persistent_ram_ecc_info *ecc_info, > unsigned int memtype, u32 flags, char *label) > { > /* ... */ > /* ... */ > /* ... */ > return prz; > err: > persistent_ram_free(prz); /* <----- */ > return ERR_PTR(ret); > } > ``` > > So, to my understanding, if our `persistent_ram_new` call in `ram.c#583` > fails, it already does clean up the `label` pointer in itself and returns > an ERR_PTR back to us and our skipping logic does its job. > > I might be missing something but it seems so. > > Thank you for looking into this. Ah-ha! Yes, I see it now. We have multiple paths to the err: label, and I was focused on the kzalloc() failure path. I will get this fixed better. Thanks! -- Kees Cook