Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFE: is it necessary for kernel reply to auditd with block mode in function netlink_unicast when auditd service is stopping #129

Open
e06620227 opened this issue Jun 4, 2021 · 3 comments

Comments

@e06620227
Copy link

When the auditd service is stopped,it will call audit_set_pid(fd, 0, WAIT_NO) and do not process reply messages

int audit_set_pid(int fd, uint32_t pid, rep_wait_t wmode)
{
struct audit_status s;
struct audit_reply rep;
struct pollfd pfd[1];
int rc;

memset(&s, 0, sizeof(s));
s.mask    = AUDIT_STATUS_PID;
s.pid     = pid;
rc = audit_send(fd, AUDIT_SET, &s, sizeof(s));
if (rc < 0) {
	audit_msg(audit_priority(errno), 
		"Error setting audit daemon pid (%s)", 
		strerror(-rc));
	return rc;
}
if (wmode == WAIT_NO)
	return 1;

/* Now we'll see if there's any reply message. This only
       happens on error. It is not fatal if there is no message.
   As a matter of fact, we don't do anything with the message
   besides gobble it. */
pfd[0].fd = fd;
pfd[0].events = POLLIN;
do {
	rc = poll(pfd, 1, 100);	/* .1 second */
} while (rc < 0 && errno == EINTR);

(void)audit_get_reply(fd, &rep, GET_REPLY_NONBLOCKING, 0);
return 1;

}

so why kernel reply to auditd with block mode in function netlink_unicast? When the audit event load is heavy, netlink_attachskb will be scheduled to hang,the auditd has stopped to consume recvbuf.
netlink_unicast(sk, skb, portid, 0) -> netlink_unicast(sk, skb, portid, 1) Is it more reasonable?

audit_receive_msg->audit_replace->auditd_send_unicast_skb->netlink_unicast(sk, skb, portid, 0)->netlink_attachskb

@e06620227
Copy link
Author

@pcmoore
Copy link
Contributor

pcmoore commented Jun 11, 2021

Who is @the-M ?

Anyway, I think most of us are rather busy at the moment dealing with other audit related issues. You can try posting to the the audit mailing list, but most of my audit cycles at the moment are busy dealing with other audit issues that are a bit more critical.

@rgbriggs
Copy link
Contributor

rgbriggs commented Jun 11, 2021 via email

@pcmoore pcmoore changed the title Is it necessary for kernel reply to auditd with block mode in function netlink_unicast when auditd service is stopping Q: is it necessary for kernel reply to auditd with block mode in function netlink_unicast when auditd service is stopping Nov 29, 2021
@pcmoore pcmoore changed the title Q: is it necessary for kernel reply to auditd with block mode in function netlink_unicast when auditd service is stopping RFE: is it necessary for kernel reply to auditd with block mode in function netlink_unicast when auditd service is stopping Nov 29, 2021
pcmoore pushed a commit that referenced this issue Jan 22, 2024
Like commit 1cf3bfc ("bpf: Support 64-bit pointers to kfuncs")
for s390x, add support for 64-bit pointers to kfuncs for LoongArch.
Since the infrastructure is already implemented in BPF core, the only
thing need to be done is to override bpf_jit_supports_far_kfunc_call().

Before this change, several test_verifier tests failed:

  # ./test_verifier | grep # | grep FAIL
  #119/p calls: invalid kfunc call: ptr_to_mem to struct with non-scalar FAIL
  #120/p calls: invalid kfunc call: ptr_to_mem to struct with nesting depth > 4 FAIL
  #121/p calls: invalid kfunc call: ptr_to_mem to struct with FAM FAIL
  #122/p calls: invalid kfunc call: reg->type != PTR_TO_CTX FAIL
  #123/p calls: invalid kfunc call: void * not allowed in func proto without mem size arg FAIL
  #124/p calls: trigger reg2btf_ids[reg->type] for reg->type > __BPF_REG_TYPE_MAX FAIL
  #125/p calls: invalid kfunc call: reg->off must be zero when passed to release kfunc FAIL
  #126/p calls: invalid kfunc call: don't match first member type when passed to release kfunc FAIL
  #127/p calls: invalid kfunc call: PTR_TO_BTF_ID with negative offset FAIL
  #128/p calls: invalid kfunc call: PTR_TO_BTF_ID with variable offset FAIL
  #129/p calls: invalid kfunc call: referenced arg needs refcounted PTR_TO_BTF_ID FAIL
  #130/p calls: valid kfunc call: referenced arg needs refcounted PTR_TO_BTF_ID FAIL
  #486/p map_kptr: ref: reference state created and released on xchg FAIL

This is because the kfuncs in the loaded module are far away from
__bpf_call_base:

  ffff800002009440 t bpf_kfunc_call_test_fail1    [bpf_testmod]
  9000000002e128d8 T __bpf_call_base

The offset relative to __bpf_call_base does NOT fit in s32, which breaks
the assumption in BPF core. Enable bpf_jit_supports_far_kfunc_call() lifts
this limit.

Note that to reproduce the above result, tools/testing/selftests/bpf/config
should be applied, and run the test with JIT enabled, unpriv BPF enabled.

With this change, the test_verifier tests now all passed:

  # ./test_verifier
  ...
  Summary: 777 PASSED, 0 SKIPPED, 0 FAILED

Tested-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants