Provide a helpful error message if we don't have privs to read kernel
addresses.
This commit is contained in:
parent
0ef96ddde1
commit
f55490be1e
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: fstat.c,v 1.113 2019/09/06 17:08:22 christos Exp $ */
|
||||
/* $NetBSD: fstat.c,v 1.114 2020/08/26 23:08:29 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1988, 1993
|
||||
|
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1993\
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: fstat.c,v 1.113 2019/09/06 17:08:22 christos Exp $");
|
||||
__RCSID("$NetBSD: fstat.c,v 1.114 2020/08/26 23:08:29 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -181,6 +181,7 @@ static void vtrans(struct file *, struct vnode *, int, int, long);
|
|||
static void ftrans(fdfile_t *, int);
|
||||
static void ptrans(struct file *, struct pipe *, int);
|
||||
static void kdriver_init(void);
|
||||
static void check_privs(void);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
|
@ -244,6 +245,8 @@ main(int argc, char **argv)
|
|||
usage();
|
||||
}
|
||||
|
||||
check_privs();
|
||||
|
||||
kdriver_init();
|
||||
|
||||
if (*(argv += optind)) {
|
||||
|
@ -309,6 +312,23 @@ main(int argc, char **argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
check_privs(void)
|
||||
{
|
||||
int expaddr;
|
||||
size_t expsize = sizeof(expaddr);
|
||||
const char *expname = "kern.expose_address";
|
||||
|
||||
if (geteuid() == 0)
|
||||
return;
|
||||
|
||||
if (sysctlbyname(expname, &expaddr, &expsize, NULL, 0) == -1)
|
||||
err(EXIT_FAILURE, "Can't get sysctl `%s'", expname);
|
||||
if (expaddr == 0)
|
||||
errx(EXIT_FAILURE, "This program does not work without "
|
||||
"sysctl `%s' being set", expname);
|
||||
}
|
||||
|
||||
static const char *Uname, *Comm;
|
||||
pid_t Pid;
|
||||
|
||||
|
|
Loading…
Reference in New Issue