Skip to content

Commit 52cf247

Browse files
J. Bruce Fieldsgregkh
authored andcommitted
nfsd: encoders mustn't use unitialized values in error cases
commit f961e3f2acae94b727380c0b74e2d3954d0edf79 upstream. 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> Signed-off-by: J. Bruce Fields <bfields@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent da922dc commit 52cf247

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

fs/nfsd/nfs4xdr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4041,8 +4041,7 @@ nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr,
40414041
struct nfsd4_getdeviceinfo *gdev)
40424042
{
40434043
struct xdr_stream *xdr = &resp->xdr;
4044-
const struct nfsd4_layout_ops *ops =
4045-
nfsd4_layout_ops[gdev->gd_layout_type];
4044+
const struct nfsd4_layout_ops *ops;
40464045
u32 starting_len = xdr->buf->len, needed_len;
40474046
__be32 *p;
40484047

@@ -4059,6 +4058,7 @@ nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr,
40594058

40604059
/* If maxcount is 0 then just update notifications */
40614060
if (gdev->gd_maxcount != 0) {
4061+
ops = nfsd4_layout_ops[gdev->gd_layout_type];
40624062
nfserr = ops->encode_getdeviceinfo(xdr, gdev);
40634063
if (nfserr) {
40644064
/*
@@ -4111,8 +4111,7 @@ nfsd4_encode_layoutget(struct nfsd4_compoundres *resp, __be32 nfserr,
41114111
struct nfsd4_layoutget *lgp)
41124112
{
41134113
struct xdr_stream *xdr = &resp->xdr;
4114-
const struct nfsd4_layout_ops *ops =
4115-
nfsd4_layout_ops[lgp->lg_layout_type];
4114+
const struct nfsd4_layout_ops *ops;
41164115
__be32 *p;
41174116

41184117
dprintk("%s: err %d\n", __func__, nfserr);
@@ -4135,6 +4134,7 @@ nfsd4_encode_layoutget(struct nfsd4_compoundres *resp, __be32 nfserr,
41354134
*p++ = cpu_to_be32(lgp->lg_seg.iomode);
41364135
*p++ = cpu_to_be32(lgp->lg_layout_type);
41374136

4137+
ops = nfsd4_layout_ops[lgp->lg_layout_type];
41384138
nfserr = ops->encode_layoutget(xdr, lgp);
41394139
out:
41404140
kfree(lgp->lg_content);

0 commit comments

Comments
 (0)