selinux: Annotate struct sidtab_str_cache with __counted_by
PATCH 1/1 selinux: Annotate struct sidtab_str_cache 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 sidtab_str_cache.
[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
--- security/selinux/ss/sidtab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/selinux/ss/sidtab.c +1 -1
@@ -25,7 +25,7 @@ struct sidtab_str_cache {struct list_head lru_member;struct sidtab_entry *parent;u32 len; -char str[]; + char str[] __counted_by(len); };#define index_to_sid (index) ((index) + SECINITSID_NUM + 1)
Signature · 1 line
2.34.1
Quoted 8 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time checking viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structsidtab_str_cache.
Quoted 8 lines
[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
Cc Paul Moore <[email protected]>Cc Stephen Smalley <[email protected]>Cc Eric Paris <[email protected]>Cc Ondrej Mosnacek <[email protected]>Signed-off-by Kees Cook <[email protected]>
Thanks
--
Gustavo
Quoted 17 lines
--- security/selinux/ss/sidtab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)security/selinux/ss/sidtab.c +1
-1@@ -25,7 +25,7 @@ struct sidtab_str_cache {struct list_head lru_member;struct sidtab_entry *parent;u32 len; -char str[]; + char str[] __counted_by(len); };#define index_to_sid (index) ((index) + SECINITSID_NUM + 1)
Paul Moore
maintainerQuoted 17 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time checking viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structsidtab_str_cache.[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
Cc Paul Moore <[email protected]>Cc Stephen Smalley <[email protected]>Cc Eric Paris <[email protected]>Cc Ondrej Mosnacek <[email protected]>Signed-off-by Kees Cook <[email protected]>
Quoted 3 lines
--- security/selinux/ss/sidtab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
This also looks good to me, but similarly to the audit patch, since we are at -rc6 I'm going to wait to merge this until after the merge window. I'll send a follow up email once it's merged.
Thanks.
Quoted 15 lines
security/selinux/ss/sidtab.c +1
-2@@ -25,7 +25,7 @@ struct sidtab_str_cache {struct list_head lru_member;struct sidtab_entry *parent;u32 len; -char str[]; + char str[] __counted_by(len); };#define index_to_sid (index) ((index) + SECINITSID_NUM + 1) --2.34.1
Signature · 1 line
paul-moore.com
Quoted 22 lines · Paul Moore
Quoted 17 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time checking viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structsidtab_str_cache.[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
Cc Paul Moore <[email protected]>Cc Stephen Smalley <[email protected]>Cc Eric Paris <[email protected]>Cc Ondrej Mosnacek <[email protected]>Signed-off-by Kees Cook <[email protected]>Quoted 3 lines
--- security/selinux/ss/sidtab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 3 lines
This also looks good to me, but similarly to the audit patch, since we are at -rc6 I'm going to wait to merge this until after the merge window. I'll send a follow up email once it's merged.
Thanks! Yeah, there's no rush. :)
Signature · 1 line
Kees Cook
Quoted 17 lines · On Aug 17, 2023 Kees Cook <[email protected]> wrote:
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time checking viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structsidtab_str_cache.[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
Cc Paul Moore <[email protected]>Cc Stephen Smalley <[email protected]>Cc Eric Paris <[email protected]>Cc Ondrej Mosnacek <[email protected]>Signed-off-by Kees Cook <[email protected]>
Quoted 3 lines
--- security/selinux/ss/sidtab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Merged into selinux/next, thanks.
--
paul-moore.com