From nobody Mon Jun 8 05:25:28 2026 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 7E5252F25F5 for ; Tue, 2 Jun 2026 00:26:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780359982; cv=none; b=TC2jq4e6z0aN6IZWPL8cE9p1nzwRorQOHvc4WVI6Tm+ALOCB82yEOE1sWa4l9bnYfLEz7FfJh/vDB7beM9gqWKjXY/Kksp5EPcb++0iG3pwgxcKnEuiw9jUR+yzbosbRdM1+kSyXjeyHkQ77NFt5UUu5sGuVCSrAJfD0lWgIpNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780359982; c=relaxed/simple; bh=+Noov5hc3CKOChyUBI5LBTPPkRxfbl8Xb8rJdBUuyF0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Vr495jNwF1pVm6reF97j+gY7jomuvHlQJy0RJfs6Y6a2RsVjydVA4Uqqxe/a+4YP01PxQhfATq9C0WYS1RvoKkEc939w+HFxJvCahuWalGgJfYquaVZWIxR7zxjCY/Jx19duGH6NVHE1F4IOIOZMrj7jtZO6szvhIUhI9kxdR3M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bVrVRu2w; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bVrVRu2w" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-8423f869421so1341863b3a.3 for ; Mon, 01 Jun 2026 17:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780359975; x=1780964775; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=LOY92BXaD5vIhUlApxku9SLm44StQ5oPQUpOHpXHWq0=; b=bVrVRu2wW7s0dKyGfgzv1sgQ2OndsOIGqAQwgEmiNtUTEY8YTwlNVvA85kyj/mYBKf H0TfjLLwWKpJltZTkoPfrblWfJZko2VoYBJvY2iKrW68WGvFQzojXve23o05KOIsj8co +ZxS57kO1TXsSPPNdfu1vrKWaUYGOKPLoNcE/Wtf1H0MsS9gTm3vgXl+Ex1hTCjcGiva VzR+6AxoFi4kzSewvp6KlF3XflwtY4+e7XMtUppEcSVRDOjhh5cR3NoyNXGS7NCkC1HY W+o3EMTZhKpOISSE8Bz7DPo2RY7KdYkbmUm8JLdSCbD8mm5na/5LWXKcVuZZlJm5hrqg mgRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780359975; x=1780964775; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LOY92BXaD5vIhUlApxku9SLm44StQ5oPQUpOHpXHWq0=; b=FJWvZk8g80tYBH2Aauy/qTFQetumKbxRDFPRslc7p6T39WZxZIq0Z4b+8tlyGvUZH3 Jkuhrs3Ur3d4tVRM68UBXxPOcPjTOfPAhDgqzaLmNK7vSC7RgeOkAoKBAMqLxCebkwIi Oeb092kKaKdEPMts1Xkd4kSlWTvD74rsv1crVV+CxzgDBgurD9QGH2nuk390/GDCJtBs XSmINvApXc/LEAsi3/BJolqoe8Kh4w3KU0yOwcQU4fLsZ6lpeSfTePOluxqIuYdpgFGP /AiRCkxLbu+SjHRUOlIkKzBwjW2PUoKNg/lQkdxoxkjoqzkG64S65e5g6EukhZatBaHZ 16ag== X-Forwarded-Encrypted: i=1; AFNElJ8tH50GXe37jufV94kxDzQSRuhhFImVECQMpfwO5M6pAadW4I+TbiNzb2TpIhIybK2Z+IPTpLDzQkEIoqQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxogfhkkNhoUS/F4Z4S6bHTUQre0vdNMwzb1j2jQvxzmfmdD1a+ IPYHgPyuFCZMD+6GLckJyYMd2ktTJxXBHXCBTiQtdw4A95crIF4sZdyi X-Gm-Gg: Acq92OGD2jgNnQrVO5ssBRBhclG6n0dCqBuWA06jpyPiEKdY3mR/4jgtAl7SZODED5V eef8h5EVDptEOo7kKq4PyewIqOTbm5xlfHFf4DO0pYoRNXeXLDHHXWOH+lW01E5pB9KUP4Opo7Z 2tjX12oFo0JlDcgRtfxyFA7evtQ0YRrxQcDQWqQGCSmZOXR8L1Wvud8lwTB49mkgz3Baxyg8pUa S/Fp6aqXeKIoiSjdkPvfK5gBx0hTSZiNr7j5tHExeDmQW2fRgO0VjGhkoVXPkyct01+fi4R5+pB dBQfL39lMs2J5P6lusd+46dHUA2JZ64rt+bANMABhpiDBcCPeHY5AMQau4cniojDs8Ws2QJJOsX 7iCb9rDoAhw0Rx3HBSkbMAqYPyXOTAt+W5WIbX0bspLxZdAqVy7RVLqnKKQnu49Sq2LqNmuFKCN WvXsOSe2rMi0eENeQXpvaWXpUgBb/XJNdumqzSYaW+97AbW7bq56EME+CX+SuODww5HTS6OTTr9 EPWuW7MP9EAdAsYDg== X-Received: by 2002:a05:6a00:1ad0:b0:842:54e8:bdd with SMTP id d2e1a72fcca58-84254e80ed5mr5731304b3a.40.1780359975442; Mon, 01 Jun 2026 17:26:15 -0700 (PDT) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:383f:9be2:13da:1be0:a11a]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84246844780sm5603702b3a.30.2026.06.01.17.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2026 17:26:14 -0700 (PDT) From: Deepanshu Kartikey To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz Cc: mjguzik@gmail.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Deepanshu Kartikey , syzbot+36e50496c8ac4bcde3f9@syzkaller.appspotmail.com Subject: [PATCH] fs/namei: fix UAF in pick_link() by unlazying before atime check Date: Tue, 2 Jun 2026 05:56:07 +0530 Message-ID: <20260602002607.110866-1-kartikey406@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In pick_link(), atime_needs_update() is called while the path walk may still be in RCU mode (LOOKUP_RCU set), meaning no reference is held on the inode. A concurrent iput() from another task can free the inode while atime_needs_update() reads inode->i_opflags (offset +2) inside current_time() -> is_mgtime(), causing a use-after-free. KASAN reports: BUG: KASAN: slab-use-after-free in is_mgtime include/linux/fs.h:2313 Read of size 2 at addr ffff8880407e4282 (offset +2 =3D i_opflags) The race: Task A (pick_link) Task B (unlinkat) ------------------ ----------------- atime_needs_update(inode) iput(inode) current_time(inode) evict() is_mgtime(inode) destroy_inode() inode->i_opflags UAF inode FREED Fix: call try_to_unlazy() before atime_needs_update() so that a proper inode reference is held before any inode fields are read. If try_to_unlazy() detects the inode is already gone, it returns false and we exit safely with -ECHILD without touching freed memory. Fixes: e45960c279b098ebc0c2 ("fs: unconditionally use atime_needs_update() = in pick_link()") Reported-by: syzbot+36e50496c8ac4bcde3f9@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D36e50496c8ac4bcde3f9 Tested-by: syzbot+36e50496c8ac4bcde3f9@syzkaller.appspotmail.com Signed-off-by: Deepanshu Kartikey --- fs/namei.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index c7fac83c9a85..eac0ec35be37 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2037,11 +2037,11 @@ static noinline const char *pick_link(struct nameid= ata *nd, struct path *link, unlikely(link->mnt->mnt_flags & MNT_NOSYMFOLLOW)) return ERR_PTR(-ELOOP); =20 + if (nd->flags & LOOKUP_RCU) { + if (!try_to_unlazy(nd)) + return ERR_PTR(-ECHILD); + } if (unlikely(atime_needs_update(&last->link, inode))) { - if (nd->flags & LOOKUP_RCU) { - if (!try_to_unlazy(nd)) - return ERR_PTR(-ECHILD); - } touch_atime(&last->link); cond_resched(); } --=20 2.43.0