-
Notifications
You must be signed in to change notification settings - Fork 25
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: add test for audit lost counter reset #41
Conversation
See: linux-audit/audit-kernel#3 https://github.com/linux-audit/audit-kernel/wiki/RFE-Reset-the-Lost-Record-Counter Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
tests/lost_reset/test
Outdated
system("auditctl -d exit,always -S all -F pid=$ping_pid >/dev/null"); | ||
|
||
# Restart the daemon to collect messages in the log | ||
system("auditd -n &"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we don't restart auditd with systemctl so that we put the system back the way it was intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
systemctl doesn't exist on rhel6, but now that I think of it, this feature isn't supported in rhel6.
Instead, we could use "service auditd start" since that redirects to systemd.
tests/lost_reset/test
Outdated
### | ||
# cleanup | ||
system("auditctl -D >& /dev/null"); | ||
system("auditctl -b 320 >/dev/null 2>&1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another reason why we should restart auditd using whatever the system's service manager (almost surely systemd/systemctl these days).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True for fedora, rhel7, Debian 8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, amendment pushed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: rgbriggs@970f6d6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see comments inline.
Use the standard "service" call to stop and start the audit daemon rather than manually (or with systemctl directly since systemd isn't available on older systems and systemctl can't be used directly from the command line for auditd.service). Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
The backlog issue on test cleanup remains (see my earlier comments). |
Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
This test fails for me on my test system:
Test system information:
|
Works fine on my Rawhide and RHEL7 VMs. I need more information. If I can't put that information in the test and I can't reproduce it, I need your help. |
The failing test is the ok($result_lost == $lost) check, on my Rawhide system $loss reports 0 and $report_lost reports 2. Looking a bit closer, I think something odd is happening when auditctl reports the lost counter, for example:
It is worth mentioning that this is on an idle system that isn't generating any audit records (and no indication of lost records in the kernel's ring buffer). It is easily repeatable for me. |
Ok, all my test VMs have a boot parameter of "audit=1" to force auditting on always, so when that is not set, stopping the daemon would have the kernel ignore those messages and not increase the lost count significantly. Either that, or the flood ping command failed. Testing without "audit=1" I get the same result you did, so I'll need to think of another way to trigger this without needing a change to the kernel boot parameters and rebooting. |
Testing with "audit=1" on the kernel command line is good, but it is equally important (perhaps more so) to test the default configuration that many distributions use, e.g. "audit=0". |
On 2017-04-25 08:21, Paul Moore wrote:
Testing with "audit=1" on the kernel command line is good, but it is
equally important (perhaps more so) to test the default configuration
that many distributions use, e.g. "audit=0".
Yes, I fully agree. Maybe the tests should be iterated through both settings.
- RGB
…--
Richard Guy Briggs <rgb@redhat.com>
Sr. S/W Engineer, Kernel Security, Base Operating Systems
Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
|
Since the default configuration is to not have "audit=1" on the kernel boot command line, set buffers to lowest setting and wait time to lowest setting, loop on starting and stopping the daemon while overflowing the queue to provoke a lost message. Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
Ok, I was able to pass the test by deleting the "audit=" kernel boot parameter, setting backlog_limit (-b) to 1, backlog_wait_time to 1(ms), enable (-e) to 1, starting and stopping the daemon multiple times and using a floodping to generate messages. Update pushed to my pull request. |
tests/lost_reset/test
Outdated
system("auditctl -b 1 >/dev/null 2>&1"); | ||
system("auditctl --backlog_wait_time 1 >/dev/null 2>&1"); | ||
system("auditctl -e 1 >/dev/null 2>&1"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think this needed to be said, but please don't add a tab/indent to blank lines.
tests/lost_reset/test
Outdated
sleep 1; | ||
kill 'TERM', $ping_pid; | ||
system("auditctl -d exit,always -S all -F pid=$ping_pid >/dev/null 2>&1"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above comment about indents on blank lines.
Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
@rgbriggs Okay, this looks reasonable. Let's do two final things so we can get this merged:
|
Limit debug output based on presence/value of ATS_DEBUG flag. See linux-audit#41 See linux-audit#54 Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
Enable the lost_reset test. See: linux-audit#41 Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
It would appear there is a problem with lost_reset/test on line 7:
... if I run the test directly from the lost_reset directory things work as expected:
... however if I run it using
I'm guessing you never tested this by running |
Only ran that isolated test. This is bizarre. When run isolated, $iterations is visible inside the "BEGIN..." on line 7, but it is not visible when run as part of the suite. What could cause this? I even tried changing the variable name to avoid other name collisions, but same result. I may have to hard-code it. |
Hard code it. No need to make this more complicated. Also a lesson to be learned that tests should be verified both by running the full suite and the isolated test(s). |
Yes, really. I don't like magic numbers buried deep in the code. This gives it a name and a way to track the usage throughout the file. Otherwise I'll track down why the difference between running one test and running the suite... |
Change it. |
It just occurred to me that some additional commentary is probably warranted given the fact that we are even discussing this. I agree, like most sane people, that magic numbers are generally bad, however, not every constant in every bit of source code is a "magic number". In your current patch(set) the "$iterations" variable is only used in one location ... a rather conventional if-conditional, this makes the value rather obvious, especially given the size of the file and the rather simple nature of the test. Yes, it is annoying that we can't seem to use a variable in the test's
... it also has the benefit of not looking stupid. |
On 2017-07-14 16:38, Paul Moore wrote:
> Change it.
It just occurred to me that some additional commentary is probably
warranted given the fact that we are even discussing this.
I thought that was obvious...
I agree, like most sane people, that magic numbers are generally bad,
however, not every constant in every bit of source code is a "magic
number". In your current patch(set) the "$iterations" variable is only
used in one location ... [a rather conventional
if-conditional](https://github.com/linux-audit/audit-testsuite/blob/9f0745ebd17971ffd5a6324d0c099908f7ed4f02/tests/lost_reset/test#L28),
this makes the value rather obvious, especially given the size of the
file and the rather simple nature of the test.
Putting those kinds of numbers near the top well identified helps. I
failed to describe how it was used either in a self-describing variable
or in a comment.
Yes, it is annoying that we can't seem to use a variable in the test's
`BEGIN {...}` stanza, if we could I would agree to keeping the
$iterations variable, but we can't. You've placed a comment after the
`BEGIN` statement which seems to implying that the `5 + 10` is linked to
the $iterations variable, IMHO the following is just as meaningful, if
not more so:
BEGIN { plan tests => 15 } # five fixed tests + the main for loop below
My code comment was incomplete and misleading, assisting in the
confusion. Leaving as it as I had it but changing the comment to "# 5
fixed tests plus $iterations" I think is far clearer and much quicker to
find with basic text search tools. I tried escaping it to fix it and
made it worse.
... it also has the benefit of not looking stupid.
I strongly disagree on this last statement, but I guess that is this
"judgement" and "taste" people keep talking about.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#41 (comment)
- RGB
…--
Richard Guy Briggs <rgb@redhat.com>
Sr. S/W Engineer, Kernel Security, Base Operating Systems
Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
|
It isn't clear to me from your last response if you are planning another revision, but just to be clear on my expectations: I'm waiting on another revision to get rid of the $iterations variable and the "5 + 10" nonsense. |
Hard code iterations to work around variable scoping issues. When run alone, no problem. When run in suite, it claims iterations is uninitialized. Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
9f0745e
to
027d515
Compare
Cleaned up iterations comment: rgbriggs@027d515 |
In the future please do not merge the upstream branches back into your forked branch, it makes it very messy when I pull from you. If you need to resync with upstream, rebase your development branch. |
Merged via d549ded. I also merged a commit to fix a number of style/formatting diffs, see 1807b2f. As this PR originally predated the 'make check-syntax' style checker I didn't require the code to satisfy all those style checks, but in the future having a clean 'make check-syntax' run will be necessary for merging. |
Since restarting the daemon does not reset these two values unless they are explicitly set in the config file, reset them manually based on the kernel defaults at the time of committing this test. While it would be better to use the actual kernel defaults, those are not available to this test. See: linux-audit/audit-kernel#3 linux-audit#56 linux-audit#41 Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
Since restarting the daemon does not reset these two values unless they are explicitly set in the config file, reset them manually based on the auditctl status values at the start of the test. While it would be better to use the actual kernel defaults, those are not available to this test. See: linux-audit/audit-kernel#3 linux-audit#56 linux-audit#41 Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
Since restarting the daemon does not reset these two values unless they are explicitly set in the config file, reset them manually based on the auditctl status values at the start of the test. While it would be better to use the actual kernel defaults, those are not available to this test. See: linux-audit/audit-kernel#3 linux-audit#56 linux-audit#41 Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
See:
linux-audit/audit-kernel#3
https://github.com/linux-audit/audit-kernel/wiki/RFE-Reset-the-Lost-Record-Counter
Signed-off-by: Richard Guy Briggs rgb@redhat.com