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 17284C433EF for ; Wed, 9 Feb 2022 22:14:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235123AbiBIWOM (ORCPT ); Wed, 9 Feb 2022 17:14:12 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:35804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235072AbiBIWOA (ORCPT ); Wed, 9 Feb 2022 17:14:00 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 99F3EDF8E3F8 for ; Wed, 9 Feb 2022 14:14:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644444841; 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=BOTWBC0hOhE1ppC7pifFcqnv228X+SVXx6iZSOt6Bgk=; b=Rg4xtAXpLlqaL36gdqCH6MO/um88iO2noHOfHChkXIs0IppMWcLPfYB1ZWZ2MRzd8B5oSF +KPCvBcTSybx6cnNrFjCR60djSdV+1bK59AIf20joyevaE2uohBPAS4AhC/Qb5SiDw+GzM Sd6Bv5oHO39vUzzPqU6kr7lTgvgYmvk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-397-ulG4GofINo6KDHgWQtL00A-1; Wed, 09 Feb 2022 17:13:58 -0500 X-MC-Unique: ulG4GofINo6KDHgWQtL00A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EC95484E03F; Wed, 9 Feb 2022 22:13:56 +0000 (UTC) Received: from madcap2.tricolour.ca (unknown [10.22.48.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B4AF5DF37; Wed, 9 Feb 2022 22:13:54 +0000 (UTC) Date: Wed, 9 Feb 2022 17:13:52 -0500 From: Richard Guy Briggs To: Paul Moore Cc: Jeff Mahoney , Linux-Audit Mailing List , LKML , linux-fsdevel@vger.kernel.org, Eric Paris , Steve Grubb , Alexander Viro , Eric Paris , Tony Jones Subject: Re: [PATCH v4 2/3] audit: add support for the openat2 syscall Message-ID: <20220209221352.GG1708086@madcap2.tricolour.ca> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-02-09 16:18, Paul Moore wrote: > On Wed, Feb 9, 2022 at 10:57 AM Paul Moore wrote: > > On Tue, Feb 8, 2022 at 10:44 PM Jeff Mahoney wrote: > > > > > > Hi Richard - > > > > > > On 5/19/21 16:00, Richard Guy Briggs wrote: > > > > The openat2(2) syscall was added in kernel v5.6 with commit fddb5d430ad9 > > > > ("open: introduce openat2(2) syscall") > > > > > > > > Add the openat2(2) syscall to the audit syscall classifier. > > > > > > > > Link: https://github.com/linux-audit/audit-kernel/issues/67 > > > > Signed-off-by: Richard Guy Briggs > > > > Link: https://lore.kernel.org/r/f5f1a4d8699613f8c02ce762807228c841c2e26f.1621363275.git.rgb@redhat.com > > > > --- > > > > > > [...] > > > > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > > > index d775ea16505b..3f59ab209dfd 100644 > > > > --- a/kernel/auditsc.c > > > > +++ b/kernel/auditsc.c > > > > @@ -76,6 +76,7 @@ > > > > #include > > > > #include > > > > #include > > > > +#include > > > > > > > > #include "audit.h" > > > > > > > > @@ -196,6 +197,8 @@ static int audit_match_perm(struct audit_context *ctx, int mask) > > > > return ((mask & AUDIT_PERM_WRITE) && ctx->argv[0] == SYS_BIND); > > > > case AUDITSC_EXECVE: > > > > return mask & AUDIT_PERM_EXEC; > > > > + case AUDITSC_OPENAT2: > > > > + return mask & ACC_MODE((u32)((struct open_how *)ctx->argv[2])->flags); > > > > default: > > > > return 0; > > > > } > > > > > > ctx->argv[2] holds a userspace pointer and can't be dereferenced like this. > > > > > > I'm getting oopses, like so: > > > BUG: unable to handle page fault for address: 00007fff961bbe70 > > > > Thanks Jeff. > > > > Yes, this is obviously the wrong thing to being doing; I remember > > checking to make sure we placed the audit_openat2_how() hook after the > > open_how was copied from userspace, but I missed the argv dereference > > in the syscall exit path when reviewing the code. > > > > Richard, as we are already copying the open_how info into > > audit_context::openat2 safely, the obvious fix is to convert > > audit_match_perm() to use the previously copied value instead of argv. > > If you can't submit a patch for this today please let me know. > > I haven't heard anything from Richard so I put together a patch which > should fix the problem (link below). It's currently untested, but > I've got a kernel building now with the patch ... Well, the day wasn't over yet... I've compiled and tested it. > https://lore.kernel.org/linux-audit/164444111699.153511.15656610495968926251.stgit@olly/T/#u > > -- > paul-moore.com > - 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.129.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 B885CC433F5 for ; Wed, 9 Feb 2022 22:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644444850; 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=B42yNI93oVQVC6W7qaD2rJ9oXZQDLnWG2eK0Q6EZJek=; b=HNhsWBYA7sSO1k3v1F6QtCMFxscOsuzeRrh0gIuiB8s4px/b7bRlANrE6TKcZNG1zUvYP8 zcwoRq79W1mfq1h3AzHZewQ2q/vlhIAVrh6SN4tMojCsOfFYdqQjk2BpZVvrnG+9BoJu29 oPopeeOt0N1LPOpH8XqJYqBuek4XQzY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-583-kkv4JOHiNEG5_JksJoIHgA-1; Wed, 09 Feb 2022 17:14:07 -0500 X-MC-Unique: kkv4JOHiNEG5_JksJoIHgA-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 5944D14756; Wed, 9 Feb 2022 22:14:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E4B751037F4B; Wed, 9 Feb 2022 22:14:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 339444BB7C; Wed, 9 Feb 2022 22:14:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 219MDu67016173 for ; Wed, 9 Feb 2022 17:13:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id CBA6945308; Wed, 9 Feb 2022 22:13:56 +0000 (UTC) Received: from madcap2.tricolour.ca (unknown [10.22.48.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B4AF5DF37; Wed, 9 Feb 2022 22:13:54 +0000 (UTC) Date: Wed, 9 Feb 2022 17:13:52 -0500 From: Richard Guy Briggs To: Paul Moore Subject: Re: [PATCH v4 2/3] audit: add support for the openat2 syscall Message-ID: <20220209221352.GG1708086@madcap2.tricolour.ca> References: MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: linux-audit@redhat.com Cc: Tony Jones , Jeff Mahoney , LKML , Eric Paris , Linux-Audit Mailing List , Alexander Viro , linux-fsdevel@vger.kernel.org, Eric Paris X-BeenThere: linux-audit@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Linux Audit Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=linux-audit-bounces@redhat.com 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-02-09 16:18, Paul Moore wrote: > On Wed, Feb 9, 2022 at 10:57 AM Paul Moore wrote: > > On Tue, Feb 8, 2022 at 10:44 PM Jeff Mahoney wrote: > > > > > > Hi Richard - > > > > > > On 5/19/21 16:00, Richard Guy Briggs wrote: > > > > The openat2(2) syscall was added in kernel v5.6 with commit fddb5d430ad9 > > > > ("open: introduce openat2(2) syscall") > > > > > > > > Add the openat2(2) syscall to the audit syscall classifier. > > > > > > > > Link: https://github.com/linux-audit/audit-kernel/issues/67 > > > > Signed-off-by: Richard Guy Briggs > > > > Link: https://lore.kernel.org/r/f5f1a4d8699613f8c02ce762807228c841c2e26f.1621363275.git.rgb@redhat.com > > > > --- > > > > > > [...] > > > > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > > > index d775ea16505b..3f59ab209dfd 100644 > > > > --- a/kernel/auditsc.c > > > > +++ b/kernel/auditsc.c > > > > @@ -76,6 +76,7 @@ > > > > #include > > > > #include > > > > #include > > > > +#include > > > > > > > > #include "audit.h" > > > > > > > > @@ -196,6 +197,8 @@ static int audit_match_perm(struct audit_context *ctx, int mask) > > > > return ((mask & AUDIT_PERM_WRITE) && ctx->argv[0] == SYS_BIND); > > > > case AUDITSC_EXECVE: > > > > return mask & AUDIT_PERM_EXEC; > > > > + case AUDITSC_OPENAT2: > > > > + return mask & ACC_MODE((u32)((struct open_how *)ctx->argv[2])->flags); > > > > default: > > > > return 0; > > > > } > > > > > > ctx->argv[2] holds a userspace pointer and can't be dereferenced like this. > > > > > > I'm getting oopses, like so: > > > BUG: unable to handle page fault for address: 00007fff961bbe70 > > > > Thanks Jeff. > > > > Yes, this is obviously the wrong thing to being doing; I remember > > checking to make sure we placed the audit_openat2_how() hook after the > > open_how was copied from userspace, but I missed the argv dereference > > in the syscall exit path when reviewing the code. > > > > Richard, as we are already copying the open_how info into > > audit_context::openat2 safely, the obvious fix is to convert > > audit_match_perm() to use the previously copied value instead of argv. > > If you can't submit a patch for this today please let me know. > > I haven't heard anything from Richard so I put together a patch which > should fix the problem (link below). It's currently untested, but > I've got a kernel building now with the patch ... Well, the day wasn't over yet... I've compiled and tested it. > https://lore.kernel.org/linux-audit/164444111699.153511.15656610495968926251.stgit@olly/T/#u > > -- > paul-moore.com > - 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