staging/lustre/ptlrpc: Fix assertion failure of null_alloc_rs()
authorPatrick Farrell <paf@cray.com>
Sun, 27 Apr 2014 17:06:25 +0000 (13:06 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 27 Apr 2014 17:21:37 +0000 (10:21 -0700)
lustre_get_emerg_rs() set the size of the reply buffer to zero
by mistake, which will cause LBUG in null_alloc_rs() when memory
pressure is high. This patch fix this problem and adds a size
check to avoid the problem of insufficient buffer size.

Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Patrick Farrell <paf@cray.com>
Reviewed-on: http://review.whamcloud.com/8200
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-3680
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Signed-off-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/ptlrpc/pack_generic.c
drivers/staging/lustre/lustre/ptlrpc/sec.c

index 45c0b84621e4b617752c72df385b11139aa737d4..cddeeb6bb23d826971f2bec635d74c452b81be9e 100644 (file)
@@ -300,6 +300,7 @@ lustre_get_emerg_rs(struct ptlrpc_service_part *svcpt)
        spin_unlock(&svcpt->scp_rep_lock);
 
        memset(rs, 0, svcpt->scp_service->srv_max_reply_size);
+       rs->rs_size = svcpt->scp_service->srv_max_reply_size;
        rs->rs_svcpt = svcpt;
        rs->rs_prealloc = 1;
 out:
index b0a1c5a0d5cc803e45526033c0689d8a5f236d1f..5e7539292f5eb8d873ad29f3c23e3b645617b451 100644 (file)
@@ -2086,8 +2086,18 @@ int sptlrpc_svc_alloc_rs(struct ptlrpc_request *req, int msglen)
 
        rc = policy->sp_sops->alloc_rs(req, msglen);
        if (unlikely(rc == -ENOMEM)) {
+               struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
+               if (svcpt->scp_service->srv_max_reply_size <
+                  msglen + sizeof(struct ptlrpc_reply_state)) {
+                       /* Just return failure if the size is too big */
+                       CERROR("size of message is too big (%zd), %d allowed",
+                               msglen + sizeof(struct ptlrpc_reply_state),
+                               svcpt->scp_service->srv_max_reply_size);
+                       return -ENOMEM;
+               }
+
                /* failed alloc, try emergency pool */
-               rs = lustre_get_emerg_rs(req->rq_rqbd->rqbd_svcpt);
+               rs = lustre_get_emerg_rs(svcpt);
                if (rs == NULL)
                        return -ENOMEM;