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 1860DC19F2B for ; Wed, 3 Aug 2022 20:45:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659559530; 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=8qXlKNYcTvF9AdAugB/OGSF6Py+Pm3+bowss3doQzxA=; b=X6SUC7frBsVMmnjGjipLyOboQxYviccFWbFLYx2fG/Z75PCvgBkO5jyPoi9Kc/U0q+ebPc /vlL6KFB64vuX2tlGgMZ27XB5GFXGKFVDNJfZJWbJAnQXr8NghjSOA0DC8BXxYtafiAJGa +nNq0RNV5sWJu95heZdN1Js4vW+Pf14= 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-80-juJn0ORfMMOhn2jROAygcg-1; Wed, 03 Aug 2022 16:45:24 -0400 X-MC-Unique: juJn0ORfMMOhn2jROAygcg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E391B101A54E; Wed, 3 Aug 2022 20:45:20 +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 9145F2026D4C; Wed, 3 Aug 2022 20:45:19 +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 530901946A52; Wed, 3 Aug 2022 20:45:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B90FF1946A4E for ; Wed, 3 Aug 2022 20:24:43 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id AB3221415122; Wed, 3 Aug 2022 20:24:43 +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 A77DE1415116 for ; Wed, 3 Aug 2022 20:24:43 +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 9467E89F605 for ; Wed, 3 Aug 2022 20:24:35 +0000 (UTC) Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-404-rT63GJ7hOpSjtXdfHkMCUQ-1; Wed, 03 Aug 2022 16:24:33 -0400 X-MC-Unique: rT63GJ7hOpSjtXdfHkMCUQ-1 Received: by mail-qv1-f54.google.com with SMTP id m10so13773240qvu.4; Wed, 03 Aug 2022 13:24:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=B96Bdg0Onzy13s4UbCLzMdjvnIzLbs1ULEk+vwxhe6w=; b=gR5agOkkG+ASwGfmI1cY351NxduspFDcIPR+uuLL7vptyigEWPmXnMKWCmqVCGKZVF oLc2JUCqjxmrXOVRpvgzlpTT8BoYoU2dZZiOY42ubD0sWjjKDxte+uYZkFzWd1e4O655 IVnjvxLeFfHnddZnT2RZNfaJZIj2g5RKH4vMhBiMxUeRKSSeiiWp7fWm4Pjb0AyASiRU Xq66hjmlJi7CnLlDo99ySq3ACK1vaqN/0KoLy2AbOFNy/6/vg8aQxpLcZlKMPrSqNRjt JL2gRTNTX2SviTm+QLFEHy6bp1Kt9o1aH4qwyCzsjqUv/UxM3UTuXrxQx+ShrDm7IVtB glBw== X-Gm-Message-State: ACgBeo3bpCeOb/2o7ieBfZxygkLgmZNviUrLOgggzqGTlv/zbuHj2OW6 fXZWmRH8uKpWBPqyMlZ5jA== X-Google-Smtp-Source: AA6agR4zPKE+bteQz7BICzyQdDD01B8OZ+skbS9NvxF6LTbmkCquatAxhuNVjhJ3ZBa7Pdm0mVzWfA== X-Received: by 2002:a0c:cb0c:0:b0:476:d5e7:e0ca with SMTP id o12-20020a0ccb0c000000b00476d5e7e0camr8783614qvk.57.1659558273197; Wed, 03 Aug 2022 13:24:33 -0700 (PDT) Received: from bytedance ([74.199.177.246]) by smtp.gmail.com with ESMTPSA id dm40-20020a05620a1d6800b006a6ab259261sm3415250qkb.29.2022.08.03.13.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Aug 2022 13:24:31 -0700 (PDT) Date: Wed, 3 Aug 2022 13:24:26 -0700 From: Peilin Ye To: Paul Moore Subject: Re: [PATCH] audit, io_uring, io-wq: Fix memory leak in io_sq_thread() and io_wqe_worker() Message-ID: <20220803202426.GA31375@bytedance> References: <20220803050230.30152-1-yepeilin.cs@gmail.com> MIME-Version: 1.0 In-Reply-To: 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.7 X-Mailman-Approved-At: Wed, 03 Aug 2022 20:45:16 +0000 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: Jens Axboe , linux-kernel@vger.kernel.org, Eric Paris , io-uring@vger.kernel.org, linux-audit@redhat.com, Peilin Ye , Pavel Begunkov Errors-To: linux-audit-bounces@redhat.com Sender: "Linux-audit" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi, On Wed, Aug 03, 2022 at 03:28:19PM -0400, Paul Moore wrote: > On Wed, Aug 3, 2022 at 9:16 AM Paul Moore wrote: > > On Wed, Aug 3, 2022 at 1:03 AM Peilin Ye wrote: > > > Hi all, > > > > > > A better way to fix this memleak would probably be checking > > > @args->io_thread in copy_process()? Something like: > > > > > > if (args->io_thread) > > > retval = audit_alloc_kernel(); > > > else > > > retval = audit_alloc(); > > > > > > But I didn't want to add another if to copy_process() for this bugfix. > > > Please suggest, thanks! > > > > Thanks for the report and patch! I'll take a closer look at this > > today and get back to you. > > I think the best solution to this is simply to remove the calls to > audit_alloc_kernel() in the io_uring and io-wq code, as well as the > audit_alloc_kernel() function itself. As long as create_io_thread() > ends up calling copy_process to create the new kernel thread the > audit_context should be allocated correctly. Peilin Ye, are you able > to draft a patch to do that and give it a test? Sure, I will write a v2 today. Thanks for the suggestion! > For those that may be wondering how this happened (I definitely was!), > it looks like when I first started working on the LSM/audit support > for io_uring it was before the v5.12-rc1 release when > create_io_thread() was introduced. Prior to create_io_thread() it > appears that io_uring/io-wq wasn't calling into copy_process() and > thus was not getting an audit_context allocated in the kernel thread's > task_struct; the solution for those original development drafts was to > add a call to a new audit_alloc_kernel() which would handle the > audit_context allocation. Unfortunately, I didn't notice the move to > create_io_thread() during development and the redundant > audit_alloc_kernel() calls remained :/ Thanks, Peilin Ye -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit