From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 537D022A1E6; Mon, 17 Feb 2025 18:50:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739818202; cv=none; b=D83weKJ3hFgTyTWZyoxM2XDLXtAl9EVkWgPNxnZvO+1r7ao3S5i1F9P20+EPFyra0Yxd50bfvTnVHQCxF8gLl4atAta9oRmbEzYPeXOeN7wc9TTKW5v0bAd2bxuHtBG0GhJ+soOXNv/9nrWQGf2TgdHDBlmZM5YGcx1njDf/FWk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739818202; c=relaxed/simple; bh=bSkaPVIT6VfRE0JIpCa1oHUI1xXQj1fjU7es/My1gRM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EjQDnEEJiVnj49vYG+iof/QxY4p9zf2NnQWXrdcTE4Oe0WEvlMsSAPAfP+lSIRYOKgjAjA5HKz6gCgb8+yufBN5yvqH6azAAqCve9NF9K+EvyEEEhLgmpsc2xYYBpIw/wAAUCkmQ8zpuBKlN6tvDN7V4atlwM8+6ftLzwyzK5wg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cY4c2KC2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cY4c2KC2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 870CCC4CED1; Mon, 17 Feb 2025 18:50:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739818201; bh=bSkaPVIT6VfRE0JIpCa1oHUI1xXQj1fjU7es/My1gRM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=cY4c2KC24HnubKXjrX0Oxg25o0kMezl+Yqkk1suSt1BWnLHdJxZM5w8PjZRm12lak DVCAMefgBVLG3tNaqjG8wJFCZZtc37AsAsTXSabdrhFjKa/ULzyLolFhkR3HcFzyVT 7QZjOeN0Uh3kvvqTO5rCzZ1jSla1YRc5R70ydCJ/C0Sv8YwTsVv2f6hfC3l7zyXrIV Vocghvvv5K9EWGO6dEoLjQ0fJrGmD4wRMNusQI6ePZvFBYM2kdC0E1lFBH9XvsYF0r 71sV0zD4FjCp8K0blysR2qUTSfB/mOkbT6Nw5jpXc8EZ3HFSVeFDKzh+THvF/46hc0 U5MGuq+iNeQFQ== Date: Mon, 17 Feb 2025 10:50:00 -0800 From: Eric Biggers To: Lucas Tanure Cc: kernelnewbies , linux-fscrypt@vger.kernel.org, LKML , linux-crypto@vger.kernel.org, "krzysztof.opasiak@neat.no" , "lucas.tanure@neat.no" Subject: Re: crypto: fscrypt: crypto_create_tfm_node memory leak Message-ID: <20250217185000.GC1258@sol.localdomain> References: Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Feb 17, 2025 at 06:43:15PM +0000, Lucas Tanure wrote: > Hi, > > I am working with Android 13 and V5.15 kernel. During our development, > I found a memory leak using kmemleak. > > Steps I did to find the memleak: > mount -t debugfs debugfs /sys/kernel/debug > echo scan=5 > /sys/kernel/debug/kmemleak > cat /sys/kernel/debug/kmemleak > > Stack I got (hundreds of them): > unreferenced object 0xffffff8101d31000 (size 1024): > comm "binder:1357_2", pid 1357, jiffies 4294899464 (age 394.468s) > hex dump (first 32 bytes): > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > backtrace: > [] crypto_create_tfm_node+0x64/0x228 > [] fscrypt_prepare_key+0xbc/0x230 > [] fscrypt_setup_v1_file_key+0x48c/0x510 > [] fscrypt_setup_encryption_info+0x210/0x43c > [] fscrypt_prepare_new_inode+0x128/0x1a4 > [] f2fs_new_inode+0x27c/0x89c > [] f2fs_mkdir+0x78/0x278 > [] vfs_mkdir+0x138/0x204 > [] do_mkdirat+0x88/0x204 > [] __arm64_sys_mkdirat+0x40/0x58 > [] invoke_syscall+0x60/0x150 > [] el0_svc_common+0xc8/0x114 > [] do_el0_svc+0x28/0x98 > [] el0_svc+0x28/0x90 > [] el0t_64_sync_handler+0x88/0xec > [] el0t_64_sync+0x1b8/0x1bc > > After checking upstream, I came up with the following: > cff805b1518f fscrypt: fix keyring memory leak on mount failure > > But my kernel has this patch. So I continued to dig around this and > saw the function fscrypt_prepare_key in fs/crypto/keysetup.c for > V5.15. > I can't see the pointer tfm being used anywhere or saved, and > smp_store_release doesn't kfree it. > Is smp_store_release doing something with that pointer that makes this > memory leak a false positive? > > Any help with this issue would be much appreciated. > Thanks The pointer to the crypto_skcipher 'tfm' is stored in the fscrypt_inode_info (previously fscrypt_info) which is stored in inode::i_crypt_info. It gets freed when the inode is evicted. I don't know why you're getting a kmemleak warning. Perhaps f2fs in that version of the kernel has a bug that is leaking inodes. smp_store_release is just a fancy way of doing a store that includes a memory barrier. - Eric