block: fix potential dereference null pointer
Subsystems (2)
PATCH 1/1 block: fix potential dereference null pointer
From: Lv Ruyi <[email protected]>
rcu_dereference may return NULL, so check the returned pointer.
Reported-by Zeal Robot <[email protected]>
Signed-off-by Lv Ruyi <[email protected]>
--- drivers/block/drbd/drbd_req.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/block/drbd/drbd_req.c +8 -0
@@ -577,6 +577,10 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what,D_ASSERT (device, !(req->rq_state &RQ_NET_MASK ));rcu_read_lock (); nc =rcu_dereference (connection->net_conf); +if (!nc) { +rcu_read_unlock (); +break ; + } p = nc->wire_protocol;rcu_read_unlock (); req->rq_state |=
@@ -690,6 +694,10 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what,/* close the epoch, in case it outgrew the limit */ rcu_read_lock (); nc =rcu_dereference (connection->net_conf); +if (!nc) { +rcu_read_unlock (); +break ; + } p = nc->max_epoch_size;rcu_read_unlock ();if (connection->current_tle_writes >= p)
Signature · 1 line
2.25.1
Philipp Reisner
maintainerHi Lv Ruyi,
This patch does not make sense to me. A request can only get "TO_BE_SENT" when the connection is established with the corresponding cstate. Establishing a connection can only work if net_conf is set. net_conf can be exchanged to a new one, but never become NULL.
Please share more details why you think this NULL check is necessary here?
Quoted 40 lines · On Fri, Apr 1, 2022 at 10:36 AM <[email protected]> wrote:
From: Lv Ruyi <[email protected]>
rcu_dereferencemay return NULL, so check the returned pointer.Reported-by Zeal Robot <[email protected]>Signed-off-by Lv Ruyi <[email protected]>--- drivers/block/drbd/drbd_req.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/block/drbd/drbd_req.c +8
-1@@ -577,6 +577,10 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what,D_ASSERT (device, !(req->rq_state &RQ_NET_MASK ));rcu_read_lock (); nc =rcu_dereference (connection->net_conf); +if (!nc) { +rcu_read_unlock (); +break ; + } p = nc->wire_protocol;rcu_read_unlock (); req->rq_state |=@@ -690,6 +694,10 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what,/* close the epoch, in case it outgrew the limit */ rcu_read_lock (); nc =rcu_dereference (connection->net_conf); +if (!nc) { +rcu_read_unlock (); +break ; + } p = nc->max_epoch_size;rcu_read_unlock ();if (connection->current_tle_writes >= p) --2.25.1