From: Wang Shilong Date: Fri, 31 Mar 2017 02:50:44 +0000 (+0800) Subject: LU-9278 quota: avoid crash when access failed quota proc file X-Git-Tag: 2.9.56~39 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=cf539e343d3f91df7973720c26a07560a7f7904d LU-9278 quota: avoid crash when access failed quota proc file If quota dose not have accounting objects because of failing to load or unsupported type, @lqp_obj will be NULL, we could not access directly, add proper handling to avoid following crash [] ? lprocfs_quota_seq_show+0x460/0x460 [lquota] [] proc_reg_open+0x6f/0x100 [] do_dentry_open+0x1a7/0x2e0 [] ? security_inode_permission+0x1c/0x30 [] ? proc_reg_release+0x70/0x70 [] vfs_open+0x5f/0xe0 [] ? may_open+0x68/0x110 [] do_last+0x1ed/0x12a0 [] path_openat+0xc2/0x490 [] ? unlock_page+0x2b/0x30 [] do_filp_open+0x4b/0xb0 [] ? __alloc_fd+0xa7/0x130 [] do_sys_open+0xf3/0x1f0 [] SyS_open+0x1e/0x20 [] system_call_fastpath+0x16/0x1b Signed-off-by: Wang Shilong Change-Id: I8dfc2b35c1f38416ed0f933296bdaa455e117926 Reviewed-on: https://review.whamcloud.com/26277 Tested-by: Jenkins Reviewed-by: Niu Yawei Reviewed-by: Li Xi Tested-by: Maloo Reviewed-by: Andreas Dilger --- diff --git a/lustre/quota/lproc_quota.c b/lustre/quota/lproc_quota.c index ecee4a9..4ecbaa7 100644 --- a/lustre/quota/lproc_quota.c +++ b/lustre/quota/lproc_quota.c @@ -308,6 +308,11 @@ static int lprocfs_quota_seq_open(struct inode *inode, struct file *file) if (rc) goto out_env; + if (!lqp->lqp_obj) { + lqp->lqp_it = NULL; + goto out_seq; + } + /* initialize iterator */ iops = &lqp->lqp_obj->do_index_ops->dio_it; it = iops->init(&lqp->lqp_env, lqp->lqp_obj, 0); @@ -322,6 +327,7 @@ static int lprocfs_quota_seq_open(struct inode *inode, struct file *file) lqp->lqp_it = it; lqp->lqp_cookie = 0; +out_seq: seq = file->private_data; seq->private = lqp; return 0; @@ -340,9 +346,10 @@ static int lprocfs_quota_seq_release(struct inode *inode, struct file *file) const struct dt_it_ops *iops; LASSERT(lqp); - iops = &lqp->lqp_obj->do_index_ops->dio_it; - if (lqp->lqp_it != NULL) + if (lqp->lqp_it != NULL) { + iops = &lqp->lqp_obj->do_index_ops->dio_it; iops->fini(&lqp->lqp_env, lqp->lqp_it); + } lu_env_fini(&lqp->lqp_env); OBD_FREE_PTR(lqp);