Skip to content

Commit c77efc1

Browse files
kinglongmeetrondmypd
authored andcommitted
nfs/blocklayout: Check max uuids and devices before decoding
Avoid nfs return uuids/devices larger than maximum. Signed-off-by: Kinglong Mee <kinglongmee@gmail.com> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
1 parent ecc2b88 commit c77efc1

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎fs/nfs/blocklayout/dev.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ nfs4_block_decode_volume(struct xdr_stream *xdr, struct pnfs_block_volume *b)
6565
if (!p)
6666
return -EIO;
6767
b->simple.nr_sigs = be32_to_cpup(p++);
68-
if (!b->simple.nr_sigs) {
69-
dprintk("no signature\n");
68+
if (!b->simple.nr_sigs || b->simple.nr_sigs > PNFS_BLOCK_MAX_UUIDS) {
69+
dprintk("Bad signature count: %d\n", b->simple.nr_sigs);
7070
return -EIO;
7171
}
7272

@@ -105,7 +105,12 @@ nfs4_block_decode_volume(struct xdr_stream *xdr, struct pnfs_block_volume *b)
105105
p = xdr_inline_decode(xdr, 4);
106106
if (!p)
107107
return -EIO;
108+
108109
b->concat.volumes_count = be32_to_cpup(p++);
110+
if (b->concat.volumes_count > PNFS_BLOCK_MAX_DEVICES) {
111+
dprintk("Too many volumes: %d\n", b->concat.volumes_count);
112+
return -EIO;
113+
}
109114

110115
p = xdr_inline_decode(xdr, b->concat.volumes_count * 4);
111116
if (!p)
@@ -117,8 +122,13 @@ nfs4_block_decode_volume(struct xdr_stream *xdr, struct pnfs_block_volume *b)
117122
p = xdr_inline_decode(xdr, 8 + 4);
118123
if (!p)
119124
return -EIO;
125+
120126
p = xdr_decode_hyper(p, &b->stripe.chunk_size);
121127
b->stripe.volumes_count = be32_to_cpup(p++);
128+
if (b->stripe.volumes_count > PNFS_BLOCK_MAX_DEVICES) {
129+
dprintk("Too many volumes: %d\n", b->stripe.volumes_count);
130+
return -EIO;
131+
}
122132

123133
p = xdr_inline_decode(xdr, b->stripe.volumes_count * 4);
124134
if (!p)

0 commit comments

Comments
 (0)