Skip to content

Commit f6f84be

Browse files
hiqbal-ionosaxboe
authored andcommitted
block/rnbd-srv: Add sanity check and remove redundant assignment
The bio->bi_iter.bi_size is updated when bio_add_page() is called. So we do not need to assign msg->bi_size again to it, since its redudant and can also be harmful. Instead we can use it to add a sanity check, which checks the locally calculated bi_size, with the one sent in msg. Signed-off-by: Md Haris Iqbal <[email protected]> Signed-off-by: Jack Wang <[email protected]> Signed-off-by: Grzegorz Prajsner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 752a592 commit f6f84be

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/block/rnbd/rnbd-srv.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,22 @@ static int process_rdma(struct rnbd_srv_session *srv_sess,
149149
rnbd_to_bio_flags(le32_to_cpu(msg->rw)), GFP_KERNEL);
150150
if (bio_add_page(bio, virt_to_page(data), datalen,
151151
offset_in_page(data)) != datalen) {
152-
rnbd_srv_err(sess_dev, "Failed to map data to bio\n");
152+
rnbd_srv_err_rl(sess_dev, "Failed to map data to bio\n");
153153
err = -EINVAL;
154154
goto bio_put;
155155
}
156156

157+
bio->bi_opf = rnbd_to_bio_flags(le32_to_cpu(msg->rw));
158+
if (bio_has_data(bio) &&
159+
bio->bi_iter.bi_size != le32_to_cpu(msg->bi_size)) {
160+
rnbd_srv_err_rl(sess_dev, "Datalen mismatch: bio bi_size (%u), bi_size (%u)\n",
161+
bio->bi_iter.bi_size, msg->bi_size);
162+
err = -EINVAL;
163+
goto bio_put;
164+
}
157165
bio->bi_end_io = rnbd_dev_bi_end_io;
158166
bio->bi_private = priv;
159167
bio->bi_iter.bi_sector = le64_to_cpu(msg->sector);
160-
bio->bi_iter.bi_size = le32_to_cpu(msg->bi_size);
161168
prio = srv_sess->ver < RNBD_PROTO_VER_MAJOR ||
162169
usrlen < sizeof(*msg) ? 0 : le16_to_cpu(msg->prio);
163170
bio_set_prio(bio, prio);

0 commit comments

Comments
 (0)