Skip to content

Commit

Permalink
NFSv4.2: Fix a memory stomp in decode_attr_security_label
Browse files Browse the repository at this point in the history
[ Upstream commit 43c1031 ]

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

Fixes: b4487b9 ("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>
  • Loading branch information
Trond Myklebust authored and gregkh committed Dec 31, 2022
1 parent 34dffc7 commit 51899ee
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions fs/nfs/nfs4xdr.c
Expand Up @@ -4181,12 +4181,10 @@ static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
return -EIO;
bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
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;
Expand Down

0 comments on commit 51899ee

Please sign in to comment.