-/* $OpenBSD: kern_ktrace.c,v 1.113 2023/12/12 15:30:55 deraadt Exp $ */
+/* $OpenBSD: kern_ktrace.c,v 1.114 2023/12/15 15:12:08 deraadt Exp $ */
/* $NetBSD: kern_ktrace.c,v 1.23 1996/02/09 18:59:36 christos Exp $ */
/*
atomic_clearbits_int(&p->p_flag, P_INKTR);
}
+void
+ktrpinsyscall(struct proc *p, int error, int syscall, vaddr_t addr)
+{
+ struct ktr_header kth;
+ struct ktr_pinsyscall kp;
+
+ atomic_setbits_int(&p->p_flag, P_INKTR);
+ ktrinitheader(&kth, p, KTR_PINSYSCALL);
+ kp.error = error;
+ kp.syscall = syscall;
+ kp.addr = addr;
+
+ KERNEL_LOCK();
+ ktrwrite(p, &kth, &kp, sizeof(kp));
+ KERNEL_UNLOCK();
+ atomic_clearbits_int(&p->p_flag, P_INKTR);
+}
+
/* Interface and common routines */
int
-/* $OpenBSD: ktrace.h,v 1.47 2023/12/12 15:30:55 deraadt Exp $ */
+/* $OpenBSD: ktrace.h,v 1.48 2023/12/15 15:12:08 deraadt Exp $ */
/* $NetBSD: ktrace.h,v 1.12 1996/02/04 02:12:29 christos Exp $ */
/*
uint64_t code;
};
+/*
+ * KTR_PINSYSCALL - details of pinsyscall violation
+ */
+#define KTR_PINSYSCALL 13
+struct ktr_pinsyscall {
+ int error;
+ int syscall;
+ vaddr_t addr;
+};
+
/*
* kernel trace points (in ps_traceflag)
*/
#define KTRFAC_EXECARGS (1<<KTR_EXECARGS)
#define KTRFAC_EXECENV (1<<KTR_EXECENV)
#define KTRFAC_PLEDGE (1<<KTR_PLEDGE)
+#define KTRFAC_PINSYSCALL (1<<KTR_PINSYSCALL)
/*
* trace flags (also in ps_traceflag)
int ktruser(struct proc *, const char *, const void *, size_t);
void ktrexec(struct proc *, int, const char *, ssize_t);
void ktrpledge(struct proc *, int, uint64_t, int);
+void ktrpinsyscall(struct proc *, int, int, vaddr_t);
void ktrcleartrace(struct process *);
void ktrsettrace(struct process *, int, struct vnode *, struct ucred *);
-.\" $OpenBSD: kdump.1,v 1.39 2023/11/09 15:43:28 kn Exp $
+.\" $OpenBSD: kdump.1,v 1.40 2023/12/15 15:12:08 deraadt Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" from: @(#)kdump.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd $Mdocdate: November 9 2023 $
+.Dd $Mdocdate: December 15 2023 $
.Dt KDUMP 1
.Os
.Sh NAME
restrictions
.It Cm s
trace signal processing
+.It Cm S
+trace violation of
+.Xr pinsyscalls 2
.It Cm t
trace various structures
.It Cm u
-/* $OpenBSD: kdump.c,v 1.160 2023/12/12 15:30:55 deraadt Exp $ */
+/* $OpenBSD: kdump.c,v 1.161 2023/12/15 15:12:08 deraadt Exp $ */
/*-
* Copyright (c) 1988, 1993
static void ktruser(struct ktr_user *, size_t);
static void ktrexec(const char*, size_t);
static void ktrpledge(struct ktr_pledge *, size_t);
+static void ktrpinsyscall(struct ktr_pinsyscall *, size_t);
static void usage(void);
static void ioctldecode(int);
static void ptracedecode(int);
case KTR_PLEDGE:
ktrpledge(m, ktrlen);
break;
+ case KTR_PINSYSCALL:
+ ktrpinsyscall(m, ktrlen);
+ break;
default:
printf("\n");
break;
case KTR_PLEDGE:
type = "PLDG";
break;
+ case KTR_PINSYSCALL:
+ type = "PINS";
+ break;
default:
/* htobe32() not guaranteed to work as case label */
if (kth->ktr_type == htobe32(KTR_START)) {
printf("\n");
}
+static void
+ktrpinsyscall(struct ktr_pinsyscall *pinsyscall, size_t len)
+{
+ const char *name = "";
+ int i;
+
+ if (len < sizeof(struct ktr_pinsyscall))
+ errx(1, "invalid ktr pinsyscall length %zu", len);
+
+ if (pinsyscall->syscall >= SYS_MAXSYSCALL || pinsyscall->syscall < 0)
+ (void)printf("[%d]", pinsyscall->syscall);
+ else
+ (void)printf("%s", syscallnames[pinsyscall->syscall]);
+ (void)printf(", addr %lx, errno %d", pinsyscall->addr,
+ pinsyscall->error);
+ (void)printf(", errno %d", pinsyscall->error);
+ if (fancy)
+ (void)printf(" %s", strerror(pinsyscall->error));
+ printf("\n");
+}
+
static void
usage(void)
{
-.\" $OpenBSD: ktrace.1,v 1.33 2023/09/30 13:03:40 naddy Exp $
+.\" $OpenBSD: ktrace.1,v 1.34 2023/12/15 15:12:08 deraadt Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" from: @(#)ktrace.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd $Mdocdate: September 30 2023 $
+.Dd $Mdocdate: December 15 2023 $
.Dt KTRACE 1
.Os
.Sh NAME
restrictions
.It Cm s
trace signal processing
+.It Cm S
+trace violation of
+.Xr pinsyscalls 2
.It Cm t
trace various structures
.It Cm u
-/* $OpenBSD: subr.c,v 1.16 2022/02/22 17:35:01 deraadt Exp $ */
+/* $OpenBSD: subr.c,v 1.17 2023/12/15 15:12:08 deraadt Exp $ */
/* $NetBSD: subr.c,v 1.6 1995/08/31 23:01:45 jtc Exp $ */
/*-
case 's':
facs |= KTRFAC_PSIG;
break;
+ case 'S':
+ facs |= KTRFAC_PINSYSCALL;
+ break;
case 't':
facs |= KTRFAC_STRUCT;
break;