linux/drivers/net/ethernet/chelsio/cxgb4/clip_tbl.h
Kees Cook c3db467b08 cxgb4: Annotate struct clip_tbl 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 clip_tbl.

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

Cc: Raju Rangoju <rajur@chelsio.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20230929181149.3006432-2-keescook@chromium.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2023-10-04 15:37:13 -07:00

45 lines
1.3 KiB
C

/*
* This file is part of the Chelsio T4 Ethernet driver for Linux.
* Copyright (C) 2003-2014 Chelsio Communications. All rights reserved.
*
* Written by Deepak (deepak.s@chelsio.com)
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the LICENSE file included in this
* release for licensing terms and conditions.
*/
#include <linux/refcount.h>
struct clip_entry {
spinlock_t lock; /* Hold while modifying clip reference */
refcount_t refcnt;
struct list_head list;
union {
struct sockaddr_in addr;
struct sockaddr_in6 addr6;
};
};
struct clip_tbl {
unsigned int clipt_start;
unsigned int clipt_size;
rwlock_t lock;
atomic_t nfree;
struct list_head ce_free_head;
void *cl_list;
struct list_head hash_list[] __counted_by(clipt_size);
};
enum {
CLIPT_MIN_HASH_BUCKETS = 2,
};
struct clip_tbl *t4_init_clip_tbl(unsigned int clipt_start,
unsigned int clipt_end);
int cxgb4_clip_get(const struct net_device *dev, const u32 *lip, u8 v6);
void cxgb4_clip_release(const struct net_device *dev, const u32 *lip, u8 v6);
int clip_tbl_show(struct seq_file *seq, void *v);
int cxgb4_update_root_dev_clip(struct net_device *dev);
void t4_cleanup_clip_tbl(struct adapter *adap);