From patchwork Fri Oct 4 13:05:53 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: 13822290 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 181D1CFA77A for ; Fri, 4 Oct 2024 13:06:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46E4D6B0373; Fri, 4 Oct 2024 09:06:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F8F86B037A; Fri, 4 Oct 2024 09:06:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24A186B0373; Fri, 4 Oct 2024 09:06:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 023C86B0371 for ; Fri, 4 Oct 2024 09:06:06 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9722CC16EE for ; Fri, 4 Oct 2024 13:06:06 +0000 (UTC) X-FDA: 82635942732.18.71649D1 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf21.hostedemail.com (Postfix) with ESMTP id A6DF41C0023 for ; Fri, 4 Oct 2024 13:06:03 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rhqf9Wsp; spf=pass (imf21.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; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728047033; 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=RlUE6JlRFsNfnXYGngt2T7OCxg9+cFaUxsQboOrUc74=; b=cGq14oDP1tQ8M+GjwnWT3hz5tXvKyuyztO3f3OTa3l8MLippHEzUCVPi9EZld8/qTC5kb0 odN4P9BbLRiobqEU6XGJGbfacoIExJLc1Ckwvz7NnWUuDkzpuwDQJEOaB4SfQ3xOCBNRyY BRyiz0Lm640dqAa0qYi45Lddfj5qsL0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728047033; a=rsa-sha256; cv=none; b=SBkYtOM/fzGiTTOTbzwVqXRBm6SGCuzm+VV3gd/Yh7oxEYlVt4dfCsabXWC+yjtBPYP0kA DWaYeLdpXwGqETxnckzoSoQBFvr2MGLsS2hvQV+OFAlylXCVUJ8ubAbX96zmmAjsuu3Sb0 HY/DuGz6giJn3mo1BUF2CgA4hnV/4/k= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rhqf9Wsp; spf=pass (imf21.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; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 76C73A433FA; Fri, 4 Oct 2024 13:05:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 8D87DC4CEC6; Fri, 4 Oct 2024 13:06:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728047162; bh=kRQQe61Akz7VG5idUgr2NwVMRuIiutrELrCHMyAzh9U=; h=From:Date:Subject:To:Cc:Reply-To:From; b=rhqf9WspffTi6HwYv7jz8l7B79VZ1btJkye2i6HpuEglHBzm5yG7Tx0l6yWk5fi6D Xd+kB828npcjY+YQnyiYGvMuUr2TcxNxIfpvyWiFGKm6/NpN1ssRzi5qUJu+KUIaTE yiU2Mr4nJzkXF0UsU4Ywr77J/RWXDApVOky0WaL2wp8jJS5WS/QDk9RqiFJp+hjEST Go6FMQDBlSKVHCeQQPez6P7SItV24KobUJWkqYFbQj46epXRB29VvGB1t5yTw6+aqR 0gp1ljKNFHibLd7cuXsVvURyJ7sS+Y1cYffQtFQlS2jVFm3YXMY4Dv2WOlZB0C7JS2 s4B7FhWW5Cbmw== 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 80567CFA779; Fri, 4 Oct 2024 13:06:02 +0000 (UTC) From: Manas via B4 Relay Date: Fri, 04 Oct 2024 18:35:53 +0530 Subject: [PATCH v2] Fixes: null pointer dereference in pfnmap_lockdep_assert MIME-Version: 1.0 Message-Id: <20241004-fix-null-deref-v2-1-23ad90999cd1@iiitd.ac.in> X-B4-Tracking: v=1; b=H4sIADDo/2YC/3WMywrCMBAAf6Xs2S151Iqe+h/SQ0w2dqGkktRQK fl3Y+8eZ2Bmh0SRKcGt2SFS5sRLqKBODdjJhCchu8qghOqkEBo9bxje84yOInnsH94IrS/krYY avark7Rjex8oTp3WJn+Of5c/+XWWJEoXpzs5fnZC9GZh5da2xLQcYSylfcLqDk64AAAA= 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=1728047161; l=1777; i=manas18244@iiitd.ac.in; s=20240813; h=from:subject:message-id; bh=OEwuLRIdbf6uWYdfndo9PjGAmtyN4VZDWmzer8sLYJ8=; b=W2C+cObLrtqqTQu9dKflHQD9t3M4Uc2SCrH7g/8NavfEy9xgTNmwfI3B7b6NGxEDyfpNY9+cG h6QICQmopUsB4nmk6WjMlgRk/+afkoAWTEZ1bWxFF4UeeekxbyAp8Ag 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-Server: rspam04 X-Rspamd-Queue-Id: A6DF41C0023 X-Stat-Signature: hhgkaiuc7twch53eteatu8p8x5xg7knw X-HE-Tag: 1728047163-703534 X-HE-Meta: U2FsdGVkX1/H/44ndYHFsqhe05KYwaBUIltU57+C7PnOhFCJNEZ6Oes6Jcb4NzCf+z5QGxkP50dnQ3C/nqrCrZubgfZdc+6cpu791tCX38Ly54+gEw8MgGvTpm4BnpQnXxj8gGgwuocoqWmOx5ZN+vJEHA6eNALA/GGtjjib1NtJV852DLzaVSTQsiCo+U72YmxhOvofBE/D9pYoznOS1JrYirVcJctpEz239xAra3XUl4erB1eXA+PCiksbCQEsM6KGHLCw2JtErKljRNpyy1Ag0aeTG7M6T5TXbdPSuzIQMK7GybRERyoeTXe/S3CJER+TspP18rNSwXQQPxGOuCdKGphJAtjk+Is8EIXBQUBYPtD1ZNnw2JTNEbhDH2skaVCiApBo6d7PmhC0fwgFKTiVGmnNTVrFw17K/+3T8sn7OpG93TPL12tjwEsQqjXHE8sC8JgVbIpwo1+oaPChnGbXFkaRvnivd2lPtQ+ejLiOsUlRH8LEeia4ZlK4+g2cgcL/PqcQ54OxqauCHvNdMcOubzhpvsfJmrOVj+gF2Bf5EuwVehaQPt5Hs9HwkT4u8OjQh9CdJomoTNzORLtSXqLyEuQSgmvFqA8/Aj1VHqn9j6BX3Psjc2iqMybluWeHeO3NItwJVkXXtC05CETjuZQBbXC0Sdy64Eca4rBJdtdXyUlEQphFwII1csAlGLw6DlsDuZc3ek8db6DLLx4YX/c7qtxTjXu3DagwDfJA9wiBi+NGildbo6HaVxSk6Vifdc0e2D93wl4Afls7kk+S5XRikgaC7yDYleOQlMKAMnNkSS+7HAp2EJaIIyLHDov6j5E0HrSiq5UVaQnuJAgq6xjNzt02KK91nsCR4+hzMyx5bRM1orpjltWEEJfudXrmN7pz9D5Xq23sjvb9g7/PyZK1KZ5RKnbqv+8DFJkNkBGalhfzBk3/0cly96OPez+J9LagEiZX4on+XFngJff 2GvVSXaN NRQDJiBvNaXqQcGap/bKVZOHhhqaBRmvXOGBNVtjpCPh+9foSqLJFiNtWAq2aljDdQRNOVin4/Ku967++T8FYykYtDFKGNWMTZBDxep/Sql060tCU63NV6FTHtGzr3z86gzKUzWDRj3v9XxSYsJkLD+PU4BkYa1QxFk9nOb9GI7yl5Du9oAfqabffPHIxdgwiq4bKS97lQRhG0nzVqvHmWNIov0dKBmKUNFdOyNNdmZEV3CBDJ7YuZwKeFEG8cVwYaI7/Ki0eznOntxRuB8t46GttRtZEveit6V1EJhgDq6T6KmWHghnuKjsG1gkNkOzNbgoUuV2Oehu0+CT4QBzbe2kp6WHHuBmdeAJ7lNH5GgTTTHvAtMKymIG42yzmzUOgQoJ1maHxW9BrykC9AjiYVOqIibB4LUfvz44HMWI1OFETFoEpEyUe57hJyV+8zaPORTFdHn+ucp3XAzn0ZCBOBA2FTk5falrfEh8PvVMq5CELDFPg28vFhtG+oqkpXf5Sv0TkoA6FCtawVXlxeaivbJtFde3OrslWnWPMTf7qKtwvk0MlVuxoVNB+2T2Cwo/wS+5Cbigvq+vUvFHx/BuSFVW/pbU7GsKF2nw0l8kXjgjTc8EAPwnqA5CJTs738WYYIXQyPrGnPXQOnuA= 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 returns if vm_file member in vm_area_struct is NULL. Reported-by: syzbot+093d096417e7038a689b@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=093d096417e7038a689b Reviewed-by: Peter Xu --- 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 returns from the assertion pfnmap_lockdep_assert if vm_file is found to be NULL. [1] https://syzkaller.appspot.com/bug?extid=093d096417e7038a689b Signed-off-by: Manas --- 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- base-commit: 9852d85ec9d492ebef56dc5f229416c925758edc change-id: 20241003-fix-null-deref-6bfa0337efc3 Best regards, diff --git a/mm/memory.c b/mm/memory.c index 2366578015ad..5ed109a8f02e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6346,7 +6346,7 @@ 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) ||