Re: [PATCH 3/5] staging/lustre/lnet: fix potential null pointer dereference

From: Greg Kroah-Hartman
Date: Sun Apr 27 2014 - 18:39:41 EST


On Sun, Apr 27, 2014 at 05:17:24PM -0400, Oleg Drokin wrote:
> From: Dmitry Eremin <dmitry.eremin@xxxxxxxxx>
>
> Pointer 'tsc' returned from call to function 'sfw_find_test_case'
> at line 571 may be NULL and will be dereferenced at line 572.
> found by Klocwork Insight tool
>
> Signed-off-by: Dmitry Eremin <dmitry.eremin@xxxxxxxxx>
> Reviewed-on: http://review.whamcloud.com/9386
> Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-4629
> Reviewed-by: John L. Hammond <john.hammond@xxxxxxxxx>
> Reviewed-by: Isaac Huang <he.huang@xxxxxxxxx>
> Signed-off-by: Oleg Drokin <oleg.drokin@xxxxxxxxx>
> ---
> drivers/staging/lustre/lnet/selftest/framework.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
> index 050723a..c141f93 100644
> --- a/drivers/staging/lustre/lnet/selftest/framework.c
> +++ b/drivers/staging/lustre/lnet/selftest/framework.c
> @@ -547,10 +547,16 @@ sfw_test_rpc_fini (srpc_client_rpc_t *rpc)
> static inline int
> sfw_test_buffers(sfw_test_instance_t *tsi)
> {
> - struct sfw_test_case *tsc = sfw_find_test_case(tsi->tsi_service);
> - struct srpc_service *svc = tsc->tsc_srv_service;
> + struct sfw_test_case *tsc;
> + struct srpc_service *svc;
> int nbuf;
>
> + LASSERT(tsi != NULL);

Asserts suck rocks, which is why we avoid them at all costs. Please
just fix the code to work properly. If that parameter can be NULL, then
properly handle the error and return, don't oops the kernel.

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/