Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp537073pxh; Tue, 9 Nov 2021 14:52:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJyPQq0twjLUi0P6ZRPNZp4PDmsBz9XbuLHzk3xS4tvM/3cnbuXlzAzX/8cooK3Rs53XK1aX X-Received: by 2002:a5d:87c8:: with SMTP id q8mr7504471ios.117.1636498374529; Tue, 09 Nov 2021 14:52:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636498374; cv=none; d=google.com; s=arc-20160816; b=c6vN4Ov79GiLV5G5oVYZWyrCT/dM7IKcj1Qyj6mw8ZhpehZXRFvJAAjmP8i34ra09i 621zqtsjBuOZEF6C/SkHnpDxdz0/EvQPlfuWuMsrZD4fcL9FLjf3qSZRPj3yvqfl1KuT EH1RhXO2ewh49rGywW+nGOi4+qKVAK5/w2H0PVMTXI5Oet9hSkRe4qLTEyCwhCB5Kqdp sNOnGUNOA6jnLxATmIuX3IiSIBTPi9qnwVtfxy3VTl9OMbKn7yPot6Djp1HPqjkFLBqt pLFT5hLEUIBclfQ/0JlpO089j03Id0rndomj7OZgDPrLaawMBP3KkL/Dx+a954NTxRwF XpJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:mime-version:subject:reply-to :from:cc:to; bh=XSnuwvxazIUeWeVKBdLofXD0ryExl7oTPkZzvewZNj8=; b=Aznodw92qwIHV+Z46h1JjwJHnt6VRZJMWZmgN9m4LsTSK9McTdrq+ynU3mE9sJs32+ mrd6vt5ZIXuDOpxg9LFsCfyDPQE8gdcJpWCzrUjJ8gOZIlCQlVk+1hVw/2epYMXsCYcc mqSBcinW8Rebbo6gbhmCTtZhg7uT4ruDEmi8qUR0x95H9bf814P15ZsrRFkF2UGEIIic /6XwsJaitQJuCtS0JE+DIqwbJSM1RmGwYEAGyot7MtuzST58cGQ5tJIyy7I9FAhoVEnc TprgrLIb2sx52/E3H9uo/TnDgO1Nj7RJ00Imt4Ogtx++yOGPO7IaqjTPk75wlHIdgY/Z 7KvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=csail.mit.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t10si38576779iov.95.2021.11.09.14.52.34; Tue, 09 Nov 2021 14:52:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=csail.mit.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243144AbhKITvU (ORCPT + 99 others); Tue, 9 Nov 2021 14:51:20 -0500 Received: from outgoing-stata.csail.mit.edu ([128.30.2.210]:35338 "EHLO outgoing-stata.csail.mit.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231455AbhKITvU (ORCPT ); Tue, 9 Nov 2021 14:51:20 -0500 Received: from c-24-60-30-97.hsd1.ma.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 1mkX6d-000Kjw-9n; Tue, 09 Nov 2021 14:48:31 -0500 Received: from crash.local (localhost [127.0.0.1]) by crash.local (Postfix) with ESMTP id B5671129DBD29; Tue, 9 Nov 2021 14:48: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: NFS client crash if server is confused about file handles MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Date: Tue, 09 Nov 2021 14:48:30 -0500 Message-ID: <57326.1636487310@crash.local> Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org --=-=-= Content-Type: text/plain _nfs4_open_and_get_state() calls d_splice_alias() and assumes that a non-NULL returned dentry pointer is valid. However, d_splice_alias() returns ERR_PTR(-ELOOP) if the server assigns the same file handle to a file and its directory. This causes a later crash when nfs_set_verifier() tries to use the dentry pointer. I've attached a demo program, which works for me on kernel 5.15 on riscv, and 5.4.0 on amd64. # cc nfs_5.c # ./a.out ... [ 29.702595] VFS: Lookup of 'x' in nfs4 0:16 would have caused loop [ 29.710258] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000034 [ 29.754320] epc : ffffffff8004e24e ra : ffffffff807a8dc2 sp : ffffffd00056b960 [ 29.843403] status: 0000000200000121 badaddr: 0000000000000034 cause: 000000000000000d [ 29.851434] [] do_raw_spin_lock+0xa/0xd8 [ 29.857532] [] _raw_spin_lock+0x1a/0x22 [ 29.863650] [] nfs_set_verifier+0x20/0x6e [ 29.869795] [] nfs4_do_open.constprop.0+0x3f6/0x774 [ 29.877084] [] nfs4_atomic_open+0xc/0x1c [ 29.883255] [] nfs_atomic_open+0x194/0x332 [ 29.890784] [] path_openat+0x5ca/0xaf6 [ 29.896912] [] do_filp_open+0x70/0xd0 [ 29.903003] [] do_sys_openat2+0x1fc/0x298 [ 29.909150] [] do_sys_open+0x3c/0x78 [ 29.915308] [] sys_openat+0x18/0x20 [ 29.921424] [] ret_from_syscall+0x0/0x2 --=-=-= Content-Type: application/octet-stream Content-Disposition: attachment; filename=nfs_5.c Content-Transfer-Encoding: base64 I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHN0ZGxpYi5o PgojaW5jbHVkZSA8dW5pc3RkLmg+CiNpbmNsdWRlIDxzeXMvc29ja2V0Lmg+C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gaWYoZmggPT0gMCB8fCBmaCA9PSAx KQogICAgICAgICAgdHlwZSA9IDI7CiAgICAgICAgaWYoc3ltX3R5cGUpIHR5cGUgXj0gYWFbYWFp KytdOwogICAgICAgIHB1dDMyKHR5cGUpOyAvLyBORjRESVI9MiBvciBORjRSRUc9MQogICAgICAg IHByaW50ZigiICB0eXBlICVkXG4iLCB0eXBlKTsKICAgICAgfSBlbHNlIGlmKGEgPT0gMil7CiAg ICAgICAgcHV0MzIoMCk7IC8vIGZoX2V4cGlyZV90eXBlCiAgICAgIH0gZWxzZSBpZihhID09IDMp ewogICAgICAgIHB1dDY0KDApOyAvLyBjaGFuZ2UKICAgICAgfSBlbHNlIGlmKGEgPT0gNCl7CiAg ICAgICAgcHV0NjQoNDA5NioxMCk7IC8vIHNpemUKICAgICAgfSBlbHNlIGlmKGEgPT0gNSl7CiAg ICAgICAgcHV0MzIoMSk7IC8vIGxpbmsgc3VwcG9ydAogICAgICB9IGVsc2UgaWYoYSA9PSA2KXsK ICAgICAgICBwdXQzMigxKTsgLy8gc3ltbGluayBzdXBwb3J0CiAgICAgIH0gZWxzZSBpZihhID09 IDgpewogICAgICAgIHB1dDY0KDEpOyAvLyBmc2lkIG1ham9yCiAgICAgICAgcHV0NjQoMSk7IC8v IGZzaWQgbWlub3IKICAgICAgfSBlbHNlIGlmKGEgPT0gMTApewogICAgICAgIHB1dDMyKDEpOyAv LyBsZWFzZSB0aW1lCiAgICAgIH0gZWxzZSBpZihhID09IDExKXsKICAgICAgICBwdXQzMigwKTsg Ly8gcmRhdHRyX2Vycm9yCiAgICAgIH0gZWxzZSBpZihhID09IDEzKXsKICAgICAgICBwdXQzMigw eGYpOyAvLyBhY2xzdXBwb3J0CiAgICAgIH0gZWxzZSBpZihhID09IDE5KXsKICAgICAgICAvLyBm aWxlaGFuZGxlCiAgICAgICAgaW50IHhmaCA9IGZoOwogICAgICAgIGlmKHN5bV9maCkgeGZoIF49 IGFhW2FhaSsrXTsKICAgICAgICBwdXRfb3BhcXVlKDQsIChjaGFyKikmeGZoKTsgLy8gZmgKICAg ICAgICBwcmludGYoIiAgZmggJWRcbiIsIHhmaCk7CiAgICAgIH0gZWxzZSBpZihhID09IDIwKXsK ICAgICAgICBwdXQ2NChmaCk7IC8vIGZpbGVpZAogICAgICAgIHByaW50ZigiICBmaWxlaWQgJWRc biIsIGZoKTsKICAgICAgfSBlbHNlIGlmKGEgPT0gMjcpewogICAgICAgIHB1dDY0KDB4ZmZmZmZm ZmZmZmZmKTsgLy8gbWF4IGZpbGUgc2l6ZQogICAgICB9IGVsc2UgaWYoYSA9PSAyOCl7CiAgICAg ICAgcHV0MzIoMHhmZmZmKTsgLy8gbWF4IGxpbmsKICAgICAgfSBlbHNlIGlmKGEgPT0gMjkpewog ICAgICAgIHB1dDMyKDI1Nik7IC8vIG1heCBuYW1lCiAgICAgIH0gZWxzZSBpZihhID09IDMwKXsK ICAgICAgICBwdXQ2NCgxMCo0MDk2KTsgLy8gbWF4IHJlYWQKICAgICAgfSBlbHNlIGlmKGEgPT0g MzEpewogICAgICAgIHB1dDY0KDEwKjQwOTYpOyAvLyBtYXggd3JpdGUKICAgICAgfSBlbHNlIGlm KGEgPT0gMzMpewogICAgICAgIHB1dDMyKDA3NzcpOyAvLyBtb2RlCiAgICAgIH0gZWxzZSBpZihh ID09IDM1KXsKICAgICAgICBwdXQzMigzKTsgLy8gbnVtbGlua3MKICAgICAgfSBlbHNlIGlmKGEg PT0gMzYpewogICAgICAgIHB1dF9vcGFxdWUoNiwgIm90aGVyIik7IC8vIG93bmVyCiAgICAgIH0g ZWxzZSBpZihhID09IDM3KXsKICAgICAgICBwdXRfb3BhcXVlKDYsICJvdGhlciIpOyAvLyBvd25l cl9ncm91cAogICAgICB9IGVsc2UgaWYoYSA9PSA0MSl7CiAgICAgICAgcHV0MzIoMSk7IC8vIHJh d2RldiBtYWpvcgogICAgICAgIHB1dDMyKDEpOyAvLyByYXdkZXYgbWlub3IKICAgICAgfSBlbHNl IGlmKGE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mZjsKICAgICAgaWYocmVh ZG4oczEsIGlidWYsIGlsZW4pIDwgMCkgYnJlYWs7CiAgICAgIG9pID0gaWkgPSAwOwogICAgICBw dXQzMigwKTsgLy8gcGxhY2UtaG9sZGVyIGZvciBsZW5ndGgKICAgICAgcGFyc2VfcnBjKCk7CiAg ICAgIGlmKGFhaSA+IE5BQSl7CiAgICAgICAgcHJpbnRmKCJhYWkgJWQgTkFBICVkXG4iLCBhYWks IE5BQSk7CiAgICAgICAgZXhpdCgxKTsKICAgICAgfQogICAgICAqKGludCopKG9idWYrMCkgPSBo dG9ubCgob2kgLSA0KSB8IDB4ODAwMDAwMDApOwogICAgICBpZihzeW1zdGFydCAhPSAtMSl7CiAg ICAgICAgZm9yKGludCBpID0gc3ltc3RhcnQ7IGkgPCBvaSAmJiBpIDwgc3ltZW5kICYmIGFhaSA8 IE5BQTsgaSArPSA4KQogICAgICAgICAgKih1bnNpZ25lZCBsb25nIGxvbmcgKikob2J1ZiArIGkp IF49IGFhW2FhaSsrXTsKICAgICAgICBzeW1zdGFydCA9IC0xOwogICAgICB9CiAgICAgIGlmKHdy aXRlKHMxLCBvYnVmLCBvaSk8PTApIHBlcnJvcigid3JpdGUiKTsKICAgIH0KICAgIGV4aXQoMSk7 CiAgfQogIGNsb3NlKHMpOwogIHNsZWVwKDEwKTsKfQo= --=-=-=--