From patchwork Wed Sep 15 13:19:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 12496241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECCC5C433EF for ; Wed, 15 Sep 2021 13:19:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9B2A661263 for ; Wed, 15 Sep 2021 13:19:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9B2A661263 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 44C406B0072; Wed, 15 Sep 2021 09:19:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FC396B0073; Wed, 15 Sep 2021 09:19:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EBD2900002; Wed, 15 Sep 2021 09:19:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0115.hostedemail.com [216.40.44.115]) by kanga.kvack.org (Postfix) with ESMTP id 1D3AC6B0072 for ; Wed, 15 Sep 2021 09:19:41 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 217512D009 for ; Wed, 15 Sep 2021 13:19:40 +0000 (UTC) X-FDA: 78589864920.21.EB5D38E Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf09.hostedemail.com (Postfix) with ESMTP id BEDBC300010B for ; Wed, 15 Sep 2021 13:19:39 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id C7A2D61251; Wed, 15 Sep 2021 13:19:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631711979; bh=tjYE+w+hVKFuNE7M94ifyu2S6XUIpnaX8UMLFXe0coU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZDqe1aTewpyN1tOX6hRfENmOnA173xBNFs6FcoacqVZAkQXpAcvWkHaKX8DHxv2Of xjwNkN425Ir3TvSrHGGely0P6g/Jm651RKRuyx6KLk8dC0b9TbLVz72VkfMwwQxjKa 7gws47GEnK9Z4PG74cQi3cpMqgH1seBf8cTKUwoWOLI9/6EqgzmMEko1rK3sTwMZAi kNHNZbBB86t523s64ZgrwPYutlSnJiOmvU13LfYOoTDX7KjkvOpKXDc5yWfWF7dKGh gQCSD/7/s/IRICnj4RfeShEj4OzkrIOeRsgi4qYmAitcE34L/jhR/B4cxYh3t9+ama nh9YDdRRZAsQw== From: Masami Hiramatsu To: Steven Rostedt Cc: Linus Torvalds , Mike Rapoport , Andrew Morton , LKML , Ingo Molnar , Masami Hiramatsu , Linux-MM , Vlastimil Babka Subject: [PATCH v3 1/3] bootconfig: init: Fix memblock leak in xbc_make_cmdline() Date: Wed, 15 Sep 2021 22:19:36 +0900 Message-Id: <163171197599.590070.10960384725563297226.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163171196689.590070.15063104707696447188.stgit@devnote2> References: <163171196689.590070.15063104707696447188.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZDqe1aTe; spf=pass (imf09.hostedemail.com: domain of mhiramat@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Stat-Signature: meqts8bku7n1diukejkxnircu6fo195d X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: BEDBC300010B X-HE-Tag: 1631711979-873998 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Free unused memblock in a error case to fix memblock leak in xbc_make_cmdline(). Fixes: 51887d03aca1 ("bootconfig: init: Allow admin to use bootconfig for kernel command line") Signed-off-by: Masami Hiramatsu --- init/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/init/main.c b/init/main.c index 3f7216934441..0b054fff8e92 100644 --- a/init/main.c +++ b/init/main.c @@ -382,6 +382,7 @@ static char * __init xbc_make_cmdline(const char *key) ret = xbc_snprint_cmdline(new_cmdline, len + 1, root); if (ret < 0 || ret > len) { pr_err("Failed to print extra kernel cmdline.\n"); + memblock_free_ptr(new_cmdline, len + 1); return NULL; } From patchwork Wed Sep 15 13:19:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 12496243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E0ABC433F5 for ; Wed, 15 Sep 2021 13:19:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 29F8A61263 for ; Wed, 15 Sep 2021 13:19:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 29F8A61263 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C630C6B0073; Wed, 15 Sep 2021 09:19:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C12C46B0074; Wed, 15 Sep 2021 09:19:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0229900002; Wed, 15 Sep 2021 09:19:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id A18266B0073 for ; Wed, 15 Sep 2021 09:19:48 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3B2282BFC3 for ; Wed, 15 Sep 2021 13:19:48 +0000 (UTC) X-FDA: 78589865256.04.528C3FC Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf06.hostedemail.com (Postfix) with ESMTP id E9787801A8B2 for ; Wed, 15 Sep 2021 13:19:47 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 19FF961261; Wed, 15 Sep 2021 13:19:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631711987; bh=3BaNmCZTv0c11pAEto4TWOw5JJNkPY3QPpJT3D6yH7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DaVKaeSUVggUaGZpLhN9NgxUAwuOe1r79ryv0Ruaz4RIqBWrUUL0PxhWjX5BIcEDD CbqHnMBXHdderNLR5reHA8lZXf4CK01I0bIojQNyIzoqRSqKNfDeWhU0gOp47RosEW 0lf90OJfSeG8Rz5o83cWajuAmL6/jmkC2SRwS4X7gBpFMXgR/oljjlgN2ZpKSH2evb ImFFmrqSLYVFGV+0+/ssNA4nAv5+PpnGdcfqw7oMqlW0wcz2CcIXLEycdMrIZDvZba JFQxUAMAMzOvg29M1/EctL2H3N5hZeQ9PRUWKbXULh3yTS8UVKpzFpv5uBrxLwHB6i 48fqObAGCzq1A== From: Masami Hiramatsu To: Steven Rostedt Cc: Linus Torvalds , Mike Rapoport , Andrew Morton , LKML , Ingo Molnar , Masami Hiramatsu , Linux-MM , Vlastimil Babka Subject: [PATCH v3 2/3] bootconfig: init: Fix memblock leak in setup_boot_config() Date: Wed, 15 Sep 2021 22:19:44 +0900 Message-Id: <163171198422.590070.5414135296244084523.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163171196689.590070.15063104707696447188.stgit@devnote2> References: <163171196689.590070.15063104707696447188.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E9787801A8B2 X-Stat-Signature: aztpgojwci5r7x4n3n8pc189b8whapek Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DaVKaeSU; spf=pass (imf06.hostedemail.com: domain of mhiramat@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1631711987-626422 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Free unused memblock in a error case to fix memblock leak in setup_boot_config(). Fixes: 7684b8582c24 ("bootconfig: Load boot config from the tail of initrd") Signed-off-by: Masami Hiramatsu --- init/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/init/main.c b/init/main.c index 0b054fff8e92..4f059fde1df0 100644 --- a/init/main.c +++ b/init/main.c @@ -459,6 +459,7 @@ static void __init setup_boot_config(void) else pr_err("Failed to parse bootconfig: %s at %d.\n", msg, pos); + memblock_free_ptr(copy, size + 1); } else { pr_info("Load bootconfig: %d bytes %d nodes\n", size, ret); /* keys starting with "kernel." are passed via cmdline */ From patchwork Wed Sep 15 13:19:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 12496245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42D5AC4332F for ; Wed, 15 Sep 2021 13:19:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E7F5B6121F for ; Wed, 15 Sep 2021 13:19:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E7F5B6121F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 8B9E26B0074; Wed, 15 Sep 2021 09:19:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 869656B0075; Wed, 15 Sep 2021 09:19:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 757F5900002; Wed, 15 Sep 2021 09:19:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0188.hostedemail.com [216.40.44.188]) by kanga.kvack.org (Postfix) with ESMTP id 68F3C6B0074 for ; Wed, 15 Sep 2021 09:19:57 -0400 (EDT) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 36F572C59C for ; Wed, 15 Sep 2021 13:19:57 +0000 (UTC) X-FDA: 78589865634.36.AD53B9B Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf08.hostedemail.com (Postfix) with ESMTP id F241D30000B5 for ; Wed, 15 Sep 2021 13:19:56 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id E0F5A61251; Wed, 15 Sep 2021 13:19:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631711996; bh=UpxfRZK8T2RDPLPb11HxaKpLoTbgunj3UUurBaCsjc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V5T0gQuAHHfsocNubOi/llKfWcL+tZueU/clHXUh+2LvVwTuhEMF2F/cFksZWS+lP qyvw+/QFvftdKNxZQfXBYndCXrp8UTLLlgtYYmW2CP1wjNm13z0ZGfp6s92bMACx9D nC9ryzggH3XN+9ga1eHG41AYJOIA2mcs2Z4HQNf5VoRCUpahbKHSb0J94IaDYj+Fp9 RUpmg/pLJ/I0lPeObgHV9o0o9Gt1mEtVZi+Q89uqb8WxRZLuPjWv15VGG4LnrrYHqf DQFXXa1Fe11KU8r+AKypfGS5NonZezvAkW7c4ZYIjYNbJVZ+6wSHeFPapJWP+xRAfm MyKY+G3nsoHXQ== From: Masami Hiramatsu To: Steven Rostedt Cc: Linus Torvalds , Mike Rapoport , Andrew Morton , LKML , Ingo Molnar , Masami Hiramatsu , Linux-MM , Vlastimil Babka Subject: [PATCH v3 3/3] bootconfig: Free xbc_data in xbc_destroy_all() Date: Wed, 15 Sep 2021 22:19:52 +0900 Message-Id: <163171199244.590070.6356174550728998874.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163171196689.590070.15063104707696447188.stgit@devnote2> References: <163171196689.590070.15063104707696447188.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=V5T0gQuA; spf=pass (imf08.hostedemail.com: domain of mhiramat@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: F241D30000B5 X-Stat-Signature: c8qpuwyqsyza3jhf9bnuzhimxrz1xfee X-HE-Tag: 1631711996-571686 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Free xbc_data memory in xbc_destroy_all() with other data. Note that this changes the ownership of the passed bootconfig data. Signed-off-by: Masami Hiramatsu --- lib/bootconfig.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/bootconfig.c b/lib/bootconfig.c index 5ae248b29373..2ba7d945adc9 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -789,6 +789,7 @@ static int __init xbc_verify_tree(void) */ void __init xbc_destroy_all(void) { + memblock_free_ptr(xbc_data, xbc_data_size); xbc_data = NULL; xbc_data_size = 0; xbc_node_num = 0; @@ -810,6 +811,8 @@ void __init xbc_destroy_all(void) * In error cases, @emsg will be updated with an error message and * @epos will be updated with the error position which is the byte offset * of @buf. If the error is not a parser error, @epos will be -1. + * Note that the @buf ownership is transferred, so it will be freed + * in xbc_destroy_all(). */ int __init xbc_init(char *buf, const char **emsg, int *epos) {