audit: improve NETFILTER_PKT records
Subsystems (3)
v7 cover audit: improve NETFILTER_PKT records
Currently, NETFILTER_PKT records lack source and destination port information, which is often valuable for troubleshooting. This patch series adds ports numbers, to NETFILTER_PKT records.
The first patch refactors netfilter-related code, by moving duplicated code to audit.c, by creating audit_log_nf_skb() helper function.
The second one, improves the NETFILTER_PKT records, by including source and destination ports for protocols of interest.
Ricardo Robaina (2):
audit: add audit_log_nf_skb helper function
audit: include source and destination ports to NETFILTER_PKT
include/linux/audit.h | 8 ++ kernel/audit.c | 159 +++++++++++++++++++++++++++++++++++++++ net/netfilter/nft_log.c | 58 +------------- net/netfilter/xt_AUDIT.c | 58 +------------- 4 files changed, 169 insertions(+), 114 deletions(-)
Signature · 1 line
2.51.1
PATCH v7 1/2 audit: add audit_log_nf_skb helper function
Netfilter code (net/netfilter/nft_log.c and net/netfilter/xt_AUDIT.c) have to be kept in sync. Both source files had duplicated versions of audit_ip4() and audit_ip6() functions, which can result in lack of consistency and/or duplicated work.
This patch adds a helper function in audit.c that can be called by netfilter code commonly, aiming to improve maintainability and consistency.
--- include/linux/audit.h | 8 +++++ kernel/audit.c | 64 ++++++++++++++++++++++++++++++++++++++++ net/netfilter/nft_log.c | 58 +----------------------------------- net/netfilter/xt_AUDIT.c | 58 +----------------------------------- 4 files changed, 74 insertions(+), 114 deletions(-)
include/linux/audit.h +8 -0
@@ -195,6 +195,8 @@ extern int audit_log_subj_ctx(struct audit_buffer *ab, struct lsm_prop *prop);extern int audit_log_obj_ctx (struct audit_buffer *ab,struct lsm_prop *prop);extern int audit_log_task_context (struct audit_buffer *ab);extern void audit_log_task_info (struct audit_buffer *ab); +extern int audit_log_nf_skb (struct audit_buffer *ab, +const struct sk_buff *skb,u8 nfproto);extern int audit_update_lsm_rules (void );
@@ -272,6 +274,12 @@ static inline int audit_log_task_context(struct audit_buffer *ab)static inline void audit_log_task_info (struct audit_buffer *ab) { } +static inline int audit_log_nf_skb (struct audit_buffer *ab, +const struct sk_buff *skb,u8 nfproto) +{ +return 0 ; +} +static inline kuid_t audit_get_loginuid (struct task_struct *tsk) {return INVALID_UID ;
kernel/audit.c +64 -0
76 lines not on this page · raw message
net/netfilter/nft_log.c +1 -57
74 lines not on this page · raw message
net/netfilter/xt_AUDIT.c +1 -57
74 lines not on this page · raw message
Signature · 1 line
2.51.1
Re: [PATCH v7 1/2] audit: add audit_log_nf_skb helper function
Quoted 8 lines · Ricardo Robaina
Netfilter code (
net/netfilter/nft_log.candnet/netfilter/xt_AUDIT.c) have to be kept in sync. Both source files had duplicated versions ofaudit_ip4()andaudit_ip6()functions, which can result in lack of consistency and/or duplicated work.This patch adds a helper function in
audit.cthat can be called by netfilter code commonly, aiming to improve maintainability and consistency.
PATCH v7 2/2 audit: include source and destination ports to NETFILTER_PKT
In reply to Ricardo RobainaNETFILTER_PKT records show both source and destination addresses, in addition to the associated networking protocol. However, it lacks the ports information, which is often valuable for troubleshooting.
This patch adds both source and destination port numbers, 'sport' and 'dport' respectively, to TCP, UDP, UDP-Lite and SCTP-related NETFILTER_PKT records.
$ TESTS="netfilter_pkt" make -e test &> /dev/null $ ausearch -i -ts recent |grep NETFILTER_PKT type=NETFILTER_PKT ... proto=icmp type=NETFILTER_PKT ... proto=ipv6-icmp type=NETFILTER_PKT ... proto=udp sport=46333 dport=42424 type=NETFILTER_PKT ... proto=udp sport=35953 dport=42424 type=NETFILTER_PKT ... proto=tcp sport=50314 dport=42424 type=NETFILTER_PKT ... proto=tcp sport=57346 dport=42424
--- kernel/audit.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 4 deletions(-)
kernel/audit.c +99 -4
@@ -60,6 +60,7 @@#include <net/netns/generic.h> #include <net/ip.h> #include <net/ipv6.h> +#include <linux/sctp.h> #include "audit.h"
@@ -2517,8 +2518,55 @@ int audit_log_nf_skb(struct audit_buffer *ab,if (!ih)return -ENOMEM ; -audit_log_format (ab," saddr=%pI4 daddr=%pI4 proto=%hhu" , - &ih->saddr, &ih->daddr, ih->protocol); +switch (ih->protocol) { +case IPPROTO_TCP : { +struct tcphdr _tcph; +const struct tcphdr *th; + + th =skb_header_pointer (skb,skb_transport_offset (skb), +sizeof (_tcph), &_tcph); +if (!th) +return -ENOMEM ; + +audit_log_format (ab," saddr=%pI4 daddr=%pI4 proto=%hhu sport=%hu dport=%hu" , + &ih->saddr, &ih->daddr, ih->protocol, +ntohs (th->source),ntohs (th->dest)); +break ; + } +case IPPROTO_UDP : +case IPPROTO_UDPLITE : { +struct udphdr _udph; +const struct udphdr *uh; + + uh =skb_header_pointer (skb,skb_transport_offset (skb), +sizeof (_udph), &_udph); +if (!uh) +return -ENOMEM ; + +audit_log_format (ab," saddr=%pI4 daddr=%pI4 proto=%hhu sport=%hu dport=%hu" , + &ih->saddr, &ih->daddr, ih->protocol, +ntohs (uh->source),ntohs (uh->dest)); +break ; + } +case IPPROTO_SCTP : { +struct sctphdr _sctph; +const struct sctphdr *sh; + + sh =skb_header_pointer (skb,skb_transport_offset (skb), +sizeof (_sctph), &_sctph); +if (!sh) +return -ENOMEM ; + +audit_log_format (ab," saddr=%pI4 daddr=%pI4 proto=%hhu sport=%hu dport=%hu" , + &ih->saddr, &ih->daddr, ih->protocol, +ntohs (sh->source),ntohs (sh->dest)); +break ; + } +default : +audit_log_format (ab," saddr=%pI4 daddr=%pI4 proto=%hhu" , + &ih->saddr, &ih->daddr, ih->protocol); + } +break ; }case NFPROTO_IPV6 : {
@@ -2536,8 +2584,55 @@ int audit_log_nf_skb(struct audit_buffer *ab,ipv6_skip_exthdr (skb,skb_network_offset (skb) +sizeof (iph), &nexthdr, &frag_off); -audit_log_format (ab," saddr=%pI6c daddr=%pI6c proto=%hhu" , - &ih->saddr, &ih->daddr, nexthdr); +switch (nexthdr) { +case IPPROTO_TCP : { +struct tcphdr _tcph; +const struct tcphdr *th; + + th =skb_header_pointer (skb,skb_transport_offset (skb), +sizeof (_tcph), &_tcph); +if (!th) +return -ENOMEM ; + +audit_log_format (ab," saddr=%pI6c daddr=%pI6c proto=%hhu sport=%hu dport=%hu" , + &ih->saddr, &ih->daddr, nexthdr, +ntohs (th->source),ntohs (th->dest)); +break ; + } +case IPPROTO_UDP : +case IPPROTO_UDPLITE : { +struct udphdr _udph; +const struct udphdr *uh; + + uh =skb_header_pointer (skb,skb_transport_offset (skb), +sizeof (_udph), &_udph); +if (!uh) +return -ENOMEM ; + +audit_log_format (ab," saddr=%pI6c daddr=%pI6c proto=%hhu sport=%hu dport=%hu" , + &ih->saddr, &ih->daddr, nexthdr, +ntohs (uh->source),ntohs (uh->dest)); +break ; + } +case IPPROTO_SCTP : { +struct sctphdr _sctph; +const struct sctphdr *sh; + + sh =skb_header_pointer (skb,skb_transport_offset (skb), +sizeof (_sctph), &_sctph); +if (!sh) +return -ENOMEM ; + +audit_log_format (ab," saddr=%pI6c daddr=%pI6c proto=%hhu sport=%hu dport=%hu" , + &ih->saddr, &ih->daddr, nexthdr, +ntohs (sh->source),ntohs (sh->dest)); +break ; + } +default : +audit_log_format (ab," saddr=%pI6c daddr=%pI6c proto=%hhu" , + &ih->saddr, &ih->daddr, nexthdr); + } +break ; }default :
Signature · 1 line
2.51.1
Re: [PATCH v7 2/2] audit: include source and destination ports to NETFILTER_PKT
Quoted 18 lines · Ricardo Robaina
NETFILTER_PKTrecords show both source and destination addresses, in addition to the associated networking protocol. However, it lacks the ports information, which is often valuable for troubleshooting.This patch adds both source and destination port numbers, 'sport' and 'dport' respectively, to TCP, UDP, UDP-Lite and SCTP-related
NETFILTER_PKTrecords.$ TESTS="netfilter_pkt" make -e test &> /dev/null $ ausearch -i -ts recent |grep NETFILTER_PKT type=NETFILTER_PKT ... proto=icmp type=NETFILTER_PKT ... proto=ipv6-icmp type=NETFILTER_PKT ... proto=udp sport=46333 dport=42424 type=NETFILTER_PKT ... proto=udp sport=35953 dport=42424 type=NETFILTER_PKT ... proto=tcp sport=50314 dport=42424 type=NETFILTER_PKT ... proto=tcp sport=57346 dport=42424
Quoted 1 line
Paul Moore
maintainerQuoted 16 lines · Ricardo Robaina
Currently,
NETFILTER_PKTrecords lack source and destination port information, which is often valuable for troubleshooting. This patch series adds ports numbers, toNETFILTER_PKTrecords.The first patch refactors netfilter-related code, by moving duplicated code to
audit.c, by creatingaudit_log_nf_skb()helper function.
The second one, improves theNETFILTER_PKTrecords, by including source and destination ports for protocols of interest.Ricardo Robaina (2):
audit: addaudit_log_nf_skbhelper function
audit: include source and destination ports toNETFILTER_PKT
Quoted 5 lines
include/linux/audit.h | 8 ++ kernel/audit.c | 159 +++++++++++++++++++++++++++++++++++++++ net/netfilter/nft_log.c | 58 +------------- net/netfilter/xt_AUDIT.c | 58 +------------- 4 files changed, 169 insertions(+), 114 deletions(-)
Thanks Ricardo, both patches look good to me, I'm going to merge them into audit/dev-staging just to get some very basic testing, but if I can get an ACK from Florian on the patchset I'll go ahead and move the patches over to audit/dev (feeds into linux-next and the next merge window).
Signature · 1 line
paul-moore.com
Paul Moore
maintainerQuoted 23 lines · Paul Moore
Quoted 16 lines · Ricardo Robaina
Currently,
NETFILTER_PKTrecords lack source and destination port information, which is often valuable for troubleshooting. This patch series adds ports numbers, toNETFILTER_PKTrecords.The first patch refactors netfilter-related code, by moving duplicated code to
audit.c, by creatingaudit_log_nf_skb()helper function.
The second one, improves theNETFILTER_PKTrecords, by including source and destination ports for protocols of interest.Ricardo Robaina (2):
audit: addaudit_log_nf_skbhelper function
audit: include source and destination ports toNETFILTER_PKTQuoted 5 lines
include/linux/audit.h | 8 ++ kernel/audit.c | 159 +++++++++++++++++++++++++++++++++++++++ net/netfilter/nft_log.c | 58 +------------- net/netfilter/xt_AUDIT.c | 58 +------------- 4 files changed, 169 insertions(+), 114 deletions(-)
Quoted 5 lines
Thanks Ricardo, both patches look good to me, I'm going to merge them into audit/dev-staging just to get some very basic testing, but if I can get an ACK from Florian on the patchset I'll go ahead and move the patches over to audit/dev (feeds into linux-next and the next merge window).
I just moved these patches in audit/dev with Florian's ACK. Thanks everyone!
Signature · 1 line
paul-moore.com
Quoted 31 lines · Paul Moore
Quoted 23 lines · Paul Moore
Quoted 16 lines · Ricardo Robaina
Currently,
NETFILTER_PKTrecords lack source and destination port information, which is often valuable for troubleshooting. This patch series adds ports numbers, toNETFILTER_PKTrecords.The first patch refactors netfilter-related code, by moving duplicated code to
audit.c, by creatingaudit_log_nf_skb()helper function.
The second one, improves theNETFILTER_PKTrecords, by including source and destination ports for protocols of interest.Ricardo Robaina (2):
audit: addaudit_log_nf_skbhelper function
audit: include source and destination ports toNETFILTER_PKTQuoted 5 lines
include/linux/audit.h | 8 ++ kernel/audit.c | 159 +++++++++++++++++++++++++++++++++++++++ net/netfilter/nft_log.c | 58 +------------- net/netfilter/xt_AUDIT.c | 58 +------------- 4 files changed, 169 insertions(+), 114 deletions(-)Quoted 5 lines
Thanks Ricardo, both patches look good to me, I'm going to merge them into audit/dev-staging just to get some very basic testing, but if I can get an ACK from Florian on the patchset I'll go ahead and move the patches over to audit/dev (feeds into linux-next and the next merge window).
Quoted 5 lines
I just moved these patches in audit/dev with Florian's ACK. Thanks everyone!
--
paul-moore.com
I'm happy to hear it. Thanks, Paul and Florian!