From 997c4cdc979a262b9774f19adabfcae6ddf17622 Mon Sep 17 00:00:00 2001 From: kamil Date: Sun, 18 Aug 2019 04:10:22 +0000 Subject: [PATCH] sysctl: Add indirection of symbols to remove clash with sanitizers Add indirection and symbol renaming under MKSANITIZER for the linked in version of sysctlbyname and sysctlgetmibinfo. --- sbin/sysctl/Makefile | 6 +++++- sbin/sysctl/prog_ops.h | 16 +++++++++++++++- sbin/sysctl/sysctl.c | 16 ++++++++-------- sbin/sysctl/sysctl_hostops.c | 8 ++++++-- sbin/sysctl/sysctl_rumpops.c | 8 ++++++-- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/sbin/sysctl/Makefile b/sbin/sysctl/Makefile index 8fb0a14d533d..f9f77a918fe0 100644 --- a/sbin/sysctl/Makefile +++ b/sbin/sysctl/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.21 2012/11/29 02:05:38 christos Exp $ +# $NetBSD: Makefile,v 1.22 2019/08/18 04:10:22 kamil Exp $ # @(#)Makefile 8.1 (Berkeley) 6/6/93 .include @@ -13,4 +13,8 @@ SRCS= sysctl.c CPPFLAGS+= -DRUMP_ACTION RUMPSRCS+= sysctlbyname.c sysctlgetmibinfo.c +SANITIZER_RENAME_CLASSES+= rump +SANITIZER_RENAME_FILES.rump+= ${PROG}_rumpops.c ${RUMPSRCS} +SANITIZER_RENAME_SYMBOL.rump+= sysctlbyname sysctlgetmibinfo + .include diff --git a/sbin/sysctl/prog_ops.h b/sbin/sysctl/prog_ops.h index f57426858ef9..65a35a723f16 100644 --- a/sbin/sysctl/prog_ops.h +++ b/sbin/sysctl/prog_ops.h @@ -1,4 +1,4 @@ -/* $NetBSD: prog_ops.h,v 1.2 2010/12/13 21:48:01 pooka Exp $ */ +/* $NetBSD: prog_ops.h,v 1.3 2019/08/18 04:10:22 kamil Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -32,19 +32,33 @@ #include #ifndef CRUNCHOPS +struct sysctlnode; + struct prog_ops { int (*op_init)(void); int (*op_sysctl)(const int *, u_int, void *, size_t *, const void *, size_t); + + /* Indirection needed for sanitizers. */ + + int (*op_sysctlbyname)(const char *, void *, size_t *, + const void *, size_t); + + int (*op_sysctlgetmibinfo)(const char *, int *, u_int *, char *, + size_t *, struct sysctlnode **, int); }; extern const struct prog_ops prog_ops; #define prog_init prog_ops.op_init #define prog_sysctl prog_ops.op_sysctl +#define prog_sysctlbyname prog_ops.op_sysctlbyname +#define prog_sysctlgetmibinfo prog_ops.op_sysctlgetmibinfo #else #define prog_init ((int (*)(void))NULL) #define prog_sysctl sysctl +#define prog_sysctlbyname sysctlbyname +#define prog_sysctlgetmibinfo sysctlgetmibinfo #endif #endif /* _PROG_OPS_H_ */ diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index e44d2384fe47..09c764f6a79f 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: sysctl.c,v 1.161 2018/10/30 19:41:21 kre Exp $ */ +/* $NetBSD: sysctl.c,v 1.162 2019/08/18 04:10:22 kamil Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ __COPYRIGHT("@(#) Copyright (c) 1993\ #if 0 static char sccsid[] = "@(#)sysctl.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: sysctl.c,v 1.161 2018/10/30 19:41:21 kre Exp $"); +__RCSID("$NetBSD: sysctl.c,v 1.162 2019/08/18 04:10:22 kamil Exp $"); #endif #endif /* not lint */ @@ -896,7 +896,7 @@ parse(char *l, regex_t *re, size_t *lastcompiled) namelen = CTL_MAXNAME; sz = sizeof(gsname); - if (sysctlgetmibinfo(key, &name[0], &namelen, gsname, &sz, &node, + if (prog_sysctlgetmibinfo(key, &name[0], &namelen, gsname, &sz, &node, SYSCTL_VERSION) == -1) { if (optional) return; @@ -1441,7 +1441,7 @@ parse_create(char *l) namelen = sizeof(name) / sizeof(name[0]); sz = sizeof(gsname); *t = '\0'; - rc = sysctlgetmibinfo(nname, &name[0], &namelen, + rc = prog_sysctlgetmibinfo(nname, &name[0], &namelen, gsname, &sz, NULL, SYSCTL_VERSION); *t = sep[0]; if (rc == -1) { @@ -1489,7 +1489,7 @@ parse_destroy(char *l) memset(name, 0, sizeof(name)); namelen = sizeof(name) / sizeof(name[0]); sz = sizeof(gsname); - rc = sysctlgetmibinfo(l, &name[0], &namelen, gsname, &sz, NULL, + rc = prog_sysctlgetmibinfo(l, &name[0], &namelen, gsname, &sz, NULL, SYSCTL_VERSION); if (rc == -1) { sysctlparseerror(namelen, l); @@ -1538,7 +1538,7 @@ parse_describe(char *l) memset(name, 0, sizeof(name)); namelen = sizeof(name) / sizeof(name[0]); sz = sizeof(gsname); - rc = sysctlgetmibinfo(l, &name[0], &namelen, gsname, &sz, NULL, + rc = prog_sysctlgetmibinfo(l, &name[0], &namelen, gsname, &sz, NULL, SYSCTL_VERSION); if (rc == -1) { sysctlparseerror(namelen, l); @@ -2266,7 +2266,7 @@ kern_cp_time(HANDLER_ARGS) if (namelen == 2 && Aflag) { sz = sizeof(n); - rc = sysctlbyname("hw.ncpu", &n, &sz, NULL, 0); + rc = prog_sysctlbyname("hw.ncpu", &n, &sz, NULL, 0); if (rc != 0) return; /* XXX print an error, eh? */ n++; /* Add on space for the sum. */ @@ -2414,7 +2414,7 @@ kern_cp_id(HANDLER_ARGS) if (namelen == 2) { sz = sizeof(n); - rc = sysctlbyname("hw.ncpu", &n, &sz, NULL, 0); + rc = prog_sysctlbyname("hw.ncpu", &n, &sz, NULL, 0); if (rc != 0) return; /* XXX print an error, eh? */ sz = n * sizeof(u_int64_t); diff --git a/sbin/sysctl/sysctl_hostops.c b/sbin/sysctl/sysctl_hostops.c index 9f1b25a24530..03ad1d243309 100644 --- a/sbin/sysctl/sysctl_hostops.c +++ b/sbin/sysctl/sysctl_hostops.c @@ -1,4 +1,4 @@ -/* $NetBSD: sysctl_hostops.c,v 1.1 2010/12/13 17:47:40 pooka Exp $ */ +/* $NetBSD: sysctl_hostops.c,v 1.2 2019/08/18 04:10:22 kamil Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ #include #ifndef lint -__RCSID("$NetBSD: sysctl_hostops.c,v 1.1 2010/12/13 17:47:40 pooka Exp $"); +__RCSID("$NetBSD: sysctl_hostops.c,v 1.2 2019/08/18 04:10:22 kamil Exp $"); #endif /* !lint */ #include @@ -38,4 +38,8 @@ __RCSID("$NetBSD: sysctl_hostops.c,v 1.1 2010/12/13 17:47:40 pooka Exp $"); const struct prog_ops prog_ops = { .op_sysctl = sysctl, + + .op_sysctlbyname = sysctlbyname, + + .op_sysctlgetmibinfo = sysctlgetmibinfo, }; diff --git a/sbin/sysctl/sysctl_rumpops.c b/sbin/sysctl/sysctl_rumpops.c index c00b67b4fd8f..ed958669fd3d 100644 --- a/sbin/sysctl/sysctl_rumpops.c +++ b/sbin/sysctl/sysctl_rumpops.c @@ -1,4 +1,4 @@ -/* $NetBSD: sysctl_rumpops.c,v 1.1 2010/12/13 17:47:40 pooka Exp $ */ +/* $NetBSD: sysctl_rumpops.c,v 1.2 2019/08/18 04:10:22 kamil Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ #include #ifndef lint -__RCSID("$NetBSD: sysctl_rumpops.c,v 1.1 2010/12/13 17:47:40 pooka Exp $"); +__RCSID("$NetBSD: sysctl_rumpops.c,v 1.2 2019/08/18 04:10:22 kamil Exp $"); #endif /* !lint */ #include @@ -44,4 +44,8 @@ const struct prog_ops prog_ops = { .op_init = rumpclient_init, .op_sysctl = rump_sys___sysctl, + + .op_sysctlbyname = sysctlbyname, + + .op_sysctlgetmibinfo = sysctlgetmibinfo, };