* Re: [PATCH] block: bio: Trim bio to sensible size in bio_trim()
@ 2020-08-31 6:26 linmiaohe
0 siblings, 0 replies; 3+ messages in thread
From: linmiaohe @ 2020-08-31 6:26 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, linux-kernel
Jens Axboe <axboe@kernel.dk> wrote:
>On 8/29/20 3:37 AM, Miaohe Lin wrote:
>> Trim bio to sensible size in bio_trim() or something bad may happen.
>
>This really needs a LOT more detail. What is "something bad"? How does this condition trigger to begin with?
>
Many thanks for your reply.
I do this mainly by code review, so I didn't find the condition trigger to begin with. But I think it's better
to do such a check as this is a external Interface. Also If bio_trim() set bio->bi_iter.bi_size to a value larger than the origin one,
we may access the bio_vec past the last one of bio->bi_io_vec in for_each_bvec macro.
>--
>Jens Axboe
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] block: bio: Trim bio to sensible size in bio_trim()
2020-08-29 9:37 Miaohe Lin
@ 2020-08-29 14:32 ` Jens Axboe
0 siblings, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2020-08-29 14:32 UTC (permalink / raw)
To: Miaohe Lin; +Cc: linux-block, linux-kernel
On 8/29/20 3:37 AM, Miaohe Lin wrote:
> Trim bio to sensible size in bio_trim() or something bad may happen.
This really needs a LOT more detail. What is "something bad"? How does
this condition trigger to begin with?
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] block: bio: Trim bio to sensible size in bio_trim()
@ 2020-08-29 9:37 Miaohe Lin
2020-08-29 14:32 ` Jens Axboe
0 siblings, 1 reply; 3+ messages in thread
From: Miaohe Lin @ 2020-08-29 9:37 UTC (permalink / raw)
To: axboe; +Cc: linux-block, linux-kernel, linmiaohe
Trim bio to sensible size in bio_trim() or something bad may happen.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
block/bio.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/block/bio.c b/block/bio.c
index a9931f23d933..94e4f97d3d4e 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1509,7 +1509,8 @@ void bio_trim(struct bio *bio, int offset, int size)
return;
bio_advance(bio, offset << 9);
- bio->bi_iter.bi_size = size;
+ if (likely(bio->bi_iter.bi_size >= size))
+ bio->bi_iter.bi_size = size;
if (bio_integrity(bio))
bio_integrity_trim(bio);
--
2.19.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-08-31 6:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31 6:26 [PATCH] block: bio: Trim bio to sensible size in bio_trim() linmiaohe
-- strict thread matches above, loose matches on Subject: below --
2020-08-29 9:37 Miaohe Lin
2020-08-29 14:32 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).