Skip to content

Commit 422652e

Browse files
author
zhongjiang-ali
committed
alinux: block: replace reserved field with extended bio_flags
task #28327019 Commit bc0cc36 ("alinux: blk-throttle: fix tg NULL pointer dereference") add an self-defined bio flags to fix an issue of use-after-free. But it is limited to 13 entry and has used up, hence it will fails to sync related patch. The patch replace reserved field with extended bio_flags to allow us to define more bio flags. Reviewed-by: Xunlei Pang <xlpang@linux.alibaba.com> Signed-off-by: zhongjiang-ali <zhongjiang-ali@linux.alibaba.com>
1 parent cdcf8a4 commit 422652e

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

block/blk-throttle.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ static void throtl_bio_end_io(struct bio *bio)
11201120

11211121
rcu_read_lock();
11221122
/* see comments in throtl_bio_stats_start() */
1123-
if (!bio_flagged(bio, BIO_THROTL_STATED))
1123+
if (!bio_ext_flagged(bio, BIO_THROTL_STATED))
11241124
goto out;
11251125

11261126
tg = (struct throtl_grp *)bio->bi_tg_private;
@@ -1131,7 +1131,7 @@ static void throtl_bio_end_io(struct bio *bio)
11311131
bio_io_start_time_ns(bio),
11321132
bio_op(bio));
11331133
blkg_put(tg_to_blkg(tg));
1134-
bio_clear_flag(bio, BIO_THROTL_STATED);
1134+
bio_clear_ext_flag(bio, BIO_THROTL_STATED);
11351135
out:
11361136
rcu_read_unlock();
11371137
}
@@ -1147,9 +1147,9 @@ static inline void throtl_bio_stats_start(struct bio *bio, struct throtl_grp *tg
11471147
* BIO_THROTL_STATED to do only once statistics.
11481148
*/
11491149
if ((op == REQ_OP_READ || op == REQ_OP_WRITE) &&
1150-
!bio_flagged(bio, BIO_THROTL_STATED)) {
1150+
!bio_ext_flagged(bio, BIO_THROTL_STATED)) {
11511151
blkg_get(tg_to_blkg(tg));
1152-
bio_set_flag(bio, BIO_THROTL_STATED);
1152+
bio_set_ext_flag(bio, BIO_THROTL_STATED);
11531153
bio->bi_tg_end_io = throtl_bio_end_io;
11541154
bio->bi_tg_private = tg;
11551155
bio_set_start_time_ns(bio);

include/linux/bio.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,21 @@ static inline void bio_clear_flag(struct bio *bio, unsigned int bit)
291291
bio->bi_flags &= ~(1U << bit);
292292
}
293293

294+
static inline bool bio_ext_flagged(struct bio *bio, unsigned int bit)
295+
{
296+
return (bio->bi_ext_flags & (1U << bit)) != 0;
297+
}
298+
299+
static inline void bio_set_ext_flag(struct bio *bio, unsigned int bit)
300+
{
301+
bio->bi_ext_flags |= (1U << bit);
302+
}
303+
304+
static inline void bio_clear_ext_flag(struct bio *bio, unsigned int bit)
305+
{
306+
bio->bi_ext_flags &= ~(1U << bit);
307+
}
308+
294309
static inline void bio_get_first_bvec(struct bio *bio, struct bio_vec *bv)
295310
{
296311
*bv = bio_iovec(bio);

include/linux/blk_types.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ struct bio {
214214

215215
struct bio_set *bi_pool;
216216

217+
unsigned long bi_ext_flags; /* extend the bi_flags */
218+
217219
ALI_HOTFIX_RESERVE(1)
218-
ALI_HOTFIX_RESERVE(2)
219220

220221
/*
221222
* We can inline a number of vecs at the end of the bio, to avoid
@@ -244,7 +245,11 @@ struct bio {
244245
#define BIO_TRACE_COMPLETION 10 /* bio_endio() should trace the final completion
245246
* of this bio. */
246247
#define BIO_QUEUE_ENTERED 11 /* can use blk_queue_enter_live() */
247-
#define BIO_THROTL_STATED 12 /* bio already stated */
248+
249+
/*
250+
* Extend bio flags should be added in here
251+
*/
252+
#define BIO_THROTL_STATED 0 /* bio already stated */
248253

249254
/* See BVEC_POOL_OFFSET below before adding new flags */
250255

0 commit comments

Comments
 (0)