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 X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDD22C04FF3 for ; Sat, 22 May 2021 00:23:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B19D861152 for ; Sat, 22 May 2021 00:23:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230265AbhEVAZO (ORCPT ); Fri, 21 May 2021 20:25:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230268AbhEVAZF (ORCPT ); Fri, 21 May 2021 20:25:05 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B000C061357; Fri, 21 May 2021 17:22:48 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id a4so22625861wrr.2; Fri, 21 May 2021 17:22:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:references:from:subject:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=gyzVl8OaygknyiQ92wI9NqUUnUzVTtSj7pAG6enmPyo=; b=h9+5dlZVZNErqj/VlQoU6FFADlMgqz1rcXrf+FRcGqRuWu6/+GSmFfJGzQ6UjZPasQ EI6OuFqiQZQgzqfNxjJJgx9yfPugxzr+7ry7XjEXAbqF6Nyt+oaUmo+pvs6sA7HNk3le v+j+HoV7anBhT0OQjfS1we4WTMQq6BnhMNAI3o6DZCNCS9uiYHUAhLYIkJroa2TsH1U5 a1NB/CPiMyK/jA/IW1lsqCHSGOfzD0zibwaictf/lHaPY64rUPpK4kfZTMVIFzXlFra1 JKxjgsoecROHhoTykwAdiHkJmmVd62kS24ZeLbepeB/r75wypmXI5iVKgliCKPIz5RWC NCxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=gyzVl8OaygknyiQ92wI9NqUUnUzVTtSj7pAG6enmPyo=; b=ahQJiUHRlDNSEUKiILnJvFip3Q1S2c2GYqVQtJh89eKGIF7f1IeInzwEqRoEP8mhjj iz0Q14V8BmeTvIjFQn7TfwtvWYASq86hIg+IvPnG/+Sl86yjtnxS5T2jwcr4GuHurpqJ 3W2QAHFfLtpG9HVsnspIPMrbxRRab6MvOQh9sdFNeTxFPhxcSQ7BxmkhPvwF2jUftkUJ fZCcHmycTgfw0fmk9RYS9VcVOLlql0+Aur/xM16ZJSYM7boxUJk6kDNwwalZ/dy4kTeq yBc2w82DYMG1TsPRqrdyb2AKr0f08X89dCnWxBYCDCdBo1J70Wx/tqUA7lZmVK/YXCxy 5FaQ== X-Gm-Message-State: AOAM530xMyuQRO0KBo/LFIiKXl4DNght7sWAcUBIHeFULlRgTlx/7/5R 26vGJ1kZ7PG9toDPRkXsqHM= X-Google-Smtp-Source: ABdhPJxaXbjmt4xOHYAJ+WucB6UB7YwedwnqpF4Vvt+zZvoVOd6AMuq4GF3A5xjCoLHvNNbU9LIObw== X-Received: by 2002:adf:a519:: with SMTP id i25mr11858230wrb.312.1621642966773; Fri, 21 May 2021 17:22:46 -0700 (PDT) Received: from [192.168.8.197] ([85.255.236.182]) by smtp.gmail.com with ESMTPSA id s199sm1032010wme.43.2021.05.21.17.22.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 May 2021 17:22:46 -0700 (PDT) To: Paul Moore , linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-audit@redhat.com, io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org, Kumar Kartikeya Dwivedi , Jens Axboe , Alexander Viro References: <162163367115.8379.8459012634106035341.stgit@sifl> <162163379461.8379.9691291608621179559.stgit@sifl> From: Pavel Begunkov Subject: Re: [RFC PATCH 2/9] audit,io_uring,io-wq: add some basic audit support to io_uring Message-ID: Date: Sat, 22 May 2021 01:22:39 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <162163379461.8379.9691291608621179559.stgit@sifl> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On 5/21/21 10:49 PM, Paul Moore wrote: > WARNING - This is a work in progress and should not be merged > anywhere important. It is almost surely not complete, and while it > probably compiles it likely hasn't been booted and will do terrible > things. You have been warned. > > This patch adds basic auditing to io_uring operations, regardless of > their context. This is accomplished by allocating audit_context > structures for the io-wq worker and io_uring SQPOLL kernel threads > as well as explicitly auditing the io_uring operations in > io_issue_sqe(). The io_uring operations are audited using a new > AUDIT_URINGOP record, an example is shown below: > > % > > Thanks to Richard Guy Briggs for review and feedback. > > Signed-off-by: Paul Moore > --- [...] > diff --git a/fs/io_uring.c b/fs/io_uring.c > index e481ac8a757a..e9941d1ad8fd 100644 > --- a/fs/io_uring.c > +++ b/fs/io_uring.c > @@ -78,6 +78,7 @@ > #include > #include > #include > +#include > > #define CREATE_TRACE_POINTS > #include > @@ -6105,6 +6106,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) > if (req->work.creds && req->work.creds != current_cred()) > creds = override_creds(req->work.creds); > > + if (req->opcode < IORING_OP_LAST) always true at this point > + audit_uring_entry(req->opcode); So, it adds two if's with memory loads (i.e. current->audit_context) per request in one of the hottest functions here... No way, nack Maybe, if it's dynamically compiled into like kprobes if it's _really_ used. > + > switch (req->opcode) { > case IORING_OP_NOP: > ret = io_nop(req, issue_flags); > @@ -6211,6 +6215,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) > break; > } > > + if (req->opcode < IORING_OP_LAST) > + audit_uring_exit(!ret, ret); > + > if (creds) > revert_creds(creds); -- Pavel Begunkov 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 X-Spam-Level: X-Spam-Status: No, score=-12.2 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB687C4707F for ; Sun, 23 May 2021 01:54:09 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 22CEB6115C for ; Sun, 23 May 2021 01:54:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22CEB6115C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=linux-audit-bounces@redhat.com 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-190-9WE2Up6kO5-70aeUSzEjKg-1; Sat, 22 May 2021 21:54:06 -0400 X-MC-Unique: 9WE2Up6kO5-70aeUSzEjKg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7EF3D800C60; Sun, 23 May 2021 01:54:03 +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 E58232C14A; Sun, 23 May 2021 01:54:02 +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 82ED418095C2; Sun, 23 May 2021 01:54:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14M0MqsJ001688 for ; Fri, 21 May 2021 20:22:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id B279B11F4D0; Sat, 22 May 2021 00:22:52 +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 AD111121610 for ; Sat, 22 May 2021 00:22:50 +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 6089683395B for ; Sat, 22 May 2021 00:22:50 +0000 (UTC) Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-154-b0iSz8-0M-2jHqfvV2rsLw-1; Fri, 21 May 2021 20:22:48 -0400 X-MC-Unique: b0iSz8-0M-2jHqfvV2rsLw-1 Received: by mail-wr1-f53.google.com with SMTP id r12so22577713wrp.1 for ; Fri, 21 May 2021 17:22:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=gyzVl8OaygknyiQ92wI9NqUUnUzVTtSj7pAG6enmPyo=; b=W1h/dQmClt+pSs7dcqUejHs97o+t19F0UWSWs4WkssCkTtMI8TJN3lAzKo73LNKD8N SK525w5R/uUlXOoztlMYIkLygHw8PpqlDjONAMG6P/MyVquwGW3GDX2FOJ9ZGs4aBxoC lOpF+Ns/yl3IpOw/91Dny3SMPprVtBAgcRdOOQ0YMKoS4WAkdGSEyWvTpQ7LeBF1xA/k V1qkFsRtwx0RPI2ClX+fXQxP00gzOyMH01I52GyS593vAKlmsPaG9i06qA87CI8Zif7L YOAPaajrDzfeIZ6ThAXuRie0h624iqtpLQbi2Y80kTtZtTkhaZElRojkxd9d0PRBhE8a BYcQ== X-Gm-Message-State: AOAM531u8GCpthvt17NQq/K+fGK0n3O+edGETJKoeevemw9pC36b9IAQ Im/VKh0QSyUudk88Nttqa9o= X-Google-Smtp-Source: ABdhPJxaXbjmt4xOHYAJ+WucB6UB7YwedwnqpF4Vvt+zZvoVOd6AMuq4GF3A5xjCoLHvNNbU9LIObw== X-Received: by 2002:adf:a519:: with SMTP id i25mr11858230wrb.312.1621642966773; Fri, 21 May 2021 17:22:46 -0700 (PDT) Received: from [192.168.8.197] ([85.255.236.182]) by smtp.gmail.com with ESMTPSA id s199sm1032010wme.43.2021.05.21.17.22.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 May 2021 17:22:46 -0700 (PDT) To: Paul Moore , linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-audit@redhat.com, io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org, Kumar Kartikeya Dwivedi , Jens Axboe , Alexander Viro References: <162163367115.8379.8459012634106035341.stgit@sifl> <162163379461.8379.9691291608621179559.stgit@sifl> From: Pavel Begunkov Subject: Re: [RFC PATCH 2/9] audit,io_uring,io-wq: add some basic audit support to io_uring Message-ID: Date: Sat, 22 May 2021 01:22:39 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <162163379461.8379.9691291608621179559.stgit@sifl> 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.79 on 10.11.54.5 X-loop: linux-audit@redhat.com X-Mailman-Approved-At: Sat, 22 May 2021 21:53:58 -0400 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.11 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-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On 5/21/21 10:49 PM, Paul Moore wrote: > WARNING - This is a work in progress and should not be merged > anywhere important. It is almost surely not complete, and while it > probably compiles it likely hasn't been booted and will do terrible > things. You have been warned. > > This patch adds basic auditing to io_uring operations, regardless of > their context. This is accomplished by allocating audit_context > structures for the io-wq worker and io_uring SQPOLL kernel threads > as well as explicitly auditing the io_uring operations in > io_issue_sqe(). The io_uring operations are audited using a new > AUDIT_URINGOP record, an example is shown below: > > % > > Thanks to Richard Guy Briggs for review and feedback. > > Signed-off-by: Paul Moore > --- [...] > diff --git a/fs/io_uring.c b/fs/io_uring.c > index e481ac8a757a..e9941d1ad8fd 100644 > --- a/fs/io_uring.c > +++ b/fs/io_uring.c > @@ -78,6 +78,7 @@ > #include > #include > #include > +#include > > #define CREATE_TRACE_POINTS > #include > @@ -6105,6 +6106,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) > if (req->work.creds && req->work.creds != current_cred()) > creds = override_creds(req->work.creds); > > + if (req->opcode < IORING_OP_LAST) always true at this point > + audit_uring_entry(req->opcode); So, it adds two if's with memory loads (i.e. current->audit_context) per request in one of the hottest functions here... No way, nack Maybe, if it's dynamically compiled into like kprobes if it's _really_ used. > + > switch (req->opcode) { > case IORING_OP_NOP: > ret = io_nop(req, issue_flags); > @@ -6211,6 +6215,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) > break; > } > > + if (req->opcode < IORING_OP_LAST) > + audit_uring_exit(!ret, ret); > + > if (creds) > revert_creds(creds); -- Pavel Begunkov -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit