Message ID | 20230801144136.23565-1-lhenriques@suse.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2788396vqg; Tue, 1 Aug 2023 09:34:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlGOHgHDOSNdWEOSjibtq1/Ue81KKJOBc9VK1Zg3q+4O6v1tv9RTKq9kMfOqxs/bxOyG+A/3 X-Received: by 2002:a05:6a20:394d:b0:134:a4e2:4ac8 with SMTP id r13-20020a056a20394d00b00134a4e24ac8mr13951458pzg.39.1690907676588; Tue, 01 Aug 2023 09:34:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690907676; cv=none; d=google.com; s=arc-20160816; b=lU5qTyJ1CovJepOEMrwDyejThixmTd3dXtASk3PpoGQca4OYTvJLNWxydLDyg7Fd3A d8QeNwp2weUrdut50GYvwFJUF87WFx4HJ/dPzWMyihm9tiuIHnvLUY0uNVUQN3jC7eNK pylH+ICyUe9xca9LKtXQTrPIDhpHpQaUhVlf7SmpCITg5yZk3yRkCaPePLQ5xC/p3Zws KiT2zG3rgfiTQjNC6ygouFgyenzEInlXYlrDOeSsr11ggJSoc/b8K+mjrL9AAwmKu1eY EnGP2bdlS6JAr/WMaD6pX3RkzQxBRC2PNYty3BgsxgzT7HfYkdHMQYBqZsuG89fxXCUy 7Jlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=L4scspEofNFZsqaoPa/uagvn9jfb5SNDwDcPebxybj8=; fh=JYaWYeLjwbsjMwCf/2VPhfvpjXUb3Ona0cK/uW8PAt0=; b=fFZtNE36wwgJGj83D5S79DRX9O//7QdQQWJHr2HQKPXH44HVuavxtecTvnv/ru/tAG +ILS/k0JzlncfpcaImkG2jxCbk4T3fp+0tlHGyEOtmPtsSd0eI0kl8b87j4JyzZ9EahY 3Z1oIxKAxqwM9Qu1iepDnyy0LAK9ecw46Ur9Hls2ibAiu8bznH4eAgvuHeHlHGRHbrcy 8uc7vphGOhoYj4q0RkqXFChv6SQkvcp/43G+taEiWcopCJEl/4C53/tBZIN8N4tNVSBP 5S76u6OjGa4dg48xBHQ9PE9V0cgx/t67TIwgMGBlEGoUUZgQDbPnwGHKIrBrOxL874T4 h8FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=wbpIQRBA; dkim=neutral (no key) header.i=@suse.de header.b=3suknXgZ; 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=suse.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z76-20020a63334f000000b0055a5434684bsi9015925pgz.106.2023.08.01.09.34.18; Tue, 01 Aug 2023 09:34:36 -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=@suse.de header.s=susede2_rsa header.b=wbpIQRBA; dkim=neutral (no key) header.i=@suse.de header.b=3suknXgZ; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234863AbjHAOlo (ORCPT <rfc822;maxi.paulin@gmail.com> + 99 others); Tue, 1 Aug 2023 10:41:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234590AbjHAOll (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 1 Aug 2023 10:41:41 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D7DF9C; Tue, 1 Aug 2023 07:41:40 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 398301F45A; Tue, 1 Aug 2023 14:41:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1690900899; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=L4scspEofNFZsqaoPa/uagvn9jfb5SNDwDcPebxybj8=; b=wbpIQRBA4leKtrWq52bsLBPy3dasXNlM83tBFXuy6DKfjbbfTiHo+axech1TR9YcAjNFxm rruFVUXEQoNC/kW3TJ9jrT4seEJpEv75/6nSGYF7FSYR7vzHmoB1sl/CZWr5a5BTiUG5Sj 0PBJqhyyRCZJsfr0YQPhrvRKReLjLMQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1690900899; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=L4scspEofNFZsqaoPa/uagvn9jfb5SNDwDcPebxybj8=; b=3suknXgZXNbb7oxlw6YY9Gz9wN78Da5aPmMCq+EIw5P0h66ZrtxdI+PODTd1UhKripPE6m m03MKfp5kmaluABg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C7F8A139BD; Tue, 1 Aug 2023 14:41:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8CbhLaIZyWSOawAAMHmgww (envelope-from <lhenriques@suse.de>); Tue, 01 Aug 2023 14:41:38 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id 3bec45b3; Tue, 1 Aug 2023 14:41:37 +0000 (UTC) From: =?utf-8?q?Lu=C3=ADs_Henriques?= <lhenriques@suse.de> To: "Theodore Ts'o" <tytso@mit.edu>, Andreas Dilger <adilger.kernel@dilger.ca> Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Lu?= =?utf-8?q?=C3=ADs_Henriques?= <lhenriques@suse.de> Subject: [PATCH] ext4: fix memory leak in ext4_fname_setup_filename() error path Date: Tue, 1 Aug 2023 15:41:36 +0100 Message-Id: <20230801144136.23565-1-lhenriques@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773045207895660884 X-GMAIL-MSGID: 1773045207895660884 |
Series |
ext4: fix memory leak in ext4_fname_setup_filename() error path
|
|
Commit Message
Luis Henriques
Aug. 1, 2023, 2:41 p.m. UTC
If casefolding the filename fails, we'll be leaking fscrypt_buf name.
Make sure we free it in the error path.
Signed-off-by: Luís Henriques <lhenriques@suse.de>
---
fs/ext4/crypto.c | 2 ++
1 file changed, 2 insertions(+)
Comments
On Tue, Aug 01, 2023 at 03:41:36PM +0100, Luís Henriques wrote: > If casefolding the filename fails, we'll be leaking fscrypt_buf name. > Make sure we free it in the error path. > > Signed-off-by: Luís Henriques <lhenriques@suse.de> > --- > fs/ext4/crypto.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c > index e20ac0654b3f..9e4503b051c4 100644 > --- a/fs/ext4/crypto.c > +++ b/fs/ext4/crypto.c > @@ -33,6 +33,8 @@ int ext4_fname_setup_filename(struct inode *dir, const struct qstr *iname, > > #if IS_ENABLED(CONFIG_UNICODE) > err = ext4_fname_setup_ci_filename(dir, iname, fname); > + if (err) > + fscrypt_free_filename(&name); > #endif > return err; > } Doesn't ext4_fname_prepare_lookup() have the same bug? Also, please include a Fixes tag. - Eric
Eric Biggers <ebiggers@kernel.org> writes: > On Tue, Aug 01, 2023 at 03:41:36PM +0100, Luís Henriques wrote: >> If casefolding the filename fails, we'll be leaking fscrypt_buf name. >> Make sure we free it in the error path. >> >> Signed-off-by: Luís Henriques <lhenriques@suse.de> >> --- >> fs/ext4/crypto.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c >> index e20ac0654b3f..9e4503b051c4 100644 >> --- a/fs/ext4/crypto.c >> +++ b/fs/ext4/crypto.c >> @@ -33,6 +33,8 @@ int ext4_fname_setup_filename(struct inode *dir, const struct qstr *iname, >> >> #if IS_ENABLED(CONFIG_UNICODE) >> err = ext4_fname_setup_ci_filename(dir, iname, fname); >> + if (err) >> + fscrypt_free_filename(&name); >> #endif >> return err; >> } > > Doesn't ext4_fname_prepare_lookup() have the same bug? Doh! I looked into that function too and then completely forgot about it. It may also call fscrypt_setup_filename(), so it has to do the free in the error path as well. I'll send out v2 to include that fix too. > Also, please include a Fixes tag. Ok, makes sense. Thanks! Cheers,
diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c index e20ac0654b3f..9e4503b051c4 100644 --- a/fs/ext4/crypto.c +++ b/fs/ext4/crypto.c @@ -33,6 +33,8 @@ int ext4_fname_setup_filename(struct inode *dir, const struct qstr *iname, #if IS_ENABLED(CONFIG_UNICODE) err = ext4_fname_setup_ci_filename(dir, iname, fname); + if (err) + fscrypt_free_filename(&name); #endif return err; }