Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp318528imn; Thu, 4 Aug 2022 07:11:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR5P2nLMTs6nSjRy/hbm/7+KEAyoqOa3UARn+6NZZtu5VfewzkN8eeTbGLM5qpwy9zsxU9rt X-Received: by 2002:a17:906:7b82:b0:6f3:ee8d:b959 with SMTP id s2-20020a1709067b8200b006f3ee8db959mr1532507ejo.458.1659622262265; Thu, 04 Aug 2022 07:11:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659622262; cv=none; d=google.com; s=arc-20160816; b=uInbVsaTjSNlVQqGGg71oieBrh7k9FpA7BHt+8K4wgIDSBO6MwKd3Hg63mnO5CyxQd aN/bQkCvj4KWfjbXCDupIDpfIVh6dNqJDCGlRnuxP9IkIN5pRtoGnl1sfPvsj82nANYD hVCigK7/zLd+ysOE6C8hZoUTysKxaKyBaokZw/Er0XvrqEirKnv4EjxkODbwszL0iYQz F3uGAHDSl9B4vhQR+LAiWJPY/2wAbR8oYaO28lpxhZ56g0ml3fHfLO6mt4kj+PguV68M 8vz+0UXEqvv1zr5Xan5UphjEvlTyVAo3mRCSdvCD5Y82mMCndu5/I/uzEIPpNPLMMrhy HulA== 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=4H8DTDCY7KHh19Y7U066i9Gs9khthyKkaKzvx73zQGo=; b=zKhdbF+G2aaHxPkaYOLe2gcH5KwCijIiY/AFqcZzmkID/XWvHyTQkHIv4p8Vmp5yxU GNbx5+yhSzhhsXkfm2ktzD8YyJZaJgZhzancJnKPHCepn7wxM69OWjp95oUEydvoKtZY 6VxumDmWDBFzlkRMSolgbK6l5jZZJX+bBTlNxC3odJEaeCx5SHa7vZLDWz8rh5FDO1/R mkR3E4hLdWcmNCzd0qrindxi2SFPxg+LEzXhBAxwuOQxSZaWgcY7OZ87DuQYL07vif9v 2bu9UIccNFfmddoRzB7S1R2B8Zzz6r6fLtESMWf58ree9Ht8aGL0xWfIPURpEd7n+Utc Uq/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20210112.gappssmtp.com header.s=20210112 header.b=5fMRnByF; 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 l19-20020a170906795300b0072b45e10bb0si816462ejo.922.2022.08.04.07.10.36; Thu, 04 Aug 2022 07:11:02 -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=5fMRnByF; 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 S239988AbiHDNwN (ORCPT + 99 others); Thu, 4 Aug 2022 09:52:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239970AbiHDNwJ (ORCPT ); Thu, 4 Aug 2022 09:52:09 -0400 Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70B3C13F33 for ; Thu, 4 Aug 2022 06:52:08 -0700 (PDT) Received: by mail-oi1-x231.google.com with SMTP id s204so23285907oif.5 for ; Thu, 04 Aug 2022 06:52:08 -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=4H8DTDCY7KHh19Y7U066i9Gs9khthyKkaKzvx73zQGo=; b=5fMRnByF1RAsJF5q0aZRUcqFysc78mQstZyMpyQ3gywRs1pSHMkjj6PpRzmB6taNrY mckYCcTJcPhibdnQ1khfLGmuQbkMW4h59uYb8CZXEl+P4TjxwDDQf2hi2yDfbEmFRcLM D46QHhJuo3r0W5V/dBDPt8Afcs/Hsgj3IP6PtBUcAtTnzDIUZQ0Q1JxJGGU9O2gpCT+D lWeeO4d/jZx9YHgej3HAccSuWYXOkO2LA6gJ21jQHkcXCqIl1zqZjBKUfNwFP3EjyQlE S4sp9WWj+v3KvWBACmsEzKsWxmkD21Mh0ab3WFaXofaGFYz0jmZ7TrikKRYfHfLo7BhN +PIg== 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=4H8DTDCY7KHh19Y7U066i9Gs9khthyKkaKzvx73zQGo=; b=xj9W5SoSt+CpdY3VkRXU7DG0t7hrDJWzfN5qdYwHvka21eqGJlERqYWhuzvNflyXBH LlZPovAihOeZkmo5BGKMPtd5i1XsdHdfTtBpVkmuksilwNBSIMpO4OjGDgMDa+V2vwQh xbzQjvkiJiTP4FH5HGkU9/JeJEQYRCdWVE7nz5Fhnou7SXu9vVjRnBr5xpvYgFzgmuqP 2t3BCYq2wG1WSa67W5OhkOPpDEH1oEe34kAIX82TJUqnzkT3MlnEkz6aTXMKqE2xbTe7 P0naooH1TLKf5VjsbJIciLWzw8FL95MZsjh3Z5j+w2SAOzgLssdIKWR++ZOvqQY2ftXQ aYbA== X-Gm-Message-State: ACgBeo2FpajwrMy7cuHnSY/Vrop6Z+5L809Hww2IhpelU7u3xQJbsRvt /G3MkoyzL3SANqk72FyN0t6pjEZyrHGgKIwej4ma X-Received: by 2002:a05:6808:2389:b0:33a:cbdb:f37a with SMTP id bp9-20020a056808238900b0033acbdbf37amr938602oib.136.1659621127735; Thu, 04 Aug 2022 06:52:07 -0700 (PDT) MIME-Version: 1.0 References: <20220803050230.30152-1-yepeilin.cs@gmail.com> <20220803222343.31673-1-yepeilin.cs@gmail.com> In-Reply-To: <20220803222343.31673-1-yepeilin.cs@gmail.com> From: Paul Moore Date: Thu, 4 Aug 2022 09:51:56 -0400 Message-ID: Subject: Re: [PATCH v2] audit, io_uring, io-wq: Fix memory leak in io_sq_thread() and io_wqe_worker() To: Peilin Ye Cc: Jens Axboe , 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=unavailable 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 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 -- paul-moore.com