Skip to contentSkip to conversation

NFSv4: Possible buffer overflow in security label decode.

PATCH Nazarov Sergey 2 participants 2 messages Dec 9, 2015 – Dec 26, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi!
Buffer overflow possible in decode_attr_security_label, if given label buffer size is not enough to store data received from server. This adds additional check for buffer capacity:

---
 fs/nfs/nfs4xdr.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
fs/nfs/nfs4xdr.c +6 -2
index 4e44412..6a6302b 100644
@@ -4157,7 +4157,9 @@ 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 && label->label) {
+				if (len > label->len)
+					return -ERANGE;
 				memcpy(label->label, p, len);
 				label->len = len;
 				label->pi = pi;
@@ -4165,9 +4167,11 @@ static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
 				status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
 			}
 			bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
-		} else
+		} else {
 			printk(KERN_WARNING "%s: label too long (%u)!\n",
 					__func__, len);
+			return -EIO;
+		}
 	}
 	if (label && label->label)
 		dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
#1 lore raw

Hi Sergey,

Quoted 26 lines · Nazarov Sergey

Hi!
Buffer overflow possible in decode_attr_security_label, if given label buffer size is not enough to store data received from server. This adds additional check for buffer capacity:

---
 fs/nfs/nfs4xdr.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
fs/nfs/nfs4xdr.c +3 -1
index 4e44412..6a6302b 100644
@@ -4157,7 +4157,9 @@ 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 && label->label) {
+                               if (len > label->len)
+                                       return -ERANGE;
                                memcpy(label->label, p, len);
                                label->len = len;
                                label->pi = pi;
@@ -4165,9 +4167,11 @@ static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
                                status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
                        }
                        bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;

fs/nfs/nfs4xdr.c static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,

Quoted 10 lines
fs/nfs/nfs4xdr.c +3 -2
-               } else
+               } else {
                        printk(KERN_WARNING "%s: label too long (%u)!\n",
                                        __func__, len);
+                       return -EIO;
+               }
        }
        if (label && label->label)
                dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
--

Looks good, but could you please add a Signed-off-by: line as per the instructions in Documentation/SubmittingPatches?

Thanks!
Trond

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, PrimaryData
[email protected]