]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
NFSv4.2: Fix a memory stomp in decode_attr_security_label
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Tue, 18 Oct 2022 22:21:14 +0000 (18:21 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 7 Jan 2023 11:07:18 +0000 (12:07 +0100)
[ Upstream commit 43c1031f7110967c240cb6e922adcfc4b8899183 ]

We must not change the value of label->len if it is zero, since that
indicates we stored a label.

Fixes: b4487b935452 ("nfs: Fix getxattr kernel panic and memory overflow")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/nfs/nfs4xdr.c

index b50c97c6aecb3c025c28cff61635e543beade586..fc5583531fc0a096fa5774ba2a7aecfbca36ef31 100644 (file)
@@ -4160,12 +4160,10 @@ static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
                if (unlikely(!p))
                        goto out_overflow;
                if (len < NFS4_MAXLABELLEN) {
-                       if (label) {
-                               if (label->len) {
-                                       if (label->len < len)
-                                               return -ERANGE;
-                                       memcpy(label->label, p, len);
-                               }
+                       if (label && label->len) {
+                               if (label->len < len)
+                                       return -ERANGE;
+                               memcpy(label->label, p, len);
                                label->len = len;
                                label->pi = pi;
                                label->lfs = lfs;