From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12228C32771 for ; Fri, 19 Aug 2022 21:43:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238956AbiHSVnG (ORCPT ); Fri, 19 Aug 2022 17:43:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234664AbiHSVnC (ORCPT ); Fri, 19 Aug 2022 17:43:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4381010DCD5 for ; Fri, 19 Aug 2022 14:43:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660945380; 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=TF8rNb8UgO6lfW4pRfX+5WK+hLe/xJvdy6+pJrx+mzo=; b=Eg4QeJa2Uinq9RKGhOZGKOIth06jpOYyrsnVqn9eitjqxUbUEPInsHRP2qL8JgWQ4abfeT E2eeylD1AvaAjAmI7K8obWnhN1KeRhpiN6nF3unhPraPYHg2GsBBtqEbcH35KhaICzNM/4 oOheyNDujAYc1tEdFq7bZKPq24UhtgM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-54-qTr8DUvZPf6knxIM81wOjw-1; Fri, 19 Aug 2022 17:42:57 -0400 X-MC-Unique: qTr8DUvZPf6knxIM81wOjw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E307B811E76; Fri, 19 Aug 2022 21:42:56 +0000 (UTC) Received: from madcap2.tricolour.ca (unknown [10.22.48.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 974FD492C3B; Fri, 19 Aug 2022 21:42:55 +0000 (UTC) Date: Fri, 19 Aug 2022 17:42:53 -0400 From: Richard Guy Briggs To: Steve Grubb Cc: Linux-Audit Mailing List , LKML , linux-fsdevel@vger.kernel.org, Paul Moore , Eric Paris , Jan Kara , Amir Goldstein Subject: Re: [PATCH v4 4/4] fanotify,audit: deliver fan_info as a hex-encoded string Message-ID: References: <2d8159cec4392029dabfc39b55ac5fbd0faa9fbd.1659996830.git.rgb@redhat.com> <4767361.31r3eYUQgx@x2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4767361.31r3eYUQgx@x2> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-08-16 09:37, Steve Grubb wrote: > Hello Richard, > > Although I have it working, I have some comments below that might improve > things. > > On Tuesday, August 9, 2022 1:22:55 PM EDT Richard Guy Briggs wrote: > > Currently the only type of fanotify info that is defined is an audit > > rule number, but convert it to hex encoding to future-proof the field. > > > > Sample record: > > type=FANOTIFY msg=audit(1659730979.839:284): resp=1 fan_type=0 > > fan_info=3F > > > > Suggested-by: Paul Moore > > Signed-off-by: Richard Guy Briggs > > --- > > kernel/auditsc.c | 28 +++++++++++++++++++++------- > > 1 file changed, 21 insertions(+), 7 deletions(-) > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > index f000fec52360..0f747015c577 100644 > > --- a/kernel/auditsc.c > > +++ b/kernel/auditsc.c > > @@ -2908,22 +2908,36 @@ void __audit_fanotify(u32 response, size_t len, > > char *buf) > > > > if (!(len && buf)) { > > audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY, > > - "resp=%u fan_type=0 fan_info=?", response); > > + "resp=%u fan_type=0 fan_info=3F", response); /* "?" */ > > return; > > } > > while (c >= sizeof(struct fanotify_response_info_header)) { > > + struct audit_context *ctx = audit_context(); > > + struct audit_buffer *ab; > > + > > friar = (struct fanotify_response_info_audit_rule *)buf; > > switch (friar->hdr.type) { > > case FAN_RESPONSE_INFO_AUDIT_RULE: > > if (friar->hdr.len < sizeof(*friar)) { > > - audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY, > > - "resp=%u fan_type=%u fan_info=(incomplete)", > > - response, friar->hdr.type); > > + ab = audit_log_start(ctx, GFP_KERNEL, AUDIT_FANOTIFY); > > + if (ab) { > > + audit_log_format(ab, "resp=%u fan_type=%u fan_info=", > > + response, friar->hdr.type); > > +#define INCOMPLETE "(incomplete)" > > + audit_log_n_hex(ab, INCOMPLETE, sizeof(INCOMPLETE)); > > + audit_log_end(ab); > > + } > > return; > > } > > - audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY, > > - "resp=%u fan_type=%u fan_info=%u", > > - response, friar->hdr.type, friar->audit_rule); > > + ab = audit_log_start(ctx, GFP_KERNEL, AUDIT_FANOTIFY); > > + if (ab) { > > + audit_log_format(ab, "resp=%u fan_type=%u fan_info=", > > + response, friar->hdr.type); > > + audit_log_n_hex(ab, (char *)&friar->audit_rule, > > + sizeof(friar->audit_rule)); > > One thing to point out, the structure has a member audit_rule. It is > probably better to call it rule_number. This is because it has nothing to > do with any actual audit rule. It is a rule number meant to be recorded by > the audit system. > > Also, that member is a __u32 type. Hex encoding that directly gives back a > __u32 when decoded - which is a bit unexpected since everything else is > strings. It would be better to convert the u32 to a base 10 string and then > hex encode that. A buffer of 12 bytes should be sufficient. Sure, these seem reasonable. > Thanks, > -Steve > > > + audit_log_end(ab); > > + > > + } > > } > > c -= friar->hdr.len; > > ib += friar->hdr.len; > > > > - 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86019C32773 for ; Fri, 19 Aug 2022 21:43:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660945385; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=jjp6aH345BrKsLWlNNqrDJWHCAY9bMPlP2fCe7BCJ9k=; b=NRuLJ0yAyn7psjY2hZOKI6zwSWnil+3unyses1l7JTTfAvcdPQH2+KngH86I2sCq5goq08 o2S1SC3QAcC5hDBvyZ4FVzddHykQFVLfVm4hb1M94rrTHCW0mqYtaEr3EeQ2/p2BEvvFeD OJu0MBgOC1CkkhZBwRd7BrCZ4sBBNUA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-216-10tfgtlbNnimlvgBNAMnJQ-1; Fri, 19 Aug 2022 17:43:01 -0400 X-MC-Unique: 10tfgtlbNnimlvgBNAMnJQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 934698037AE; Fri, 19 Aug 2022 21:42:59 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85B6040D2827; Fri, 19 Aug 2022 21:42:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 51F69194F841; Fri, 19 Aug 2022 21:42:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 21620194F4B3 for ; Fri, 19 Aug 2022 21:42:57 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E2E06492CA5; Fri, 19 Aug 2022 21:42:56 +0000 (UTC) Received: from madcap2.tricolour.ca (unknown [10.22.48.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 974FD492C3B; Fri, 19 Aug 2022 21:42:55 +0000 (UTC) Date: Fri, 19 Aug 2022 17:42:53 -0400 From: Richard Guy Briggs To: Steve Grubb Subject: Re: [PATCH v4 4/4] fanotify, audit: deliver fan_info as a hex-encoded string Message-ID: References: <2d8159cec4392029dabfc39b55ac5fbd0faa9fbd.1659996830.git.rgb@redhat.com> <4767361.31r3eYUQgx@x2> MIME-Version: 1.0 In-Reply-To: <4767361.31r3eYUQgx@x2> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-BeenThere: linux-audit@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Audit Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kara , Amir Goldstein , LKML , Linux-Audit Mailing List , linux-fsdevel@vger.kernel.org, Eric Paris Errors-To: linux-audit-bounces@redhat.com Sender: "Linux-audit" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On 2022-08-16 09:37, Steve Grubb wrote: > Hello Richard, > > Although I have it working, I have some comments below that might improve > things. > > On Tuesday, August 9, 2022 1:22:55 PM EDT Richard Guy Briggs wrote: > > Currently the only type of fanotify info that is defined is an audit > > rule number, but convert it to hex encoding to future-proof the field. > > > > Sample record: > > type=FANOTIFY msg=audit(1659730979.839:284): resp=1 fan_type=0 > > fan_info=3F > > > > Suggested-by: Paul Moore > > Signed-off-by: Richard Guy Briggs > > --- > > kernel/auditsc.c | 28 +++++++++++++++++++++------- > > 1 file changed, 21 insertions(+), 7 deletions(-) > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > index f000fec52360..0f747015c577 100644 > > --- a/kernel/auditsc.c > > +++ b/kernel/auditsc.c > > @@ -2908,22 +2908,36 @@ void __audit_fanotify(u32 response, size_t len, > > char *buf) > > > > if (!(len && buf)) { > > audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY, > > - "resp=%u fan_type=0 fan_info=?", response); > > + "resp=%u fan_type=0 fan_info=3F", response); /* "?" */ > > return; > > } > > while (c >= sizeof(struct fanotify_response_info_header)) { > > + struct audit_context *ctx = audit_context(); > > + struct audit_buffer *ab; > > + > > friar = (struct fanotify_response_info_audit_rule *)buf; > > switch (friar->hdr.type) { > > case FAN_RESPONSE_INFO_AUDIT_RULE: > > if (friar->hdr.len < sizeof(*friar)) { > > - audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY, > > - "resp=%u fan_type=%u fan_info=(incomplete)", > > - response, friar->hdr.type); > > + ab = audit_log_start(ctx, GFP_KERNEL, AUDIT_FANOTIFY); > > + if (ab) { > > + audit_log_format(ab, "resp=%u fan_type=%u fan_info=", > > + response, friar->hdr.type); > > +#define INCOMPLETE "(incomplete)" > > + audit_log_n_hex(ab, INCOMPLETE, sizeof(INCOMPLETE)); > > + audit_log_end(ab); > > + } > > return; > > } > > - audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY, > > - "resp=%u fan_type=%u fan_info=%u", > > - response, friar->hdr.type, friar->audit_rule); > > + ab = audit_log_start(ctx, GFP_KERNEL, AUDIT_FANOTIFY); > > + if (ab) { > > + audit_log_format(ab, "resp=%u fan_type=%u fan_info=", > > + response, friar->hdr.type); > > + audit_log_n_hex(ab, (char *)&friar->audit_rule, > > + sizeof(friar->audit_rule)); > > One thing to point out, the structure has a member audit_rule. It is > probably better to call it rule_number. This is because it has nothing to > do with any actual audit rule. It is a rule number meant to be recorded by > the audit system. > > Also, that member is a __u32 type. Hex encoding that directly gives back a > __u32 when decoded - which is a bit unexpected since everything else is > strings. It would be better to convert the u32 to a base 10 string and then > hex encode that. A buffer of 12 bytes should be sufficient. Sure, these seem reasonable. > Thanks, > -Steve > > > + audit_log_end(ab); > > + > > + } > > } > > c -= friar->hdr.len; > > ib += friar->hdr.len; > > > > - 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 -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit