Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1867382rwl; Thu, 30 Mar 2023 02:36:18 -0700 (PDT) X-Google-Smtp-Source: AKy350bWQ6QQpj/eMz9MTszNv9D9oVYynITeCqdr5S6MJPw8Y5GGU8GYHyARyxXATRTVWjle63bD X-Received: by 2002:a05:6402:2811:b0:4bb:c3ce:63fc with SMTP id h17-20020a056402281100b004bbc3ce63fcmr26255469ede.3.1680168978449; Thu, 30 Mar 2023 02:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680168978; cv=none; d=google.com; s=arc-20160816; b=Sqmo5ZyEM3Ylvsb8UObuXUqvv+cnJGAhnIwwBo1PLLn8pBVMsOThkWwGxH/WTDLUO9 lZSvDds06hpNJjn/47wED5FZSJ+jjutWa3Moz0S+frI0jQE58QU2XZNHJzWd31TEXb2O 3K/JdVzDG2+fDdd2SxeELFi4Io6LkDYUTuCMOcOLK7tOPOWCIca1+CAVOSbF0Qqz5eTX 0KDZQdjZPfPjequK4mYEsdA2uiAs1dtmxe4YwcIoZjlsOD727YgaUtBp0DR6OpD3muAh AdzkdSTqN+dVjhvE6MWWvxS80PWDKYtkVi6Rp8REUFKsg4nX3ESii4kqQ2hNXXlFwqiJ 2/MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=ARulaqHJxPwB/WKU7rfcwJ3+y3Mu0UnpMwYgGZ/ZzmM=; b=hub9NURkMqBVcxWIneU0kYk23wBubMbU4iWs5Ie1VoTM+mTD/I1RE1Vwe5Ka8ytB7R JP91fkcs7l1hStJmgWMCCEWTLqrcPaoeZGtIjtAGV6qLkLBreFUoTvfJYnuLsgRbRHDx C7GirOG89y8HjqUJawArrEI4Lf6h+QaFv1xkEMUcKAH/TrNQmiXgGg89IRqdT8Y85Q5P 7cADVtmDDmhlhQza9Snjwk+VqLmzo8lZ9uBjqdf1IurErk272oKPc7TvgyEg6t95xbSz LhS8V8hhJ0eHIeXAxbEmVjA5EfDHNTzex2u0xsM/CNrDYsaD+FCxnNZRboX5IHDto3ln myDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=cirIf2Dr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c14-20020aa7d60e000000b004ab0f51244csi32767430edr.622.2023.03.30.02.35.53; Thu, 30 Mar 2023 02:36:18 -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 (test mode) header.i=@axis.com header.s=axis-central1 header.b=cirIf2Dr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229839AbjC3Jcn (ORCPT + 99 others); Thu, 30 Mar 2023 05:32:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbjC3Jcl (ORCPT ); Thu, 30 Mar 2023 05:32:41 -0400 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93CFE7698 for ; Thu, 30 Mar 2023 02:32:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1680168761; x=1711704761; h=from:date:subject:mime-version:content-transfer-encoding: message-id:to:cc; bh=ARulaqHJxPwB/WKU7rfcwJ3+y3Mu0UnpMwYgGZ/ZzmM=; b=cirIf2Dr7mJ9K4/sA7f8sfQNepMza7P747a+4lsojzpZwCtM8hCXbwYf lW6r6RKXkkECNfpk4yIGvkY7kEkN5zGEcCIwGaZl11t65zYbGHSg3M0I0 sESW0vJ7RlZbcrd3Keb+mU0ObyWzBC+/f/QJf2X4jQytjZkRKIUseZSJR gVm3f52x9Jh5I5eFFtPm2a8wbH9W/QgurmL5zWtmpOdQ2/7Ry2q3rfdpx n5Z5wrvZhmtGsrigycRLLXYp5bo7FpeC+lyf1x7+npXqXZUDQaPzhEZBY 0dQh/7tl+C/+nSksvV+KjL8laxIoF21XkKcamX8jtwLHBNXahi1ch9Uyr Q==; From: =?utf-8?q?M=C3=A5rten_Lindahl?= Date: Thu, 30 Mar 2023 11:32:14 +0200 Subject: [PATCH v2] ubifs: Free memory for tmpfile name MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-ID: <20230329-memleak-fix-v2-1-cb8d9394300b@axis.com> X-B4-Tracking: v=1; b=H4sIAB1XJWQC/22Nyw6CQAxFf4V0bQ0zozxc+R+GRYEijQ6YKSEYw r87sHZ57iNnBeUgrHBLVgg8i8o4RLCnBJqehiejtJHBptalzpbo2b+ZXtjJgkVOqWmpu2QlQ3z UpIx1oKHp948nnTjsxSdw3B+aRxW5F53G8D2ss9nT/4LZoMHcONfSNWMqujstoudm9FBt2/YDO U6Ms74AAAA= To: Richard Weinberger CC: , , , =?utf-8?q?M=C3=A5rten_Lindahl?= X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1680168758; l=1585; i=marten.lindahl@axis.com; s=20230329; h=from:subject:message-id; bh=DvHc9WiK+hCXxAJFzO5SlY8uEWNpRF0ZPAgyp0dhgpQ=; b=+VxG8dBorTmhj1CUJGkeCxLyzvmUn+kHjSxEOH4y6tqHD/w29wuRZ3n5bTPTEvZR/XLLGNmCU e4XJ5VCW9Y4DDcaapawU1ESDAnzvAz+1R4Nfbf5X56egcCPv//z2JCX X-Developer-Key: i=marten.lindahl@axis.com; a=ed25519; pk=JfbjqFPJnIDIQOkJBeatC8+S3Ax3N0RIdmN+fL3wXgw= X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS 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 When opening a ubifs tmpfile on an encrypted directory, function fscrypt_setup_filename allocates memory for the name that is to be stored in the directory entry, but after the name has been copied to the directory entry inode, the memory is not freed. When running kmemleak on it we see that it is registered as a leak. The report below is triggered by a simple program 'tmpfile' just opening a tmpfile: unreferenced object 0xffff88810178f380 (size 32): comm "tmpfile", pid 509, jiffies 4294934744 (age 1524.742s) backtrace: __kmem_cache_alloc_node __kmalloc fscrypt_setup_filename ubifs_tmpfile vfs_tmpfile path_openat Free this memory after it has been copied to the inode. Signed-off-by: Mårten Lindahl --- Changes in v2: - Call fscrypt_free_filename after ubifs_release_budget - Link to v1: https://lore.kernel.org/r/20230329-memleak-fix-v1-1-7133da56ea8f@axis.com --- fs/ubifs/dir.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index 0f29cf201136..7dd6dd34b84c 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -492,6 +492,7 @@ static int ubifs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir, unlock_2_inodes(dir, inode); ubifs_release_budget(c, &req); + fscrypt_free_filename(&nm); return finish_open_simple(file, 0); --- base-commit: c9c3395d5e3dcc6daee66c6908354d47bf98cb0c change-id: 20230329-memleak-fix-87a01daf469e Best regards, -- Mårten Lindahl