From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795989890; b=aUiYnvMQdLrH2/c7bd8xOWbHezhJ7nkayHtgQ5QeUbhPu5vBYrG5qtn+bXt7+x9VzUyE VYuysurslNiNtQ0gUG20Nh0V5viGlUOiXLyaOEz4/LuhUMlTdDQBKmgMRaDVrWR5RaIZj 7KbkvX8/9fy5jPGMD0ht2PEgDjiXW6VbjqRK0Zar/XDuap2GPl8wEZi6HI3y7eGXIa75X 7RCqbtgbRHUeq4QPZurt0bWjJberv03Bwl5VgEZ8VSgRaR8U3gaNpusF04n6UFotP3VDO wKoeB4SJUlGFWJwEcxYQd0fVYgSlCcMDu7c0Y0rfuaOrP3MjmPn6h4SQ2z/NKAIA9PA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795989890; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:Content-Transfer-Encoding:User-Agent:MIME-Version; bh=AjaeJzRkbAl6H/AV+0KDVH4oAvc+VPpjx3jGy6j6Nsg=; b=yEBRPmFJsrQPyknxM/k6aEs93zvyzwoDeJmPRyniwKopxW9oQDf4FzROt9nnE7tA8u7h kojaNbSyTH9bYul6wUdY4HgVPxecrAag5Dk0hHZP0wfcmaqNEZJlTLBUE6QXqeNbULm+d Z5uPrv2n96O/+AjhAYnGjn7Wsq/geUQv2G+o0XaOxzR9zIgOuaydFnCmLWbGNGfzC4Ak7 KepwFeA/GdR00uEH8nwHaMOYzaPqI8QewRMdqphsOF019m2U6YGNZPW1qeVBeJ5npLXXJ PdEVKNiWk8C2ONZF7qP7jgQ590AJYlyG5D1fxW0yZpg6cokLRselcSfPTiQHomj8KEA== 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=CtF5TZa6; arc=none smtp.remote-ip=209.85.161.41 Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) (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 B8418606A325 for ; Sun, 29 Nov 2026 22:04:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B8418606A325 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=CtF5TZa6 Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-71ad099391dso4614385eaf.3 for ; Sun, 29 Nov 2026 14:04:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795989888; x=1796594688; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to:content-type; bh=AjaeJzRkbAl6H/AV+0KDVH4oAvc+VPpjx3jGy6j6Nsg=; b=CtF5TZa6S5pbv+QM8GK6ndkaW7cta2gUXFeH6wHO3hnfGGC8U6n6kfNKf4WBpLa5xC xpPKGyKJAyOQszpgk8D09Vcn3weEB46VJX6UT0LSuDQF9cwDwzTMqPLcZKGQsUZgG9kh DtM4u9IjbeqJjt02uh4zD6s8kIh4cXLyx3zV+Z/VV7dBHjNz/piQ7UuBFMwtJXf3BPj9 wgMjqLg6K+5Pe06X8JEl1clXAK5KBIxtv69mAM95dV20uOo+uAeMl98+n1/PxKRo/T+O F2qp4KCvYsk+elVFZDc9SYtasb8jRQuPsoa4q4AsOAw56OdKguHqCBUlmXjN3ekY/iwi 929Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795989888; x=1796594688; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=AjaeJzRkbAl6H/AV+0KDVH4oAvc+VPpjx3jGy6j6Nsg=; b=fo716KZGq+8kK5yEtcbts92CmvjnFUGF9IpLBvnMYtUh0vvhk3vb3I0udyAan2F70v L2tzzYhObi1hPL8CdUBgqP1rW6hBD1YyJ6ZIFukOLd6+hIngbqV61ONo16VVh5ESK0hv UR8umWLCrJVogzrDbQGphXTiiPf/cAlXsmDC4WFXBSlMTQqdi7cLEfD7lydZgylfxilH hJ9ESov7ByQXE9ADHn6wiQ9/v/Y1R8OLEoSAEZG+4lIzf8KXymcUymdlXgeAHQOTVlmG /F7AFVmD30aAqv7lNeFF2ro+Tk3yGKpK4KSSJtZOIU9yY7iYTq/qb6a+QFVrKA/TaY2b 6iLg== X-Forwarded-Encrypted: i=1; AL+hErErgDFVR9z18EobCVZLwrgxiGnE4gOpz4PVv6fTojOksoFPvtVlgKXC3jT/vBoKZHvqSN0fgevKjBjEGc8=@vger.kernel.org X-Gm-Message-State: APuU4Z/0qEhRRNqPd+pJa+roNjxhfeAjIC4arrtzoSFX0V9ko0cTB8uL T+qThVOUG3TERpdp0HwzzhkefmDntbK+SKQKGk6cWnVc0/xLufEtm1I= X-Gm-Gg: AZFdTZfD106mS+VTSLYQ26cA8L/2IU/CWKT91d8JCVXHObeq5yds+V2XoYp6XALVrm7 PU0DpquKXv4miptNltCrZIuKSWDaVuN0AhnPnFIbIYouQXA3dSF61iND0TxU8XO6UX08e9h3cGw n2Jbaqos/lshNxmTnA6k83M02qAzPPrsmPK9SBWwUkFrggKCqnCtU9KNpVTR48kbdLxDsUfIPI7 +WsfFQqjfYehvxxNbU5sex4FUzXh733ACP2xeznGYaIG9H2cdVyAmCddoQoAJRdkU1rZakgBvFO LWIZr3ego+H9tuJE/LZVOLKTLPk5GLjnRJjt/GOf/iQHxmmgL7NBRTKhG3+29Yj8tmsmD6/Yw/V cLOhsKuEZFJFr1A41Elb7mkwqJ8uJRmwJTWeNZdcFd2UUjDFcYs8c0JF16jktAtkBiTmVTc5YsR uxssoOMOiLPmJVFovwr00gOnccZI0PaEW+BXaYWUCuUVMwwgRzkMOXY0zMe2vKOHQGn2So9E1OU oAjxYf2xr8+Pzgp1l1rw9XaCcyKcH7zc/2Q8GFfgzDHh4zlVVFgO0nOpYFD6UsCORWHPWacrIHy /Z5BmY2NtmEPpW7VYQjOM7+p+2ujjalh05n1VYbn7Ut8oB22XBenvGYluwQ5DQmbiGOxKDptmwl 6F7oolcUumyhJ1uSBbncBehVxNK1U+SSrQd0F6z/l2yYaWEuWjkAivJGupTMXP554QnRIUMTIyA FPoB+rboUoBVXyhdrxCQGIBs8mdD9PVPd8jKE= X-Received: by 2002:a05:6820:a747:10b0:6b3:bb82:2736 with SMTP id 006d021491bc7-71b3942ed27mr18673079eaf.17.1795989888577; Sun, 29 Nov 2026 14:04:48 -0800 (PST) Received: from [192.168.75.157] (162-232-235-235.lightspeed.livnmi.sbcglobal.net. [162.232.235.235]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-71b3806ef20sm21064317eaf.7.2026.11.29.14.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 14:04:47 -0800 (PST) Message-ID: <413396f84dc887a43ccd3a752cd78ad58b7c1670.camel@gmail.com> Subject: Re: [PATCH] NFSv4: fix bitmap length check in decode_bitmap() From: Trond Myklebust To: zhugl3@xiaopeng.com Cc: anna@kernel.org, linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, liuwb@xiaopeng.com Date: Sun, 29 Nov 2026 17:04:46 -0500 In-Reply-To: <20261012090834.920912-1-zhugl3@xiaopeng.com> References: <20261012090834.920912-1-zhugl3@xiaopeng.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.62.1 (3.62.1-1.fc45) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Mon, 12 Oct 2026 17:08:34 +0800, Guanglei Zhu wrote: > Reject attrlen values larger than 3, the size of the bitmap array. The wrap is real, but bitmap4 is a variable length array, and a well-formed bitmap with four or more words, for instance one with trailing zero words, is legal. The current code accepts such a bitmap in CB_GETATTR and CB_RECALL_ANY, and ignores the words past bitmap[2]. [ ... ] > + /* bitmap[] has only 3 words; also stops attrlen<<2 from wrapping */ > + if (unlikely(attrlen > 3)) > + return htonl(NFS4ERR_BADXDR); Doesn't this make both of those callbacks fail with NFS4ERR_BADXDR for such a bitmap? Could the length be bounded without rejecting long bitmaps instead? xdr_stream_decode_uint32_array() checks the count against SIZE_MAX / sizeof(__be32) before it calls xdr_inline_decode(), and returns -EMSGSIZE for an array longer than the destination. decode_bitmap4() in fs/nfs/nfs4xdr.c already treats that -EMSGSIZE as success. Anna is also reworking this function in "NFS: Modernize the callback decode_bitmap() function", and has said that her v2 will keep the current behaviour for long bitmaps, so the two changes would need to be reconciled. [ ... ] I've dropped this from my testing branch for now. On Mon, Oct 12, 2026 05:08 AM, Guanglei Zhu wrote: > decode_bitmap() reads attrlen from the callback message and passes > attrlen << 2 to xdr_inline_decode() as the number of bytes to > consume.=C2=A0 The shift is done in 32-bit arithmetic, so an attrlen of > 0x40000000 wraps to zero, the bounds check in > __xdr_inline_decode() passes, and the subsequent reads of > bitmap[0..2] walk up to 12 bytes past the end of the received > buffer. >=20 > Reject attrlen values larger than 3, the size of the bitmap array. >=20 > Signed-off-by: Guanglei Zhu > --- > Verified with an ASAN build of an exact user-space replica of > decode_bitmap() and __xdr_inline_decode(): attrlen=3D0x40000000 with > the message ending right after the attrlen word results in a > heap-buffer-overflow READ of size 4, 0 bytes after the allocation. >=20 > =C2=A0fs/nfs/callback_xdr.c | 3 +++ > =C2=A01 file changed, 3 insertions(+) >=20 > diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c > index 88e1af0fd..bea967e0c 100644 > --- a/fs/nfs/callback_xdr.c > +++ b/fs/nfs/callback_xdr.c > @@ -109,6 +109,9 @@ static __be32 decode_bitmap(struct xdr_stream > *xdr, uint32_t *bitmap) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (unlikely(p =3D=3D NULL)) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return htonl(NFS4= ERR_RESOURCE); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 attrlen =3D ntohl(*p); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0/* bitmap[] has only 3 words; also stops attr= len<<2 from > wrapping */ > +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (unlikely(attrlen > 3)) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return htonl(NFS4= ERR_BADXDR); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 p =3D xdr_inline_decode(xdr, attrlen << 2); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (unlikely(p =3D=3D NULL)) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return htonl(NFS4= ERR_RESOURCE); > --=20 > 2.43.0 >=20 --=20 Trond Myklebust Linux NFS client maintainer, Hammerspace trondmy@kernel.org, trond.myklebust@hammerspace.com