All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers:block:drbd:drbd_state:fix null-pointer dereference
@ 2017-04-25  6:35 Heloise
  2017-04-25  7:06 ` Lars Ellenberg
  0 siblings, 1 reply; 2+ messages in thread
From: Heloise @ 2017-04-25  6:35 UTC (permalink / raw)
  To: philipp.reisner, lars.ellenberg; +Cc: drbd-dev, linux-kernel, Heloise

Signed-off-by: Heloise <os@iscas.ac.cn>

In is_valid_state(), there is NULL validation for the variable nc
"if (nc)". However,the code will continue to execute when nc is NULL.
nc->verify_alg[0] is used in subsequent code, which may cause
null-pointer dereference, fix it.
---
 drivers/block/drbd/drbd_state.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/drbd/drbd_state.c b/drivers/block/drbd/drbd_state.c
index eea0c4a..1963b83 100644
--- a/drivers/block/drbd/drbd_state.c
+++ b/drivers/block/drbd/drbd_state.c
@@ -845,7 +845,7 @@ is_valid_state(struct drbd_device *device, union drbd_state ns)
 		rv = SS_CONNECTED_OUTDATES;
 
 	else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) &&
-		 (nc->verify_alg[0] == 0))
+		 (nc != NULL && nc->verify_alg[0] == 0))
 		rv = SS_NO_VERIFY_ALG;
 
 	else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) &&
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drivers:block:drbd:drbd_state:fix null-pointer dereference
  2017-04-25  6:35 [PATCH] drivers:block:drbd:drbd_state:fix null-pointer dereference Heloise
@ 2017-04-25  7:06 ` Lars Ellenberg
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ellenberg @ 2017-04-25  7:06 UTC (permalink / raw)
  To: Heloise; +Cc: philipp.reisner, drbd-dev, linux-kernel

On Mon, Apr 24, 2017 at 11:35:18PM -0700, Heloise wrote:
> Signed-off-by: Heloise <os@iscas.ac.cn>
> 
> In is_valid_state(), there is NULL validation for the variable nc
> "if (nc)". However,the code will continue to execute when nc is NULL.
> nc->verify_alg[0] is used in subsequent code, which may cause
> null-pointer dereference, fix it.
> ---
>  drivers/block/drbd/drbd_state.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/block/drbd/drbd_state.c b/drivers/block/drbd/drbd_state.c
> index eea0c4a..1963b83 100644
> --- a/drivers/block/drbd/drbd_state.c
> +++ b/drivers/block/drbd/drbd_state.c
> @@ -845,7 +845,7 @@ is_valid_state(struct drbd_device *device, union drbd_state ns)
>  		rv = SS_CONNECTED_OUTDATES;
>  
>  	else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) &&
> -		 (nc->verify_alg[0] == 0))
> +		 (nc != NULL && nc->verify_alg[0] == 0))


What the static checker cannot know:
ns.conn != C_STANDALONE implies nc != NULL.

But if you feel like it, the additional check won't hurt.

Thanks,

    Lars

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-04-25  7:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-25  6:35 [PATCH] drivers:block:drbd:drbd_state:fix null-pointer dereference Heloise
2017-04-25  7:06 ` Lars Ellenberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.