Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2596499rdb; Fri, 22 Sep 2023 03:26:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGugGQr98ZbjnPiszB5PY6JnpJcz2ntbiBtIXZ21MLVGsrShIlRLOB9DbZzcJBViXQAiPNE X-Received: by 2002:a05:6a00:15d0:b0:68e:2822:fb36 with SMTP id o16-20020a056a0015d000b0068e2822fb36mr9974778pfu.8.1695378415201; Fri, 22 Sep 2023 03:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695378415; cv=none; d=google.com; s=arc-20160816; b=d+h9xlNXS265shNDAX+sbkt6tbhEmP6x/dQFsTobpNc0UhUff1ZUgr3iY6Rgzstd6I oVvvH9/9Zrco/nZqHi66jcvl/Pi07X12+jvyjB55BDhZLrbBUf0hlbvKASJRR/Mj24Pj 7xs0DhJuTtFcL+opzSEeVE9BSGV7alNb5dqSOyu3je0tKCBD4G5yY1H5q8dAubYHlVgX 4DvgAydDvG+RaYpAchkM4CKWL+ZdLelKyC5h+LYazQyA/nTDjkneuPbxkA5j5xCYrvdJ vCUsToQh+6vHvodGhWZBH9PB/M1aR9gCoaU4QqXSY3dCvKdNxK5mBDTMrNSrJKqxy6/3 YlJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8A7aWDQDyWb0spbHxAm9dcoBHYpW9Cn4QHodGNfDNCc=; fh=dumNNbCJCjvHrFPBOgtHY87pJHoJgAB5Wq5oWhKArCo=; b=zyjDzeyKj8k5amWPwLIFGqbLaLAR0NGh3kTFJTH++FeeF0vtBPNOFrnztd9nL2wS/j z5Jo6OUxp8gkQCQpLz3nkCRsfIdftaN9dKeajIIbJ3JjvSsHhgTGkYVl9JMZ+G2emQXl bM2IA4rQgY2hqG3s3tKWXqzN9Y1TVqvg9LLWQVVAwwLB/bgopXu4gIG/27vx2YgjD+6k XeLPInypUXZ4HeqJoZISyL2xfn6limWWZnWxA0+JYEcTDyOxZX24JuH9XdBqhA/J7Rz9 uj6lL+7S2DJAiyJRI3mxRGT0+NKFxyLuqGqEsrWDg4ugAoT0hVIo9bCqJbnXxm4Nw9Bv LpjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=NIh9AE6i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id cq12-20020a056a00330c00b0068a54cfcd74si3442096pfb.192.2023.09.22.03.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 03:26:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=NIh9AE6i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 8627683ADCA8; Thu, 21 Sep 2023 14:14:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232375AbjIUVOB (ORCPT + 99 others); Thu, 21 Sep 2023 17:14:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230479AbjIUVNb (ORCPT ); Thu, 21 Sep 2023 17:13:31 -0400 Received: from smtp-190b.mail.infomaniak.ch (smtp-190b.mail.infomaniak.ch [IPv6:2001:1600:3:17::190b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CC1712447 for ; Thu, 21 Sep 2023 10:06:53 -0700 (PDT) Received: from smtp-2-0001.mail.infomaniak.ch (unknown [10.5.36.108]) by smtp-2-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4RrlY738kszMpnsb; Thu, 21 Sep 2023 06:16:59 +0000 (UTC) Received: from unknown by smtp-2-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4RrlY62SQNzMppKT; Thu, 21 Sep 2023 08:16:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1695277019; bh=C96mByL5VMgKe+z3S4sdB6o2Dq3umyYV2RysHQLeFgI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NIh9AE6iGXfm/w7dRtI3eR/bv26/nMk6QUSrB46LLWPGRDS69Fz10CJeqMYOtM3Jf ptzdpk0XS+wZajN8f6q6NpzX9bYPyCWibReuzVDfHT/HDZAh7GkkTTYCTiZiNYxqj0 1xcDI7CD86C3lYgqB/e/ZiQ2kUmJEoNIcZ/oLGME= From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: Eric Paris , James Morris , Paul Moore , "Serge E . Hallyn" Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Ben Scarlato , =?UTF-8?q?G=C3=BCnther=20Noack?= , Jeff Xu , Jorge Lucangeli Obes , Konstantin Meskhidze , Shervin Oloumi , audit@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [RFC PATCH v1 1/7] lsm: Add audit_log_lsm_data() helper Date: Thu, 21 Sep 2023 08:16:35 +0200 Message-ID: <20230921061641.273654-2-mic@digikod.net> In-Reply-To: <20230921061641.273654-1-mic@digikod.net> References: <20230921061641.273654-1-mic@digikod.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Infomaniak-Routing: alpha X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:14:32 -0700 (PDT) Extract code from common_dump_audit_data() into the audit_log_lsm_data() helper. This helps reuse common LSM audit data while not abusing AUDIT_AVC records because of the common_lsm_audit() helper. Signed-off-by: Mickaël Salaün --- include/linux/lsm_audit.h | 2 ++ security/lsm_audit.c | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/include/linux/lsm_audit.h b/include/linux/lsm_audit.h index 97a8b21eb033..5f9a7ed0e7a5 100644 --- a/include/linux/lsm_audit.h +++ b/include/linux/lsm_audit.h @@ -122,6 +122,8 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb, int ipv6_skb_to_auditdata(struct sk_buff *skb, struct common_audit_data *ad, u8 *proto); +void audit_log_lsm_data(struct audit_buffer *ab, struct common_audit_data *a); + void common_lsm_audit(struct common_audit_data *a, void (*pre_audit)(struct audit_buffer *, void *), void (*post_audit)(struct audit_buffer *, void *)); diff --git a/security/lsm_audit.c b/security/lsm_audit.c index 849e832719e2..58f9b8bde22a 100644 --- a/security/lsm_audit.c +++ b/security/lsm_audit.c @@ -189,16 +189,12 @@ static inline void print_ipv4_addr(struct audit_buffer *ab, __be32 addr, } /** - * dump_common_audit_data - helper to dump common audit data + * audit_log_lsm_data - helper to log common LSM audit data * @ab : the audit buffer * @a : common audit data - * */ -static void dump_common_audit_data(struct audit_buffer *ab, - struct common_audit_data *a) +void audit_log_lsm_data(struct audit_buffer *ab, struct common_audit_data *a) { - char comm[sizeof(current->comm)]; - /* * To keep stack sizes in check force programmers to notice if they * start making this union too large! See struct lsm_network_audit @@ -206,9 +202,6 @@ static void dump_common_audit_data(struct audit_buffer *ab, */ BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2); - audit_log_format(ab, " pid=%d comm=", task_tgid_nr(current)); - audit_log_untrustedstring(ab, memcpy(comm, current->comm, sizeof(comm))); - switch (a->type) { case LSM_AUDIT_DATA_NONE: return; @@ -428,6 +421,21 @@ static void dump_common_audit_data(struct audit_buffer *ab, } /* switch (a->type) */ } +/** + * dump_common_audit_data - helper to dump common audit data + * @ab : the audit buffer + * @a : common audit data + */ +static void dump_common_audit_data(struct audit_buffer *ab, + struct common_audit_data *a) +{ + char comm[sizeof(current->comm)]; + + audit_log_format(ab, " pid=%d comm=", task_tgid_nr(current)); + audit_log_untrustedstring(ab, memcpy(comm, current->comm, sizeof(comm))); + audit_log_lsm_data(ab, a); +} + /** * common_lsm_audit - generic LSM auditing function * @a: auxiliary audit data -- 2.42.0