mirror of
https://github.com/opnsense/src.git
synced 2026-06-09 08:43:19 -04:00
sockbuf: Add KMSAN checks to sbappend*()
Otherwise KMSAN only detects uninitialized memory when the contents of the buffer are copied out to userspace or transmitted to a network interface. At that point the KMSAN violation will be far removed from its origin, so let's try to make debugging such problems a bit easier. Reviewed by: glebius MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D38101
This commit is contained in:
parent
83fd35b3f3
commit
ec45f952a2
1 changed files with 16 additions and 0 deletions
|
|
@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
|
||||||
#include <sys/lock.h>
|
#include <sys/lock.h>
|
||||||
#include <sys/malloc.h>
|
#include <sys/malloc.h>
|
||||||
#include <sys/mbuf.h>
|
#include <sys/mbuf.h>
|
||||||
|
#include <sys/msan.h>
|
||||||
#include <sys/mutex.h>
|
#include <sys/mutex.h>
|
||||||
#include <sys/proc.h>
|
#include <sys/proc.h>
|
||||||
#include <sys/protosw.h>
|
#include <sys/protosw.h>
|
||||||
|
|
@ -908,6 +909,7 @@ sbappend_locked(struct sockbuf *sb, struct mbuf *m, int flags)
|
||||||
|
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
return;
|
return;
|
||||||
|
kmsan_check_mbuf(m, "sbappend");
|
||||||
sbm_clrprotoflags(m, flags);
|
sbm_clrprotoflags(m, flags);
|
||||||
SBLASTRECORDCHK(sb);
|
SBLASTRECORDCHK(sb);
|
||||||
n = sb->sb_mb;
|
n = sb->sb_mb;
|
||||||
|
|
@ -1022,6 +1024,8 @@ sbappendstream_locked(struct sockbuf *sb, struct mbuf *m, int flags)
|
||||||
|
|
||||||
KASSERT(m->m_nextpkt == NULL,("sbappendstream 0"));
|
KASSERT(m->m_nextpkt == NULL,("sbappendstream 0"));
|
||||||
|
|
||||||
|
kmsan_check_mbuf(m, "sbappend");
|
||||||
|
|
||||||
#ifdef KERN_TLS
|
#ifdef KERN_TLS
|
||||||
/*
|
/*
|
||||||
* Decrypted TLS records are appended as records via
|
* Decrypted TLS records are appended as records via
|
||||||
|
|
@ -1170,7 +1174,10 @@ sbappendrecord_locked(struct sockbuf *sb, struct mbuf *m0)
|
||||||
|
|
||||||
if (m0 == NULL)
|
if (m0 == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
kmsan_check_mbuf(m0, "sbappend");
|
||||||
m_clrprotoflags(m0);
|
m_clrprotoflags(m0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Put the first mbuf on the queue. Note this permits zero length
|
* Put the first mbuf on the queue. Note this permits zero length
|
||||||
* records.
|
* records.
|
||||||
|
|
@ -1207,6 +1214,12 @@ sbappendaddr_locked_internal(struct sockbuf *sb, const struct sockaddr *asa,
|
||||||
struct mbuf *m0, struct mbuf *control, struct mbuf *ctrl_last)
|
struct mbuf *m0, struct mbuf *control, struct mbuf *ctrl_last)
|
||||||
{
|
{
|
||||||
struct mbuf *m, *n, *nlast;
|
struct mbuf *m, *n, *nlast;
|
||||||
|
|
||||||
|
if (m0 != NULL)
|
||||||
|
kmsan_check_mbuf(m0, "sbappend");
|
||||||
|
if (control != NULL)
|
||||||
|
kmsan_check_mbuf(control, "sbappend");
|
||||||
|
|
||||||
#if MSIZE <= 256
|
#if MSIZE <= 256
|
||||||
if (asa->sa_len > MLEN)
|
if (asa->sa_len > MLEN)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
@ -1317,6 +1330,9 @@ sbappendcontrol_locked(struct sockbuf *sb, struct mbuf *m0,
|
||||||
{
|
{
|
||||||
struct mbuf *m, *mlast;
|
struct mbuf *m, *mlast;
|
||||||
|
|
||||||
|
kmsan_check_mbuf(m0, "sbappend");
|
||||||
|
kmsan_check_mbuf(control, "sbappend");
|
||||||
|
|
||||||
sbm_clrprotoflags(m0, flags);
|
sbm_clrprotoflags(m0, flags);
|
||||||
m_last(control)->m_next = m0;
|
m_last(control)->m_next = m0;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue