diff options
author | J. Bruce Fields <bfields@redhat.com> | 2017-05-05 16:17:57 -0400 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2017-05-10 14:25:19 -0400 |
commit | f961e3f2acae94b727380c0b74e2d3954d0edf79 (patch) | |
tree | de0fd2594a2efeaa34bdefff2880ef9824975cf3 | |
parent | b550a32e60a4941994b437a8d662432a486235a5 (diff) |
nfsd: encoders mustn't use unitialized values in error cases
In error cases, lgp->lg_layout_type may be out of bounds; so we
shouldn't be using it until after the check of nfserr.
This was seen to crash nfsd threads when the server receives a LAYOUTGET
request with a large layout type.
GETDEVICEINFO has the same problem.
Reported-by: Ari Kauppi <Ari.Kauppi@synopsys.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Cc: stable@vger.kernel.org
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
-rw-r--r-- | fs/nfsd/nfs4xdr.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 33017d652b1d..8e9652f37f1f 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c | |||
@@ -4119,8 +4119,7 @@ nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr, | |||
4119 | struct nfsd4_getdeviceinfo *gdev) | 4119 | struct nfsd4_getdeviceinfo *gdev) |
4120 | { | 4120 | { |
4121 | struct xdr_stream *xdr = &resp->xdr; | 4121 | struct xdr_stream *xdr = &resp->xdr; |
4122 | const struct nfsd4_layout_ops *ops = | 4122 | const struct nfsd4_layout_ops *ops; |
4123 | nfsd4_layout_ops[gdev->gd_layout_type]; | ||
4124 | u32 starting_len = xdr->buf->len, needed_len; | 4123 | u32 starting_len = xdr->buf->len, needed_len; |
4125 | __be32 *p; | 4124 | __be32 *p; |
4126 | 4125 | ||
@@ -4137,6 +4136,7 @@ nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr, | |||
4137 | 4136 | ||
4138 | /* If maxcount is 0 then just update notifications */ | 4137 | /* If maxcount is 0 then just update notifications */ |
4139 | if (gdev->gd_maxcount != 0) { | 4138 | if (gdev->gd_maxcount != 0) { |
4139 | ops = nfsd4_layout_ops[gdev->gd_layout_type]; | ||
4140 | nfserr = ops->encode_getdeviceinfo(xdr, gdev); | 4140 | nfserr = ops->encode_getdeviceinfo(xdr, gdev); |
4141 | if (nfserr) { | 4141 | if (nfserr) { |
4142 | /* | 4142 | /* |
@@ -4189,8 +4189,7 @@ nfsd4_encode_layoutget(struct nfsd4_compoundres *resp, __be32 nfserr, | |||
4189 | struct nfsd4_layoutget *lgp) | 4189 | struct nfsd4_layoutget *lgp) |
4190 | { | 4190 | { |
4191 | struct xdr_stream *xdr = &resp->xdr; | 4191 | struct xdr_stream *xdr = &resp->xdr; |
4192 | const struct nfsd4_layout_ops *ops = | 4192 | const struct nfsd4_layout_ops *ops; |
4193 | nfsd4_layout_ops[lgp->lg_layout_type]; | ||
4194 | __be32 *p; | 4193 | __be32 *p; |
4195 | 4194 | ||
4196 | dprintk("%s: err %d\n", __func__, nfserr); | 4195 | dprintk("%s: err %d\n", __func__, nfserr); |
@@ -4213,6 +4212,7 @@ nfsd4_encode_layoutget(struct nfsd4_compoundres *resp, __be32 nfserr, | |||
4213 | *p++ = cpu_to_be32(lgp->lg_seg.iomode); | 4212 | *p++ = cpu_to_be32(lgp->lg_seg.iomode); |
4214 | *p++ = cpu_to_be32(lgp->lg_layout_type); | 4213 | *p++ = cpu_to_be32(lgp->lg_layout_type); |
4215 | 4214 | ||
4215 | ops = nfsd4_layout_ops[lgp->lg_layout_type]; | ||
4216 | nfserr = ops->encode_layoutget(xdr, lgp); | 4216 | nfserr = ops->encode_layoutget(xdr, lgp); |
4217 | out: | 4217 | out: |
4218 | kfree(lgp->lg_content); | 4218 | kfree(lgp->lg_content); |