diff mbox

SUNRPC: Fix possible NULL pointer dereference

Message ID 1361744605-28235-1-git-send-email-s.syam@samsung.com
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Syam Sidhardhan Feb. 24, 2013, 10:23 p.m. UTC
Check for cred == NULL has to be done before accessing cred.

Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
---
 net/sunrpc/auth.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Trond Myklebust Feb. 24, 2013, 10:35 p.m. UTC | #1
On Mon, 2013-02-25 at 03:53 +0530, Syam Sidhardhan wrote:
> Check for cred == NULL has to be done before accessing cred.
> 
> Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
> ---
>  net/sunrpc/auth.c |    7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
> index f529404..18678a6 100644
> --- a/net/sunrpc/auth.c
> +++ b/net/sunrpc/auth.c
> @@ -695,10 +695,13 @@ rpcauth_invalcred(struct rpc_task *task)
>  {
>  	struct rpc_cred *cred = task->tk_rqstp->rq_cred;
>  
> +	if (cred == NULL)
> +		return;
> +
>  	dprintk("RPC: %5u invalidating %s cred %p\n",
>  		task->tk_pid, cred->cr_auth->au_ops->au_name, cred);
> -	if (cred)
> -		clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
> +
> +	clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
>  }
>  
>  int

Do we need that check at all?
Syam Sidhardhan Feb. 25, 2013, 3:21 p.m. UTC | #2
Hi Trond,

On Mon, Feb 25, 2013 at 4:05 AM, Myklebust, Trond
<Trond.Myklebust@netapp.com> wrote:
> On Mon, 2013-02-25 at 03:53 +0530, Syam Sidhardhan wrote:
>> Check for cred == NULL has to be done before accessing cred.
>>
>> Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
>> ---
>>  net/sunrpc/auth.c |    7 +++++--
>>  1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
>> index f529404..18678a6 100644
>> --- a/net/sunrpc/auth.c
>> +++ b/net/sunrpc/auth.c
>> @@ -695,10 +695,13 @@ rpcauth_invalcred(struct rpc_task *task)
>>  {
>>       struct rpc_cred *cred = task->tk_rqstp->rq_cred;
>>
>> +     if (cred == NULL)
>> +             return;
>> +
>>       dprintk("RPC: %5u invalidating %s cred %p\n",
>>               task->tk_pid, cred->cr_auth->au_ops->au_name, cred);
>> -     if (cred)
>> -             clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
>> +
>> +     clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
>>  }
>>
>>  int
>
> Do we need that check at all?

I'm not sure whether we need that check or not. However
similar functions such as rpcauth_refreshcred(), rpcauth_uptodatecred() etc
are doing the same check inside. Cppcheck is throwing an error too.

Regards,
Syam
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index f529404..18678a6 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -695,10 +695,13 @@  rpcauth_invalcred(struct rpc_task *task)
 {
 	struct rpc_cred *cred = task->tk_rqstp->rq_cred;
 
+	if (cred == NULL)
+		return;
+
 	dprintk("RPC: %5u invalidating %s cred %p\n",
 		task->tk_pid, cred->cr_auth->au_ops->au_name, cred);
-	if (cred)
-		clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
+
+	clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
 }
 
 int