summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authoriedowse <iedowse@FreeBSD.org>2001-11-09 23:58:07 +0000
committeriedowse <iedowse@FreeBSD.org>2001-11-09 23:58:07 +0000
commit8122c9fcb409b8b399474666a0fe1fc5d8c8d8a2 (patch)
tree31795853c548ef46c1eabcbed8c20d75ffce1c44 /sys
parentd061342650aa6f8538bdb9ba2ce11271cb899dd6 (diff)
downloadFreeBSD-src-8122c9fcb409b8b399474666a0fe1fc5d8c8d8a2.zip
FreeBSD-src-8122c9fcb409b8b399474666a0fe1fc5d8c8d8a2.tar.gz
Properly sanity-check the old msgbuf structure before we accept it
as being valid. Previously only the magic number and the virtual address were checked, but it makes little sense to require that the virtual address is the same (the message buffer is located at the end of physical memory), and checks on the msg_bufx and msg_bufr indices were missing. Submitted by: Bodo Rueskamp <br@clabsms.de> Tripped over during a kernel debugging tutorial given by: grog Reviewed by: grog, dwmalone MFC after: 1 week
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/subr_prf.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c
index 8708704..5e2d310 100644
--- a/sys/kern/subr_prf.c
+++ b/sys/kern/subr_prf.c
@@ -802,14 +802,17 @@ msgbufinit(void *ptr, size_t size)
char *cp;
static struct msgbuf *oldp = NULL;
+ size -= sizeof(*msgbufp);
cp = (char *)ptr;
- msgbufp = (struct msgbuf *) (cp + size - sizeof(*msgbufp));
- if (msgbufp->msg_magic != MSG_MAGIC || msgbufp->msg_ptr != cp) {
+ msgbufp = (struct msgbuf *) (cp + size);
+ if (msgbufp->msg_magic != MSG_MAGIC || msgbufp->msg_size != size ||
+ msgbufp->msg_bufx >= size || msgbufp->msg_bufr >= size) {
bzero(cp, size);
+ bzero(msgbufp, sizeof(*msgbufp));
msgbufp->msg_magic = MSG_MAGIC;
msgbufp->msg_size = (char *)msgbufp - cp;
- msgbufp->msg_ptr = cp;
}
+ msgbufp->msg_ptr = cp;
if (msgbufmapped && oldp != msgbufp)
msgbufcopy(oldp);
msgbufmapped = 1;
OpenPOWER on IntegriCloud