From patchwork Fri Oct 4 17:42:16 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: 13822860 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 DFA1CCF8854 for ; Fri, 4 Oct 2024 17:42:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 771A68E0006; Fri, 4 Oct 2024 13:42:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F83C8D0003; Fri, 4 Oct 2024 13:42:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5722D8E0006; Fri, 4 Oct 2024 13:42:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 373E88D0003 for ; Fri, 4 Oct 2024 13:42:23 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E0B1E120833 for ; Fri, 4 Oct 2024 17:42:22 +0000 (UTC) X-FDA: 82636638924.15.B2D9668 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf01.hostedemail.com (Postfix) with ESMTP id 096DA40015 for ; Fri, 4 Oct 2024 17:42:20 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=O2NwM+QZ; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf01.hostedemail.com: domain of devnull+manas18244.iiitd.ac.in@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=devnull+manas18244.iiitd.ac.in@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728063634; a=rsa-sha256; cv=none; b=ESOMnZpwOIrZDBVb5YXNCmsg81Cf89tJ5oXGTH9A//uXOCvulxlp5i7dOilEgRZCen3SY2 atapGT/zQzm/LXLRZXu+TUyZ916JMzNw7QvnnBMEVI2+7iPaMXX9luZCtkK+EjL2PkuPcx OnPsS6sXg0j4F2So4Ht0Gxhm0s6kKQo= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=O2NwM+QZ; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf01.hostedemail.com: domain of devnull+manas18244.iiitd.ac.in@kernel.org designates 147.75.193.91 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=1728063634; 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=RkCzifzdXLxzHVwxTAbspxVmiac95Og8ZOoP5c/sjbY=; b=mseNYiEWM2yQO7HVhGChZ8vxwHc03q3HGPNQE2zXa2n4JfygfTWURlPNHxp3GiyZwtlRkG Sn8XK21lVHPwAoEZ5ZPzAMq6Hmw2tuF5+hM6iv+d58/+A2dzlG6DbkB75hm4yoEOpHS3gq Q2qka5TtN/M2SfGBv5YREWrOTccQ5bY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id C7A2DA44C08; Fri, 4 Oct 2024 17:42:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 658B7C4CEC6; Fri, 4 Oct 2024 17:42:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728063739; bh=Ci6UDfbEkgVHJ1O4+ijHMWfFl/HnYN5BhA5QGugHCIQ=; h=From:Date:Subject:To:Cc:Reply-To:From; b=O2NwM+QZbvTbzSsnrATl5bbMRoudsCzXv2DY1qyUHAvYhzasK/Pe9TEDOy3JjNo76 USZW9Ok+uAGfQLZhN92Edshlfbts1zjYEcGnpcaa/L2A5BqqwD4KyHJdvIzhLouP9e xRuP/jXF8hhUOA5y/LEIlV9U+apffT2KHDCQYuCevX1EqPRQmNZiLJPuc3ubcoK+d8 ZGXYENKP0RHwKk+a2dmq9afgcwYrzFEqmEXWY8sEWq9QXnK7PxedhGU8vW1n5gPcL0 PqKN784rkkliPkn10NHfqbWhL+pWlasMdO5Oq5lqsGhfN88SfbmwfDQaMRV1PXgys5 Pu/EkfVmPvuZw== 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 471CFCF8854; Fri, 4 Oct 2024 17:42:19 +0000 (UTC) From: Manas via B4 Relay Date: Fri, 04 Oct 2024 23:12:16 +0530 Subject: [PATCH v4] Fixes: null pointer dereference in pfnmap_lockdep_assert MIME-Version: 1.0 Message-Id: <20241004-fix-null-deref-v4-1-d0a8ec01ac85@iiitd.ac.in> X-B4-Tracking: v=1; b=H4sIAPcoAGcC/33MSwrCMBSF4a1Ixqbk1cp15D7EQZqHvVBSSWqol O7dtCOl6PA/cL6ZJBfRJXI+zCS6jAmHUEIdD8R0OtwdRVuaCCYUZ0xSjxMNz76n1kXnadN6zaQ 8OW8kKadHGXHawOutdIdpHOJr8zNf159U5pRTplVtPVjGG31BxNFW2lQYyIpl8QmoHSAKIKS2w ADAWL4H5H9AFsCDqqHlxkDtv4FlWd4ZavzqMAEAAA== 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=1728063737; l=2269; i=manas18244@iiitd.ac.in; s=20240813; h=from:subject:message-id; bh=I6Jr34YY5WytSnppfZbbp0DlHGTntvqBvZhYI28pyh8=; b=ME9HVvF5BLf+ljmXjMr9EboNjFIhb6RD+gVbB7g2RRx5amHDSoLOzjd2z8J/zMByP+poVufwN wdbqRHYDoPoD+JIj9naERulOdKx0/x45vCt8hXKnMzwqnZDLR/Z1MRA 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-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 096DA40015 X-Stat-Signature: sa9cbyhcndyoknacmf6c6o9zs8xwji3g X-Rspam-User: X-HE-Tag: 1728063740-56256 X-HE-Meta: U2FsdGVkX19bR0vJ/qMj3Jalr6NWEttl4mJffTpDxVt7e+rDcuBw4jxBY6+w0z1zBuvsyLOctI01uGDnaMFNl9IPA4NHaDmEuQIPj5hJCEXJ5WqDJzpd16z5QU3dCykWwFA2IOkMSRdJ4jGGU/QO3NWN+ty9XyfpjU23yyC4iuz0x8u6Ap1EHiT+TiWzE8a5Kab+TI2++1yM3nuP1Iv2K0kR2E5BkndxbJ8LYadduyDUzF/pd4hjUkJ8GfZ5aWA1ISPOUVOBZd+kNhPqT7siS98PLczCriXtaif8FxG04oBP39RoZLOf1eXXHLGc6G7+1bySqv8Q3TpPTiqFieDNcu3+1JyiR+STx4Pbn9mZEzhL3ug7fZ9MqKDpJi32WPadBb+Cj82sM6JJoZa1J9JYUTgYsz9Gc9xUg5EL5FlT66dcfzuEDOT42KOqncz8AwJ2JUGxf1IEwZlfUjGPS4O+jK+cqP9Peuv2231Uagj5P7j4kAXkrfNWpPF6weLMYMBYRrQylshUoObZywPZ6UNEa+9z2WQXr1if5l0daBwtGGSdzmKq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sqIjvS1/c= X-Bogosity: Ham, tests=bogofilter, spamicity=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 v4: - v4: simplify ternary conditional - Link to v3: https://lore.kernel.org/r/20241004-fix-null-deref-v3-1-f9459b1cc95f@iiitd.ac.in 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 | 7 +++++-- 1 file changed, 5 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..4e4d598496a8 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6346,10 +6346,13 @@ 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 = NULL; + + if (vma->vm_file) + mapping = vma->vm_file->f_mapping; 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));