Skip to content

Commit 1cb6422

Browse files
keesdavem330
authored andcommitted
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>
1 parent 0201409 commit 1cb6422

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

include/linux/ceph/mon_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct ceph_monmap {
1919
struct ceph_fsid fsid;
2020
u32 epoch;
2121
u32 num_mon;
22-
struct ceph_entity_inst mon_inst[];
22+
struct ceph_entity_inst mon_inst[] __counted_by(num_mon);
2323
};
2424

2525
struct ceph_mon_client;

net/ceph/mon_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,7 @@ static int build_initial_monmap(struct ceph_mon_client *monc)
11361136
GFP_KERNEL);
11371137
if (!monc->monmap)
11381138
return -ENOMEM;
1139+
monc->monmap->num_mon = num_mon;
11391140

11401141
for (i = 0; i < num_mon; i++) {
11411142
struct ceph_entity_inst *inst = &monc->monmap->mon_inst[i];
@@ -1147,7 +1148,6 @@ static int build_initial_monmap(struct ceph_mon_client *monc)
11471148
inst->name.type = CEPH_ENTITY_TYPE_MON;
11481149
inst->name.num = cpu_to_le64(i);
11491150
}
1150-
monc->monmap->num_mon = num_mon;
11511151
return 0;
11521152
}
11531153

0 commit comments

Comments
 (0)