Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1884080rdb; Sat, 2 Dec 2023 13:23:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IEGQqEI4AjqnAerqQjZDsnObvPdDanuX+UOwitwbIcNLUQW49/nAlZZe/AxbSxtkQCiAYxS X-Received: by 2002:a92:c710:0:b0:35d:6664:2ae5 with SMTP id a16-20020a92c710000000b0035d66642ae5mr703045ilp.19.1701552187899; Sat, 02 Dec 2023 13:23:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701552187; cv=none; d=google.com; s=arc-20160816; b=lOu5We9piGprL1sz/hvmP0uMme5Jfgdefg+EhveD11NeRZ08suLKCXM/LKQ+QFsYww IxR6WRZO46cAgB4Qhtjc9C8tcUm014Bb28wdIhHOF17RS3dBS66cqmPoyzyBLgPlTkAC NmHnW32qVlIT7aCCXnpgpQWtybni8jbOPc2w6bDELRSlKoR+klml5eRLfjYeGhogn5at JtUp2ufYztRIqQGjHzrxUUVGHugE/XiRIIe7m1CxYLBguJahXdnRlxlB4qzBfR/gA2vU ZcZFKJBR7PVTpS3ulzVw3XSXh4hZCmP4zN6iQ2ijYp42d2/D6ilUo948eFXafLT34l97 Ymjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Gj+Y/6VXeJ+r0pgecRkRsTt5zcHlqOxutguYUyMKTVU=; fh=xnUE171Vllx0fx6ipOnwMghUt6fK18sSaxZfCDNQyQ4=; b=rnofC2oAPpxqGW/qZLi5/WBO3AEfLMLT+TUHa5/U9EKheb85Qls8LZveICL52XJ/Tp VU4PyLFlp5hD1knisI8ttwNgGbp/QoPsAyQA44oA7BmE4yDxPwX5dK5t6xhJemzwOzBc h+4iow/SJyfO598V6JGVvq/t6iYXqSU9DeRI14uFtdE6OiD90guOcYF61rxdFIdbQhMl frRn9+WhdIHbydx7+lmNsjVII2WaRZG/hsT1AsF/3S/EWQZig7AV0npE/U/5wHPfpiWw 6TGgOuYmHrmxvvaH6IE97+/y+DFnfNJwTQJCi72SYpAbPbLl9U32DEVDwUuJhrfKcNNz vdDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gr2teot2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l19-20020a170902d35300b001d07f2e166csi717025plk.261.2023.12.02.13.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 13:23:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gr2teot2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D5F878069F1C; Sat, 2 Dec 2023 13:22:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231928AbjLBVWW (ORCPT + 99 others); Sat, 2 Dec 2023 16:22:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231499AbjLBVWR (ORCPT ); Sat, 2 Dec 2023 16:22:17 -0500 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1EAB185 for ; Sat, 2 Dec 2023 13:22:22 -0800 (PST) Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-6d8750718adso857622a34.0 for ; Sat, 02 Dec 2023 13:22:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1701552142; x=1702156942; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Gj+Y/6VXeJ+r0pgecRkRsTt5zcHlqOxutguYUyMKTVU=; b=gr2teot24exISStimGuA6uwZHfe8C8GO9of9Yown0wbJwWfmsXN0HEm+HMYnJHXR0K 9BPA7IobVYUOiNHw64fjIRcAzthG9Yf1rAUaizoN6bbILac2nvdeQFcPYTv/SDRcrsMc aFZviUgx0jG0xlgyeAFQpuaji9Z8HASRtWgFY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701552142; x=1702156942; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gj+Y/6VXeJ+r0pgecRkRsTt5zcHlqOxutguYUyMKTVU=; b=EoQd9olEzaoVLGsKw7FOpT4dBXkHjJu/Uqpb9CXNBflEWmOSlXoYy9xejbODMatSkG fYQSjvs7HUPepiq+lZcPgqBZzioOVFGrLqg2zpGlHWAXOjK4mfWRC614JiiuANqf2T19 xnMryRaEIopMYcPSbJL5/nye5JwxxFUjBrgRepwX3vj9H9N+eztjF31WLPJkQdVdXlTp KD7G08bZn/6rltFTQZvGR29pN6guQz56iwsnEm6KN8Q6ANU0b7PAPnq0sxTmQKLMRhN8 7r1qhhfuWROHK+gP8tbiVME/6hIujQc1C3HnFXrKAUT50slAkfzRviah67k77PygHupx NSHw== X-Gm-Message-State: AOJu0Yy8PN7KgyD4jXtlYXxaNkgXRQnzGha0VF8Ts/8TB0V6JJ97pLrL GnGFexaNpeiobn7R5S9S+cACxw== X-Received: by 2002:a05:6808:309c:b0:3b8:b063:6b8d with SMTP id bl28-20020a056808309c00b003b8b0636b8dmr1923224oib.60.1701552142290; Sat, 02 Dec 2023 13:22:22 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id p10-20020a17090a930a00b002867594de40sm1351802pjo.14.2023.12.02.13.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 13:22:18 -0800 (PST) From: Kees Cook To: "Guilherme G. Piccoli" Cc: Kees Cook , Tony Luck , linux-hardening@vger.kernel.org, Christian Brauner , "Peter Zijlstra (Intel)" , Al Viro , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 1/5] pstore: inode: Convert kfree() usage to __free(kfree) Date: Sat, 2 Dec 2023 13:22:11 -0800 Message-Id: <20231202212217.243710-1-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231202211535.work.571-kees@kernel.org> References: <20231202211535.work.571-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1508; i=keescook@chromium.org; h=from:subject; bh=FqMfSJ9tnf+E4NKsMDABD4Hv9XWcLEDAeeuD1HVeW1g=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBla6AGUcAUjxMoJ6U4X0vLxi+fYt1AWVqAhC5g3 8R9qQmTZrCJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZWugBgAKCRCJcvTf3G3A JqoTD/sEQ48wmQkFhwAOp4TsKfq+vZmWkT5yfGDyxOQ2ucZIBmBzGRljVmzMiuznpXr3hR6RMn6 CI5L7iPa+hQEPuuIdH4ULzOkZKlNGhNWGY6qT/NysWagTanA2+tPygJoTDa3shFPV8Qg/ktXOmA EzaYBnYM32d95qHxY+O7UzeQQHZ+L8mW0w+7Pi4LnpbaEdoxc66d/yrcVqkNxC51p/VeozU/deM rk5C2MNd7/VwWxOqHlp1SIiA899X4IXHIaMopuLi/lfj5TGjWQYSw89mtkk3p/zmCoxe0za6uqJ 5EkmLzOEZ5XC2P4LS/bWhBwNEzOv4Jy7tDzYhbi37IkEM5XnLTEoVRCAB66Swzv/2WOGDhqh3rK IWicrRHiv496Kk7nhiqTyyIQ7vTvoRxCEcarCa+abBlzBe1hcVZa3QWkzGBJyXCYxo8Eqh+vspr 9GNiGEtp4IHwd4bDA7xIm+m36TXHvQTk31FKlch+AdsiZpHPZwxRZ7uslC2pmtV8uCcqoa+MEOQ HeLGQpB9Lheyc3q0B2RPlcqX4RCXu1MzGSJV446zBw7SUb5C/OD4rMGYlzWCHvuMwBVo9ScPTLY Yvnc9q7XkjLRd9JF0+Bf3QSnvRXDIn8bk1Sv2zb2M11q84weUwdkEaxXXSh3/8kBccf3Vc0s6fO bwrQdBKoi0BSe6w== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 02 Dec 2023 13:22:46 -0800 (PST) Mostly as an example to myself, replace a simple allocation pattern with the automatic kfree cleanup features now exposed by cleanup.h. Cc: "Guilherme G. Piccoli" Cc: Tony Luck Cc: linux-hardening@vger.kernel.org Signed-off-by: Kees Cook --- fs/pstore/inode.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index d41c20d1b5e8..20f3452c8196 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "internal.h" @@ -64,7 +65,7 @@ static void free_pstore_private(struct pstore_private *private) static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos) { struct pstore_private *ps = s->private; - struct pstore_ftrace_seq_data *data; + struct pstore_ftrace_seq_data *data __free(kfree) = NULL; data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) @@ -72,13 +73,10 @@ static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos) data->off = ps->total_size % REC_SIZE; data->off += *pos * REC_SIZE; - if (data->off + REC_SIZE > ps->total_size) { - kfree(data); + if (data->off + REC_SIZE > ps->total_size) return NULL; - } - - return data; + return_ptr(data); } static void pstore_ftrace_seq_stop(struct seq_file *s, void *v) -- 2.34.1