ipc/mqueue: add tracepoints for message load and store

This patch adds tracepoints to load_msg and store_msg, which would helps
if any message get lost or corrupted when traversing through kernel.

Signed-off-by: Jiaolong He <hejiaolong@kernelsoft.com>
This commit is contained in:
Jiaolong He 2023-07-12 16:06:25 +08:00 committed by Xinpeng Liu
parent 39e7ddce21
commit 259eb72da2
2 changed files with 55 additions and 2 deletions

46
include/trace/events/mq.h Normal file
View File

@ -0,0 +1,46 @@
/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM mq
#if !defined(_TRACE_MQ_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_MQ_H
#include <linux/tracepoint.h>
DECLARE_EVENT_CLASS(mq,
TP_PROTO(struct msg_msg *msg, size_t mlen),
TP_ARGS(msg, mlen),
TP_STRUCT__entry(
__field(struct msg_msg *, msg)
__field(size_t, mlen)
),
TP_fast_assign(
__entry->msg = msg;
__entry->mlen = mlen;
),
TP_printk("msg=%p len=%zu", __entry->msg, __entry->mlen)
);
DEFINE_EVENT(mq, load_msg,
TP_PROTO(struct msg_msg *msg, size_t mlen),
TP_ARGS(msg, mlen)
);
DEFINE_EVENT(mq, store_msg,
TP_PROTO(struct msg_msg *msg, size_t mlen),
TP_ARGS(msg, mlen)
);
#endif /* _TRACE_MQ_H */
/* This part must be outside protection */
#include <trace/define_trace.h>

View File

@ -18,6 +18,9 @@
#include "util.h"
#define CREATE_TRACE_POINTS
#include <trace/events/mq.h>
DEFINE_SPINLOCK(mq_lock);
/*
@ -83,11 +86,12 @@ out_err:
return NULL;
}
struct msg_msg *load_msg(const void __user *src, size_t len)
struct msg_msg *load_msg(const void __user *src, size_t mlen)
{
struct msg_msg *msg;
struct msg_msgseg *seg;
int err = -EFAULT;
size_t len = mlen;
size_t alen;
msg = alloc_msg(len);
@ -110,6 +114,7 @@ struct msg_msg *load_msg(const void __user *src, size_t len)
if (err)
goto out_err;
trace_load_msg(msg, mlen);
return msg;
out_err:
@ -149,11 +154,13 @@ struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst)
return ERR_PTR(-ENOSYS);
}
#endif
int store_msg(void __user *dest, struct msg_msg *msg, size_t len)
int store_msg(void __user *dest, struct msg_msg *msg, size_t mlen)
{
size_t alen;
size_t len = mlen;
struct msg_msgseg *seg;
trace_store_msg(msg, mlen);
alen = min(len, DATALEN_MSG);
if (copy_to_user(dest, msg + 1, alen))
return -1;