Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp365585imn; Thu, 4 Aug 2022 08:57:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR4y/IgqbApqv9Eqp8g8c+J1uT40qed7jpXTJ3KcdDsMaK8v9xcJQ0e9EhzN5TUWMqnDAigh X-Received: by 2002:a17:902:e5c9:b0:16e:f3b6:ddc4 with SMTP id u9-20020a170902e5c900b0016ef3b6ddc4mr2445500plf.30.1659628676808; Thu, 04 Aug 2022 08:57:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659628676; cv=none; d=google.com; s=arc-20160816; b=mm34Ynqq1u6XPNeyGA2wgy2RC64xPvSUOXsIYhjnYyEbtj2EWyERH5B3LDCW7zEoR9 Gmuxjk+VZgejwwkrnUwDoUUNcpDMy7b/ejIeDtluvOvki6D1Lb06TRYgMYcE7gbLZ4AO Ncg4Xxn+0/OhHtfeEcRnB6LGfOlyaqghagQVC0XwK+X628p5g+FGVVoirEd6pBKbn2PY YYxM+zjdiw61GTzKWbSSjUwuC2Sc1Al0U5jLU+4nUnnQzDDSuiFVeKzhcJ/PrCMv/TXG 2gOTLDxUQTi/0FDH9zctzefpoIQqoSz8ImltS14Q3srMHYzHPI7MOMAbWlsAtTwNyOqn Gzfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=K/0tfswiWr5Lvpf3OZ7/6RjAIN83kdceEedNYhOi6eA=; b=Y4ScwPQ+LKvM4l98LnF6LM9uvCkrDfHPdHZiM8MDCyr0sbpVU/Xn41RMhBQ6aFc4dI z6MA1MJDJNlSKVf4Xo0vX4E81IB4nhu8MQNFO7k7PcwUabzP/F8U8X3hAfKGh2jWqleO 64iJF90gpIQtgYeudHCEllGNIeUwdfY4OHq/A0Td/DoWrSHq1Ytye2CHFyg54t9O16Eq MMwlLJW2fq83U37jzKBn92Ppo/GL7+W6mxWIlBFsAyw99F0dXXKSg1W4hTGpn7mqmTRH +ShcCsm4S8QI7GJz56uriZ516GjIrIBAUtYsJ1Gx89iFGdroXZl4WpWTXW1JITU3LNTH N37g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20210112.gappssmtp.com header.s=20210112 header.b=VylXISKj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u5-20020a170903124500b0016d018cc597si1432366plh.416.2022.08.04.08.57.42; Thu, 04 Aug 2022 08:57:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore-com.20210112.gappssmtp.com header.s=20210112 header.b=VylXISKj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240058AbiHDOpO (ORCPT + 99 others); Thu, 4 Aug 2022 10:45:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239629AbiHDOpL (ORCPT ); Thu, 4 Aug 2022 10:45:11 -0400 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E67F4111C for ; Thu, 4 Aug 2022 07:45:09 -0700 (PDT) Received: by mail-oi1-x22f.google.com with SMTP id u9so23400480oiv.12 for ; Thu, 04 Aug 2022 07:45:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=K/0tfswiWr5Lvpf3OZ7/6RjAIN83kdceEedNYhOi6eA=; b=VylXISKjzqJ3TzMpV1KV0KUi1LcXcBr8J307PBKOuSQ5PWraDGavJxDfw10YupsHoq dw9OOGSdjuBCUbxqdPULDLFntROHoS/8q/Dikm2cEqy6zK3fx/x7f7ix/2AX6La1R3Gs RaZQ9sIKn9O2kd+IcsYVcXvFSu0MYPSryo5H9hS01ELGUu4er1EsgaGsh5zjfDIWcFmT KHodrrilhqMZo3jhuPLJFD+D3q9uRtDZLsn2CN4o3nuI9hjGJB5EQb/6hvKTujeb6ASV m0ceWQL1DoYkp0o9CD/QwbeQD6Hcz1JWtwLusDDqXIHpoBhKKLPVL9GnWgTFDjPmBCAt MAUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=K/0tfswiWr5Lvpf3OZ7/6RjAIN83kdceEedNYhOi6eA=; b=yPIFpQ84GvrYizSoBFnDZ6LWt6PptSJM8TCeQojxtPngpC0F1FYGkLernYJsNpN3Wb PBg6iLfwpAJYNcaoZvAC+xfK823IjR1luMFpTw4PgYCe+VORjWfa6bUHqFk1c+FKFvfZ foTScuA+FCOSi1D3osL7rxWi3IRUwua3bUaJlycEkVPw6F/SVzlZ5fJx/d3vkDhuqkWZ pURqej173xRD9Fe6QTy8ew2BLozsyvhyAo3Ehs1Cd37iFzsRb4hcxYtkcrjioYwuKtRK 6jNXL6Vi9yvuu8A/anK5SjCl9KBPKboh35Ko5QpIxwElHaQNwAWQAzUYmA+yr0+zXgm9 giZg== X-Gm-Message-State: ACgBeo3gtdPwu1CG425lXAVYIfhrZDxW72glvsneZd7UQmmgPHRBbh/w scf7IXJ6kFqqvob6wCyk588ZfepalFdqFDda2p7r X-Received: by 2002:a05:6808:2389:b0:33a:cbdb:f37a with SMTP id bp9-20020a056808238900b0033acbdbf37amr1062501oib.136.1659624309228; Thu, 04 Aug 2022 07:45:09 -0700 (PDT) MIME-Version: 1.0 References: <20220803050230.30152-1-yepeilin.cs@gmail.com> <20220803222343.31673-1-yepeilin.cs@gmail.com> <5756a75e-ea84-a04b-be07-90e7ee6626d6@kernel.dk> In-Reply-To: <5756a75e-ea84-a04b-be07-90e7ee6626d6@kernel.dk> From: Paul Moore Date: Thu, 4 Aug 2022 10:44:58 -0400 Message-ID: Subject: Re: [PATCH v2] audit, io_uring, io-wq: Fix memory leak in io_sq_thread() and io_wqe_worker() To: Jens Axboe Cc: Peilin Ye , Pavel Begunkov , Eric Paris , Peilin Ye , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, linux-audit@redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 4, 2022 at 10:32 AM Jens Axboe wrote: > On 8/4/22 7:51 AM, Paul Moore wrote: > > On Wed, Aug 3, 2022 at 6:24 PM Peilin Ye wrote: > >> > >> From: Peilin Ye > >> > >> Currently @audit_context is allocated twice for io_uring workers: > >> > >> 1. copy_process() calls audit_alloc(); > >> 2. io_sq_thread() or io_wqe_worker() calls audit_alloc_kernel() (which > >> is effectively audit_alloc()) and overwrites @audit_context, > >> causing: > >> > >> BUG: memory leak > >> unreferenced object 0xffff888144547400 (size 1024): > >> <...> > >> hex dump (first 32 bytes): > >> 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 ................ > >> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > >> backtrace: > >> [] audit_alloc+0x133/0x210 > >> [] copy_process+0xcd3/0x2340 > >> [] create_io_thread+0x63/0x90 > >> [] create_io_worker+0xb4/0x230 > >> [] io_wqe_enqueue+0x248/0x3b0 > >> [] io_queue_iowq+0xba/0x200 > >> [] io_queue_async+0x113/0x180 > >> [] io_req_task_submit+0x18f/0x1a0 > >> [] io_apoll_task_func+0xdd/0x120 > >> [] tctx_task_work+0x11f/0x570 > >> [] task_work_run+0x7e/0xc0 > >> [] get_signal+0xc18/0xf10 > >> [] arch_do_signal_or_restart+0x2b/0x730 > >> [] exit_to_user_mode_prepare+0x5e/0x180 > >> [] syscall_exit_to_user_mode+0x12/0x20 > >> [] do_syscall_64+0x40/0x80 > >> > >> Then, > >> > >> 3. io_sq_thread() or io_wqe_worker() frees @audit_context using > >> audit_free(); > >> 4. do_exit() eventually calls audit_free() again, which is okay > >> because audit_free() does a NULL check. > >> > >> As suggested by Paul Moore, fix it by deleting audit_alloc_kernel() and > >> redundant audit_free() calls. > >> > >> Fixes: 5bd2182d58e9 ("audit,io_uring,io-wq: add some basic audit support to io_uring") > >> Suggested-by: Paul Moore > >> Cc: stable@vger.kernel.org > >> Signed-off-by: Peilin Ye > >> --- > >> Change since v1: > >> - Delete audit_alloc_kernel() (Paul Moore) > >> > >> fs/io-wq.c | 3 --- > >> fs/io_uring.c | 4 ---- > >> include/linux/audit.h | 5 ----- > >> kernel/auditsc.c | 25 ------------------------- > >> 4 files changed, 37 deletions(-) > > > > This looks good to me, thanks! Although it looks like the io_uring > > related changes will need to be applied by hand as they are pointing > > to the old layout under fs/ as opposed to the newer layout in > > io_uring/ introduced during this merge window. > > > > Jens, did you want to take this via the io_uring tree or should I take > > it via the audit tree? If the latter, an ACK would be appreciated, if > > the former my ACK is below. > > > > Acked-by: Paul Moore > > Probably better if I take it, since I need to massage it into the > current tree anyway. We can then use this one as the base for the stable > backports that are going to be required. Sounds good to me, thanks everyone. -- paul-moore.com