lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5pauuhdlh2jaeqixofoips7f4zjl7pcyeykkglkmihsko3cnjy@4cbebl2x3qod>
Date: Mon, 24 Feb 2025 22:04:41 +0800
From: Coly Li <colyli@...nel.org>
To: "Gustavo A. R. Silva" <gustavoars@...nel.org>
Cc: Kent Overstreet <kent.overstreet@...ux.dev>, 
	linux-bcache@...r.kernel.org, linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: [PATCH 8/8][next] bcache: Avoid -Wflex-array-member-not-at-end
 warnings

On Mon, Feb 24, 2025 at 08:31:26PM +0800, Gustavo A. R. Silva wrote:
> -Wflex-array-member-not-at-end was introduced in GCC-14, and we are
> getting ready to enable it, globally.
> 
> Change the type of the middle struct members currently causing trouble
> from `struct bio` to `struct bio_hdr`.
> 
> We also use `container_of()` whenever we need to retrieve a pointer to
> the flexible structure `struct bio`, through which we can access the
> flexible-array member in it, if necessary.
> 
> With these changes fix 112 of the following warnings:
> 
> drivers/md/bcache/bcache.h:233:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/md/bcache/bcache.h:241:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/md/bcache/bcache.h:242:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/md/bcache/bcache.h:308:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/md/bcache/bcache.h:422:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/md/bcache/bcache.h:639:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/md/bcache/journal.h:152:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/md/bcache/journal.h:156:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> 
> Signed-off-by: Gustavo A. R. Silva <gustavoars@...nel.org>

Hi Gustavo,

each struct bio followed by a struct bio_vec at the location where
struct bio is embedded into middle of a structure. So the general
flex-array-in-middle issue doesn't exist here indeed.

I don't suggest to introduce extra complication in bcache code.

How about to improve the checking script, if there is no following
struct bio_vec after struct bio, then that should be something really
suspicious.

Thanks.

Coly Li

> ---
>  drivers/md/bcache/bcache.h  |  4 ++--
>  drivers/md/bcache/journal.c | 10 +++++-----
>  drivers/md/bcache/journal.h |  4 ++--
>  drivers/md/bcache/super.c   |  8 +++++---
>  4 files changed, 14 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
> index 785b0d9008fa..328023e90eb2 100644
> --- a/drivers/md/bcache/bcache.h
> +++ b/drivers/md/bcache/bcache.h
> @@ -305,7 +305,7 @@ struct cached_dev {
>  
>  	struct cache_sb		sb;
>  	struct cache_sb_disk	*sb_disk;
> -	struct bio		sb_bio;
> +	struct bio_hdr		sb_bio;
>  	struct bio_vec		sb_bv[1];
>  	struct closure		sb_write;
>  	struct semaphore	sb_write_mutex;
> @@ -419,7 +419,7 @@ struct cache {
>  	struct cache_set	*set;
>  	struct cache_sb		sb;
>  	struct cache_sb_disk	*sb_disk;
> -	struct bio		sb_bio;
> +	struct bio_hdr		sb_bio;
>  	struct bio_vec		sb_bv[1];
>  
>  	struct kobject		kobj;
> diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
> index 7ff14bd2feb8..2ead129f7758 100644
> --- a/drivers/md/bcache/journal.c
> +++ b/drivers/md/bcache/journal.c
> @@ -36,7 +36,7 @@ static int journal_read_bucket(struct cache *ca, struct list_head *list,
>  			       unsigned int bucket_index)
>  {
>  	struct journal_device *ja = &ca->journal;
> -	struct bio *bio = &ja->bio;
> +	struct bio *bio = container_of(&ja->bio, struct bio, __hdr);
>  
>  	struct journal_replay *i;
>  	struct jset *j, *data = ca->set->journal.w[0].data;
> @@ -571,7 +571,7 @@ static void btree_flush_write(struct cache_set *c)
>  static void journal_discard_endio(struct bio *bio)
>  {
>  	struct journal_device *ja =
> -		container_of(bio, struct journal_device, discard_bio);
> +		container_of(&bio->__hdr, struct journal_device, discard_bio);
>  	struct cache *ca = container_of(ja, struct cache, journal);
>  
>  	atomic_set(&ja->discard_in_flight, DISCARD_DONE);
> @@ -585,13 +585,13 @@ static void journal_discard_work(struct work_struct *work)
>  	struct journal_device *ja =
>  		container_of(work, struct journal_device, discard_work);
>  
> -	submit_bio(&ja->discard_bio);
> +	submit_bio(container_of(&ja->discard_bio, struct bio, __hdr));
>  }
>  
>  static void do_journal_discard(struct cache *ca)
>  {
>  	struct journal_device *ja = &ca->journal;
> -	struct bio *bio = &ja->discard_bio;
> +	struct bio *bio = container_of(&ja->discard_bio, struct bio, __hdr);
>  
>  	if (!ca->discard) {
>  		ja->discard_idx = ja->last_idx;
> @@ -787,7 +787,7 @@ static CLOSURE_CALLBACK(journal_write_unlocked)
>  
>  	for (i = 0; i < KEY_PTRS(k); i++) {
>  		ca = c->cache;
> -		bio = &ca->journal.bio;
> +		bio = container_of(&ca->journal.bio, struct bio, __hdr);
>  
>  		atomic_long_add(sectors, &ca->meta_sectors_written);
>  
> diff --git a/drivers/md/bcache/journal.h b/drivers/md/bcache/journal.h
> index cd316b4a1e95..b4ff5269aee3 100644
> --- a/drivers/md/bcache/journal.h
> +++ b/drivers/md/bcache/journal.h
> @@ -149,11 +149,11 @@ struct journal_device {
>  	atomic_t		discard_in_flight;
>  
>  	struct work_struct	discard_work;
> -	struct bio		discard_bio;
> +	struct bio_hdr		discard_bio;
>  	struct bio_vec		discard_bv;
>  
>  	/* Bio for journal reads/writes to this device */
> -	struct bio		bio;
> +	struct bio_hdr		bio;
>  	struct bio_vec		bv[8];
>  };
>  
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index e42f1400cea9..cd1342355cf2 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -337,7 +337,7 @@ static CLOSURE_CALLBACK(bch_write_bdev_super_unlock)
>  void bch_write_bdev_super(struct cached_dev *dc, struct closure *parent)
>  {
>  	struct closure *cl = &dc->sb_write;
> -	struct bio *bio = &dc->sb_bio;
> +	struct bio *bio = container_of(&dc->sb_bio, struct bio, __hdr);
>  
>  	down(&dc->sb_write_mutex);
>  	closure_init(cl, parent);
> @@ -374,7 +374,7 @@ void bcache_write_super(struct cache_set *c)
>  {
>  	struct closure *cl = &c->sb_write;
>  	struct cache *ca = c->cache;
> -	struct bio *bio = &ca->sb_bio;
> +	struct bio *bio = container_of(&ca->sb_bio, struct bio, __hdr);
>  	unsigned int version = BCACHE_SB_VERSION_CDEV_WITH_UUID;
>  
>  	down(&c->sb_write_mutex);
> @@ -2230,7 +2230,9 @@ static int cache_alloc(struct cache *ca)
>  	__module_get(THIS_MODULE);
>  	kobject_init(&ca->kobj, &bch_cache_ktype);
>  
> -	bio_init(&ca->journal.bio, NULL, ca->journal.bio.bi_inline_vecs, 8, 0);
> +	bio_init(container_of(&ca->journal.bio, struct bio, __hdr), NULL,
> +		 container_of(&ca->journal.bio, struct bio, __hdr)->bi_inline_vecs,
> +		 8, 0);
>  
>  	/*
>  	 * when ca->sb.njournal_buckets is not zero, journal exists,
> -- 
> 2.43.0
> 

-- 
Coly Li

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ