]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
drbd: Add NULL check for net_conf to prevent dereference in state validation
authorMikhail Lobanov <m.lobanov@rosalinux.ru>
Mon, 9 Sep 2024 13:37:36 +0000 (09:37 -0400)
committerJens Axboe <axboe@kernel.dk>
Tue, 10 Sep 2024 19:44:06 +0000 (13:44 -0600)
If the net_conf pointer is NULL and the code attempts to access its
fields without a check, it will lead to a null pointer dereference.
Add a NULL check before dereferencing the pointer.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 44ed167da748 ("drbd: rcu_read_lock() and rcu_dereference() for tconn->net_conf")
Cc: stable@vger.kernel.org
Signed-off-by: Mikhail Lobanov <m.lobanov@rosalinux.ru>
Link: https://lore.kernel.org/r/20240909133740.84297-1-m.lobanov@rosalinux.ru
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/drbd/drbd_state.c

index e858e7e0383f262fa0bf412c5867ee6832ffcb64..c2b6c4d9729db9a6cdfc2538feddef53d0de6a97 100644 (file)
@@ -876,7 +876,7 @@ is_valid_state(struct drbd_device *device, union drbd_state ns)
                  ns.disk == D_OUTDATED)
                rv = SS_CONNECTED_OUTDATES;
 
-       else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) &&
+       else if (nc && (ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) &&
                 (nc->verify_alg[0] == 0))
                rv = SS_NO_VERIFY_ALG;