From: Tuo Li <islituo@gmail.com>
To: philipp.reisner@linbit.com, lars.ellenberg@linbit.com,
christoph.boehmwalder@linbit.com, axboe@kernel.dk
Cc: drbd-dev@lists.linbit.com, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, Tuo Li <islituo@gmail.com>
Subject: [PATCH] drbd: fix a null-pointer dereference when the request event in drbd_request_endio() is READ_COMPLETED_WITH_ERROR
Date: Mon, 5 Jan 2026 00:53:55 +0800 [thread overview]
Message-ID: <20260104165355.151864-1-islituo@gmail.com> (raw)
In drbd_request_endio(), the request event what can be set to
READ_COMPLETED_WITH_ERROR. In this case, __req_mod() is invoked with a NULL
peer_device:
__req_mod(req, what, NULL, &m);
When handling READ_COMPLETED_WITH_ERROR, __req_mod() unconditionally calls
drbd_set_out_of_sync():
case READ_COMPLETED_WITH_ERROR:
drbd_set_out_of_sync(peer_device, req->i.sector, req->i.size);
The drbd_set_out_of_sync() macro expands to __drbd_change_sync():
#define drbd_set_out_of_sync(peer_device, sector, size) \
__drbd_change_sync(peer_device, sector, size, SET_OUT_OF_SYNC)
However, __drbd_change_sync() assumes a valid peer_device and immediately
dereferences it:
struct drbd_device *device = peer_device->device;
If peer_device is NULL, this results in a NULL-pointer dereference.
Fix this by adding a NULL check in __req_mod() before calling
drbd_set_out_of_sync().
Signed-off-by: Tuo Li <islituo@gmail.com>
---
drivers/block/drbd/drbd_req.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/block/drbd/drbd_req.c b/drivers/block/drbd/drbd_req.c
index d15826f6ee81..aa3da2733f14 100644
--- a/drivers/block/drbd/drbd_req.c
+++ b/drivers/block/drbd/drbd_req.c
@@ -621,7 +621,8 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what,
break;
case READ_COMPLETED_WITH_ERROR:
- drbd_set_out_of_sync(peer_device, req->i.sector, req->i.size);
+ if (peer_device)
+ drbd_set_out_of_sync(peer_device, req->i.sector, req->i.size);
drbd_report_io_error(device, req);
__drbd_chk_io_error(device, DRBD_READ_ERROR);
fallthrough;
--
2.43.0
next reply other threads:[~2026-01-04 16:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-04 16:53 Tuo Li [this message]
2026-02-19 14:53 ` Christoph Böhmwalder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260104165355.151864-1-islituo@gmail.com \
--to=islituo@gmail.com \
--cc=axboe@kernel.dk \
--cc=christoph.boehmwalder@linbit.com \
--cc=drbd-dev@lists.linbit.com \
--cc=lars.ellenberg@linbit.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=philipp.reisner@linbit.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®