From patchwork Tue May 7 06:44:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 13656326 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB325C10F1A for ; Tue, 7 May 2024 06:45:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:References:MIME-Version:Message-Id:Date :Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: List-Owner; bh=VgKEO6G5M8BXiy6IUZtr5gIlRhrz8i+B1NIW4EQ5ApM=; b=jPct0mDDrU5aKL q5exzJs/N/s/RY+BTorxVngipkCeCRj87m21b+GHh4Y7bRG4o5HMnrDyvEqDKi4CSHofNGgwcQIbe KeuOZlQN/L+SXGp6U0YPvFUXbeHjFd3wsvKUWRmbnlf5vPKnvJE7ai8X6erPyTSTUt0J2bbjvLjjh s+7LAMOH2Es0Ej0FdyNc7Li+qTVYh1ltrNqkMkzyz8XTDgTuCtsnXLCvN05TbATltnvYHeIQrbyi5 JHq6qIzhJefq+LKtKRqgXurzyraZ9WnKmiaUsBVGO7D3Z6q2bN2BvdhbjTw+Xcbx9YC4QDiRCpyfE zFzgAFPEoPY0mlsGrv9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4EZO-00000009sae-0b4p; Tue, 07 May 2024 06:44:58 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4EZJ-00000009sZ6-09L5 for linux-arm-kernel@lists.infradead.org; Tue, 07 May 2024 06:44:55 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240507064446euoutp02d35ee3add300cf70c68c4fec4fd18eb8~NIeG0m0Mk2430124301euoutp02E for ; Tue, 7 May 2024 06:44:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240507064446euoutp02d35ee3add300cf70c68c4fec4fd18eb8~NIeG0m0Mk2430124301euoutp02E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715064286; bh=ihBifNfNyNRL0omOGoA7M6GHq/5MHdBh1bGVpG9xKZ4=; h=From:To:Cc:Subject:Date:References:From; b=Q/TNNkzHFq2zSySNEApGAX/2lUW10ua+mACP4COx20+7WTA4wBY/SsGOt0t59NFxQ gIqH5YLH21qYd8TYQhatRhrNNvIe1PG8Bo3bhMVMttiIb/Zz0bjCWDvwW8Au+AKocO VfuOBoF0k89pTTkY0NuFZKrD3FZVdZgIc01PwfEk= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240507064445eucas1p2d506f698369c8b112c4e2bec500e492f~NIeGbY_n90938309383eucas1p2U; Tue, 7 May 2024 06:44:45 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id EC.9D.09624.DDDC9366; Tue, 7 May 2024 07:44:45 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240507064445eucas1p1bfc17da4f824ef46567774634482f12f~NIeGL8hiY3062730627eucas1p1Q; Tue, 7 May 2024 06:44:45 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240507064445eusmtrp28ab9f5c768f66e26c2a4b57a7f10f720~NIeGLS-sI2837728377eusmtrp2b; Tue, 7 May 2024 06:44:45 +0000 (GMT) X-AuditID: cbfec7f2-c11ff70000002598-90-6639cddd8258 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 78.33.09010.DDDC9366; Tue, 7 May 2024 07:44:45 +0100 (BST) Received: from AMDC4653.digital.local (unknown [106.120.51.32]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240507064445eusmtip1792a0627ab86b07a87c5651e264d07d0~NIeFxK4Fq0479904799eusmtip1n; Tue, 7 May 2024 06:44:45 +0000 (GMT) From: Marek Szyprowski To: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Russell King , Michael Turquette , Stephen Boyd Subject: [PATCH] clkdev: fix potential NULL pointer dereference Date: Tue, 7 May 2024 08:44:34 +0200 Message-Id: <20240507064434.3213933-1-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprOKsWRmVeSWpSXmKPExsWy7djP87p3z1qmGcx9b2ax6fE1VouPPfdY LS7vmsNmcWjqXkaLtUfusltcPOVq8e/aRhYHdo/L1y4ye7y/0crusWlVJ5vH5iX1Hn1bVjF6 fN4kF8AWxWWTkpqTWZZapG+XwJVxfPVhloJnohUfXt9jbWCcLtTFyMkhIWAi0fb7OFMXIxeH kMAKRok1O9+xQDhfGCW+9FxmhXA+M0pcffOODabl6dEOqJbljBKXv19ihmuZ/GISI0gVm4Ch RNfbLrAOEYFkiQtfvoPNZQbpeH39LytIQljAXqLz/01mEJtFQFWi68c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yEienNbBC 2MISf651sUEUfWKUuH7jFzNIgk3AUKLrLUiCk0NEIFVi/9GX7CBFzAIrGSXuzL8M1i0sYC/R +f8mWAOLgKpE1495YBt4geIrr99lhNggL7H/4FlmiLigxMmZT1hAbGagePPW2cwTGPlmIUnN QpJawMi0ilEktbQ4Nz232EivODG3uDQvXS85P3cTIzDYtx37uWUH48pXH/UOMTJxMB5ilOBg VhLhPdpunibEm5JYWZValB9fVJqTWnyI0RTovonMUqLJ+cB4yyuJNzQzMDU0MbM0MLU0M1YS 5/Us6EgUEkhPLEnNTk0tSC2C6WPi4JRqYLI/OdHUJfF4hNz1K3+LHjyYWSwSKVexvkjq8K0b Scrbnsu0BXA9XZzz1vDg4YREGxejBVz1fVcFLJNvcx/2vPNFueV/gHzbHSfV1T+W8Te9ELkZ wPAv4egiV3OFzjbmrAV+a9663p98c1L8d9G5W1ceKP2yrfTvix+nvn3h0ffmZrn4/EnHaS9n B7n23bMPTY0QusPYcSe0VNBr05npErybjqoLlv9rXJwos/WAFNONDedPxu4xbc/KfDxv6tXL bcGyiSaHSiLu7F9vFpmY9Htd8bOi24+/XrCtVzWvM/TzKJTQdeWTfSNu4vq7z9U/7cCs664L fnPK6lRx/m1La2w567L31t9na6Xrg17ntCixFGckGmoxFxUnAgD/eMoY/wIAAA== X-CMS-MailID: 20240507064445eucas1p1bfc17da4f824ef46567774634482f12f X-Msg-Generator: CA X-RootMTR: 20240507064445eucas1p1bfc17da4f824ef46567774634482f12f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240507064445eucas1p1bfc17da4f824ef46567774634482f12f References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240506_234453_749492_8563CDEB X-CRM114-Status: GOOD ( 15.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Sam Protsenko Tested-by: Sam Protsenko --- 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 : [] lr : [] 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;