* [PATCH 2/2 net-next] libceph: Use __counted_by() in struct ceph_snap_context
2024-05-19 9:09 [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context() Christophe JAILLET
@ 2024-05-19 9:09 ` Christophe JAILLET
2024-05-19 11:34 ` [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context() kernel test robot
2024-05-19 11:55 ` kernel test robot
2 siblings, 0 replies; 5+ messages in thread
From: Christophe JAILLET @ 2024-05-19 9:09 UTC (permalink / raw)
To: Ilya Dryomov, Xiubo Li, Kees Cook, Gustavo A. R. Silva
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, ceph-devel,
linux-hardening
Annotate the 'snaps' flexible array in "struct ceph_snap_context" with
__counted_by() so that additional checks can be made, if enabled.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only
---
include/linux/ceph/libceph.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/ceph/libceph.h b/include/linux/ceph/libceph.h
index 4497d0a6772c..485efc8837d5 100644
--- a/include/linux/ceph/libceph.h
+++ b/include/linux/ceph/libceph.h
@@ -164,7 +164,7 @@ struct ceph_snap_context {
refcount_t nref;
u64 seq;
u32 num_snaps;
- u64 snaps[];
+ u64 snaps[] __counted_by(num_snaps);
};
extern struct ceph_snap_context *ceph_create_snap_context(u32 snap_count,
--
2.45.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context()
2024-05-19 9:09 [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context() Christophe JAILLET
2024-05-19 9:09 ` [PATCH 2/2 net-next] libceph: Use __counted_by() in struct ceph_snap_context Christophe JAILLET
@ 2024-05-19 11:34 ` kernel test robot
2024-05-19 12:45 ` Christophe JAILLET
2024-05-19 11:55 ` kernel test robot
2 siblings, 1 reply; 5+ messages in thread
From: kernel test robot @ 2024-05-19 11:34 UTC (permalink / raw)
To: Christophe JAILLET, Ilya Dryomov, Xiubo Li, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: oe-kbuild-all, netdev, linux-kernel, kernel-janitors,
Christophe JAILLET, ceph-devel
Hi Christophe,
kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Christophe-JAILLET/libceph-Use-__counted_by-in-struct-ceph_snap_context/20240519-172142
base: net-next/main
patch link: https://lore.kernel.org/r/5b7c72bdb52703bbfa5511ed500aed4babde1308.1716109606.git.christophe.jaillet%40wanadoo.fr
patch subject: [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context()
config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20240519/202405191909.7qhhefnu-lkp@intel.com/config)
compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240519/202405191909.7qhhefnu-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202405191909.7qhhefnu-lkp@intel.com/
All errors (new ones prefixed by >>):
net/ceph/snapshot.c: In function 'ceph_create_snap_context':
>> net/ceph/snapshot.c:32:25: error: implicit declaration of function 'sruct_size'; did you mean 'struct_size'? [-Werror=implicit-function-declaration]
32 | snapc = kzalloc(sruct_size(snapc, snaps, snap_count), gfp_flags);
| ^~~~~~~~~~
| struct_size
>> net/ceph/snapshot.c:32:43: error: 'snaps' undeclared (first use in this function); did you mean 'snapc'?
32 | snapc = kzalloc(sruct_size(snapc, snaps, snap_count), gfp_flags);
| ^~~~~
| snapc
net/ceph/snapshot.c:32:43: note: each undeclared identifier is reported only once for each function it appears in
cc1: some warnings being treated as errors
vim +32 net/ceph/snapshot.c
11
12 /*
13 * Ceph snapshot contexts are reference counted objects, and the
14 * returned structure holds a single reference. Acquire additional
15 * references with ceph_get_snap_context(), and release them with
16 * ceph_put_snap_context(). When the reference count reaches zero
17 * the entire structure is freed.
18 */
19
20 /*
21 * Create a new ceph snapshot context large enough to hold the
22 * indicated number of snapshot ids (which can be 0). Caller has
23 * to fill in snapc->seq and snapc->snaps[0..snap_count-1].
24 *
25 * Returns a null pointer if an error occurs.
26 */
27 struct ceph_snap_context *ceph_create_snap_context(u32 snap_count,
28 gfp_t gfp_flags)
29 {
30 struct ceph_snap_context *snapc;
31
> 32 snapc = kzalloc(sruct_size(snapc, snaps, snap_count), gfp_flags);
33 if (!snapc)
34 return NULL;
35
36 refcount_set(&snapc->nref, 1);
37 snapc->num_snaps = snap_count;
38
39 return snapc;
40 }
41 EXPORT_SYMBOL(ceph_create_snap_context);
42
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context()
2024-05-19 11:34 ` [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context() kernel test robot
@ 2024-05-19 12:45 ` Christophe JAILLET
0 siblings, 0 replies; 5+ messages in thread
From: Christophe JAILLET @ 2024-05-19 12:45 UTC (permalink / raw)
To: kernel test robot, Ilya Dryomov, Xiubo Li, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: oe-kbuild-all, netdev, linux-kernel, kernel-janitors, ceph-devel
Le 19/05/2024 à 13:34, kernel test robot a écrit :
> Hi Christophe,
>
> kernel test robot noticed the following build errors:
>
> [auto build test ERROR on net-next/main]
>
> url: https://github.com/intel-lab-lkp/linux/commits/Christophe-JAILLET/libceph-Use-__counted_by-in-struct-ceph_snap_context/20240519-172142
> base: net-next/main
> patch link: https://lore.kernel.org/r/5b7c72bdb52703bbfa5511ed500aed4babde1308.1716109606.git.christophe.jaillet%40wanadoo.fr
> patch subject: [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context()
> config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20240519/202405191909.7qhhefnu-lkp@intel.com/config)
> compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240519/202405191909.7qhhefnu-lkp@intel.com/reproduce)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202405191909.7qhhefnu-lkp@intel.com/
>
> All errors (new ones prefixed by >>):
>
> net/ceph/snapshot.c: In function 'ceph_create_snap_context':
>>> net/ceph/snapshot.c:32:25: error: implicit declaration of function 'sruct_size'; did you mean 'struct_size'? [-Werror=implicit-function-declaration]
> 32 | snapc = kzalloc(sruct_size(snapc, snaps, snap_count), gfp_flags);
> | ^~~~~~~~~~
> | struct_size
>>> net/ceph/snapshot.c:32:43: error: 'snaps' undeclared (first use in this function); did you mean 'snapc'?
> 32 | snapc = kzalloc(sruct_size(snapc, snaps, snap_count), gfp_flags);
> | ^~~~~
> | snapc
> net/ceph/snapshot.c:32:43: note: each undeclared identifier is reported only once for each function it appears in
> cc1: some warnings being treated as errors
>
>
> vim +32 net/ceph/snapshot.c
>
> 11
> 12 /*
> 13 * Ceph snapshot contexts are reference counted objects, and the
> 14 * returned structure holds a single reference. Acquire additional
> 15 * references with ceph_get_snap_context(), and release them with
> 16 * ceph_put_snap_context(). When the reference count reaches zero
> 17 * the entire structure is freed.
> 18 */
> 19
> 20 /*
> 21 * Create a new ceph snapshot context large enough to hold the
> 22 * indicated number of snapshot ids (which can be 0). Caller has
> 23 * to fill in snapc->seq and snapc->snaps[0..snap_count-1].
> 24 *
> 25 * Returns a null pointer if an error occurs.
> 26 */
> 27 struct ceph_snap_context *ceph_create_snap_context(u32 snap_count,
> 28 gfp_t gfp_flags)
> 29 {
> 30 struct ceph_snap_context *snapc;
> 31
> > 32 snapc = kzalloc(sruct_size(snapc, snaps, snap_count), gfp_flags);
Ouch!
this was build-tested, but I must have made a mistake when editing the
patch file to add the "net-next".
Sorry about that.
I'll resend when the net-next branch will re-open.
CJ
> 33 if (!snapc)
> 34 return NULL;
> 35
> 36 refcount_set(&snapc->nref, 1);
> 37 snapc->num_snaps = snap_count;
> 38
> 39 return snapc;
> 40 }
> 41 EXPORT_SYMBOL(ceph_create_snap_context);
> 42
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context()
2024-05-19 9:09 [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context() Christophe JAILLET
2024-05-19 9:09 ` [PATCH 2/2 net-next] libceph: Use __counted_by() in struct ceph_snap_context Christophe JAILLET
2024-05-19 11:34 ` [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context() kernel test robot
@ 2024-05-19 11:55 ` kernel test robot
2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2024-05-19 11:55 UTC (permalink / raw)
To: Christophe JAILLET, Ilya Dryomov, Xiubo Li, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: llvm, oe-kbuild-all, netdev, linux-kernel, kernel-janitors,
Christophe JAILLET, ceph-devel
Hi Christophe,
kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Christophe-JAILLET/libceph-Use-__counted_by-in-struct-ceph_snap_context/20240519-172142
base: net-next/main
patch link: https://lore.kernel.org/r/5b7c72bdb52703bbfa5511ed500aed4babde1308.1716109606.git.christophe.jaillet%40wanadoo.fr
patch subject: [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context()
config: x86_64-rhel-8.3-rust (https://download.01.org/0day-ci/archive/20240519/202405191916.QmDasdJ5-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240519/202405191916.QmDasdJ5-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202405191916.QmDasdJ5-lkp@intel.com/
All errors (new ones prefixed by >>):
>> net/ceph/snapshot.c:32:18: error: call to undeclared function 'sruct_size'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
32 | snapc = kzalloc(sruct_size(snapc, snaps, snap_count), gfp_flags);
| ^
>> net/ceph/snapshot.c:32:36: error: use of undeclared identifier 'snaps'; did you mean 'snapc'?
32 | snapc = kzalloc(sruct_size(snapc, snaps, snap_count), gfp_flags);
| ^~~~~
| snapc
net/ceph/snapshot.c:30:28: note: 'snapc' declared here
30 | struct ceph_snap_context *snapc;
| ^
2 errors generated.
vim +/sruct_size +32 net/ceph/snapshot.c
11
12 /*
13 * Ceph snapshot contexts are reference counted objects, and the
14 * returned structure holds a single reference. Acquire additional
15 * references with ceph_get_snap_context(), and release them with
16 * ceph_put_snap_context(). When the reference count reaches zero
17 * the entire structure is freed.
18 */
19
20 /*
21 * Create a new ceph snapshot context large enough to hold the
22 * indicated number of snapshot ids (which can be 0). Caller has
23 * to fill in snapc->seq and snapc->snaps[0..snap_count-1].
24 *
25 * Returns a null pointer if an error occurs.
26 */
27 struct ceph_snap_context *ceph_create_snap_context(u32 snap_count,
28 gfp_t gfp_flags)
29 {
30 struct ceph_snap_context *snapc;
31
> 32 snapc = kzalloc(sruct_size(snapc, snaps, snap_count), gfp_flags);
33 if (!snapc)
34 return NULL;
35
36 refcount_set(&snapc->nref, 1);
37 snapc->num_snaps = snap_count;
38
39 return snapc;
40 }
41 EXPORT_SYMBOL(ceph_create_snap_context);
42
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread