Linux-Clk Archive mirror
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
	Russell King <linux@armlinux.org.uk>,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>
Subject: [PATCH] clkdev: fix potential NULL pointer dereference
Date: Tue,  7 May 2024 08:44:34 +0200	[thread overview]
Message-ID: <20240507064434.3213933-1-m.szyprowski@samsung.com> (raw)
In-Reply-To: CGME20240507064445eucas1p1bfc17da4f824ef46567774634482f12f@eucas1p1.samsung.com

dev_fmt argument is optional, so avoid dereferencing it unconditionally.

Fixes: 4d11c62ca8d7 ("clkdev: report over-sized strings when creating clkdev entries")
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---

This fixes the following kernel panic observed on Samsung Exynos542x
SoCs family:

8<--- cut here ---
Unable to handle kernel NULL pointer dereference at virtual address 00000000 when read
[00000000] *pgd=00000000
Internal error: Oops: 5 [#1] PREEMPT SMP ARM
Modules linked in:
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 6.8.0-00001-g4d11c62ca8d7 #14975
Hardware name: Samsung Exynos (Flattened Device Tree)
PC is at vsnprintf+0x4c/0x3c8
LR is at init_stack+0x1dd6/0x2000
pc : [<c0c09d3c>]    lr : [<c1301dd6>]    psr: 800000d3
...
Flags: Nzcv  IRQs off  FIQs off  Mode SVC_32  ISA ARM  Segment none
Control: 10c5387d  Table: 4000406a  DAC: 00000051
...
Process swapper/0 (pid: 0, stack limit = 0x(ptrval))
Stack: (0xc1301c70 to 0xc1302000)
...
 vsnprintf from va_format.constprop.0+0x70/0x160
 va_format.constprop.0 from pointer+0x454/0x670
 pointer from vsnprintf+0x228/0x3c8
 vsnprintf from vprintk_store+0x100/0x428
 vprintk_store from vprintk_emit+0x6c/0x328
 vprintk_emit from vprintk_default+0x24/0x2c
 vprintk_default from _printk+0x28/0x4c
 _printk from vclkdev_alloc+0xf0/0x110
 vclkdev_alloc from clkdev_hw_create+0x28/0x88
 clkdev_hw_create from clk_hw_register_clkdev+0x38/0x3c
 clk_hw_register_clkdev from samsung_clk_register_fixed_rate+0xa4/0xd4
 samsung_clk_register_fixed_rate from exynos5x_clk_init+0xf0/0x2b0
 exynos5x_clk_init from of_clk_init+0x15c/0x228
 of_clk_init from time_init+0x24/0x30
 time_init from start_kernel+0x4b8/0x620
 start_kernel from 0x0
Code: e09e9001 e1a05002 e28da01c 2a000086 (e5d50000)
---[ end trace 0000000000000000 ]---
Kernel panic - not syncing: Attempted to kill the idle task!
---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---

Best regards
Marek Szyprowski, PhD
Samsung R&D Institute Poland
---
 drivers/clk/clkdev.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index ddacab7863d0..d2801ae70e34 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -194,10 +194,12 @@ vclkdev_alloc(struct clk_hw *hw, const char *con_id, const char *dev_fmt,
 	return &cla->cl;
 
 fail:
-	fmt.fmt = dev_fmt;
-	fmt.va = &ap_copy;
-	pr_err("%pV:%s: %s ID is greater than %zu\n",
-	       &fmt, con_id, failure, max_size);
+	if (dev_fmt) {
+		fmt.fmt = dev_fmt;
+		fmt.va = &ap_copy;
+		pr_err("%pV:%s: %s ID is greater than %zu\n",
+		       &fmt, con_id, failure, max_size);
+	}
 	va_end(ap_copy);
 	kfree(cla);
 	return NULL;
-- 
2.34.1


       reply	other threads:[~2024-05-07  6:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20240507064445eucas1p1bfc17da4f824ef46567774634482f12f@eucas1p1.samsung.com>
2024-05-07  6:44 ` Marek Szyprowski [this message]
2024-05-07  9:34   ` [PATCH] clkdev: fix potential NULL pointer dereference Russell King (Oracle)
2024-05-07 16:42   ` André Draszik
2024-05-07 17:58     ` Russell King (Oracle)
2024-05-08 20:52   ` Sam Protsenko

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=20240507064434.3213933-1-m.szyprowski@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).