Bug 1402 - Support auditing through Linux Audit subsystem
Summary: Support auditing through Linux Audit subsystem
Status: NEW
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sshd (show other bugs)
Version: 5.6p1
Hardware: Other Linux
: P2 enhancement
Assignee: Assigned to nobody
URL:
Keywords: patch
: 1642 (view as bug list)
Depends on: fingerprint-alg 1879
Blocks:
  Show dependency treegraph
 
Reported: 2007-12-12 19:43 AEDT by Tomas Mraz
Modified: 2020-01-27 22:53 AEDT (History)
9 users (show)

See Also:


Attachments
Proposed patch (6.31 KB, patch)
2007-12-12 19:43 AEDT, Tomas Mraz
no flags Details | Diff
Patch using the ssh_audit subsystem (8.81 KB, patch)
2010-09-26 04:50 AEST, jchadima
no flags Details | Diff
improoved patch (8.74 KB, patch)
2010-10-01 17:33 AEST, jchadima
no flags Details | Diff
clean up patch some more (9.59 KB, patch)
2010-10-12 14:35 AEDT, Darren Tucker
no flags Details | Diff
aditinal patch fr auditing authrized keys usage (5.49 KB, patch)
2010-10-26 13:13 AEDT, jchadima
no flags Details | Diff
Aditional patch for auditing authorized keys usage (6.24 KB, patch)
2010-10-27 01:50 AEDT, jchadima
no flags Details | Diff
Aditional patch for auditing authorized keys usage (6.14 KB, patch)
2010-11-02 22:55 AEDT, jchadima
no flags Details | Diff
Aditional patch for auditing authorized keys usage (6.73 KB, patch)
2010-11-03 07:17 AEDT, jchadima
no flags Details | Diff
Aditional patch for auditing protocol negotiation results (15.48 KB, patch)
2010-11-04 00:39 AEDT, jchadima
no flags Details | Diff
Aditional patch for auditing authorized keys usage (6.72 KB, patch)
2010-11-05 20:31 AEDT, jchadima
no flags Details | Diff
Aditional patch for auditing (user and host) authorized keys usage (8.27 KB, patch)
2010-11-06 02:03 AEDT, jchadima
no flags Details | Diff
Aditional patch for auditing protocol negotiation results (15.50 KB, patch)
2010-11-06 02:04 AEDT, jchadima
no flags Details | Diff
Aditional patch for auditing (user and host) authorized keys usage (8.50 KB, patch)
2010-11-11 22:29 AEDT, jchadima
no flags Details | Diff
Please add this to "clean up patch some more" (548 bytes, patch)
2010-12-11 17:16 AEDT, jchadima
no flags Details | Diff
Aditional patch for auditing (user and host) authorized keys usage (8.37 KB, patch)
2010-12-11 17:19 AEDT, jchadima
no flags Details | Diff
Aditional patch for auditing protocol negotiation results (16.28 KB, patch)
2010-12-11 17:21 AEDT, jchadima
no flags Details | Diff
base linux audit support (combined #1934 and #1974) (10.26 KB, patch)
2011-01-17 11:52 AEDT, Darren Tucker
djm: ok+
Details | Diff
patch removing duplicate audit (507 bytes, patch)
2011-03-17 20:44 AEDT, jchadima
no flags Details | Diff
patch for better audit of user actions (18.29 KB, patch)
2011-03-17 20:47 AEDT, jchadima
no flags Details | Diff
patch adding logging the key based authentzations (11.95 KB, patch)
2011-03-17 20:48 AEDT, jchadima
no flags Details | Diff
patch adding results of the kex exchange (16.86 KB, patch)
2011-03-17 20:50 AEDT, jchadima
no flags Details | Diff
patch adding audit of session key destruction (19.49 KB, patch)
2011-03-17 20:51 AEDT, jchadima
no flags Details | Diff
patch adding audit of server kay destruction (15.73 KB, patch)
2011-03-17 20:52 AEDT, jchadima
no flags Details | Diff
00 remving duplicate audit suitable for 5.9p1 (507 bytes, patch)
2011-09-18 12:39 AEST, jchadima
no flags Details | Diff
01 better audit of user actions suitable for 5.9p1 (18.30 KB, patch)
2011-09-18 12:43 AEST, jchadima
no flags Details | Diff
02 log the key based authentications suitable for 5.9p1 (11.93 KB, patch)
2011-09-18 12:45 AEST, jchadima
no flags Details | Diff
03 audit protocol negotition results suitable for 5.9p1 (17.08 KB, patch)
2011-09-18 12:47 AEST, jchadima
no flags Details | Diff
04 audit session key destruction suitable for 5.9p1 (20.33 KB, patch)
2011-09-18 12:48 AEST, jchadima
no flags Details | Diff
05 audit server key destruction suitable for 5.9p1 (15.63 KB, patch)
2011-09-18 12:49 AEST, jchadima
no flags Details | Diff
audit patch rebased for 7.2 HEAD (67.98 KB, patch)
2016-03-05 02:39 AEDT, Jakub Jelen
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tomas Mraz 2007-12-12 19:43:27 AEDT
Created attachment 1396 [details]
Proposed patch

The attached patch adds support for auditing through the Linux Audit subsystem. The patch is included in Fedora and RHEL builds of OpenSSH.
It was written by Steve Grubb, I did some small adjustments to it too.
Comment 1 Darren Tucker 2007-12-12 23:42:18 AEDT
Is there any reason you did not use the existing audit framework in audit.c rather than adding new code in the mainline?  Also, what's the purpose of the "hexescape" code, and could strnvis be used for this purpose instead?
Comment 2 Tomas Mraz 2007-12-13 03:20:41 AEDT
(In reply to comment #1)
> Is there any reason you did not use the existing audit framework in
> audit.c rather than adding new code in the mainline?  Also, what's the
The patch is rather old and it was originaly written for openssh-3.9p1 I think. But you're right that it should be rewritten to use the audit.c framework.

> purpose of the "hexescape" code, and could strnvis be used for this
> purpose instead?
The escaping in Linux Audit is different from strnvis - either the whole string is escaped by using hexadecimal numbers or it starts and ends with '"' character.
Comment 3 Darren Tucker 2009-09-01 17:44:10 AEST
*** Bug 1642 has been marked as a duplicate of this bug. ***
Comment 4 jchadima 2010-09-26 04:50:35 AEST
Created attachment 1930 [details]
Patch using the ssh_audit subsystem

Finally I got the time to rewrite the patch, can anybody review it? Please.
Comment 5 jchadima 2010-10-01 17:33:04 AEST
Created attachment 1931 [details]
improoved patch
Comment 6 Darren Tucker 2010-10-12 13:54:10 AEDT
Thanks, this looks pretty good, target 5.7.
Comment 7 Darren Tucker 2010-10-12 14:20:29 AEDT
Comment on attachment 1931 [details]
improoved patch


>+/* #pragma ident	"@(#)audit-linux.c	1.1	01/09/17 SMI" */

It looks like this file was originally based on the Sun-copyright audit-bsm.c.  That said, it looks like none of the original Sun code remains.

>+		else
>+                        return 0; /* Must prevent login */

whitespace.

>+	if (rc >= 0)
>+		return 1;
>+	else
>+		return 0;

  return(rc >= 0); ?

>+	if (linux_audit_record_event(li->uid, NULL, li->hostname,
>+		NULL, li->line, 1) == 0)

indenting wrong (see http://www.openbsd.org/cgi-bin/man.cgi?query=style for the guidelines).

>+	fatal("linux_audit_write_entry failed: %s", strerror(errno));

the close() call in linux_audit_record_event() can reset errno, so if you're relying on what audit_log_acct_message sets you should save errno and restore it.

> AUDIT_MODULE=none
> AC_ARG_WITH(audit,
>-	[  --with-audit=module     Enable EXPERIMENTAL audit support (modules=debug,bsm)],
>+	[  --with-audit=module     Enable EXPERIMENTAL audit support (modules=debug,bsm,linux)],

I'm removing the EXPERIMENTAL tag as BSM has been in for years.

>-	audit.o audit-bsm.o platform.o sftp-server.o sftp-common.o \
>+	audit.o audit-bsm.o audit-linux.o platform.o sftp-server.o sftp-common.o \

I'm moving the audit bits to a line on its own just for ease of maintenance.

Will attach an updated patch shortly.
Comment 8 Darren Tucker 2010-10-12 14:35:37 AEDT
Created attachment 1934 [details]
clean up patch some more
Comment 9 jchadima 2010-10-26 13:13:07 AEDT
Created attachment 1939 [details]
aditinal patch fr auditing authrized keys usage
Comment 10 jchadima 2010-10-26 13:18:22 AEDT
Attached anther patch component, which allow to audit authorized keys usage. The key type, size and fingerprint are logged in the case of successful authorization using authorized (user) keys.
Comment 11 jchadima 2010-10-27 01:50:00 AEDT
Created attachment 1940 [details]
Aditional patch for auditing authorized keys usage
Comment 12 jchadima 2010-11-02 22:55:34 AEDT
Created attachment 1942 [details]
Aditional patch for auditing authorized keys usage
Comment 13 jchadima 2010-11-03 07:17:36 AEDT
Created attachment 1943 [details]
Aditional patch for auditing authorized keys usage
Comment 14 jchadima 2010-11-04 00:39:43 AEDT
Created attachment 1945 [details]
Aditional patch for auditing protocol negotiation results
Comment 15 jchadima 2010-11-05 20:31:09 AEDT
Created attachment 1950 [details]
Aditional patch for auditing authorized keys usage
Comment 16 jchadima 2010-11-06 02:03:49 AEDT
Created attachment 1951 [details]
Aditional patch for auditing (user and host) authorized keys usage
Comment 17 jchadima 2010-11-06 02:04:52 AEDT
Created attachment 1952 [details]
Aditional patch for auditing protocol negotiation results
Comment 18 jchadima 2010-11-06 02:08:38 AEDT
Add the possibility to audit host based keys to the additional patch for audit authorized keys usage. Update the audit protocol negotiation patch to match with the authorized keys patch.
Comment 19 jchadima 2010-11-11 22:29:28 AEDT
Created attachment 1954 [details]
Aditional patch for auditing (user and host) authorized keys usage
Comment 20 jchadima 2010-12-11 17:16:20 AEDT
Created attachment 1974 [details]
Please add this to "clean up patch some more"

This little add on repairs the reviewed patch. Without it the sshd cannot be run as non root user. Please add it to 5.7 also.
Comment 21 jchadima 2010-12-11 17:19:00 AEDT
Created attachment 1975 [details]
Aditional patch for auditing (user and host) authorized keys usage

Improve the patch. Enable the sshd run as non root user.
Comment 22 jchadima 2010-12-11 17:21:07 AEDT
Created attachment 1976 [details]
Aditional patch for auditing protocol negotiation results

Improve the patch, enable run sshd as mnon root user, enable rekeying.
Comment 23 Darren Tucker 2011-01-17 11:52:20 AEDT
Created attachment 1981 [details]
base linux audit support (combined #1934 and #1974)

This is the base-level audit support which I intend to put in for 5.7.  I think the additional auditing capabilities/code needs further review.

I changed the root-check to geteuid() and moved it to before the errno restore in case geteuid messes with errno (unlikely).
Comment 24 Darren Tucker 2011-01-17 21:16:40 AEDT
Comment on attachment 1981 [details]
base linux audit support (combined #1934 and #1974)

thanks, patch #1981 has been committed and will be in the 5.7p1 release.  We'll look at the other parts next release.
Comment 25 Damien Miller 2011-01-24 12:30:47 AEDT
Retarget unclosed bugs from 5.7=>5.8
Comment 26 jchadima 2011-03-17 20:44:17 AEDT
Created attachment 2010 [details]
patch removing duplicate audit
Comment 27 jchadima 2011-03-17 20:47:08 AEDT
Created attachment 2011 [details]
patch for better audit of user actions
Comment 28 jchadima 2011-03-17 20:48:49 AEDT
Created attachment 2012 [details]
patch adding logging the key based authentzations
Comment 29 jchadima 2011-03-17 20:50:09 AEDT
Created attachment 2013 [details]
patch adding results of the kex exchange
Comment 30 jchadima 2011-03-17 20:51:36 AEDT
Created attachment 2014 [details]
patch adding audit of session key destruction
Comment 31 jchadima 2011-03-17 20:52:41 AEDT
Created attachment 2015 [details]
patch adding audit of server kay destruction
Comment 32 jchadima 2011-03-17 20:55:29 AEDT
upload new patch set for linux audit (and general audit also)
the patchset depends on bz#1879 fingerprint patch
Comment 33 Damien Miller 2011-09-06 10:34:11 AEST
Retarget unresolved bugs/features to 6.0 release
Comment 34 Damien Miller 2011-09-06 10:36:25 AEST
Retarget unresolved bugs/features to 6.0 release
Comment 35 Damien Miller 2011-09-06 10:38:59 AEST
Retarget unresolved bugs/features to 6.0 release

(try again - bugzilla's "change several" isn't)
Comment 36 jchadima 2011-09-12 18:18:21 AEST
Current patch set (especially audit of session key destruction) does not work with openssh-5.9p1.
I'm preparing the improved patches.
Comment 37 jchadima 2011-09-18 12:39:10 AEST
Created attachment 2085 [details]
00 remving duplicate audit suitable for 5.9p1
Comment 38 jchadima 2011-09-18 12:43:03 AEST
Created attachment 2086 [details]
01 better audit of user actions suitable for 5.9p1
Comment 39 jchadima 2011-09-18 12:45:26 AEST
Created attachment 2087 [details]
02 log the key based authentications suitable for 5.9p1
Comment 40 jchadima 2011-09-18 12:47:25 AEST
Created attachment 2088 [details]
03 audit protocol negotition results suitable for 5.9p1
Comment 41 jchadima 2011-09-18 12:48:32 AEST
Created attachment 2089 [details]
04 audit session key destruction suitable for 5.9p1
Comment 42 jchadima 2011-09-18 12:49:50 AEST
Created attachment 2090 [details]
05 audit server key destruction suitable for 5.9p1
Comment 43 jchadima 2011-09-18 12:51:04 AEST
The status of the bug was updated for the openssh 5.9p1
Comment 44 Damien Miller 2011-09-19 10:08:07 AEST
(In reply to comment #42)
> Created attachment 2090 [details]
> 05 audit server key destruction suitable for 5.9p1

I don't see the point of this one at all. Should every bzero() be an audit event?
Comment 45 jchadima 2011-09-19 17:33:05 AEST
Of course not :) These particular cases are required to meet common criteria.
Comment 46 Damien Miller 2012-02-24 10:34:19 AEDT
Retarget from 6.0 to 6.1
Comment 47 Damien Miller 2012-02-24 10:37:57 AEDT
Retarget 6.0 => 6.1
Comment 48 Damien Miller 2012-09-07 11:37:43 AEST
Retarget uncompleted bugs from 6.1 => 6.2
Comment 49 Damien Miller 2012-09-07 11:40:11 AEST
Retarget bugs from 6.1 => 6.2
Comment 50 Damien Miller 2013-03-08 10:23:19 AEDT
retarget to openssh-6.3
Comment 51 Damien Miller 2013-07-25 12:17:22 AEST
Retarget to openssh-6.4
Comment 52 Damien Miller 2013-07-25 12:20:15 AEST
Retarget 6.3 -> 6.4
Comment 53 Damien Miller 2014-02-06 10:17:34 AEDT
Retarget incomplete bugs / feature requests to 6.6 release
Comment 54 Damien Miller 2014-02-06 10:19:23 AEDT
Retarget incomplete bugs / feature requests to 6.6 release
Comment 55 Damien Miller 2014-04-12 14:50:01 AEST
Retarget to 6.7 release, since 6.6 was mostly bugfixing.
Comment 56 Damien Miller 2014-04-12 14:54:24 AEST
Remove from 6.6 tracking bug
Comment 57 Damien Miller 2014-08-30 04:37:48 AEST
Retarget incomplete bugs to 6.8 release.
Comment 58 Damien Miller 2014-08-30 04:39:48 AEST
These bugs are no longer targeted at the imminent 6.7 release
Comment 59 Damien Miller 2015-03-03 07:59:23 AEDT
OpenSSH 6.8 is approaching release and closed for major work. Retarget these bugs for the next release.
Comment 60 Damien Miller 2015-03-03 08:01:44 AEDT
Retarget to 6.9
Comment 61 Damien Miller 2015-08-11 22:59:14 AEST
Retarget pending bugs to openssh-7.1
Comment 62 Damien Miller 2016-02-26 14:44:24 AEDT
Retarget to openssh-7.3
Comment 63 Damien Miller 2016-02-26 14:47:17 AEDT
Retarget to openssh-7.3
Comment 64 Jakub Jelen 2016-03-05 02:39:46 AEDT
Created attachment 2795 [details]
audit patch rebased for 7.2 HEAD

Seems like this bug/feature request is still on the tracker. We use this patch, but today all the changes are merged into single patch, therefore it is not so nice view.

I tried to clean up the patch, made it apply on the current HEAD and successfully checked functionality of configure&build&tests --with-audit=linux or without the audit enabled. All tests passed in both cases.

I understand that some of the things might not fit upstream, but it would be fine to have at least the hooks in the code. I can restructure the patch/provide comments. Please let me know what is the most suitable way from your point of view.
Comment 65 Damien Miller 2016-07-22 14:11:00 AEST
retarget unfinished bugs to next release
Comment 66 Damien Miller 2016-07-22 14:14:45 AEST
retarget unfinished bugs to next release
Comment 67 Damien Miller 2016-07-22 14:15:45 AEST
retarget unfinished bugs to next release
Comment 68 Damien Miller 2016-07-22 14:17:20 AEST
retarget unfinished bugs to next release
Comment 69 Damien Miller 2016-12-16 14:31:14 AEDT
OpenSSH 7.4 release is closing; punt the bugs to 7.5
Comment 70 Damien Miller 2017-06-30 13:43:14 AEST
Move incomplete bugs to openssh-7.6 target since 7.5 shipped a while back.

To calibrate expectations, there's little chance all of these are going to make 7.6.
Comment 71 Damien Miller 2017-06-30 13:44:29 AEST
remove 7.5 target
Comment 72 vineetha 2018-03-06 04:36:40 AEDT
Any chance of this making it into next release - 7.7?
Comment 73 Damien Miller 2018-04-06 13:12:22 AEST
Move to OpenSSH 7.8 tracking bug
Comment 74 Damien Miller 2018-08-10 11:38:01 AEST
Retarget remaining bugs planned for 7.8 release to 7.9
Comment 75 Damien Miller 2018-08-10 11:38:23 AEST
Retarget remaining bugs planned for 7.8 release to 7.9
Comment 76 Damien Miller 2018-10-19 17:13:38 AEDT
Retarget unfinished bugs to OpenSSH 8.0
Comment 77 Damien Miller 2018-10-19 17:14:46 AEDT
Retarget unfinished bugs to OpenSSH 8.0
Comment 78 Damien Miller 2018-10-19 17:15:45 AEDT
Retarget unfinished bugs to OpenSSH 8.0
Comment 79 Damien Miller 2019-04-03 10:10:30 AEDT
Retarget outstanding bugs at next release
Comment 80 Damien Miller 2019-10-09 15:07:24 AEDT
Retarget these bugs to 8.2 release
Comment 81 Damien Miller 2020-01-25 23:08:55 AEDT
Is this patch still used by anyone? It seems a bunch of stuff that is very obsolete...
Comment 82 Laurent Bigonville 2020-01-25 23:15:28 AEDT
(In reply to Damien Miller from comment #81)
> Is this patch still used by anyone? It seems a bunch of stuff that
> is very obsolete...

Red Hat and Fedora are still carrying it I believe

See:
https://src.fedoraproject.org/rpms/openssh/blob/master/f/openssh-7.6p1-audit.patch and https://git.centos.org/rpms/openssh/blob/c8/f/SOURCES/openssh-7.6p1-audit.patch
Comment 83 Jakub Jelen 2020-01-27 22:53:48 AEDT
Right, we still use it in both Fedora and RHEL as you can see the links in the previous comment and even after 13 years, we would appreciate a review and considering including these changes.

The Fedora patches are the most up-to-date version based on current OpenSSH 8.1 as the time of writing this comment:

https://src.fedoraproject.org/rpms/openssh/blob/master/f/openssh-7.6p1-audit.patch
https://src.fedoraproject.org/rpms/openssh/blob/master/f/openssh-7.1p2-audit-race-condition.patch