Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp544016ybt; Wed, 24 Jun 2020 05:39:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwr4PY6wCPWTII/toDc5nREG+6aDn7xgpoEkWd4QBL88f9yNhAe/6py59tTBEzIgR0S07AO X-Received: by 2002:a17:906:8688:: with SMTP id g8mr14663515ejx.505.1593002353289; Wed, 24 Jun 2020 05:39:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593002353; cv=none; d=google.com; s=arc-20160816; b=lJq/KosFYPLoayS4r17QoY/u7JJ2l84WxahXGK16LnKUJwPntHKRV50ok+AUPi2P55 OgvJosYhlAQeAioDL8qiBnXdouv3i+ocUEqMhlUcfDsL5Q3Omxl2QbctkBeM2bWXvjwh DaSrotG+QCBrXhwCTsVEO+ctpgL2QRh1ITDEv20lCDrzEnRZX1P5xxC8r29IG8CWMB0Y kClgbaggl3FHpdaIsGsk1bNw0ApDloH0h56/EOB4DPYWN0j2ExMl1TwA3YgQe3S8lQaP 7Y/nfTcrBd5tfXqNuqTZ5EUyXWlyKG9zxdZX4A9mCYLa2U6uz5aeTG7/NvT2pMWTe1CR 5GeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=9ew0dkmE9sZPBv3Fo0zDcKheH0XoZZSOf+61sV6N3AQ=; b=HN/+7vvOMx051V2s5CYOrFcqAiMb7K4nBHKPum0f+ieiqMu9eHb12QWS4bdA8FftTT enSl68sboaYZizHvLhaHTLGw3wXMMFtOJcmD84N9BJz8+RA3MuWL6wCn5q9jQX+a5KRW a1F175/E57OHX8nMiOSafEGS5pL9M6uP9jWVEJGGHDIkyvVJlULZKIaNTLUNy0LA6VJ7 dshwndHm4gjg8dzXKH9XoyhBKHmDyOS/KO25Uy29Lr6ys8tVldFziuAmsMbdEQZerCSH 4TVsprcGishTZXdEUWyEfYCQ5kOp1/zNEzeElnpatAuI1gbCO62dB7oF8HJ1maiw/2h5 AFcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CygQ1MLj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b8si7163264edz.89.2020.06.24.05.38.49; Wed, 24 Jun 2020 05:39:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CygQ1MLj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403953AbgFXMfP (ORCPT + 99 others); Wed, 24 Jun 2020 08:35:15 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:53551 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2403898AbgFXMen (ORCPT ); Wed, 24 Jun 2020 08:34:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593002080; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=9ew0dkmE9sZPBv3Fo0zDcKheH0XoZZSOf+61sV6N3AQ=; b=CygQ1MLjESSOFnpaJl5hbUGJMJx8xR2T9Axlt2LBIn0B6WHspa9uF2zlu5SnOfA6+JqhpX y81REAlSbIE0dUqhrPnFaRLn43Z5BVSfXo98IVNJjworOJULye20v9wrswbEiP1AHczkSr cRy+enZ57i9Zb9BUBbyZpJCDV4XmOhw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-116-JT-F7A01NDWae3BwtJKTow-1; Wed, 24 Jun 2020 08:34:36 -0400 X-MC-Unique: JT-F7A01NDWae3BwtJKTow-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EFE77464; Wed, 24 Jun 2020 12:34:34 +0000 (UTC) Received: from madcap2.tricolour.ca (unknown [10.10.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4C37D100EBB8; Wed, 24 Jun 2020 12:34:26 +0000 (UTC) Date: Wed, 24 Jun 2020 08:34:23 -0400 From: Richard Guy Briggs To: Pablo Neira Ayuso Cc: Linux-Audit Mailing List , LKML , netfilter-devel@vger.kernel.org, Paul Moore , sgrubb@redhat.com, omosnace@redhat.com, fw@strlen.de, twoerner@redhat.com, eparis@parisplace.org, tgraf@infradead.org Subject: Re: [PATCH ghak124 v3] audit: log nftables configuration change events Message-ID: <20200624123423.r2gypsdii6xgiywy@madcap2.tricolour.ca> References: <20200624100346.GA11986@salvia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200624100346.GA11986@salvia> User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-06-24 12:03, Pablo Neira Ayuso wrote: > On Thu, Jun 04, 2020 at 09:20:49AM -0400, Richard Guy Briggs wrote: > > iptables, ip6tables, arptables and ebtables table registration, > > replacement and unregistration configuration events are logged for the > > native (legacy) iptables setsockopt api, but not for the > > nftables netlink api which is used by the nft-variant of iptables in > > addition to nftables itself. > > > > Add calls to log the configuration actions in the nftables netlink api. > > > > This uses the same NETFILTER_CFG record format but overloads the table > > field. > > > > type=NETFILTER_CFG msg=audit(2020-05-28 17:46:41.878:162) : table=?:0;?:0 family=unspecified entries=2 op=nft_register_gen pid=396 subj=system_u:system_r:firewalld_t:s0 comm=firewalld > > ... > > type=NETFILTER_CFG msg=audit(2020-05-28 17:46:41.878:162) : table=firewalld:1;?:0 family=inet entries=0 op=nft_register_table pid=396 subj=system_u:system_r:firewalld_t:s0 comm=firewalld > > ... > > type=NETFILTER_CFG msg=audit(2020-05-28 17:46:41.911:163) : table=firewalld:1;filter_FORWARD:85 family=inet entries=8 op=nft_register_chain pid=396 subj=system_u:system_r:firewalld_t:s0 comm=firewalld > > ... > > type=NETFILTER_CFG msg=audit(2020-05-28 17:46:41.911:163) : table=firewalld:1;filter_FORWARD:85 family=inet entries=101 op=nft_register_rule pid=396 subj=system_u:system_r:firewalld_t:s0 comm=firewalld > > ... > > type=NETFILTER_CFG msg=audit(2020-05-28 17:46:41.911:163) : table=firewalld:1;__set0:87 family=inet entries=87 op=nft_register_setelem pid=396 subj=system_u:system_r:firewalld_t:s0 comm=firewalld > > ... > > type=NETFILTER_CFG msg=audit(2020-05-28 17:46:41.911:163) : table=firewalld:1;__set0:87 family=inet entries=0 op=nft_register_set pid=396 subj=system_u:system_r:firewalld_t:s0 comm=firewalld > > > > For further information please see issue > > https://github.com/linux-audit/audit-kernel/issues/124 > > > > Signed-off-by: Richard Guy Briggs > > --- > > Changelog: > > v3: > > - inline message type rather than table > > > > v2: > > - differentiate between xtables and nftables > > - add set, setelem, obj, flowtable, gen > > - use nentries field as appropriate per type > > - overload the "tables" field with table handle and chain/set/flowtable > > > > include/linux/audit.h | 18 ++++++++ > > kernel/auditsc.c | 24 ++++++++-- > > net/netfilter/nf_tables_api.c | 103 ++++++++++++++++++++++++++++++++++++++++++ > > 3 files changed, 142 insertions(+), 3 deletions(-) > > > > diff --git a/include/linux/audit.h b/include/linux/audit.h > > index 3fcd9ee49734..604ede630580 100644 > > --- a/include/linux/audit.h > > +++ b/include/linux/audit.h > > @@ -12,6 +12,7 @@ > > #include > > #include > > #include > > +#include > > > > #define AUDIT_INO_UNSET ((unsigned long)-1) > > #define AUDIT_DEV_UNSET ((dev_t)-1) > > @@ -98,6 +99,23 @@ enum audit_nfcfgop { > > AUDIT_XT_OP_REGISTER, > > AUDIT_XT_OP_REPLACE, > > AUDIT_XT_OP_UNREGISTER, > > + AUDIT_NFT_OP_TABLE_REGISTER, > > + AUDIT_NFT_OP_TABLE_UNREGISTER, > > + AUDIT_NFT_OP_CHAIN_REGISTER, > > + AUDIT_NFT_OP_CHAIN_UNREGISTER, > > + AUDIT_NFT_OP_RULE_REGISTER, > > + AUDIT_NFT_OP_RULE_UNREGISTER, > > + AUDIT_NFT_OP_SET_REGISTER, > > + AUDIT_NFT_OP_SET_UNREGISTER, > > + AUDIT_NFT_OP_SETELEM_REGISTER, > > + AUDIT_NFT_OP_SETELEM_UNREGISTER, > > + AUDIT_NFT_OP_GEN_REGISTER, > > + AUDIT_NFT_OP_OBJ_REGISTER, > > + AUDIT_NFT_OP_OBJ_UNREGISTER, > > + AUDIT_NFT_OP_OBJ_RESET, > > + AUDIT_NFT_OP_FLOWTABLE_REGISTER, > > + AUDIT_NFT_OP_FLOWTABLE_UNREGISTER, > > + AUDIT_NFT_OP_INVALID, > > }; > > > > extern int is_audit_feature_set(int which); > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > index 468a23390457..3a9100e95fda 100644 > > --- a/kernel/auditsc.c > > +++ b/kernel/auditsc.c > > @@ -75,6 +75,7 @@ > > #include > > #include > > #include > > +#include > > > > #include "audit.h" > > > > @@ -136,9 +137,26 @@ struct audit_nfcfgop_tab { > > }; > > > > static const struct audit_nfcfgop_tab audit_nfcfgs[] = { > > - { AUDIT_XT_OP_REGISTER, "register" }, > > - { AUDIT_XT_OP_REPLACE, "replace" }, > > - { AUDIT_XT_OP_UNREGISTER, "unregister" }, > > + { AUDIT_XT_OP_REGISTER, "xt_register" }, > > + { AUDIT_XT_OP_REPLACE, "xt_replace" }, > > + { AUDIT_XT_OP_UNREGISTER, "xt_unregister" }, > > + { AUDIT_NFT_OP_TABLE_REGISTER, "nft_register_table" }, > > + { AUDIT_NFT_OP_TABLE_UNREGISTER, "nft_unregister_table" }, > > + { AUDIT_NFT_OP_CHAIN_REGISTER, "nft_register_chain" }, > > + { AUDIT_NFT_OP_CHAIN_UNREGISTER, "nft_unregister_chain" }, > > + { AUDIT_NFT_OP_RULE_REGISTER, "nft_register_rule" }, > > + { AUDIT_NFT_OP_RULE_UNREGISTER, "nft_unregister_rule" }, > > + { AUDIT_NFT_OP_SET_REGISTER, "nft_register_set" }, > > + { AUDIT_NFT_OP_SET_UNREGISTER, "nft_unregister_set" }, > > + { AUDIT_NFT_OP_SETELEM_REGISTER, "nft_register_setelem" }, > > + { AUDIT_NFT_OP_SETELEM_UNREGISTER, "nft_unregister_setelem" }, > > + { AUDIT_NFT_OP_GEN_REGISTER, "nft_register_gen" }, > > + { AUDIT_NFT_OP_OBJ_REGISTER, "nft_register_obj" }, > > + { AUDIT_NFT_OP_OBJ_UNREGISTER, "nft_unregister_obj" }, > > + { AUDIT_NFT_OP_OBJ_RESET, "nft_reset_obj" }, > > + { AUDIT_NFT_OP_FLOWTABLE_REGISTER, "nft_register_flowtable" }, > > + { AUDIT_NFT_OP_FLOWTABLE_UNREGISTER, "nft_unregister_flowtable" }, > > + { AUDIT_NFT_OP_INVALID, "nft_invalid" }, > > }; > > > > static int audit_match_perm(struct audit_context *ctx, int mask) > > diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c > > index 3558e76e2733..b9e7440cc87d 100644 > > --- a/net/netfilter/nf_tables_api.c > > +++ b/net/netfilter/nf_tables_api.c > > @@ -12,6 +12,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -693,6 +694,16 @@ static void nf_tables_table_notify(const struct nft_ctx *ctx, int event) > > { > > struct sk_buff *skb; > > int err; > > + char *buf = kasprintf(GFP_KERNEL, "%s:%llu;?:0", > > + ctx->table->name, ctx->table->handle); > > + > > + audit_log_nfcfg(buf, > > + ctx->family, > > + ctx->table->use, > > + event == NFT_MSG_NEWTABLE ? > > + AUDIT_NFT_OP_TABLE_REGISTER : > > + AUDIT_NFT_OP_TABLE_UNREGISTER); > > + kfree(buf); > > As a follow up: Would you wrap this code into a function? > > nft_table_audit() > > Same thing for other pieces of code below. If I'm guessing right, you are asking for a supplementary follow-up cleanup patch to this one (or are you nacking this patch)? Also, I gather you would like to see the kasprintf and kfree hidden in nft_table_audit(), handing this function at least 8 parameters? This sounds pretty messy given the format of the table field. > Thanks. - RGB -- Richard Guy Briggs 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