Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178291113
D58985.1796444567.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
10 KB
Referenced Files
None
Subscribers
None
D58985.1796444567.diff
View Options
diff --git a/sys/amd64/include/cpufunc.h b/sys/amd64/include/cpufunc.h
--- a/sys/amd64/include/cpufunc.h
+++ b/sys/amd64/include/cpufunc.h
@@ -100,7 +100,7 @@
}
static __inline void
-cpuid_count(u_int ax, u_int cx, u_int *p)
+cpuid_count(u_int ax, u_int cx, u_int *__unsafe_indexable p)
{
__asm __volatile("cpuid"
: "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3])
@@ -108,7 +108,7 @@
}
static __inline void
-do_cpuid(u_int ax, u_int *p)
+do_cpuid(u_int ax, u_int *__unsafe_indexable p)
{
cpuid_count(ax, 0, p);
}
diff --git a/sys/amd64/include/pcpu_aux.h b/sys/amd64/include/pcpu_aux.h
--- a/sys/amd64/include/pcpu_aux.h
+++ b/sys/amd64/include/pcpu_aux.h
@@ -52,7 +52,7 @@
static __inline __pure2 struct thread *
__curthread(void)
{
- struct thread *td;
+ struct thread *__single td;
__asm("movq %%gs:%c1,%0" : "=r" (td)
: "i" (offsetof(struct pcpu, pc_curthread)));
diff --git a/sys/arm64/include/pcpu.h b/sys/arm64/include/pcpu.h
--- a/sys/arm64/include/pcpu.h
+++ b/sys/arm64/include/pcpu.h
@@ -60,7 +60,7 @@
static inline struct pcpu *
get_pcpu(void)
{
- struct pcpu *pcpu;
+ struct pcpu *__single pcpu;
__asm __volatile("mov %0, x18" : "=&r"(pcpu));
return (pcpu);
@@ -69,7 +69,7 @@
static inline struct thread *
get_curthread(void)
{
- struct thread *td;
+ struct thread *__single td;
__asm __volatile("ldr %0, [x18]" : "=&r"(td));
return (td);
diff --git a/sys/compat/linuxkpi/common/include/linux/compiler.h b/sys/compat/linuxkpi/common/include/linux/compiler.h
--- a/sys/compat/linuxkpi/common/include/linux/compiler.h
+++ b/sys/compat/linuxkpi/common/include/linux/compiler.h
@@ -45,11 +45,18 @@
#define ____cacheline_aligned __aligned(CACHE_LINE_SIZE)
#define ____cacheline_aligned_in_smp __aligned(CACHE_LINE_SIZE)
+/*
+ * sys/cdefs.h defines __counted_by as a no-op unless the file is built with
+ * -fbounds-safety, since our own uses of it are shapes the plain attribute
+ * rejects. The imported drivers only annotate flexible array members whose
+ * counter is declared first, which clang and gcc both accept unaided, so
+ * restore the attribute for them.
+ */
#if __has_attribute(__counted_by__)
+#undef __counted_by
#define __counted_by(_x) __attribute__((__counted_by__(_x)))
-#else
-#define __counted_by(_x)
#endif
+
#if BYTE_ORDER == LITTLE_ENDIAN
#define __counted_by_le(_x) __counted_by(_x)
#define __counted_by_be(_x)
diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h
--- a/sys/netinet/tcp_var.h
+++ b/sys/netinet/tcp_var.h
@@ -1435,7 +1435,7 @@
int register_tcp_functions(struct tcp_function_block *blk, int wait);
int register_tcp_functions_as_names(struct tcp_function_block *blk,
- int wait, const char *names[], int *num_names);
+ int wait, const char **names, int *num_names);
int register_tcp_functions_as_name(struct tcp_function_block *blk,
const char *name, int wait);
int deregister_tcp_functions(struct tcp_function_block *blk, bool quiesce,
diff --git a/sys/sys/buf_ring.h b/sys/sys/buf_ring.h
--- a/sys/sys/buf_ring.h
+++ b/sys/sys/buf_ring.h
@@ -144,7 +144,7 @@
{
uint32_t cons_head, cons_next, cons_idx;
uint32_t prod_tail, mask;
- void *buf;
+ void *__single buf;
critical_enter();
mask = br->br_cons_mask;
@@ -193,7 +193,7 @@
{
uint32_t cons_head, cons_next, cons_idx;
uint32_t prod_tail, mask;
- void *buf;
+ void *__single buf;
mask = br->br_cons_mask;
cons_head = atomic_load_32(&br->br_cons_head);
@@ -305,7 +305,7 @@
buf_ring_peek_clear_sc(struct buf_ring *br)
{
uint32_t cons_head, prod_tail, mask;
- void *buf;
+ void *__single buf;
#if defined(DEBUG_BUFRING) && defined(_KERNEL)
if (!mtx_owned(br->br_lock))
diff --git a/sys/sys/ck.h b/sys/sys/ck.h
--- a/sys/sys/ck.h
+++ b/sys/sys/ck.h
@@ -4,8 +4,16 @@
#define _SYS_CK_H_
#ifdef _KERNEL
+#include <sys/cdefs.h>
+/*
+ * Third-party code with inline asm on pointers; leave it unchecked. This
+ * toolchain has no abi_ptr_attr push/pop, so restore the default (single)
+ * afterwards.
+ */
+__ptrcheck_abi_assume_unsafe_indexable()
#include <ck_queue.h>
#include <ck_epoch.h>
+__ptrcheck_abi_assume_single()
#else
#include <sys/queue.h>
#define CK_STAILQ_HEAD STAILQ_HEAD
diff --git a/sys/sys/fnv_hash.h b/sys/sys/fnv_hash.h
--- a/sys/sys/fnv_hash.h
+++ b/sys/sys/fnv_hash.h
@@ -18,11 +18,12 @@
#define FNV_64_PRIME ((Fnv64_t) 0x100000001b3ULL)
static __inline Fnv32_t
-fnv_32_buf(const void *buf, size_t len, Fnv32_t hval)
+fnv_32_buf(const void *__sized_by(len) buf, size_t len, Fnv32_t hval)
{
const u_int8_t *s = (const u_int8_t *)buf;
+ size_t n = len;
- while (len-- != 0) {
+ while (n-- != 0) {
hval *= FNV_32_PRIME;
hval ^= *s++;
}
@@ -43,11 +44,12 @@
}
static __inline Fnv64_t
-fnv_64_buf(const void *buf, size_t len, Fnv64_t hval)
+fnv_64_buf(const void *__sized_by(len) buf, size_t len, Fnv64_t hval)
{
const u_int8_t *s = (const u_int8_t *)buf;
+ size_t n = len;
- while (len-- != 0) {
+ while (n-- != 0) {
hval *= FNV_64_PRIME;
hval ^= *s++;
}
diff --git a/sys/sys/libkern.h b/sys/sys/libkern.h
--- a/sys/sys/libkern.h
+++ b/sys/sys/libkern.h
@@ -44,14 +44,14 @@
#endif
/* BCD conversions. */
-extern u_char const bcd2bin_data[];
-extern u_char const bin2bcd_data[];
-extern char const hex2ascii_data[];
-
#define LIBKERN_LEN_BCD2BIN 154
#define LIBKERN_LEN_BIN2BCD 100
#define LIBKERN_LEN_HEX2ASCII 36
+extern u_char const bcd2bin_data[LIBKERN_LEN_BCD2BIN];
+extern u_char const bin2bcd_data[LIBKERN_LEN_BIN2BCD];
+extern char const hex2ascii_data[LIBKERN_LEN_HEX2ASCII + 1];
+
static inline u_char
bcd2bin(int bcd)
{
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
--- a/sys/sys/mbuf.h
+++ b/sys/sys/mbuf.h
@@ -344,7 +344,12 @@
SLIST_ENTRY(mbuf) m_slistpkt;
STAILQ_ENTRY(mbuf) m_stailqpkt;
};
- caddr_t m_data; /* location of data */
+ /*
+ * __unsafe_indexable: the bound is inside the backing cluster, not
+ * expressible as a sibling annotation. A checked mtod() accessor is TBD;
+ * until then reads through mtod() are unchecked.
+ */
+ caddr_t __unsafe_indexable m_data; /* location of data */
int32_t m_len; /* amount of data in this mbuf */
uint32_t m_type:8, /* type of data in this mbuf */
m_flags:24; /* flags; see below */
@@ -909,6 +914,8 @@
/*
* Associated an external reference counted buffer with an mbuf.
+ *
+ * TODO: annotate buf __sized_by(size) once the checked mbuf accessors land.
*/
static __inline void
m_extaddref(struct mbuf *m, char *buf, u_int size, u_int *ref_cnt,
@@ -933,7 +940,7 @@
static __inline uma_zone_t
m_getzone(int size)
{
- uma_zone_t zone;
+ uma_zone_t __single zone;
switch (size) {
case MCLBYTES:
@@ -987,7 +994,7 @@
static __inline struct mbuf *
m_get_raw(int how, short type)
{
- struct mbuf *m;
+ struct mbuf *__single m;
struct mb_args args;
args.flags = 0;
@@ -1000,7 +1007,7 @@
static __inline struct mbuf *
m_get(int how, short type)
{
- struct mbuf *m;
+ struct mbuf *__single m;
struct mb_args args;
args.flags = 0;
@@ -1013,7 +1020,7 @@
static __inline struct mbuf *
m_gethdr_raw(int how, short type)
{
- struct mbuf *m;
+ struct mbuf *__single m;
struct mb_args args;
args.flags = M_PKTHDR;
@@ -1026,7 +1033,7 @@
static __inline struct mbuf *
m_gethdr(int how, short type)
{
- struct mbuf *m;
+ struct mbuf *__single m;
struct mb_args args;
args.flags = M_PKTHDR;
@@ -1039,7 +1046,7 @@
static __inline struct mbuf *
m_getcl(int how, short type, int flags)
{
- struct mbuf *m;
+ struct mbuf *__single m;
struct mb_args args;
args.flags = flags;
@@ -1497,7 +1504,7 @@
static __inline struct m_tag *
m_tag_find(struct mbuf *m, uint16_t type, struct m_tag *start)
{
- return (SLIST_EMPTY(&m->m_pkthdr.tags) ? (struct m_tag *)NULL :
+ return (SLIST_EMPTY(&m->m_pkthdr.tags) ? NULL :
m_tag_locate(m, MTAG_ABI_COMPAT, type, start));
}
diff --git a/sys/sys/pcpu.h b/sys/sys/pcpu.h
--- a/sys/sys/pcpu.h
+++ b/sys/sys/pcpu.h
@@ -246,6 +246,19 @@
#endif
/* Accessor to elements allocated via UMA_ZONE_PCPU zone. */
+#if __has_ptrcheck
+#define zpcpu_get(base) ({ \
+ __typeof(base) _ptr = __unsafe_forge_single(__typeof(base), \
+ (char *__unsafe_indexable)(base) + zpcpu_offset()); \
+ _ptr; \
+})
+
+#define zpcpu_get_cpu(base, cpu) ({ \
+ __typeof(base) _ptr = __unsafe_forge_single(__typeof(base), \
+ (char *__unsafe_indexable)(base) + zpcpu_offset_cpu(cpu)); \
+ _ptr; \
+})
+#else
#define zpcpu_get(base) ({ \
__typeof(base) _ptr = (void *)((char *)(base) + zpcpu_offset()); \
_ptr; \
@@ -255,6 +268,7 @@
__typeof(base) _ptr = (void *)((char *)(base) + zpcpu_offset_cpu(cpu)); \
_ptr; \
})
+#endif
/*
* This operation is NOT atomic and does not post any barriers.
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1345,13 +1345,19 @@
td_get_sched(struct thread *td)
{
- return ((struct td_sched *)&td[1]);
+ return (__unsafe_forge_single(struct td_sched *,
+ (char *__unsafe_indexable)td + sizeof(*td)));
}
-static __inline char *
+static __inline char *__unsafe_indexable
td_kstack_top(struct thread *td)
{
- return (td->td_kstack + ptoa(td->td_kstack_pages));
+ /*
+ * One-past-the-end limit; callers do arithmetic on it, so
+ * __unsafe_indexable rather than __single.
+ */
+ return ((char *__unsafe_indexable)((__uintptr_t)td->td_kstack +
+ ptoa(td->td_kstack_pages)));
}
static __inline void
diff --git a/sys/sys/queue.h b/sys/sys/queue.h
--- a/sys/sys/queue.h
+++ b/sys/sys/queue.h
@@ -155,7 +155,7 @@
#ifdef QUEUE_MACRO_DEBUG_TRASH
#define QMD_SAVELINK(name, link) void **name = (void *)&(link)
-#define TRASHIT(x) do {(x) = (void *)-1;} while (0)
+#define TRASHIT(x) do {(x) = __unsafe_forge_single(void *, (__uintptr_t)-1);} while (0)
#define QMD_IS_TRASHED(x) ((x) == (void *)(intptr_t)-1)
#else /* !QUEUE_MACRO_DEBUG_TRASH */
#define QMD_SAVELINK(name, link)
diff --git a/sys/sys/sdt.h b/sys/sys/sdt.h
--- a/sys/sys/sdt.h
+++ b/sys/sys/sdt.h
@@ -231,8 +231,8 @@
_SDT_ASM_WORD " 0\n" \
".popsection\n" \
: \
- : _SDT_ASM_PROBE_CONSTRAINT (&_SDT_PROBE_NAME(prov, mod, \
- func, name)) \
+ : _SDT_ASM_PROBE_CONSTRAINT ((uintptr_t)&_SDT_PROBE_NAME(prov, \
+ mod, func, name)) \
: \
: __sdt_probe##uniq); \
if (0) { \
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 5, 4:22 AM (19 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42218862
Default Alt Text
D58985.1796444567.diff (10 KB)
Attached To
Mode
D58985: sys: build core headers under bounds-safety
Attached
Detach File
Event Timeline