linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: chuck.lever@oracle.com, linux-nfs@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fs: nfsd: Fix three possible null-pointer dereferences
Date: Tue, 30 Jul 2019 19:03:39 -0400	[thread overview]
Message-ID: <20190730230339.GD3544@fieldses.org> (raw)
In-Reply-To: <20190724082803.1077-1-baijiaju1990@gmail.com>

On Wed, Jul 24, 2019 at 04:28:03PM +0800, Jia-Ju Bai wrote:
> In nfs4_xdr_dec_cb_recall(), nfs4_xdr_dec_cb_layout() and
> nfs4_xdr_dec_cb_notify_lock(), there is an if statement to check whether
> cb is NULL.
> 
> When cb is NULL, the three functions all call:
>     decode_cb_op_status(..., &cb->cb_status);
> 
> Thus, possible null-pointer dereferences may occur.
> 
> To fix these possible bugs, -EINVAL is returned when cb is NULL.
> 
> These bugs are found by a static analysis tool STCheck written by us.

Thanks!  But I think actually the correct fix is just to remove the NULL
checks entirely.

--b.

> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  fs/nfsd/nfs4callback.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
> index 397eb7820929..55949a158b6b 100644
> --- a/fs/nfsd/nfs4callback.c
> +++ b/fs/nfsd/nfs4callback.c
> @@ -516,7 +516,8 @@ static int nfs4_xdr_dec_cb_recall(struct rpc_rqst *rqstp,
>  		status = decode_cb_sequence4res(xdr, cb);
>  		if (unlikely(status || cb->cb_seq_status))
>  			return status;
> -	}
> +	} else
> +		return -EINVAL;
>  
>  	return decode_cb_op_status(xdr, OP_CB_RECALL, &cb->cb_status);
>  }
> @@ -608,7 +609,9 @@ static int nfs4_xdr_dec_cb_layout(struct rpc_rqst *rqstp,
>  		status = decode_cb_sequence4res(xdr, cb);
>  		if (unlikely(status || cb->cb_seq_status))
>  			return status;
> -	}
> +	} else
> +		return -EINVAL;
> +
>  	return decode_cb_op_status(xdr, OP_CB_LAYOUTRECALL, &cb->cb_status);
>  }
>  #endif /* CONFIG_NFSD_PNFS */
> @@ -667,7 +670,9 @@ static int nfs4_xdr_dec_cb_notify_lock(struct rpc_rqst *rqstp,
>  		status = decode_cb_sequence4res(xdr, cb);
>  		if (unlikely(status || cb->cb_seq_status))
>  			return status;
> -	}
> +	} else
> +		return -EINVAL;
> +	
>  	return decode_cb_op_status(xdr, OP_CB_NOTIFY_LOCK, &cb->cb_status);
>  }
>  
> -- 
> 2.17.0

  reply	other threads:[~2019-07-30 23:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-24  8:28 [PATCH] fs: nfsd: Fix three possible null-pointer dereferences Jia-Ju Bai
2019-07-30 23:03 ` J. Bruce Fields [this message]
2019-07-30 23:08   ` J. Bruce Fields

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190730230339.GD3544@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=baijiaju1990@gmail.com \
    --cc=chuck.lever@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).