From patchwork Fri Oct 4 13:45:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manas via B4 Relay X-Patchwork-Id: 13822387 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6135FCFA775 for ; Fri, 4 Oct 2024 13:45:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A30956B0402; Fri, 4 Oct 2024 09:45:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B9596B0405; Fri, 4 Oct 2024 09:45:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 859E56B0406; Fri, 4 Oct 2024 09:45:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 63B0C6B0402 for ; Fri, 4 Oct 2024 09:45:56 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 11F43ACF0B for ; Fri, 4 Oct 2024 13:45:56 +0000 (UTC) X-FDA: 82636043112.15.F93E3E1 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id 202E2A0017 for ; Fri, 4 Oct 2024 13:45:52 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kY5smuTo; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of devnull+manas18244.iiitd.ac.in@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=devnull+manas18244.iiitd.ac.in@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728049512; a=rsa-sha256; cv=none; b=57DryN41S9IZ+osXHdRnUMnZ+/8pKQxVbdd+d3bLHGSwXU3bXIH6mujbjXUUmq//hEnoLI 59X76Tsox1o/kY8b3j20aOw5akxflkzhmyPtvoViygVXJnyYTu5WlmFoOLdk9mLifNeMy+ 9yG/zQoZmzg/RrDfqqLR6B/B5Yb3Q2o= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kY5smuTo; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of devnull+manas18244.iiitd.ac.in@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=devnull+manas18244.iiitd.ac.in@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728049512; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=lxawzV72ELsqAhSer0n28xgGz5wN1Omyoi/fwO+7xsc=; b=J2hF+lInPGPKgaRaPRVeSJ+Vf+wl7Ir4lu6mNLiudVUwqJPr+R4gFREOvEdeI7SRhHvlwt rZIi8k0j34JIAbBorynHDcDEUvstLOfD3NBPS7p//l91NXS8SzG4y+eCt47KBwMvwbUBN/ R3Z0wXBk/B5OShJkbYzLEuL8DNi6oWQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D5D5E5C54CF; Fri, 4 Oct 2024 13:45:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id B6B62C4CEC6; Fri, 4 Oct 2024 13:45:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728049551; bh=1RS+17mH4AXNIN1g+vb0r2cDyMfutwB690D0Mhv8Yh8=; h=From:Date:Subject:To:Cc:Reply-To:From; b=kY5smuToRMZKl6xm4yZRdHQApYQ3/XOLtSnwsedUdU/Cef+xb1HiPFi64SBlYsCba VJk8LxCL1zCGUEMyhNTlSfC7QtMehfn1KfI6iNaqaWWrWn9/7H0++Ch27GuDPFU1QZ dzrxaFui6BnRPXq1c9lHK5ZSkMA/RgnOHg3uWk8m/LqlLv6C3qpi/LmK0iD4/LI699 V8+w/dpS7AGDo1MjeStmezhRKBjqr+HETrNxVVTCfdTn6LvvT2ZFxaIleoR6p/k96b d1VSfJngByDPXxN7JRlq7utRdNgXkZ99otxezBc04F53JV7cZmJWaXPQvIpmf1G39Q TRF7o+2YMggTA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB61DCFA775; Fri, 4 Oct 2024 13:45:51 +0000 (UTC) From: Manas via B4 Relay Date: Fri, 04 Oct 2024 19:15:48 +0530 Subject: [PATCH v3] Fixes: null pointer dereference in pfnmap_lockdep_assert MIME-Version: 1.0 Message-Id: <20241004-fix-null-deref-v3-1-f9459b1cc95f@iiitd.ac.in> X-B4-Tracking: v=1; b=H4sIAIvx/2YC/3XMSwrCMBSF4a2UOzYlj1qJo+5DHMTkxl4oqSQ1V Er3btqRIg7/A+dbIGEkTHCuFoiYKdEYSqhDBbY34Y6MXGmQXDaCc8U8zSw8h4E5jOhZe/OGK3V CbxWU06OMNO/g5Vq6pzSN8bX7WWzrXyoLJhg3zdF57bhoTUdEk6uNrSnAhmX5CTQ/gCyAVMZpr rW2TnwD67q+Ac2cABzvAAAA To: Andrew Morton Cc: Peter Xu , Shuah Khan , Anup Sharma , linux-mm@kvack.org, linux-kernel@vger.kernel.org, syzbot+093d096417e7038a689b@syzkaller.appspotmail.com, Manas X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728049550; l=2095; i=manas18244@iiitd.ac.in; s=20240813; h=from:subject:message-id; bh=ew+qGxm4Lxxrd6Mo6kl+2EOEGjzE1+x1lwHF41mIdfg=; b=8TyYBtUuYhyHZVRpCSzgDVmHLuJkeS15eZxJViSrrKRr3LtHwGkO1VBNGFwq2t3iosIWnHmIn SRsaG1T5cwhDUs0SpaHKlXe9E97qDUHK29VN1sdeSx7taszr+x56E9Z X-Developer-Key: i=manas18244@iiitd.ac.in; a=ed25519; pk=pXNEDKd3qTkQe9vsJtBGT9hrfOR7Dph1rfX5ig2AAoM= X-Endpoint-Received: by B4 Relay for manas18244@iiitd.ac.in/20240813 with auth_id=196 X-Original-From: Manas Reply-To: manas18244@iiitd.ac.in X-Rspam-User: X-Rspamd-Queue-Id: 202E2A0017 X-Rspamd-Server: rspam01 X-Stat-Signature: 6egwgca7y8t8uw7wcjs97hcopibtzng1 X-HE-Tag: 1728049552-525290 X-HE-Meta: U2FsdGVkX1/7D48TYhc2OyhWCUNEy1GIgoVz1tla/oiYi7Y0iul5Fo+3gsUIGSrpgsDO/6rI+8Lv/4ngMTFZwAvm8xg+DBhWXZoG1uPL6ksKQt3CNQa0RWr0So/6rMyWEixGJ++aUJvtrNsKr1bgKlF/PLmTpN6yayuzCKIbBBWIDw4Q8VnbGSXNp/mOBR13jCSFSmyIBLYozr78wPWAF7wIRv16fh8zoHdRhPPZoHplkx4AQot4pkwwhKCqw/S3bDcOxkI6ry1uubtt8B6wBeH3ztVJ5LKHgofaksSuBditjjiRY1s3tv/2MnYTez1/Sy14UOajsSwZISe7/UY18e4hUaLHcdX1D6R0k8HddU+AIOIXHg7/0QAh62eZeZnjrJMF+Ozbf4oiIk6P3wTYbNgQ4BfNLl9pKYjWluz7sjUMtXXrQLZyBhItCKLet2hNrOFmMIpxgJlLik/Zuuz5e5ptCJ/7b9Dje+3RrN5j9KQ/XaJxSrOampEoPcrpEOfcFAttC6evGVfVNuClcsgVuY/caMuhDwA4mKmL8/BsaTJALF2jzqz7rxKr59YOvDPKAgPStpM9/j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ity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Manas syzbot has pointed to a possible null pointer dereference in pfnmap_lockdep_assert. vm_file member of vm_area_struct is being dereferenced without any checks. This fix assigns mapping only if vm_file is not NULL. Reported-by: syzbot+093d096417e7038a689b@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=093d096417e7038a689b --- This bug[1] triggers a general protection fault in follow_pfnmap_start function. An assertion pfnmap_lockdep_assert inside this function dereferences vm_file member of vm_area_struct. And panic gets triggered when vm_file is NULL. This patch assigns mapping only if vm_file is not NULL. [1] https://syzkaller.appspot.com/bug?extid=093d096417e7038a689b Signed-off-by: Manas --- Changes in v3: - v3: use assigned var instead of accessing member again - Link to v2: https://lore.kernel.org/r/20241004-fix-null-deref-v2-1-23ad90999cd1@iiitd.ac.in Changes in v2: - v2: use ternary operator according to feedback - Link to v1: https://lore.kernel.org/r/20241003-fix-null-deref-v1-1-0a45df9d016a@iiitd.ac.in --- mm/memory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- base-commit: 9852d85ec9d492ebef56dc5f229416c925758edc change-id: 20241003-fix-null-deref-6bfa0337efc3 Best regards, diff --git a/mm/memory.c b/mm/memory.c index 2366578015ad..828967a13596 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6346,10 +6346,10 @@ static inline void pfnmap_args_setup(struct follow_pfnmap_args *args, static inline void pfnmap_lockdep_assert(struct vm_area_struct *vma) { #ifdef CONFIG_LOCKDEP - struct address_space *mapping = vma->vm_file->f_mapping; + struct address_space *mapping = vma->vm_file ? vma->vm_file->f_mapping : NULL; if (mapping) - lockdep_assert(lockdep_is_held(&vma->vm_file->f_mapping->i_mmap_rwsem) || + lockdep_assert(lockdep_is_held(&mapping->i_mmap_rwsem) || lockdep_is_held(&vma->vm_mm->mmap_lock)); else lockdep_assert(lockdep_is_held(&vma->vm_mm->mmap_lock));