From patchwork Fri Sep 15 12:36:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 140408 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1016807vqi; Fri, 15 Sep 2023 05:48:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2nEs3u9uPA/qoplo/RXbsyWV6BeKMSZ8Z1v2d666Q5LNfbPCDmTKcb0EpH0GONSDykBRK X-Received: by 2002:a05:6358:7e54:b0:132:d078:9a05 with SMTP id p20-20020a0563587e5400b00132d0789a05mr1774908rwm.14.1694782081624; Fri, 15 Sep 2023 05:48:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694782081; cv=none; d=google.com; s=arc-20160816; b=y5ti+/xO4okJKLvr30XY7QvdhGD2EUfAaJBQbL4CAHRNZx768Q5avY145LWDPVze6F 9hbSWBJMntawHQ/AKc+7DhCxXR9dRYQ8eb/HpMLe5w9z21U9pMUeTgnIWjq0JainrJUo Ag5FJ+sEy/pYFoWgVEl8rsZ6Z/AXgMZujXn+p+AHAuIDuCULipjnXznEEqqsdV8rj1DF XAF/gZqbQPCtu71gT8UzQ/cZHIRXN4SPNlp1uMhkfUEF4DpmyliIJp+hBwwtlUDraAk/ HgiQos4q5qMxWnxxAEmkdFLY5iskKYgo+g0iR7DgHZs2ccGozhNArUrQTMqU4iYrU2W3 xtuA== 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; bh=nnf5oMr/2nfLEUBXk1MP6KaTYPhiFx3zpXxqVQdLfn8=; fh=cAATQBhy3suvhTuuVVrdM7Ka/4SAGu7tDT9Mm2RT6ys=; b=l6zOAhVuabIXCskDl8sJAjnKMyirLE6Ws3uiS8dH7mBdLC3FyHilHptZnHgfnTpeNq RTMOU4Vt8qT18G3Pdq+JjsxUhIBjj79/FRm/q354YCVdtMaQlShBRnSLRs3bdTIlaI4u 8W0B3AxiyaksgiNMfJfYlK96fWKDGA1Ew1TK9l/CESMazSMCavkpbQEmWLo/78WDkLpi 4oDEnpcr8vM3hKW2quMvn4yQiW4aaV7ILcYSFBBZsGejY2VyvA957ens5rmlakd6M9mC 1QzHA/zDLLN2PlcMDgYqglGca0UNXLsaBMEt59U9Rd0rRIct8hzcPOxpLjuVA2O3o9Ug D3cw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id l62-20020a639141000000b00565bcc15ee2si3233432pge.815.2023.09.15.05.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:48:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id C2D82826FB48; Fri, 15 Sep 2023 05:37:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234946AbjIOMhC (ORCPT + 32 others); Fri, 15 Sep 2023 08:37:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234939AbjIOMhA (ORCPT ); Fri, 15 Sep 2023 08:37:00 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 021E019F for ; Fri, 15 Sep 2023 05:36:54 -0700 (PDT) Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RnDBx1L4szVknN; Fri, 15 Sep 2023 20:34:01 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 15 Sep 2023 20:36:51 +0800 From: Jinjie Ruan To: , , , , , , CC: Subject: [PATCH v2 1/2] static_call: Fix a wild-memory-access bug in static_call_del_module() Date: Fri, 15 Sep 2023 20:36:04 +0800 Message-ID: <20230915123605.3732345-2-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230915123605.3732345-1-ruanjinjie@huawei.com> References: <20230915123605.3732345-1-ruanjinjie@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Fri, 15 Sep 2023 05:37:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777107816174380120 X-GMAIL-MSGID: 1777107816174380120 Inject fault while probing btrfs.ko, if the first kzalloc() fails in __static_call_init(), key->mods will all no be initialized in this site and subsequent sites. And then in static_call_del_module() the site_mod->mod will cause wild-memory-access as below. To fix the issue, assign key->mods to NULL in __static_call_init() if it fails. On the other hand, if kzalloc fails, it will just return in init func. Even if static_call_key_sites(key) = true, the exit func will match the mod before the site_mod->next = NULL node is traversed. So just break if it the key->mods is NULL in exit func to avoid wild-memory-access in the subsequent site traversal. general protection fault, probably for non-canonical address 0xeb800159c89f94a0: 0000 [#1] PREEMPT SMP KASAN KASAN: maybe wild-memory-access in range [0x5c002ace44fca500-0x5c002ace44fca507] CPU: 2 PID: 1843 Comm: modprobe Tainted: G W N 6.6.0-rc1+ #60 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 RIP: 0010:static_call_del_module+0x113/0x280 Code: 3c 20 00 0f 85 ef 00 00 00 49 8b 6e 08 48 85 ed 75 0d eb 75 48 85 db 74 70 49 89 ef 48 89 dd 48 8d 7d 08 48 89 f8 48 c1 e8 03 <42> 80 3c 20 00 75 78 48 89 e8 4c 8b 6d 08 48 c1 e8 03 42 80 3c 20 RSP: 0018:ffff888101d3f860 EFLAGS: 00010206 RAX: 0b800559c89f94a0 RBX: 5c002ace44fca4f8 RCX: ffffffffa0210f00 RDX: ffffffffa0210ed4 RSI: ffffffffa0210edc RDI: 5c002ace44fca500 RBP: 5c002ace44fca4f8 R08: 0000000000000000 R09: ffffed10233e4eea R10: ffffed10233e4ee9 R11: ffff888119f2774b R12: dffffc0000000000 R13: 80002ace3cfca4f8 R14: ffffffff85196de0 R15: ffffffff84ee9f99 FS: 00007f4ff6faa540(0000) GS:ffff888119f00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007ffc3d1f19e8 CR3: 0000000109fa6001 CR4: 0000000000170ee0 DR0: ffffffff8faefce8 DR1: ffffffff8faefce9 DR2: ffffffff8faefcea DR3: ffffffff8faefceb DR6: 00000000ffff0ff0 DR7: 0000000000000600 Call Trace: ? __die_body+0x1b/0x60 ? die_addr+0x43/0x70 ? exc_general_protection+0x121/0x210 ? asm_exc_general_protection+0x22/0x30 ? static_call_del_module+0x113/0x280 ? __SCT__tp_func_ipi_exit+0x8/0x8 static_call_module_notify+0x27f/0x390 ? rcu_segcblist_inc_len+0x17/0x20 notifier_call_chain+0xbf/0x280 notifier_call_chain_robust+0x7f/0xe0 ? notifier_call_chain+0x280/0x280 ? kasan_quarantine_put+0x46/0x160 blocking_notifier_call_chain_robust+0x5b/0x80 load_module+0x4d1d/0x69f0 ? module_frob_arch_sections+0x20/0x20 ? update_cfs_group+0x10c/0x2a0 ? __wake_up_common+0x10b/0x5d0 ? kernel_read_file+0x3ca/0x510 ? __x64_sys_fsconfig+0x650/0x650 ? __schedule+0xa0b/0x2a60 ? init_module_from_file+0xd2/0x130 init_module_from_file+0xd2/0x130 ? __ia32_sys_init_module+0xa0/0xa0 ? _raw_spin_lock_irqsave+0xe0/0xe0 ? ptrace_stop+0x487/0x790 idempotent_init_module+0x32d/0x6a0 ? init_module_from_file+0x130/0x130 ? __fget_light+0x57/0x500 __x64_sys_finit_module+0xbb/0x130 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x46/0xb0 Fixes: 9183c3f9ed71 ("static_call: Add inline static call infrastructure") Signed-off-by: Jinjie Ruan --- v2: - Update the fix tag. - Remove the redundant error information. - Update the commit message description. --- kernel/static_call_inline.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/static_call_inline.c b/kernel/static_call_inline.c index 639397b5491c..e7aa70d33530 100644 --- a/kernel/static_call_inline.c +++ b/kernel/static_call_inline.c @@ -256,8 +256,10 @@ static int __static_call_init(struct module *mod, } site_mod = kzalloc(sizeof(*site_mod), GFP_KERNEL); - if (!site_mod) + if (!site_mod) { + key->mods = NULL; return -ENOMEM; + } /* * When the key has a direct sites pointer, extract @@ -422,7 +424,7 @@ static void static_call_del_module(struct module *mod) ; if (!site_mod) - continue; + break; *prev = site_mod->next; kfree(site_mod); From patchwork Fri Sep 15 12:36:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 140412 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1018682vqi; Fri, 15 Sep 2023 05:51:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGsAw0XPO5HKRSLlmdnN01HJ9yIu2jNjz+ntTajDZYoquyraYaiYCf6/89XcVuuteYC++Rl X-Received: by 2002:a05:6a20:7fa6:b0:140:3aa:e2ce with SMTP id d38-20020a056a207fa600b0014003aae2cemr2183331pzj.42.1694782305583; Fri, 15 Sep 2023 05:51:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694782305; cv=none; d=google.com; s=arc-20160816; b=LLWHiEVRXtE6ohelsu7YAFDD6MRPhH78rhRBeGPrVO7Wl6ippHVFvN5fZ78OCTF6Rd qrLwFgX6rQYNyF+4YECHjBUawmLIbEDWiakh4A8ztfCWamHe7qd0zA75cuiW2Ev8W6cE BytpYBoK65heFHBwmeuu5GhTuXurJ9derdvN9gSIvxGSlrkIN5U1aXz8G1JSNyj1WI/4 G/oO1i03IDdYKeZB3GZRXLicpieXcpMwFpDXvvZXtDK3bt5gjIAmbs7CF7KRwHhW/WKw xd0G5SunfDpVtnSeZ0DOT044DqLAO4FfF8DTpyutRRYYJQzoBAFTLtEos3kzXLrorrlE /E3w== 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; bh=7nvJvxacbczi9TPl8D43A9yS+h/82tv+vgHda3TfL7w=; fh=cAATQBhy3suvhTuuVVrdM7Ka/4SAGu7tDT9Mm2RT6ys=; b=ZPgjY1v/YJzfKvTN6y98tV+YrHlRcQ3HwPRTDfoxJrA77UOmIqEvlisKnBq7UiOOZ5 piM7OltTdVa6FlJk2sYSoWUK0nTauq0kkRW8dTOLDXBPmToXzoPjrFuJX294ioe8m8LS 8MYL2QNOXvKFwHZtyKZ1Ws8lshmDfah5XXdMWFxSvpdizWuMVmUv6KdVTX31KhI0+QLC GZfwhSStxHn5CUI3zjntOPrh4AxCNWM48/l4xiG5PQbuotCLUfLtC7n4hEpLWK5GM/ZH BXr3O35BBGstCQUgQJfkDstKtnIZg99sdg+SIOhIo80jwiiYI9yokweYP7hU/vjdK7ja 1BrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ca20-20020a056a02069400b00577f87e6214si3593307pgb.386.2023.09.15.05.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:51:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id F289282BB56B; Fri, 15 Sep 2023 05:37:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234909AbjIOMhP (ORCPT + 32 others); Fri, 15 Sep 2023 08:37:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232706AbjIOMhI (ORCPT ); Fri, 15 Sep 2023 08:37:08 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA62C1A5 for ; Fri, 15 Sep 2023 05:36:58 -0700 (PDT) Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RnD9W4BswztS29; Fri, 15 Sep 2023 20:32:47 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 15 Sep 2023 20:36:56 +0800 From: Jinjie Ruan To: , , , , , , CC: Subject: [PATCH v2 2/2] static_call: Fix a wild-memory-access bug when static_call_key_sites(key) is true Date: Fri, 15 Sep 2023 20:36:05 +0800 Message-ID: <20230915123605.3732345-3-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230915123605.3732345-1-ruanjinjie@huawei.com> References: <20230915123605.3732345-1-ruanjinjie@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS 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]); Fri, 15 Sep 2023 05:37:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777108050543529560 X-GMAIL-MSGID: 1777108050543529560 Inject fault while probing btrfs.ko, when static_call_key_sites(key) is true, if the first kzalloc() succeeds but the second kzalloc() fails in __static_call_init() in the for loop, the key->mods will not be initialized in the subsequent sites. And then in static_call_del_module() the site_mod->mod will cause wild-memory-access as below. So assign key->mods to NULL in __static_call_init() if it fails and break if key->mods is NULL in exit func to fix the issue. Free the just allocated site_mod in key->mods because site_mod->mod will be NULL without a site_mod->mod = mod head node, so it will not be found in static_call_del_module(). general protection fault, probably for non-canonical address 0xfec001628a9f8a82: 0000 [#1] PREEMPT SMP KASAN KASAN: maybe wild-memory-access in range [0xf6002b1454fc5410-0xf6002b1454fc5417] CPU: 2 PID: 1812 Comm: modprobe Tainted: G W N 6.6.0-rc1+ #96 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 RIP: 0010:static_call_del_module+0x11a/0x2a0 Code: 00 00 49 8b 6e 08 48 85 ed 75 14 e9 8c 00 00 00 48 85 db 0f 84 83 00 00 00 49 89 ef 48 89 dd 48 8d 7d 08 48 89 f8 48 c1 e8 03 <42> 80 3c 20 00 0f 85 87 00 00 00 48 89 e8 4c 8b 6d 08 48 c1 e8 03 RSP: 0018:ffff888101e97860 EFLAGS: 00010a06 RAX: 1ec005628a9f8a82 RBX: f6002b1454fc540b RCX: ffffffffa05b1880 RDX: ffffffffa05acd84 RSI: 0000000000000000 RDI: f6002b1454fc5413 RBP: f6002b1454fc540b R08: ffffffffa05adb3c R09: ffffed10203d2eda R10: ffffed10203d2ed9 R11: ffff888101e976cf R12: dffffc0000000000 R13: 68002b144cfe8871 R14: ffffffff851958a0 R15: ffffffff84ee4449 FS: 00007f20cb75f540(0000) GS:ffff888119f00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007ffe945e1bb8 CR3: 000000010c3d6003 CR4: 0000000000170ee0 DR0: ffffffff8faefce8 DR1: ffffffff8faefce9 DR2: ffffffff8faefcea DR3: ffffffff8faefceb DR6: 00000000ffff0ff0 DR7: 0000000000000600 Call Trace: ? __die_body+0x1b/0x60 ? die_addr+0x43/0x70 ? exc_general_protection+0x121/0x210 ? asm_exc_general_protection+0x22/0x30 ? static_call_del_module+0x11a/0x2a0 ? __SCT__cond_resched+0x8/0x8 static_call_module_notify+0x2a6/0x3c0 notifier_call_chain+0xbf/0x280 ? stack_trace_save+0x91/0xc0 notifier_call_chain_robust+0x7f/0xe0 ? notifier_call_chain+0x280/0x280 ? alloc_covered_add+0x30/0x60 blocking_notifier_call_chain_robust+0x5b/0x80 load_module+0x4d1d/0x69f0 ? module_frob_arch_sections+0x20/0x20 ? uprobe_apply+0x100/0x100 ? rwsem_down_write_slowpath+0x11c0/0x11c0 ? kernel_read_file+0x3ca/0x510 ? __x64_sys_fsconfig+0x650/0x650 ? init_module_from_file+0xd2/0x130 init_module_from_file+0xd2/0x130 ? __ia32_sys_init_module+0xa0/0xa0 ? userfaultfd_unmap_prep+0x3d0/0x3d0 ? _raw_spin_lock_irqsave+0xe0/0xe0 idempotent_init_module+0x32d/0x6a0 ? init_module_from_file+0x130/0x130 ? __fget_light+0x57/0x500 __x64_sys_finit_module+0xbb/0x130 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x46/0xb0 Fixes: a945c8345ec0 ("static_call: Allow early init") Signed-off-by: Jinjie Ruan --- kernel/static_call_inline.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/static_call_inline.c b/kernel/static_call_inline.c index e7aa70d33530..a8ade6208237 100644 --- a/kernel/static_call_inline.c +++ b/kernel/static_call_inline.c @@ -274,8 +274,11 @@ static int __static_call_init(struct module *mod, key->mods = site_mod; site_mod = kzalloc(sizeof(*site_mod), GFP_KERNEL); - if (!site_mod) + if (!site_mod) { + kfree(key->mods); + key->mods = NULL; return -ENOMEM; + } } site_mod->mod = mod;