staging/lustre/ptlrpc: Removes potential null dereference
authorLidza Louina <lidza.louina@oracle.com>
Mon, 16 May 2016 18:51:42 +0000 (14:51 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 8 Jun 2016 05:38:19 +0000 (22:38 -0700)
The lustre_msg_buf method could return NULL. Subsequent code didn't
check if it's null before using it. This patch adds two checks.

Signed-off-by: Lidza Louina <lidza.louina@oracle.com>
Acked-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/ptlrpc/sec.c
drivers/staging/lustre/lustre/ptlrpc/sec_plain.c

index 187fd1d6898c36ce3e97dac4167199dd7075b85a..657b41fdf4c5f504391d135d29f80bd3ac4f58a4 100644 (file)
@@ -2196,6 +2196,9 @@ int sptlrpc_pack_user_desc(struct lustre_msg *msg, int offset)
 
        pud = lustre_msg_buf(msg, offset, 0);
 
+       if (!pud)
+               return -EINVAL;
+
        pud->pud_uid = from_kuid(&init_user_ns, current_uid());
        pud->pud_gid = from_kgid(&init_user_ns, current_gid());
        pud->pud_fsuid = from_kuid(&init_user_ns, current_fsuid());
index 37c9f4c453de0128f6329648f77b09d6a337693c..ec8edbf7516d448a8a75ed5ea3045ac637effb3d 100644 (file)
@@ -574,8 +574,12 @@ int plain_alloc_reqbuf(struct ptlrpc_sec *sec,
        lustre_init_msg_v2(req->rq_reqbuf, PLAIN_PACK_SEGMENTS, buflens, NULL);
        req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_MSG_OFF, 0);
 
-       if (req->rq_pack_udesc)
-               sptlrpc_pack_user_desc(req->rq_reqbuf, PLAIN_PACK_USER_OFF);
+       if (req->rq_pack_udesc) {
+               int rc = sptlrpc_pack_user_desc(req->rq_reqbuf,
+                                             PLAIN_PACK_USER_OFF);
+               if (rc < 0)
+                       return rc;
+       }
 
        return 0;
 }