Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ceph: Annotate struct ceph_monmap with __counted_by

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct ceph_monmap.
Additionally, since the element count member must be set before accessing
the annotated flexible array member, move its initialization earlier.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: ceph-devel@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Xiubo Li <xiubli@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Kees Cook and committed by
David S. Miller
1cb6422e 02014090

+2 -2
+1 -1
include/linux/ceph/mon_client.h
··· 19 19 struct ceph_fsid fsid; 20 20 u32 epoch; 21 21 u32 num_mon; 22 - struct ceph_entity_inst mon_inst[]; 22 + struct ceph_entity_inst mon_inst[] __counted_by(num_mon); 23 23 }; 24 24 25 25 struct ceph_mon_client;
+1 -1
net/ceph/mon_client.c
··· 1136 1136 GFP_KERNEL); 1137 1137 if (!monc->monmap) 1138 1138 return -ENOMEM; 1139 + monc->monmap->num_mon = num_mon; 1139 1140 1140 1141 for (i = 0; i < num_mon; i++) { 1141 1142 struct ceph_entity_inst *inst = &monc->monmap->mon_inst[i]; ··· 1148 1147 inst->name.type = CEPH_ENTITY_TYPE_MON; 1149 1148 inst->name.num = cpu_to_le64(i); 1150 1149 } 1151 - monc->monmap->num_mon = num_mon; 1152 1150 return 0; 1153 1151 } 1154 1152