From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B88D33D3CF4 for ; Tue, 4 Aug 2026 08:43:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785832982; cv=none; b=YgRrfvdF8vWcnrkDROgSAWJzjNyNwGRLRM6gxQeuHyXOnyChgGQlNBHcfTe4/qiIxQvHbxeq4Hds3k/3+4dZAXmsa6udnYZVt8wnXOUA+qSvihqxS1xM1kHDcAjiakD9WiIE7V+AsWnZwwT9UVWk3Id1bu7v6tnb1wbRv6Cu+ac= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785832982; c=relaxed/simple; bh=6TLC9/7ZoU9gYJEbBF5hXMTDlsm/DxMOhd7D4Yi4qP8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=tSCuN90Sxo79gsI98EGO5WNN9U3LrLhZZpBlYIuZTHLftVrE9gIIwRhR/+kjaxjs4sOSiD7sVnotaL8cJMP6HQvsaUI41QmSNiSXENKJBLk2HIoFYXP4DaS3OveKvHYahfEbJ509VTH6IAby/cbyldf344FYhM9pUS9+ZPwiiJM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=AOB4ewC2; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="AOB4ewC2" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-490cf322ed0so17123085e9.1 for ; Tue, 04 Aug 2026 01:43:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1785832979; x=1786437779; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=jbldVeeF/KP7W3Olw45BNCoavqWALya2eVZqAm3Zd6k=; b=AOB4ewC2a1Yq7dVc90+FBvOuE3hzctE/+ZkWAPZKaZ3n9jwBTebc8HGri2X+OGdoxz 3epvpQU4xlWhDKU09/dpYmlwD/sbOm2w1cpieT3HqesD/UhRQx5CGDHHhVLFEI4f0YUo I1fNWOLE1JgF1Ye5YKh41ugj5EXtzRr+uOoLVTS4z2UpWGqqqJggHVtFzYo1yVWOBdNC UgF+l/VjLHqhCOFrW8bd6UKRDmEx9Qyvl0QCrrL8LYvBSisWD25lUaDux4OHJ2f/hONk z429d3jS+k+XjyisSAta/g8kf4gmX+8zW0rwWEQqXzXlq1FHo5EFmulfNxEot6LBPj/V 0U9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785832979; x=1786437779; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=jbldVeeF/KP7W3Olw45BNCoavqWALya2eVZqAm3Zd6k=; b=QNNzdh2ATwMzk6/haK/vjerzsgS48vma/cSFaWXbIwJSDNriPecCeLaNRM+MfGOYkz bOZUN+zY6EnGMgcpTCu2zHvOAzd9kAhROYbrOAO/CoAu0fgGKUV4Qmb2uSCFIeRL8evo D1iVllOftGP9B/5aud/gOY7f66A7F0acwrnb5yUrUPLH3J3ZJ5O5jlJJm3J65yTmgn9/ cWnSnLjmdt7GDQPxb/NQBSn9slVB8U2/n/t6NIauqq6MftRyyyNKD1QeJIkgbvmjtfEH qD44mJlkAFKptiT4MJaaCGYQAwd5KzBJPOJ9sUTOYgtceileMwHrLQX3BGjjdjbPNlIP wBrg== X-Forwarded-Encrypted: i=1; AHgh+RrFKQ/Jcwa3yn0b854QaqxTw7JUfW/R/gRe06IUjsHxdQ+Z7ewhzs5l31bBo2z2s4lKlcbzYAX9ydAASPA=@vger.kernel.org X-Gm-Message-State: AOJu0YzBbzSqeUFhOHS3bQECkJWV9nPYREXT9gtGfM/lWgcwKGSN/CVi lEMLrbxpJTwWSmICrUTag6lrwAGm3zsKh4EE6p/WLnzle3B88k0MsJ0FKum4Kz/Ojdw= X-Gm-Gg: AR+sD10VLwDcpPczD54A/WUmi61rd87cCUZChd/MD0trl/+bW//+ETkFryyzIjhOo2o /xEMLJr3rejrAmeNQgVD2unEHxbJxuoGBsECvVmmd3L+4scWB4tSt2p8kuaQChSlLijlocbhcIz aHuXV786s+huapeeJev+sqg1SPk9xR8lnDBhZBLvXKAR94mPxMJq4IrkQE4ddClUh9xBo8FuFQb PpXDAKUyE7kijJI1lvEvCwSuEZbvb+oFmG8mWJ1nTM4+7evdwnyzIaOk/Ce6vK/etzPyfNeJCdZ Hsp/Q/f5ZO+D187bLMsbAgRkOeIH7JSqRJ1A/8P6uit42MlHbZcRwlpEeFklbrOMYD+Fxa8IxNm 89KruhuBeNy118UYJB1aC2MfpkFFS+fUpBi2rCF6SXKYWWiZkNN91ohHBnGOa5+YxjdVsq353lS sVOQPaltfvIqMgPh0lXWzyTpjvVzUQ+JoUU2o8IzDsLrfNGAu5WEJ7FTluUNqQUDYZbCmzazbqL zYJCExHbH620VGe46J+csesHg== X-Received: by 2002:a05:600c:4e89:b0:495:5e3d:15e1 with SMTP id 5b1f17b1804b1-4980c6788f8mr270438195e9.16.1785832978799; Tue, 04 Aug 2026 01:42:58 -0700 (PDT) Received: from ?IPV6:2a07:de40:8100:0:fc6c:f9a2:4a0a:6354? ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47fd45a1240sm40009708f8f.36.2026.08.04.01.42.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Aug 2026 01:42:58 -0700 (PDT) Message-ID: <8d507b50-b5a2-48a8-a4bb-f196ac28b5e4@suse.com> Date: Tue, 4 Aug 2026 10:42:57 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] module: fix UAF and GPF in idempotent_init_module via heap allocation To: Mingyu Wang <25181214217@stu.xidian.edu.cn> Cc: Luis Chamberlain , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Johan Hovold , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20260717082601.81704-1-25181214217@stu.xidian.edu.cn> Content-Language: en-US From: Petr Pavlu In-Reply-To: <20260717082601.81704-1-25181214217@stu.xidian.edu.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 7/17/26 10:26 AM, Mingyu Wang wrote: > During concurrent module loading (e.g., triggered by syzkaller), the > idempotent module loading mechanism uses a local stack variable > (`struct idempotent idem`) to track the state of waiters. > > If a task executing idempotent_init_module() is abruptly terminated > (e.g., killed by a fatal signal or otherwise completely exits before > reaching the list cleanup paths) after adding its node to the global > `idem_hash` list, its kernel stack is prematurely freed and reclaimed. I'm confused by this description and I'm not sure what problem the patch is trying to solve. A task is not normally terminated in the middle of a syscall. This could happen only if it hits an oops. However, that means there is an earlier bug and the module loader isn't expected to be resilient to a post-oops state. Could you clarify the scenario that you ran into? -- Thanks, Petr > > However, the stack-allocated node remains linked in the list. Subsequent > module loading attempts that traverse the list will dereference this > stale stack pointer, leading to KASAN slab-out-of-bounds reads and > General Protection Faults (GPF): > > BUG: KASAN: slab-out-of-bounds in idempotent_init_module+0x54a/0x620 > Read of size 8 at addr ffff888106367df8 by task modprobe/433 > ... > The buggy address belongs to the object at ffff8881063676c0 > which belongs to the cache shmem_inode_cache of size 1392 > ... > Oops: general protection fault, probably for non-canonical address > > Fix this by dynamically allocating `struct idempotent` on the heap > via `kmalloc_obj()`. This decouples the list node's lifespan from the > process stack, ensuring that even if the task is abruptly terminated, > the global list safely points to valid heap memory until properly > unlinked, preventing memory corruption. > > Fixes: 9b9879fc0327 ("modules: catch concurrent module loads, treat them as idempotent") > Cc: stable@vger.kernel.org > Signed-off-by: Mingyu Wang <25181214217@stu.xidian.edu.cn> > --- > kernel/module/main.c | 24 ++++++++++++++++-------- > 1 file changed, 16 insertions(+), 8 deletions(-) > > diff --git a/kernel/module/main.c b/kernel/module/main.c > index 46dd8d25a605..39f05ac4b1a1 100644 > --- a/kernel/module/main.c > +++ b/kernel/module/main.c > @@ -3779,21 +3779,29 @@ static int init_module_from_file(struct file *f, const char __user * uargs, int > > static int idempotent_init_module(struct file *f, const char __user * uargs, int flags) > { > - struct idempotent idem; > + struct idempotent *idem; > + int ret; > > if (!(f->f_mode & FMODE_READ)) > return -EBADF; > > + idem = kmalloc_obj(*idem, GFP_KERNEL); > + if (!idem) > + return -ENOMEM; > + > /* Are we the winners of the race and get to do this? */ > - if (!idempotent(&idem, file_inode(f))) { > - int ret = init_module_from_file(f, uargs, flags); > - return idempotent_complete(&idem, ret); > + if (!idempotent(idem, file_inode(f))) { > + ret = init_module_from_file(f, uargs, flags); > + ret = idempotent_complete(idem, ret); > + } else { > + /* > + * Somebody else won the race and is loading the module. > + */ > + ret = idempotent_wait_for_completion(idem); > } > > - /* > - * Somebody else won the race and is loading the module. > - */ > - return idempotent_wait_for_completion(&idem); > + kfree(idem); > + return ret; > } > > SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags)