From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Haoxiang Li <haoxiang_li2024@163.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Sasha Levin <sashal@kernel.org>,
agordeev@linux.ibm.com, linux-s390@vger.kernel.org
Subject: [PATCH AUTOSEL 6.6 09/16] s390/sclp: Add check for get_zeroed_page()
Date: Thu, 3 Apr 2025 20:06:17 -0400 [thread overview]
Message-ID: <20250404000624.2688940-9-sashal@kernel.org> (raw)
In-Reply-To: <20250404000624.2688940-1-sashal@kernel.org>
From: Haoxiang Li <haoxiang_li2024@163.com>
[ Upstream commit 3db42c75a921854a99db0a2775814fef97415bac ]
Add check for the return value of get_zeroed_page() in
sclp_console_init() to prevent null pointer dereference.
Furthermore, to solve the memory leak caused by the loop
allocation, add a free helper to do the free job.
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
Acked-by: Heiko Carstens <hca@linux.ibm.com>
Link: https://lore.kernel.org/r/20250218025216.2421548-1-haoxiang_li2024@163.com
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/s390/char/sclp_con.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/s390/char/sclp_con.c b/drivers/s390/char/sclp_con.c
index e5d947c763ea5..6a030ba38bf36 100644
--- a/drivers/s390/char/sclp_con.c
+++ b/drivers/s390/char/sclp_con.c
@@ -263,6 +263,19 @@ static struct console sclp_console =
.index = 0 /* ttyS0 */
};
+/*
+ * Release allocated pages.
+ */
+static void __init __sclp_console_free_pages(void)
+{
+ struct list_head *page, *p;
+
+ list_for_each_safe(page, p, &sclp_con_pages) {
+ list_del(page);
+ free_page((unsigned long)page);
+ }
+}
+
/*
* called by console_init() in drivers/char/tty_io.c at boot-time.
*/
@@ -282,6 +295,10 @@ sclp_console_init(void)
/* Allocate pages for output buffering */
for (i = 0; i < sclp_console_pages; i++) {
page = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
+ if (!page) {
+ __sclp_console_free_pages();
+ return -ENOMEM;
+ }
list_add_tail(page, &sclp_con_pages);
}
sclp_conbuf = NULL;
--
2.39.5
next prev parent reply other threads:[~2025-04-04 0:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-04 0:06 [PATCH AUTOSEL 6.6 01/16] pinctrl: renesas: rza2: Fix potential NULL pointer dereference Sasha Levin
2025-04-04 0:06 ` [PATCH AUTOSEL 6.6 02/16] MIPS: cm: Detect CM quirks from device tree Sasha Levin
2025-04-04 0:06 ` [PATCH AUTOSEL 6.6 03/16] crypto: ccp - Add support for PCI device 0x1134 Sasha Levin
2025-04-04 0:06 ` [PATCH AUTOSEL 6.6 04/16] crypto: null - Use spin lock instead of mutex Sasha Levin
2025-04-04 0:06 ` [PATCH AUTOSEL 6.6 05/16] HSI: ssi_protocol: Fix use after free vulnerability in ssi_protocol Driver Due to Race Condition Sasha Levin
2025-04-04 0:06 ` [PATCH AUTOSEL 6.6 06/16] bpf: Fix deadlock between rcu_tasks_trace and event_mutex Sasha Levin
2025-04-04 0:06 ` [PATCH AUTOSEL 6.6 07/16] clk: check for disabled clock-provider in of_clk_get_hw_from_clkspec() Sasha Levin
2025-04-04 0:06 ` [PATCH AUTOSEL 6.6 08/16] parisc: PDT: Fix missing prototype warning Sasha Levin
2025-04-04 0:06 ` Sasha Levin [this message]
2025-04-04 0:06 ` [PATCH AUTOSEL 6.6 10/16] s390/tty: Fix a potential memory leak bug Sasha Levin
2025-04-04 0:06 ` [PATCH AUTOSEL 6.6 11/16] bpf: bpftool: Setting error code in do_loader() Sasha Levin
2025-04-04 0:06 ` [PATCH AUTOSEL 6.6 12/16] bpf: Only fails the busy counter check in bpf_cgrp_storage_get if it creates storage Sasha Levin
2025-04-04 0:06 ` [PATCH AUTOSEL 6.6 13/16] bpf: Reject attaching fexit/fmod_ret to __noreturn functions Sasha Levin
2025-04-04 0:06 ` [PATCH AUTOSEL 6.6 14/16] x86/Kconfig: Make CONFIG_PCI_CNB20LE_QUIRK depend on X86_32 Sasha Levin
2025-04-04 0:06 ` [PATCH AUTOSEL 6.6 15/16] mailbox: pcc: Fix the possible race in updation of chan_in_use flag Sasha Levin
2025-04-04 0:06 ` [PATCH AUTOSEL 6.6 16/16] mailbox: pcc: Always clear the platform ack interrupt first Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250404000624.2688940-9-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=haoxiang_li2024@163.com \
--cc=hca@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®