Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp945873ybm; Wed, 27 May 2020 11:51:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJvqlCoCOpD4a9BEt79G2ho0w2yMiMDQc01/834CDtiHv+F1r54SMfryicsQcEAfULZIFq X-Received: by 2002:a05:6402:1cb6:: with SMTP id cz22mr24216612edb.86.1590605485781; Wed, 27 May 2020 11:51:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590605485; cv=none; d=google.com; s=arc-20160816; b=cyKDrWIW4mAEJXgzt+zlFVQKFom2SPH+QzHNaraJlmHbfkYogoPEIQLY6sSQftvMVm sN6LC7Loyij4W2NXzPwX5gA6mNsoflbaikzwYvxZJQbW6xD9CXc/j6Hnk4rA3urYdT5I L+ultGrm3K63E6evYGQvVkm4uSju+XgmaVCxkSeUxDzdSeMd2WHxSAciuvM7rZPUjXfA ELczz9oJe8/MvaQs6ql0L6I0fe+zMDfIeYpPZgnIiTKO2ImrPBlvr4KuuaQgM92jcgGY cwI90fwzxUHfFwwzwMhURcF6SmNxDj9aUd6lOh3ySWFNFxhuxpUYG3UewKMez9I/1Uoa 8FiA== 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=Fn+6b4qyDIsOgniKcST0/GkaHzrvrLEuKr2L+M9NLhk=; b=GW/ainUPZv9e1ORtfOyaikYKo0T0WexIFkPybadQmBToZ10o+WoRJj4/8JLc8THN1G G0MVsxtj+FsjBts/IgHFgC9o41/Sk0WFOiXbgzboPxIw2NDUAT5pnPuBNwoTwTp0oB1F sTLyqxfOTadhnNe5Hfl2h4HLdyrqW71jHZWEGMg1F/3en8bvCYwz4y6pZZ2ljNu3yjdA DhpR6CehA4/BWXeZHlTzbtF52428a0St7UTy5ZActyi3vPFpih8zJxYskMXULvZ20Rjp bNsasZfTX4Ap63o4fcUevAccr/ZuY6/ZnqLSblCCqrvf0SbcDUu+j7gE/WqbFednBE5h iEcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WRSA8dpG; 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 sd27si2590824ejb.65.2020.05.27.11.51.03; Wed, 27 May 2020 11:51:25 -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=WRSA8dpG; 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 S1730232AbgE0PZA (ORCPT + 98 others); Wed, 27 May 2020 11:25:00 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:31836 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730098AbgE0PZA (ORCPT ); Wed, 27 May 2020 11:25:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590593098; 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=Fn+6b4qyDIsOgniKcST0/GkaHzrvrLEuKr2L+M9NLhk=; b=WRSA8dpGxEjduOETVLuj3HuOc44i4ENaHFzaQrokAXMH+TLEyS/om/oMYrRBe95LcL+N4D P1xqA2pfCzV2LgwGz64RrMozOtDYguCMk63s4uFe7l8FqaPVp5CjugQSRzFath3CVikSS+ /1h8nnviGkMYY823qU2wwawoDpAlYdM= 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-255-s67B6LPtO_WIL_Sj8j60Bw-1; Wed, 27 May 2020 11:24:56 -0400 X-MC-Unique: s67B6LPtO_WIL_Sj8j60Bw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 12ED11855A0D; Wed, 27 May 2020 15:24:55 +0000 (UTC) Received: from madcap2.tricolour.ca (unknown [10.10.110.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 775C15C1B0; Wed, 27 May 2020 15:24:46 +0000 (UTC) Date: Wed, 27 May 2020 11:24:43 -0400 From: Richard Guy Briggs To: Florian Westphal Cc: Linux-Audit Mailing List , LKML , netfilter-devel@vger.kernel.org, Paul Moore , sgrubb@redhat.com, omosnace@redhat.com, twoerner@redhat.com, eparis@parisplace.org, tgraf@infradead.org Subject: Re: [PATCH ghak124 v1] audit: log nftables configuration change events Message-ID: <20200527152443.7axktc2im3zpvk37@madcap2.tricolour.ca> References: <20200527145317.GI2915@breakpoint.cc> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200527145317.GI2915@breakpoint.cc> User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-05-27 16:53, Florian Westphal wrote: > 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. > > I know little about audit records. Does this allow the user to figure > out that this record is created via nf_tables/netlink rather than xtables? No, which is why I added that note below. It shouldn't be hard to change but I took the easy way to program it and now that I reflect on it more, it sounds like it should be a basic requriement. > > For further information please see issue > > https://github.com/linux-audit/audit-kernel/issues/124 > > > > Signed-off-by: Richard Guy Briggs > > --- > > This is an RFC patch. > > Note: I have questions about the "entries" count. Is there a more > > appropriate or relevant item to report here? > > Note: It might make sense to differentiate in the op= field that this > > was a legacy call vs an nft call. At the moment, legacy calls overlap > > with nft table calls, which are similar calls. > > > > include/linux/audit.h | 7 +++++++ > > kernel/auditsc.c | 12 +++++++++--- > > net/netfilter/nf_tables_api.c | 14 ++++++++++++++ > > 3 files changed, 30 insertions(+), 3 deletions(-) > > > > diff --git a/include/linux/audit.h b/include/linux/audit.h > > index 3fcd9ee49734..b10f54103a82 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,12 @@ enum audit_nfcfgop { > > AUDIT_XT_OP_REGISTER, > > AUDIT_XT_OP_REPLACE, > > AUDIT_XT_OP_UNREGISTER, > > + AUDIT_XT_OP_CHAIN_REGISTER = NFT_MSG_NEWCHAIN, > > Hmm, this means AUDIT_XT_OP_CHAIN_REGISTER overlaps with the 4th > audit_nfcfgop value...? There was no 4th value, so the overlap is just the first three, which are all table operations that more or less line up. > > + AUDIT_XT_OP_CHAIN_NOOP = NFT_MSG_GETCHAIN, > > GETCHAIN can't appear in the commit path (its not changing anything). > Same for all other NFT_MSG_FOO that use ".call_rcu" action. Again, I was a bit lazy in selecting the actions, and the GET actions are of no interest since they don't change the configuration. > Futhermore, I wonder what is to be logged by audit. NEW and DEL of TABLEs, CHAINs and RULEs. > The fact that there was 'some change'? If so, its enough to log > the increment of the generation count during the commit phase. Well, we are only logging "some change", so is it necessary to log the generation count to show that? Is the generation count of specific interest? > (After that, kernel can't back down anymore, i.e. all errors are > caught/handled beforehand). I did think of recording all failed attempts too, but coding that would be more effort. It is worth doing if it is deemed important, particularly for permission issues (as opposed to resource limits or packet format errors. This would be more of interest to a security officer rather than a network technician, but the latter may find it useful for debugging. > If its 'any config change', then you also need to handle adds > or delete from sets/maps, since that may allow something that wasn't > allowed before, e.g. consider > > ip saddr @trused accept > > and then, later on, > nft add element ip filter @trusted { 10.0.0.0/8, 192.168.0.1 } > > This would not add a table, or chain, or set, but it does implicitly > alter the ruleset. Ah, ok, so yes, we would need that too. I see family and table in there, op is evident. Is there a useful value we can use in the "entries" field? > > + case NFT_MSG_DELRULE: > > + audit_log_nfcfg(trans->ctx.table->name, > > + trans->ctx.family, > > + atomic_read(&trans->ctx.table->chains_ht.ht.nelems), > > + trans->msg_type); > > + break; > > Is that record format expected to emit the current number of chains? I was aiming for a relevant value such as perhaps the new rule number or the rule number being deleted. > I'm not sure if that info is meaningful. Can you suggest something meaningful? This field may need to get different information for each operation. > Since table names can be anything in nf_tables (they have no special > properties anymore), the table name is interesting from a informational > pov, but not super interesting. I don't think we need to be able to completely reconstruct the tables/chains/rules from the information in the audit log, but be aware of who is changing what when. > This will also emit the same message/record multiple times, with only > difference being the msg_type. I'm not sure thats interesting. I do think it is interesting. > Consider a batch update that commits 100 new rules in chain x, > this would result in 100 audit_log_nfcfg() calls, each with the > same information. So rule number would be a useful differentiator here. > There are test cases in nftables.git, you could run them to see what > kind of audit events are generated and how redundant they might be. As a first pass, simply booting a test system and running the audit-testsuite has provided some useful fodder. Florian, thanks for your review and input. - 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