Skip to content

Commit ece841a

Browse files
Justin Teeaxboe
authored andcommitted
block: fix memleak of bio integrity data
7c20f11 ("bio-integrity: stop abusing bi_end_io") moves bio_integrity_free from bio_uninit() to bio_integrity_verify_fn() and bio_endio(). This way looks wrong because bio may be freed without calling bio_endio(), for example, blk_rq_unprep_clone() is called from dm_mq_queue_rq() when the underlying queue of dm-mpath is busy. So memory leak of bio integrity data is caused by commit 7c20f11. Fixes this issue by re-adding bio_integrity_free() to bio_uninit(). Fixes: 7c20f11 ("bio-integrity: stop abusing bi_end_io") Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by Justin Tee <[email protected]> Add commit log, and simplify/fix the original patch wroten by Justin. Signed-off-by: Ming Lei <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 08802ed commit ece841a

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

block/bio-integrity.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ EXPORT_SYMBOL(bio_integrity_alloc);
8787
* Description: Used to free the integrity portion of a bio. Usually
8888
* called from bio_free().
8989
*/
90-
static void bio_integrity_free(struct bio *bio)
90+
void bio_integrity_free(struct bio *bio)
9191
{
9292
struct bio_integrity_payload *bip = bio_integrity(bio);
9393
struct bio_set *bs = bio->bi_pool;

block/bio.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ struct bio_vec *bvec_alloc(gfp_t gfp_mask, int nr, unsigned long *idx,
233233
void bio_uninit(struct bio *bio)
234234
{
235235
bio_disassociate_blkg(bio);
236+
237+
if (bio_integrity(bio))
238+
bio_integrity_free(bio);
236239
}
237240
EXPORT_SYMBOL(bio_uninit);
238241

block/blk.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ static inline void blk_rq_bio_prep(struct request *rq, struct bio *bio,
121121
#ifdef CONFIG_BLK_DEV_INTEGRITY
122122
void blk_flush_integrity(void);
123123
bool __bio_integrity_endio(struct bio *);
124+
void bio_integrity_free(struct bio *bio);
124125
static inline bool bio_integrity_endio(struct bio *bio)
125126
{
126127
if (bio_integrity(bio))
@@ -166,6 +167,9 @@ static inline bool bio_integrity_endio(struct bio *bio)
166167
{
167168
return true;
168169
}
170+
static inline void bio_integrity_free(struct bio *bio)
171+
{
172+
}
169173
#endif /* CONFIG_BLK_DEV_INTEGRITY */
170174

171175
unsigned long blk_rq_timeout(unsigned long timeout);

0 commit comments

Comments
 (0)