Skip to content

fix(ebpf): relax MySQL split header length check#11794

Open
yinjiping wants to merge 1 commit into
v6.6from
relax_MySQL
Open

fix(ebpf): relax MySQL split header length check#11794
yinjiping wants to merge 1 commit into
v6.6from
relax_MySQL

Conversation

@yinjiping

Copy link
Copy Markdown
Contributor

When MySQL packet header is read separately, prev_count == 4 means the 4-byte MySQL header has already been cached and the current buffer starts from the payload.

The packet payload length in the MySQL header does not necessarily equal the current syscall read/write length. Requiring len == count may cause valid split packets to skip MySQL inference.

Remove this strict check and always parse seq from the cached header and command bytes from the current payload buffer in the prev_count == 4 path. The later full packet length validation is still kept for initial protocol confirmation.

This PR is for:

  • Agent

Affected branches

  • v6.6

count += 4;
com = buf[0];
point_1 = buf[2];
point_2 = buf[4];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

@yinjiping yinjiping Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#define INFER_BUF_MAX  32

/*
 * BPF Tail Calls context
 */
struct infer_data_s {
	__u32 len;
	char data[INFER_BUF_MAX * 2];
};

 infer_mysql_message(infer_buf, count,
					conn_info))

传递参数是 infer_buf, 他是固定大小的事先缓存内存块,mysql的推断用到的数据不会超过32字节, 推断的数据在9字节以内进行,因此不会出现越界情况,另外我count < 9检查防止脏数据。

     /*
	 * To prevent stale data from a previous map value remaining in
	 * the unused portion of `__infer_buf->data` when the current
	 * syscall provides fewer than 9 bytes of actual data.
	 */
	if (count < 9) {
		point_1 = point_2 = 0;
	}

我测试内核 4.14, 4.19, 5.15 正常

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claude review下这个PR

When MySQL packet header is read separately, prev_count == 4 means the
4-byte MySQL header has already been cached and the current buffer starts
from the payload.

The packet payload length in the MySQL header does not necessarily equal
the current syscall read/write length. Requiring len == count may cause
valid split packets to skip MySQL inference.

Remove this strict check and always parse seq from the cached header and
command bytes from the current payload buffer in the prev_count == 4 path.
The later full packet length validation is still kept for initial protocol
confirmation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants