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 8A36DC433EF for ; Wed, 9 Feb 2022 22:29:48 +0000 (UTC) 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-517-fhOPee6YMH6kOdvUpElNIw-1; Wed, 09 Feb 2022 17:29:44 -0500 X-MC-Unique: fhOPee6YMH6kOdvUpElNIw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ACCB6363A4; Wed, 9 Feb 2022 22:29:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 169844E2DC; Wed, 9 Feb 2022 22:29:39 +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 016361809CB8; Wed, 9 Feb 2022 22:29:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 219MTZQM020315 for ; Wed, 9 Feb 2022 17:29:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id DBD56492CA3; Wed, 9 Feb 2022 22:29:35 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D7446492D1F for ; Wed, 9 Feb 2022 22:29:35 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BF0E88047D6 for ; Wed, 9 Feb 2022 22:29:35 +0000 (UTC) Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-518-6Od2oPz_OQqwAG-XkHx_5w-1; Wed, 09 Feb 2022 17:29:34 -0500 X-MC-Unique: 6Od2oPz_OQqwAG-XkHx_5w-1 Received: by mail-ej1-f42.google.com with SMTP id p24so11069611ejo.1 for ; Wed, 09 Feb 2022 14:29:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QwxGeIICnqHoY2j7nGhsMaxduU8evuxeVgZai3IhacA=; b=OviEPf0OFdjmWa1wNnvtxSErSfwX+I02DGtJOCNC+azF8UUOAuGmduz80wkId15JfI wNtlTPtZDrAcUIf1KiceZ6Yr+V+hKuirCKsN+eFsJeSNN9nIWYjecaZexNiV9qxCtocx SXkhzt6JBnoeGX0cQ3dudgXqRHfhNGhW6gDfW7N4te2kxRgUTJ+rovnu2lIHw3CRGlkD Zsm05iYcq4xCvRqHIbEAPdNCej1vrKZzMDAyrYaIh1PVee14i0J+ZTaHfwx29ze1364w H1qsCHgPZkKsTU1LsvxIjqrbBE0Fs2AKLPTcc1UMChr+WThGr/ACuK9A/CUQ4lBZ1BOt 0UAg== X-Gm-Message-State: AOAM531oPMapcJpdIvDyXFrgk7og6lZ0hrI63mfaQqu7Gv6eHuxjfg1l YvS4ouFFRWp1FJ0dQQXLJ8Yap5sv9gJSy6myh3pP X-Google-Smtp-Source: ABdhPJykZ3LPsq7/hz6HEeBOojoOK25gxY3dC3/fv7G6jhEj4Gog2tbmYXALr4PTsGzHEkdet8hpmJdSNw1E/6ycDqg= X-Received: by 2002:a17:907:d15:: with SMTP id gn21mr3552212ejc.701.1644445772885; Wed, 09 Feb 2022 14:29:32 -0800 (PST) MIME-Version: 1.0 References: <20220209214048.GF1708086@madcap2.tricolour.ca> In-Reply-To: <20220209214048.GF1708086@madcap2.tricolour.ca> From: Paul Moore Date: Wed, 9 Feb 2022 17:29:21 -0500 Message-ID: Subject: Re: [PATCH v4 2/3] audit: add support for the openat2 syscall To: Richard Guy Briggs X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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.79 on 10.5.11.13 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-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Wed, Feb 9, 2022 at 4:41 PM Richard Guy Briggs wrote: > On 2022-02-09 10:57, 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. > > Agreed. It would have been more awkward with the original order of the > patches. > > The syscalls_file test in the audit-testsuite should have caught this. > https://github.com/rgbriggs/audit-testsuite/commit/1c99021ae27ea23eccce2bb1861df4c9c665cd5b > The test provided does essentially the same thing. I would have thought so, but I've now run this multiple times on both affected and patched kernels but I don't see the page fault on my test system. Anyway, that test has now been merged with the audit-testsuite as well as some cleanup on top to test for the new OPENAT2 record when applicable. -- paul-moore.com -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit 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 155A1C433FE for ; Wed, 9 Feb 2022 22:30:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235806AbiBIWaN (ORCPT ); Wed, 9 Feb 2022 17:30:13 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:35866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236064AbiBIWaB (ORCPT ); Wed, 9 Feb 2022 17:30:01 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B7A1E01C8B5 for ; Wed, 9 Feb 2022 14:29:34 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id e7so6935098ejn.13 for ; Wed, 09 Feb 2022 14:29:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QwxGeIICnqHoY2j7nGhsMaxduU8evuxeVgZai3IhacA=; b=xZ/h7zej5j3WDnJltPH+HHCzgcCr9JfH+MMu9lY0KjxOVQ/+RU/qqu9tBwzalHdJAd T3C2RWDm7kbMtC81ogUlrbeAiGBC5f+z330S6lMDqnXvCPCzu4XmbM6/pRxQOk8ky/9c F2/RBMCoEsh4Ubuug8Hhy6u2sJi1OO7R+NMpKSoyhLEaHAQHZcUrTcFVy9konIUAbFQW W+LWGHaDVPKsTAy0t2um82593RIIu6JHxgPZopY9b3pOi63KKA7nu2GhDc8XJANg8VTE Bv4UvrtulBkXVJ4kriNO/O8EfJyCRZiSHFA1e9eSQA0uwewREbIu3Z1nHo/YNc1NnxnS 6K/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QwxGeIICnqHoY2j7nGhsMaxduU8evuxeVgZai3IhacA=; b=YPkDzB0iMVJmozkRrpZH9IbCOeQYZUcwW93Gi8AnIPeW3ODbOsPZiXZAf1Ys4nIfWk hkll9odp4pd/MNxbebowRJqTkF8B+GZkOYwTF92H5+Sxj+9lFczo2qP3rWzMehh+CkZK 3rW7xhsgEiFbguroy3M23OVGiTABdUTcgSykhHTYadRojJrYSHziV2TFAPDV58HIsSSm I6auF/q0/pQJkrIF5AXfOmFdNitN/ij8G5hkTyUg61WfRcRcggZSalFOW9VeCaqY4RVj XR3F6o2cJf9aE9TPk86/+Crl3Ax/lfh1oRO1841lXWgJah2ZIj0xKRrkHs6TGdg6f/+q /NkA== X-Gm-Message-State: AOAM530XLYIpE5Y7DUjMzx5IGomS+B+qvi4VqWbZrJDj4XtILk/HsGpv BfKCkO70NUC1JkEtStw7f+PKqfNSWVenf9IN5Qa8 X-Google-Smtp-Source: ABdhPJykZ3LPsq7/hz6HEeBOojoOK25gxY3dC3/fv7G6jhEj4Gog2tbmYXALr4PTsGzHEkdet8hpmJdSNw1E/6ycDqg= X-Received: by 2002:a17:907:d15:: with SMTP id gn21mr3552212ejc.701.1644445772885; Wed, 09 Feb 2022 14:29:32 -0800 (PST) MIME-Version: 1.0 References: <20220209214048.GF1708086@madcap2.tricolour.ca> In-Reply-To: <20220209214048.GF1708086@madcap2.tricolour.ca> From: Paul Moore Date: Wed, 9 Feb 2022 17:29:21 -0500 Message-ID: Subject: Re: [PATCH v4 2/3] audit: add support for the openat2 syscall To: Richard Guy Briggs Cc: Jeff Mahoney , Linux-Audit Mailing List , LKML , linux-fsdevel@vger.kernel.org, Eric Paris , Steve Grubb , Alexander Viro , Eric Paris , Tony Jones Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 9, 2022 at 4:41 PM Richard Guy Briggs wrote: > On 2022-02-09 10:57, 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. > > Agreed. It would have been more awkward with the original order of the > patches. > > The syscalls_file test in the audit-testsuite should have caught this. > https://github.com/rgbriggs/audit-testsuite/commit/1c99021ae27ea23eccce2bb1861df4c9c665cd5b > The test provided does essentially the same thing. I would have thought so, but I've now run this multiple times on both affected and patched kernels but I don't see the page fault on my test system. Anyway, that test has now been merged with the audit-testsuite as well as some cleanup on top to test for the new OPENAT2 record when applicable. -- paul-moore.com