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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 247BAC433EF for ; Thu, 11 Nov 2021 14:33:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 07F066101C for ; Thu, 11 Nov 2021 14:33:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233454AbhKKOgY (ORCPT ); Thu, 11 Nov 2021 09:36:24 -0500 Received: from outgoing-stata.csail.mit.edu ([128.30.2.210]:58063 "EHLO outgoing-stata.csail.mit.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233466AbhKKOgX (ORCPT ); Thu, 11 Nov 2021 09:36:23 -0500 Received: from c-24-60-30-97.hsd1.ct.comcast.net ([24.60.30.97] helo=crash.local) by outgoing-stata.csail.mit.edu with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1mlB8t-000Mwg-7t; Thu, 11 Nov 2021 09:33:31 -0500 Received: from crash.local (localhost [127.0.0.1]) by crash.local (Postfix) with ESMTP id AB6A612DE35AF; Thu, 11 Nov 2021 09:33:30 -0500 (EST) To: Trond Myklebust , Anna Schumaker cc: linux-nfs@vger.kernel.org From: rtm@csail.mit.edu Reply-To: rtm@csail.mit.edu Subject: an early NFS4ERR_MOVED causes client crash MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Date: Thu, 11 Nov 2021 09:33:30 -0500 Message-ID: <74993.1636641210@crash.local> Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org --=-=-= Content-Type: text/plain do_nfs4_mount() issues a bunch of getattr RPCs before server->super->s_root is set. If the server replies with an NFS4ERR_MOVED during that time, nfs4_try_migration is called and crashes when it tries to dereference s_root. This problem exists on riscv kernel 5.15 and amd64 5.4.0. I've attached a demo: # cc nfs_12.c # ./a.out ... [ 16.217793] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000030 [ 16.219341] Oops [#1] [ 16.219811] Modules linked in: [ 16.220504] CPU: 0 PID: 70 Comm: 127.0.0.1-manag Not tainted 5.15.0-rc7-dirty #47 [ 16.221715] Hardware name: ucbbar,riscvemu-bare (DT) [ 16.222491] epc : nfs4_try_migration+0x9e/0x13e [ 16.223367] ra : nfs4_try_migration+0x90/0x13e [ 16.224234] epc : ffffffff8079a5f8 ra : ffffffff8079a5ea sp : ffffffd000593df0 ... [ 16.236558] status: 0000000200000121 badaddr: 0000000000000030 cause: 000000000000000d [ 16.237694] [] nfs4_try_migration+0x9e/0x13e [ 16.238743] [] nfs4_run_state_manager+0x438/0x6aa [ 16.239804] [] kthread+0xfe/0x110 [ 16.240690] [] ret_from_exception+0x0/0xc --=-=-= Content-Type: application/octet-stream Content-Disposition: attachment; filename=nfs_12.c Content-Transfer-Encoding: base64 I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHN0ZGxpYi5o PgojaW5jbHVkZSA8dW5pc3RkLmg+CiNpbmNsdWRlIDxzeXMvc29ja2V0Lmg+CiNpbmNsdWRlIDxz eXMvaW9jdGwuaD4KI2luY2x1ZGUgPG5ldGluZXQvaW4uaD4KI2luY2x1ZGUgPHN5cy93YWl0Lmg+ CiNpbmNsdWRlIDxzeXMvcmVzb3VyY2UuaD4KI2luY2x1ZGUgPGFzc2VydC5oPgoKaW50IHN5bV9v cCA9IDk7CmludCBzeW1fc2tpcCA9IDY7CmludCBzeW1fdHlwZSA9IDA7IC8vIGFsbCBmYXR0cjQg ZmlsZSB0eXBlcwppbnQgc3ltX2ZoID0gMDsgLy8gYWxsIGZpbGUgaGFuZGxlcwoKaW50IG9wY291 bnRzWzI1Nl07CmxvbmcgbG9uZyBuZXh0X2Nvb2tpZSA9IDM7C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aW50IGxl bmkgPSBvaTsKICBwdXQzMigwKTsgLy8gcGxhY2Vob2xkZXIgZm9yIHRvdGFsIGxlbmd0aCBvZiBh dHRycwogIGZvcihpbnQgYSA9IDA7IGEgPCBiaXR3b3JkcyozMjsgYSsrKXsKICAgIGlmKHdvcmRz W2EvMzJdICYgKDEgPDwgKGEgJSAzMikpKXsKaWYoc3ltc3RhcnQgPiAwKSBwcmludGYoImE9JWQg QCAlZFxuIiwgYSwgb2kpOwogICAgICBpZihhID09IDApewogICAgICAgIHB1dDMyKDIpOyAvLyAj IGJpdG1hcCB3b3JkcyBvZiBzdXBwb3J0ZWQgYXR0cnMKICAgICAgICBwdXQzMigweGZmZmZmZmZm KTsKICAgICAgICBwdXQzMigweGZmZmZmZmZmKTsKICAgICAgfSBlbHNlIGlmKGEgPT0gMSl7CiAg ICAgICAgaW50IHR5cGUgPSAxOwogICAgICAgIGlmKGZoID09IDAgfHwgZmggPT0gMSkKICAgICAg ICAgIHR5cGUgPSAyOwogICAgICAgIGlmKHN5bV90eXBlKSB0eXBlIF49IGFhW2FhaSsrXTsKICAg ICAgICBwdXQzMih0eXBlKTsgLy8gTkY0RElSPTIgb3IgTkY0UkVHPTEKICAgICAgfSBlbHNlIGlm KGEgPT0gMil7CiAgICAgICAgcHV0MzIoMCk7IC8vIGZoX2V4cGlyZV90eXBlCiAgICAgIH0gZWxz ZSBpZihhID09IDMpewogICAgICAgIHB1dDY0KDApOyAvLyBjaGFuZ2UKICAgICAgfSBlbHNlIGlm KGEgPT0gNCl7CiAgICAgICAgcHV0NjQoNDA5NioxMCk7IC8vIHNpemUKICAgICAgfSBlbHNlIGlm KGEgPT0gNSl7CiAgICAgICAgcHV0MzIoMSk7IC8vIGxpbmsgc3VwcG9ydAogICAgICB9IGVsc2Ug aWYoYSA9PSA2KXsKICAgICAgICBwdXQzMigxKTsgLy8gc3ltbGluayBzdXBwb3J0CiAgICAgIH0g ZWxzZSBpZihhID09IDgpewogICAgICAgIHB1dDY0KDEpOyAvLyBmc2lkIG1ham9yCiAgICAgICAg cHV0NjQoMSk7IC8vIGZzaWQgbWlub3IKICAgICAgfSBlbHNlIGlmKGEgPT0gMTApewogICAgICAg IHB1dDMyKDEpOyAvLyBsZWFzZSB0aW1lCiAgICAgIH0gZWxzZSBpZihhID09IDExKXsKICAgICAg ICBwdXQzMigwKTsgLy8gcmRhdHRyX2Vycm9yCiAgICAgIH0gZWxzZSBpZihhID09IDEzKXsKICAg ICAgICBwdXQzMigweGYpOyAvLyBhY2xzdXBwb3J0CiAgICAgIH0gZWxzZSBpZihhID09IDE5KXsK ICAgICAgICAvLyBmaWxlaGFuZGxlCiAgICAgICAgaW50IHhmaCA9IGZoOwogICAgICAgIGlmKHN5 bV9maCkgeGZoIF49IGFhW2FhaSsrXTsKICAgICAgICBwdXRfb3BhcXVlKDQsIChjaGFyKikmeGZo KTsgLy8gZmgKICAgICAgfSBlbHNlIGlmKGEgPT0gMjApewogICAgICAgIHB1dDY0KGZoKTsgLy8g ZmlsZWlkCiAgICAgIH0gZWxzZSBpZihhID09IDI3KXsKICAgICAgICBwdXQ2NCgweGZmZmZmZmZm ZmZmZik7IC8vIG1heCBmaWxlIHNpemUKICAgICAgfSBlbHNlIGlmKGEgPT0gMjgpewogICAgICAg IHB1dDMyKDB4ZmZmZik7IC8vIG1heCBsaW5rCiAgICAgIH0gZWxzZSBpZihhID09IDI5KXsKICAg ICAgICBwdXQzMigyNTYpOyAvLyBtYXggbmFtZQogICAgICB9IGVsc2UgaWYoYSA9PSAzMCl7CiAg ICAgICAgcHV0NjQoMTAqNDA5Nik7IC8vIG1heCByZWFkCiAgICAgIH0gZWxzZSBpZihhID09IDMx KXsKICAgICAgICBwdXQ2NCgxMCo0MDk2KTsgLy8gbWF4IHdyaXRlCiAgICAgIH0gZWxzZSBpZihh ID09IDMzKXsKICAgICAgICBwdXQzMigwNzc3KTsgLy8gbW9kZQogICAgICB9IGVsc2UgaWYoYSA9 PSAzNSl7CiAgICAgICAgcHV0Mz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eW1fc2tpcCAtPSAx OwogICAgfQogICAgaWYob3AgPT0gNDIpewogICAgICBwYXJzZV9vcF9leGNoYW5nZV9pZCgpOwog ICAgfSBlbHNlIGlmKG9wID09IDQzKXsKICAgICAgcGFyc2Vfb3BfY3JlYXRlX3Nlc3Npb24oKTsK ICAgIH0gZWxzZSBpZihvcCA9PSA1Myl7CiAgICAgIHBhcnNlX29wX3NlcXVlbmNlKCk7CiAgICB9 IGVsc2UgaWYob3AgPT0gNTgpewogICAgICBwYXJzZV9vcF9yZWNsYWltX2NvbXBsZXRlKCk7CiAg ICB9IGVsc2UgaWYob3AgPT0gMjQpewogICAgICBwYXJzZV9vcF9wdXRyb290ZmgoKTsKICAgIH0g ZWxzZSBpZihvcCA9PSA1Mil7CiAgICAgIHBhcnNlX29wX3NlY2luZm9fbm9fbmFtZSgpOwogICAg fSBlbHNlIGlmKG9wID09IDQ0KXsKICAgICAgcGFyc2Vfb3BfZGVzdHJveV9zZXNzaW9uKCk7CiAg ICB9IGVsc2UgaWYob3AgPT0gNTcpewogICAgICBwYXJzZV9vcF9kZXN0cm95X2NsaWVudGlkKCk7 CiAgICB9IGVsc2UgaWYob3AgPT0gMTApewogICAgICBwYXJzZV9vcF9nZXRmaCgpOwogICAgfSBl bHNlIGlmKG9wID09IDkpewogICAgICBwYXJzZV9vcF9nZXRhdHRyKCk7CiAgICB9IGVsc2UgaWYo b3AgPT0gMjIpewogICAgICBwYXJzZV9vcF9wdXRmaCgpOwogICAgfSBlbHNlIGlmKG9wID09IDMp ewogICAgICBwYXJzZV9vcF9hY2Nlc3MoKTsKICAgIH0gZWxzZSBpZihvcCA9PSAxNSl7CiAgICAg IHBhcnNlX29wX2xvb2t1cCgpOwogICAgfSBlbHNlIGlmKG9wID09IDI2KXsKICAgICAgcGFyc2Vf b3BfcmVhZGRpcigpOwogICAgfSBlbHNlIGlmKG9wID09IDE4KXsKICAgICAgcGFyc2Vfb3Bfb3Bl bigpOwogICAgfSBlbHNlIGlmKG9wID09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VthYWkrK107 CiAgICAgICAgc3ltc3RhcnQgPSAtMTsKICAgICAgfQogICAgICBpZih3cml0ZShzMSwgb2J1Ziwg b2kpPD0wKSBwZXJyb3IoIndyaXRlIik7CiAgICB9CiAgICBleGl0KDEpOwogIH0KICBjbG9zZShz KTsKICBzbGVlcCgxNSk7Cn0K --=-=-=--