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 CC01FC433EF for ; Thu, 18 Nov 2021 10:48:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF6A661507 for ; Thu, 18 Nov 2021 10:48:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245753AbhKRKvH (ORCPT ); Thu, 18 Nov 2021 05:51:07 -0500 Received: from outgoing-stata.csail.mit.edu ([128.30.2.210]:53027 "EHLO outgoing-stata.csail.mit.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245691AbhKRKvE (ORCPT ); Thu, 18 Nov 2021 05:51:04 -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 1mnexV-000Ypx-3w; Thu, 18 Nov 2021 05:48:01 -0500 Received: from crash.local (localhost [127.0.0.1]) by crash.local (Postfix) with ESMTP id 6049213D7C342; Thu, 18 Nov 2021 05:48:00 -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 v4 client can dereference uninitialized pointer if server includes unrequested mdsthreshold attr MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Date: Thu, 18 Nov 2021 05:48:00 -0500 Message-ID: <60403.1637232480@crash.local> Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org --=-=-= Content-Type: text/plain I think nfs_fattr_init() ought to set fattr->mdsthreshold to NULL. If the kmalloc()'d attr memory doesn't happen to be zero at fattr->mdsthreshold, and the server returns an unrequested mdsthreshold attribute, then decode_getfattr_attrs() will try to store via the uninitialized pointer in decode_first_threshold_item4(). I've attached a demo program, which I run with slub_debug=FZP: # uname -a Linux (none) 5.15.0-rc7-dirty #78 SMP Mon Nov 15 15:49:15 UTC 2021 riscv64 riscv64 riscv64 GNU/Linux # cc nfs_15.c # ./nfs_15 ... [ 27.950132] decode_attr_mdsthreshold: Warning: Multiple pNFS layout drivers per filesystem not supported [ 27.969630] Unable to handle kernel paging request at virtual address 6b6b6b6b6b6b6b6f [ 28.058092] epc : ffffffff8023dee0 ra : ffffffff8023deb2 sp : ffffffd00055b500 [ 28.231013] status: 0000000200000121 badaddr: 6b6b6b6b6b6b6b6f cause: 000000000000000f [ 28.246069] [] decode_getfattr_attrs+0xdae/0x11fe [ 28.259758] [] decode_getfattr_generic.constprop.0+0x11e/0x1b2 [ 28.275547] [] nfs4_xdr_dec_lookup+0xa2/0xac [ 28.289208] [] rpcauth_unwrap_resp_decode+0x12/0x1a [ 28.302635] [] rpcauth_unwrap_resp+0x12/0x1a [ 28.316324] [] call_decode+0x112/0x176 [ 28.327634] [] __rpc_execute+0x76/0x216 [ 28.338932] [] rpc_execute+0x58/0x7e [ 28.350241] [] rpc_run_task+0x12c/0x16c [ 28.361567] [] nfs4_call_sync_custom+0x12/0x32 [ 28.375315] [] nfs4_do_call_sync+0x70/0x8c [ 28.389058] [] _nfs4_proc_lookup+0xf2/0x11a [ 28.402819] [] nfs4_proc_lookup_common+0x7c/0x2a2 [ 28.416516] [] nfs4_proc_lookup+0x42/0x9e [ 28.427830] [] nfs_lookup+0xa6/0x122 [ 28.439138] [] nfs_atomic_open+0x29a/0x342 [ 28.452815] [] path_openat+0x5ca/0xaf6 [ 28.464063] [] do_filp_open+0x70/0xd0 [ 28.475375] [] do_sys_openat2+0x1fc/0x298 [ 28.486697] [] do_sys_open+0x3c/0x78 [ 28.497986] [] sys_openat+0x18/0x20 [ 28.509270] [] ret_from_syscall+0x0/0x2 --=-=-= Content-Type: application/octet-stream Content-Disposition: attachment; filename=nfs_15.c Content-Transfer-Encoding: base64 I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHN0ZGxpYi5o PgojaW5jbHVkZSA8dW5pc3RkLmg+CiNpbmNsdWRlIDxmY250bC5oPgojaW5jbHVkZSA8c3lzL3Nv Y2tldC5oPgojaW5jbHVkZSA8c3lzL2lvY3RsLmg+CiNpbmNsdWRlIDxuZXRpbmV0L2luLmg+CiNp bmNsdWRlIDxzeXMvd2FpdC5oPgojaW5jbHVkZSA8c3lzL3Jlc291cmNlLmg+CiNpbmNsdWRlIDxz eXMvc3RhdC5oPgojaW5jbHVkZSA8YXNzZXJ0Lmg+CgppbnQgc3ltX29wID0gOTsKaW50IHN5bV9z a2lwID0gMTA7CmludCBzeW1fdHlwZSA9IDA7IC8vIGFsbCBmYXR0cjQgZmlsZSB0eXBlcwppbnQg c3ltX2ZoID0gMDsgLy8gYWxsIGZpbGUgaGFuZGxlcwppbnQgc3ltX2JpdG1hcHMgPSAwOwoKaW50 IG9wY291bnRzWzI1Nl07CmxvbmcgbG9uZyBuZXh0X2Nvb2tpZSA9IDM7CmludCBjdXJyZW50X2Zo ID0gMDsKCi8vIG1hcCBmaWxlL2RpciBuYW1lcyB0byBmaWxlIGhhbmRsZQpjaGFyICpmaG5hbWVz W10gPSB7CiAgICAgICAgICAgICAgICIiLAogICAgICAgICAgICAgICAidG1wIiwKICAgICAgICAg ICAgICAgIngiLAogICAgICAgICAgICAgICAieSIsCiAgICAgICAgICAgICAgICJ6IiwKICAgICAg ICAgICAgICAgInp6eiIsCiAgICAgICAgICAgICAgIDAKfTsKCmludApuYW1lMmZoKGNoYXIgKm5h bWUpCnsKICBmb3IoaW50IGkgPSAwOyBmaG5hbWVzW2ldOyBpKyspewogICAgaWYoc3RyY21wKG5h bWUsIGZobmFtZXNbaV0pID09IDApCiAgICAgIHJldHVybiBpOwogIH0KICByZXR1cm4gMTAw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gZWxzZSBpZihhID09IDU1KXsKICAgICAgICBwdXQ2NCgwKTsgLy8g bW91bnRlZF9vbl9maWxlaWQgPz8/CiAgICAgIH0gZWxzZSBpZihhID09IDYyKXsKICAgICAgICAv LyBmc19sYXlvdXRfdHlwZXMKICAgICAgICBwdXQzMigxKTsKICAgICAgICBwdXQzMigxKTsgLy8g TEFZT1VUNF9ORlNWNF8xX0ZJTEVTCiAgICAgIH0gZWxzZSBpZihhID09IDc1KXsKICAgICAgICAv LyBGQVRUUjRfU1VQUEFUVFJfRVhDTENSRUFUCiAgICAgICAgcHV0MzIoMik7IC8vIGJpdG1hcCBs ZW5ndGgKICAgICAgICBwdXQzMigweGZmZmZmZmZmKTsKICAgICAgICBwdXQzMigweGZmZmZmZmZm KTsKICAgICAgfSBlbHNlIHsKICAgICAgICBpZihzeW1fYml0bWFwcyl7CiAgICAgICAgICB3b3Jk c1thLzMyXSAmPSB+KDEgPDwgKGEgJSAzMikpOwogICAgICAgICAgKihpbnQqKShvYnVmICsgd29y ZDBpICsgNCooYS8zMikpID0gaHRvbmwod29yZHNbYS8zMl0pOwogICAgICAgIH0gZWxzZSB7CiAg ICAgICAgICBwcmludGYoInVua25vd24gcmVxdWVzdGVkIGF0dHIgJWRcbiIsIGEpOwogICAgICAg ICAgcHV0NjQoMCk7IC8vIFhYWAogICAgICAgIH0KICAgICAgfQogICAgfQogIH0KICAqKGludCop KG9idWYrbGVuaSkgPSBodG9ubChvaSAtIGxlbmkgLSA0KTsKfQoKdm9pZApwYXJzZV9vcF9nZXRh dHRyKCkKewogIGludCBiaXR3b3JkcyA9IHBhcnNlMzIoKTsKICBpbnQgd29yZHNbNjRdOwogIGZv cihpbnQgaSA9IDA7IGkgPCBiaXR3b3JkczsgaSsrKQogICAgd29yZHNbaV0gPSBwYXJzZTMyKCk7 CiAgcHV0MzIoMCk7IC8vIE9LCiAgcHV0X2ZhdHRyNChiaXR3b3Jkcywgd29yZHMsIGN1cnJlbnRf ZmgpOwp9Cgp2b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gICBwcmludGYoImFj Y2VwdCByZXR1cm5lZCAlZFxuIiwgczEpOwogICAgaWYoczEgPCAwKSB7IHBlcnJvcigiYWNjZXB0 Iik7IGV4aXQoMSk7IH0KICAgIGNsb3NlKHMpOwogIAogICAgd2hpbGUoMSl7CiAgICAgIGlmKHJl YWRuKHMxLCAmaWxlbiwgNCkgPCAwKSBicmVhazsKICAgICAgaWxlbiA9IG50b2hsKGlsZW4pOwog ICAgICBpbGVuICY9IDB4N2ZmZmZmZmY7CiAgICAgIGlmKHJlYWRuKHMxLCBpYnVmLCBpbGVuKSA8 IDApIGJyZWFrOwogICAgICBvaSA9IGlpID0gMDsKICAgICAgcHV0MzIoMCk7IC8vIHBsYWNlLWhv bGRlciBmb3IgbGVuZ3RoCiAgICAgIHBhcnNlX3JwYygpOwogICAgICAqKGludCopKG9idWYrMCkg PSBodG9ubCgob2kgLSA0KSB8IDB4ODAwMDAwMDApOwogICAgICBpZihhYWkgPiBOQUEpewogICAg ICAgIHByaW50Zigib29wcyBhYWkgJWQgTkFBICVkXG4iLCBhYWksIE5BQSk7CiAgICAgICAgZXhp dCgxKTsKICAgICAgfQogICAgICBpZihzeW1zdGFydCAhPSAtMSl7CiAgICAgICAgZm9yKGludCBp ID0gc3ltc3RhcnQ7IGkgPCBvaSAmJiBpIDwgc3ltZW5kICYmIGFhaSA8IE5BQTsgaSArPSA4KQog ICAgICAgICAgKih1bnNpZ25lZCBsb25nIGxvbmcgKikob2J1ZiArIGkpIF49IGFhW2FhaSsrXTsK ICAgICAgICBzeW1zdGFydCA9IC0xOwogICAgICB9CiAgICAgIGlmKHdyaXRlKHMxLCBvYnVmLCBv aSk8PTApIHBlcnJvcigid3JpdGUiKTsKICAgIH0KICAgIGV4aXQoMSk7CiAgfQogIGNsb3NlKHMp OwogIHNsZWVwKDIwKTsKfQo= --=-=-=--