Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796111729; b=CDrCxnbW004RDTBj7mYFMWcDQ1kFNhNFhqWOkRgW+9c2Bexuq9CU7YSNjGJ2uQ/GZbWo tgc2gGt0iHJZp9igFUsjvs7/TkMv9twQcW9DQj7SLU7+Qn5LCxZT5A+XPkmXIoEPlUJW3 dmUXBuu4IHY5Rlq9aQp4qP75PEszc7oYgyOXtIagcu8raysKFlIjKUJ79vniBgZJCRo5o GdxlZD3zlb0Ikl65i7KfLFpsJDGTkg8HllCeWruJS09DMa8GSlu5EC/IeODPrHYuasPBi t6I2HhpgjX1fTo8Ho1wvUTp7NriP3JyXJSm1Ybi4Bpb9SZV2KBfpKDpRTGulchMZVBA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796111729; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=JW4E+WL2Z2aO33NqfBFQXiqcZbpB26k9Z3PGhTGWYKQ=; b=TgGNc1ixHjCWs59f7enQnUD779cUzDicYo0F92haRHi6+D8SNLyZE0ThKrYTw8wKA3i6 ch/u4p2ddk9BSqijk+KzAoWZzvVa2FUh1L7c1kq9CJH6EtEnAGBpbwuhDI0Gxz3UtxO6+ LOkh2vaO7A2qcqoHtIVDvKNHQmp2cEdwhrZ6NviTt54rdGHHDJk8IGedluD+u0SBrkZ6a wozcYFyGTwQhdWuR8K07DtP1b6/75NNRHFEME3f+FZQlz32/yyFJYd1NhdqryxxP+kXfy HlEmUD2Xjj/FcRhKwkqIxzjakR1EWFqRBNSfVuoi1zfbo1+fTDs4X59FSEeYpNneDqg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="eoyaT/vy"; arc=none smtp.remote-ip=209.85.214.174 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A357C606A325 for ; Tue, 1 Dec 2026 07:55:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A357C606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eoyaT/vy Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2f0918f9e6cso37524035ad.1 for ; Mon, 30 Nov 2026 23:55:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796111728; x=1796716528; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JW4E+WL2Z2aO33NqfBFQXiqcZbpB26k9Z3PGhTGWYKQ=; b=eoyaT/vyrxhcUDpPwG4QHNwVrJkk1aDlOxgmZXUbRur1m0sId5+Aosn20CSOnBDFuU pQffOPwx3SWRl8rrZ0/ugAfHHcG0vK+OkEHktusEuwihvGGyHC2Iq6sZ9kMN1CYVv6rG CFvOymsf108N/sjNRzd2sLQy7nYt8JRnlS02xfo3og2NjR36jlaZcNMg2JiYcWuJa5hK bi4WMPmf8UdhfFVSi+rxhmXjM8sZRKYGj3G2TDUCZHW+Y0Focfm9jP5OzlImSymHEA1S kkER0UPF/pGJ0MNv6cNqdi8ydoqtlPLPr3wbH8bFzZamLNbojv4lFoQqisDqyQUcCD14 rzzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796111728; x=1796716528; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=JW4E+WL2Z2aO33NqfBFQXiqcZbpB26k9Z3PGhTGWYKQ=; b=FXRgGk9UhelKCASGuXBA79oW/EQqBDbZl/WiRBxdSHkKrvUfqUTllc2yO6YaGLqoLf iHZDhL3dGJuxOk5mMNxKbhTtYyxYz6x8EvSsE0MRsZ7kqeHXirb2b/mA1OC/ZfqiwkGU JOeKgvCvo4dkAQO83OHQ4gfjGDdn+KrAPMifg3vKSLNQOM1ZfvzoCi9nJHfMrhUEaUYR 5OnJ9cNlKazBeljKHoowEXZZwNNEb4ZS/kHhl/zaH4F90vlw6CNWXxzj2CXb5uiMr3ku lkSkM7GAbyrwTsHd0U+PZxh/2Orbj6A/9M5hJurP4sIYgR/dsJLVZeiKoFJCnf6PyV5R kjnw== X-Gm-Message-State: APuU4Z/+Yig3ZDsaA5oE7XTZqpb02DqBVukG7y2ANtv2N8iqJ7CuXOjG 19xU8d+gzaGd5nnAbSjQ8+pyQ+oESOSpFA0LElctk6v9mb3h8OZgSjUmc0KkAfvX/Po= X-Gm-Gg: AZFdTZfUCk2DXtF3lSOnvo76DxCSLupydO1XeGzuvXxjNfCOxtKJK5ZpC1mbAMgDRzH PN+jCtbOQfmDGk3lmIcSeOfQILh6B3C4+7TQugsNBLyS1s0r0ioS95htCkxCmIMao9Qq/rix8Fs Pbjh9sboOgUJjzl8R6Egh+S1+MFiFHqrh8SBmPdJUB/ZYvCRSlUiIm8Dn1kOuUvDTx+tLDVKzrm Yi/vyZmYpXtoml//onMGiJRaTdlROI5EG2DD2y6QxQWJEV5OZui1zEtQLCzZYLgkqozdNdp87mK QAqysYSuKq/qHGvfat/Lkd7BcV4KRo0ni73Rysu9xuB2JkNoy+uqnaeyDpmfdG0fQqtqGAsNSi9 JnvL9VmB6oFBOhBaRiZMl+bIPD5ylI8XVcxNYBod7CEnPFJDcg0mWQm6d7SrVCWvJuCVo+hAhCJ HJeaSsAVSIz32+IddHJj2XOMyic3Gta2fL+ItnDJUks69fzbhsOZcAZUbXvT6mAbDZ40bZVg0uV 6J5Gfi0YAPXzRmOvH1oafmjdbSEixFJmQKOTyRS98cQD0f0EVefIYOUTUn1kMQeLAEGihQpCny6 HSRmDmAEq6NWJHlN44WU6/jpzfO1 X-Received: by 2002:a17:902:e847:b0:2ed:294c:2b9c with SMTP id d9443c01a7336-2f03f242559mr314149845ad.51.1796111727801; Mon, 30 Nov 2026 23:55:27 -0800 (PST) Received: from Mac ([123.215.20.10]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f08d73dfe0sm142228235ad.69.2026.11.30.23.55.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 Nov 2026 23:55:27 -0800 (PST) From: Jiwoong Wi To: Chuck Lever , Jeff Layton , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: linux-nfs@vger.kernel.org, stable@vger.kernel.org, bobtobabz@gmail.com, Jiwoong Wi Subject: [PATCH v2 1/2] nfsd: reject LAYOUTGET on non-regular files Date: Tue, 1 Dec 2026 16:55:01 +0900 Message-ID: <20261201075502.22214-1-dwdnlzj@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261130070511.65684-1-dwdnlzj@gmail.com> References: <20261130070511.65684-1-dwdnlzj@gmail.com> X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit LAYOUTGET expects the current filehandle to identify a regular file, but nfsd4_layoutget() passes a zero type to fh_verify(). A client can obtain a directory delegation via GET_DIR_DELEGATION and use its stateid with the matching directory filehandle. This passes the filehandle match in nfsd4_preprocess_layout_stateid(), allowing an RW block layout for the directory. With a nonzero minimum length, the block layout provider asks the filesystem to allocate the requested range. On XFS this can create noncontiguous directory data blocks. A later CREATE can then index beyond the leaf directory bests table and cause a two-byte heap out-of-bounds write. Check the dentry type after fh_verify() so its security and access checks retain their existing order. Return NFS4ERR_WRONG_TYPE for non-regular files before any layout provider or filesystem callback is invoked. Validation used an arm64 kernel with 64 KiB pages, Generic KASAN, and lockdep. The full kernel built with GCC 13.3 and CONFIG_WERROR=y; the changed object also built with W=1. The unpatched three-block directory layout trigger reproduced the out-of-bounds write twice. With this change, directory and symlink LAYOUTGET requests returned NFS4ERR_WRONG_TYPE, while a regular-file LAYOUTGET succeeded. The CREATE following the directory request and NFSv4.1 mount, write/readback, and unmount tests completed without a KASAN, Oops, or panic report. Fixes: 8b99f6a8c116 ("nfsd: wire up GET_DIR_DELEGATION handling") Link: https://lore.kernel.org/r/dded948f-dfdb-4919-aae1-bf84147bcd72@slotpi15m67/ Cc: stable@vger.kernel.org Signed-off-by: Jiwoong Wi --- Changes since v1: - Explain the GET_DIR_DELEGATION prerequisite. - Correct the Fixes tag. - Add a separate LAYOUTCOMMIT fix as patch 2/2. v1: https://lore.kernel.org/r/20261130070511.65684-1-dwdnlzj@gmail.com/ fs/nfsd/nfs4proc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index bb149a3e9a..92a92b3e6d 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -3082,6 +3082,10 @@ nfsd4_layoutget(struct svc_rqst *rqstp, nfserr = fh_verify(rqstp, current_fh, 0, accmode); if (nfserr) goto out; + if (!d_is_reg(current_fh->fh_dentry)) { + nfserr = nfserr_wrong_type; + goto out; + } nfserr = nfserr_layoutunavailable; ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); base-commit: 3c6328ce32970f15f882ff3c6ab1b1648723b000 -- 2.50.1 (Apple Git-155)