Skip to content

Commit b4487b9

Browse files
JeffreyMitchellSLTrond Myklebust
authored andcommitted
nfs: Fix getxattr kernel panic and memory overflow
Move the buffer size check to decode_attr_security_label() before memcpy() Only call memcpy() if the buffer is large enough Fixes: aa9c266 ("NFS: Client implementation of Labeled-NFS") Signed-off-by: Jeffrey Mitchell <[email protected]> [Trond: clean up duplicate test of label->len != 0] Signed-off-by: Trond Myklebust <[email protected]>
1 parent d474f96 commit b4487b9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

fs/nfs/nfs4proc.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5856,8 +5856,6 @@ static int _nfs4_get_security_label(struct inode *inode, void *buf,
58565856
return ret;
58575857
if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL))
58585858
return -ENOENT;
5859-
if (buflen < label.len)
5860-
return -ERANGE;
58615859
return 0;
58625860
}
58635861

fs/nfs/nfs4xdr.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4166,7 +4166,11 @@ static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
41664166
return -EIO;
41674167
if (len < NFS4_MAXLABELLEN) {
41684168
if (label) {
4169-
memcpy(label->label, p, len);
4169+
if (label->len) {
4170+
if (label->len < len)
4171+
return -ERANGE;
4172+
memcpy(label->label, p, len);
4173+
}
41704174
label->len = len;
41714175
label->pi = pi;
41724176
label->lfs = lfs;

0 commit comments

Comments
 (0)