Page MenuHomeFreeBSD

periodic 100.chksetuid: supress output if diff is purely whitespace
AcceptedPublic

Authored by allanjude on Sep 20 2024, 3:19 PM.
Tags
None
Referenced Files
F175057124: D46716.id.diff
Wed, Oct 7, 11:12 PM
F175057115: D46716.id188959.diff
Wed, Oct 7, 11:12 PM
Unknown Object (File)
Wed, Oct 7, 2:06 AM
Unknown Object (File)
Wed, Oct 7, 2:01 AM
Unknown Object (File)
Tue, Oct 6, 9:05 PM
Unknown Object (File)
Mon, Oct 5, 10:49 PM
Unknown Object (File)
Thu, Oct 1, 7:56 PM
Unknown Object (File)
Tue, Sep 15, 3:01 AM

Details

Summary

the chksetuid periodic script would report differences of unchanged
files if some other file changed and made the inode column wider.

Use diff -w to suppress these actually unchanged lines

PR: 281555
Reported by: martin@lispworks.com
MFC after: 1 week
Relnotes: yes
Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 59539
Build 56426: arc lint + arc unit

Event Timeline

I think adding -b will not fix it (and in fact security_status_diff_flags already contains -b by default). The problem with -b is that it only ignores changes in the amount of white space, but doesn't ignore newly added whitespace.

Using -w would probably fix it.

michaelo added a subscriber: michaelo.
michaelo added inline comments.
usr.sbin/periodic/etc/security/security.functions
75

This one is redudant, -b is already default.

This revision now requires changes to proceed.Nov 11 2024, 8:16 AM
usr.sbin/periodic/etc/security/security.functions
71

Why -q twice? The manpage does not mention that invoking twice changes anything.

@phk This is what I was writing you privately...

For reference, this morning I received this abbreviated diff in daily run email:

[lots of files removed]
-1444958 -rwxr-sr-x  1 root     kmem     145608 2024-04-09T01:17:02 /mnt/mail/usr/local/sbin/lsof
-1445084 -rwxr-sr-x  1 root     126       15848 2024-07-06T05:52:29 /mnt/mail/usr/local/sbin/postdrop
-1445088 -rwxr-sr-x  1 root     126        9872 2024-07-06T05:52:29 /mnt/mail/usr/local/sbin/postlog
-1445328 -rwxr-sr-x  1 root     126       19296 2024-07-06T05:52:29 /mnt/mail/usr/local/sbin/postqueue
- 883033 -r-sr-xr--  1 root     operator  12872 2024-12-22T07:50:41 /sbin/mksnap_ffs
- 883052 -r-sr-xr-x  2 root     wheel     61920 2024-12-22T07:50:41 /sbin/ping
- 883052 -r-sr-xr-x  2 root     wheel     61920 2024-12-22T07:50:41 /sbin/ping6
- 883053 -r-sr-xr--  2 root     operator  16016 2024-12-22T07:50:41 /sbin/poweroff
- 883053 -r-sr-xr--  2 root     operator  16016 2024-12-22T07:50:41 /sbin/shutdown
- 484604 -r-sr-xr-x  4 root     wheel     29936 2024-12-22T07:50:41 /usr/bin/at
[lots of files removed]
+883033 -r-sr-xr--  1 root     operator  12872 2024-12-22T07:50:41 /sbin/mksnap_ffs
+883052 -r-sr-xr-x  2 root     wheel     61920 2024-12-22T07:50:41 /sbin/ping
+883052 -r-sr-xr-x  2 root     wheel     61920 2024-12-22T07:50:41 /sbin/ping6
+883053 -r-sr-xr--  2 root     operator  16016 2024-12-22T07:50:41 /sbin/poweroff
+883053 -r-sr-xr--  2 root     operator  16016 2024-12-22T07:50:41 /sbin/shutdown
+484604 -r-sr-xr-x  4 root     wheel     29936 2024-12-22T07:50:41 /usr/bin/at
[lots of files removed]

The root problem is that ls(1) autosizes the inode# column, and I found two possible ways to fix it:

  • Use LS_COLWIDTHS=12:0 (millions of millions is enough for everybody!)
  • Strip leading spaces before feeding things to diff(1)

I did consider diff -w, and while in theory it should never be able to make any difference, I feel it is going too far given that we are in a security-adjecent area.

And to be honest, I'm not even sure if I think this needs to be fixed...

allanjude marked 2 inline comments as done.

Update with feedback

allanjude added a reviewer: kevans.
allanjude added inline comments.
usr.sbin/periodic/etc/security/security.functions
71
75

switching to -w

michaelo requested changes to this revision.Tue, Oct 6, 6:24 PM

The code has changed meanwhile. Please rebase.

usr.sbin/periodic/etc/security/security.functions
71

Since you want to MFC this, D46717 needs to be MFC'ed too.

This revision now requires changes to proceed.Tue, Oct 6, 6:24 PM

The code has changed meanwhile. Please rebase.

Are you seeing something out-of-date? I did rebase the diff when I updated it.

The code has changed meanwhile. Please rebase.

Are you seeing something out-of-date? I did rebase the diff when I updated it.

My bad, I misread the review. All is fine!

There is only one hit:

osipovmi@deblndw011x:~/var/Projekte/freebsd/src (main =)
$ grep -r security_status_diff_flags .
./share/man/man5/periodic.conf.5:.It Va security_status_diff_flags
./usr.sbin/periodic/etc/security/security.functions:    diff ${security_status_diff_flags} ${LOG}/${label}.today \
./usr.sbin/periodic/periodic.conf:security_status_diff_flags="-b -U 0"                  # flags for diff output

why not change security_status_diff_flags directly?

This revision is now accepted and ready to land.Tue, Oct 6, 7:50 PM

The code has changed meanwhile. Please rebase.

Are you seeing something out-of-date? I did rebase the diff when I updated it.

My bad, I misread the review. All is fine!

There is only one hit:

osipovmi@deblndw011x:~/var/Projekte/freebsd/src (main =)
$ grep -r security_status_diff_flags .
./share/man/man5/periodic.conf.5:.It Va security_status_diff_flags
./usr.sbin/periodic/etc/security/security.functions:    diff ${security_status_diff_flags} ${LOG}/${label}.today \
./usr.sbin/periodic/periodic.conf:security_status_diff_flags="-b -U 0"                  # flags for diff output

why not change security_status_diff_flags directly?

That probably makes more sense, it gives the admin the option to opt out, if they worry that it could miss something.

why not change security_status_diff_flags directly?

It raises a different question, should daily_diff_flags="-b -U 0" also change to -w?

Add -w to periodic.conf instead

This revision now requires review to proceed.Wed, Oct 7, 1:28 PM

why not change security_status_diff_flags directly?

It raises a different question, should daily_diff_flags="-b -U 0" also change to -w?

I would say so to avoid unnecessary noise and it still can be changed if desired.

usr.sbin/periodic/etc/security/security.functions
71

Use ${security_status_diff_flags} here as well?

usr.sbin/periodic/etc/security/security.functions
71

the -U 0 is redundant with -qq, my concern is someone might add options that override -qq and make the output verbose and corrupt the output of the periodic script, when this invocation of diff is just replacing cmp to give us a boolean "is there a diff or not", and then if there is, we run diff with ${security_status_diff_flags} for the user to read

michaelo added inline comments.
usr.sbin/periodic/etc/security/security.functions
71

This sounds reasonable!

This revision is now accepted and ready to land.Thu, Oct 8, 6:41 AM