From patchwork Mon Apr 10 01:45:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "xiaosong.ma" X-Patchwork-Id: 13206055 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 4198AC77B6E for ; Mon, 10 Apr 2023 02:01:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F3D7900004; Sun, 9 Apr 2023 22:01:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A3A0900002; Sun, 9 Apr 2023 22:01:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29282900004; Sun, 9 Apr 2023 22:01:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1AF15900002 for ; Sun, 9 Apr 2023 22:01:40 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AD5CA1A079D for ; Mon, 10 Apr 2023 02:01:39 +0000 (UTC) X-FDA: 80663829918.14.748C1EC Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by imf09.hostedemail.com (Postfix) with ESMTP id 739A814000B for ; Mon, 10 Apr 2023 02:01:36 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of Xiaosong.Ma@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=Xiaosong.Ma@unisoc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681092097; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references; bh=oQpzESiJU9r6QotFPBazXuQTX0VLZo+IotpCiE1i89M=; b=BQiZ5VhQWEhzpY1Dm1dvXx9uFbTSAY4g6Hqiced7vYbZsbT3KcJxrDajWU9GI1fCGEitWY XvzW1QNlj8y/xAaIKp9PK30GmELXmiCfRwObVy2qazWLSaLyQdX5gH/jNVmZPGvwmrt4Qz 3ZiO7bv8klhtdysdyVZFjt/5sMVJ+VE= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of Xiaosong.Ma@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=Xiaosong.Ma@unisoc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681092097; a=rsa-sha256; cv=none; b=cmGMkC4ddyfBZxO1jN9rbAsiWBRnxLIToDkqtMQEWUaqTuEgDx5IVYodPk9tniF5jcSSts jFX/FPSSJ82j+6XMfLzhhAjBnZei9wePrGy6zpKOnSYmYnP2O6toNbmtLwK7tY7Ai67Okk IUZexDAgAj84dKYimEx0qD9F4vsrvGE= Received: from SHSend.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by SHSQR01.spreadtrum.com with ESMTP id 33A1xiga063929; Mon, 10 Apr 2023 09:59:44 +0800 (+08) (envelope-from Xiaosong.Ma@unisoc.com) Received: from bj10638pcu1.spreadtrum.com (10.0.74.32) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 10 Apr 2023 09:59:41 +0800 From: "xiaosong.ma" To: Andrew Morton , Alexander Viro , , , Zhaoyang Huang , , Subject: [PATCH V2] fs: perform the check when page without mapping but page->mapping contains junk or random bitscribble Date: Mon, 10 Apr 2023 09:45:02 +0800 Message-ID: <1681091102-31907-1-git-send-email-Xiaosong.Ma@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.0.74.32] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 33A1xiga063929 X-Rspamd-Queue-Id: 739A814000B X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: e3o6bfrqf3pnqq13j156nz73cnb4hqst X-HE-Tag: 1681092096-9312 X-HE-Meta: U2FsdGVkX18NFsAs3sWPP65QB0iT8WQSekfETUoJOqQ2mq9pGRkoee+le2mWGVb2kdoFhZvDahOoIJujYgVGntOAYrGl8xDxeVQXJYL/C1+I1kRPvY4NhnC5PBK5X6XO0mrQM34Leb8kNjrRMnfew5oWUo9VhgYZC+GjeQzXbE3i4JP/eg8qgqp4fsH3vJSvyac0PbgPFHxrdQ8LPlMKghn7REbyhGk/lkN7UG13WOzeImYCUZPVIg6n80p1X4QhuQEoI3qref3eROKHCG9ostGPkpBBK9DUWRq/tIp8u5C3G4Ia+xJnCBzWUmLqGkNVKF/q7gq/qTtxyR48Ge9rLv8VaQntMqKoeUceokrZFaw1qcHT37L31HzsDuzBKael1uWvZovuCwBlDEUNObC/lMwGQsHwxVnMYNBA218MEw87HdkOKjdAug6rcWoiZminh3FTPjQRC0DsFf2jBdw/OkClQiOO8kyoOl0YNY9ZlRaE8dsSkQRz8c5OkghIodzgcoynX8I74/Yz60zAX0eKIBAqeH/x8uW9CnqlgFAmLyi9h/estpMNHXO3/+8IdNX2ZcDKUM70LgwYZIW+AxF62h9HD4shYwezasCCuNyJg8IQwMWsZDnAJjzvKtAxp5F7lsr+dtkKivsQx5OiidMySapHpBaGpQ8CsMCtkoGHLizpEr0Hnj1xCjbUyA/TQfuRjo/jIv2JHcwVkDbpiyXGXP7K8JZDnM2G9pjKOEZ4lq3VGIEDQi4yk0nM4ZtyrG3+Q2X7WgUD74TK7K4fSr+yHQm9R0ZzudCnUzSPCZ4JsxhxCrbnY1WV1Lt1oniVceX9u+iSqIeOWzkxwcBSERZYl6wp8dLCdRZN4mJ43xYT6qZ1mPgAC/rxhqcebq1Q0d3Ci1Cm56V0oatF4aqWc6K3a7EZLmNNTOlTFqVpOSQ8AUSZUnjWTL/bOS0Bi61kzhX53rPibrYQ23Rzozf3Uma BLR+RAUz I4ZqUBKhqfuLsvBl3ahhmrZij+5+9NWSybYk3Qk3tAwNY/NU1MhvwWCMZrCOFVh2efStTw8+sUepxsNOpvOQEBIEsuhPcADxz5OVuQZW/EYsOKqHWdHzVdXtjUrhxr42roMomHPNMMIryvfdv0pGt6hPRPTX4LiG9jtIqlMkKaBOLJqv8UT5x6/GVkViULI2HC43vQes6llsIWaLIpZLKuKhMMHEUSQlX3O82BNjUdjlYillEOHAjy2wnrXt7kojsgsVmJW3vkkkQKWXyJlCKz88uwxPB8UKZBodieBslc2da9bmIGioUFu7meL0LZpStdqBi 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: perform the check in dump_mapping() to print warning info and avoid crash with invalid non-NULL page->mapping. For example, a panic with following backtraces show dump_page will show wrong info and panic when the bad page is non-NULL mapping and page->mapping is 0x80000000000. crash_arm64> bt PID: 232 TASK: ffffff80e8c2c340 CPU: 0 COMMAND: "Binder:232_2" #0 [ffffffc013e5b080] sysdump_panic_event$b2bce43a479f4f7762201bfee02d7889 at ffffffc0108d7c2c #1 [ffffffc013e5b0c0] atomic_notifier_call_chain at ffffffc010300228 #2 [ffffffc013e5b2c0] panic at ffffffc0102c926c #3 [ffffffc013e5b370] die at ffffffc010267670 #4 [ffffffc013e5b3a0] die_kernel_fault at ffffffc0102808a4 #5 [ffffffc013e5b3d0] __do_kernel_fault at ffffffc010280820 #6 [ffffffc013e5b410] do_bad_area at ffffffc01028059c #7 [ffffffc013e5b440] do_translation_fault$4df5decbea5d08a63349aa36f07426b2 at ffffffc0111149c8 #8 [ffffffc013e5b470] do_mem_abort at ffffffc0100a4488 #9 [ffffffc013e5b5e0] el1_ia at ffffffc0100a6c00 #10 [ffffffc013e5b5f0] __dump_page at ffffffc0104beecc #11 [ffffffc013e5b630] bad_page at ffffffc0104e6ffc #12 [ffffffc013e5b820] rmqueue_bulk at ffffffc0104e9128 #13 [ffffffc013e5b950] rmqueue at ffffffc0104e7c3c #14 [ffffffc013e5b9c0] get_page_from_freelist at ffffffc0104e3e3c #15 [ffffffc013e5ba50] __alloc_pages_nodemask at ffffffc0104e3a7c #16 [ffffffc013e5bac0] pagecache_get_page at ffffffc01047d0e4 #17 [ffffffc013e5bb20] grab_cache_page_write_begin at ffffffc010480e3c #18 [ffffffc013e5bb50] block_write_begin at ffffffc010586204 #19 [ffffffc013e5bb90] blkdev_write_begin$75b353f60767e771433fc3b19ba260ab at ffffffc01058cc48 #20 [ffffffc013e5bc00] generic_perform_write at ffffffc010480f1c #21 [ffffffc013e5bc60] __generic_file_write_iter at ffffffc01048115c #22 [ffffffc013e5bcf0] blkdev_write_iter at ffffffc01058c0a8 #23 [ffffffc013e5bda0] __vfs_write at ffffffc01052d808 #24 [ffffffc013e5bdd0] vfs_write at ffffffc01052da5c #25 [ffffffc013e5be30] __arm64_sys_pwrite64 at ffffffc01052e09c #26 [ffffffc013e5be60] el0_svc_common at ffffffc010272224 #27 [ffffffc013e5bea0] el0_svc_handler at ffffffc010272148 #28 [ffffffc013e5bff0] el0_svc at ffffffc0100a7ec4 Signed-off-by: xiaosong.ma --- fs/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index f453eb5..c9021e5 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -564,7 +564,8 @@ void dump_mapping(const struct address_space *mapping) * If mapping is an invalid pointer, we don't want to crash * accessing it, so probe everything depending on it carefully. */ - if (get_kernel_nofault(host, &mapping->host) || + if (get_kernel_nofault(mapping, &mapping) || + get_kernel_nofault(host, &mapping->host) || get_kernel_nofault(a_ops, &mapping->a_ops)) { pr_warn("invalid mapping:%px\n", mapping); return;