Message ID | 20230803091713.13239-1-lhenriques@suse.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1058307vqx; Thu, 3 Aug 2023 03:51:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlFl94izQfoTekoGZhqsECiRK3rtG9u402CQ1hVoB2RFvn0oGuSFffBmx7v9DDCdXYVLWTOu X-Received: by 2002:a17:906:8a5b:b0:99b:bdff:b0ac with SMTP id gx27-20020a1709068a5b00b0099bbdffb0acmr7423130ejc.16.1691059861568; Thu, 03 Aug 2023 03:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691059861; cv=none; d=google.com; s=arc-20160816; b=A2t2+WePRx9+K3n6tb7DBo/3FjSfAZaB/4fHPBIGCXsYxoO3ChbHt5NElB+ZIyNzoe /uOSSAB0i7+aJyAMMu4LVH+vReKhCaT4pKByaMbwupe2lnZoTR+f3GI1bXMilBS6fM0i HnojtUwc3ByLTSwTd5+Qv2lwb8N7fxNswIoz1VqJ7uW873TqxbHVPR4YAZKwQd98CWwu ItziA8Zsaox5L2hJlWcrm5dFeG1g27ao13P5hkMcAzHma13XmL2d2NWdkSwFdCXFqNNS LYhTenq6wysBn//ZJyZHE1rlRr7lkFtC8u3Qkr3KWo+qsVw7LbCg5Q2sMWdHS8TLF2Kd 5APQ== 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=ZnMoWEEpAsUPtzHKTEyf3AXNncjwngOjcJYgFuxitFU=; fh=Podj8p+K1fkxTRmxRPx4mxr3QsttTSduPMq2N9o6PM8=; b=zuYRsd92T18n41pPK3Of3LQNelaHMrPlSjTDuGOR4oW0rRM0wwTQkbGVS8wHoffNaa T0+Vj7U3GVbWQbewtPdMsZlO2VhsCWzQhUTeutgSfeFDHGnkBD0MX366FnoGohNDW68p 1IQ/S1K/M1o3g5/jRFfrk6cr5Sk3/ygUMul3zaPwu0hIbJ4DVC5a27NwEAl26v3BrUbV DEkV0rLQetYaJxvJ8O8nbdgbxBl3yYxDueXc2b4WhPeloMArUZfcdr8ZMS41T9DeSK4X MrsqzxjzAbztG9elvnaaU8l0Glc05Mr/mpynA8VRVw2k1Lb6himH1VvG/KnhAe8GAzKK tzgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Vli1TgXK; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=kHOzd5ik; 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 h10-20020a170906854a00b0099bcf9c2ec5si7257623ejy.967.2023.08.03.03.50.35; Thu, 03 Aug 2023 03:51:01 -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=Vli1TgXK; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=kHOzd5ik; 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 S234572AbjHCJSO (ORCPT <rfc822;jeff.pang.chn@gmail.com> + 99 others); Thu, 3 Aug 2023 05:18:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235014AbjHCJRY (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 3 Aug 2023 05:17:24 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D78C430D2; Thu, 3 Aug 2023 02:17:16 -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-out1.suse.de (Postfix) with ESMTPS id 4238A219CB; Thu, 3 Aug 2023 09:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1691054235; 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=ZnMoWEEpAsUPtzHKTEyf3AXNncjwngOjcJYgFuxitFU=; b=Vli1TgXK3idTK2YIoKvKoLGunLGeyq34SmTTNZ3KnmH7lPjGBV7f+Z2S9a0PNoqt7EQsAM QOujKeAmIuZ0Mx1rqIBP9RCoIA0aRyDnugN7s6/kkPZ4L7GGla/OnsrPtrAT28rmrm3Sw9 986gTtv2dW4Q73IlgvNaYkZ7nKrgVb8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1691054235; 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=ZnMoWEEpAsUPtzHKTEyf3AXNncjwngOjcJYgFuxitFU=; b=kHOzd5ikuBiXaDMrk3M+0w3w2GPatGUoRW5JSLvdteZp4OEtG/tiIBXFN29cHlC27J3mAX A4Tp3Oxbh9IkXZDg== 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 C0D911333C; Thu, 3 Aug 2023 09:17:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id xYAdLJpwy2TEbQAAMHmgww (envelope-from <lhenriques@suse.de>); Thu, 03 Aug 2023 09:17:14 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id 53a1b5e5; Thu, 3 Aug 2023 09:17:14 +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>, Daniel Rosenberg <drosen@google.com>, Eric Biggers <ebiggers@kernel.org> 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 v3] ext4: fix memory leaks in ext4_fname_{setup_filename,prepare_lookup} Date: Thu, 3 Aug 2023 10:17:13 +0100 Message-Id: <20230803091713.13239-1-lhenriques@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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: 1773204785656358367 X-GMAIL-MSGID: 1773204785656358367 |
Series |
[v3] ext4: fix memory leaks in ext4_fname_{setup_filename,prepare_lookup}
|
|
Commit Message
Luis Henriques
Aug. 3, 2023, 9:17 a.m. UTC
If the filename casefolding fails, we'll be leaking memory from the
fscrypt_name struct, namely from the 'crypto_buf.name' member.
Make sure we free it in the error path on both ext4_fname_setup_filename()
and ext4_fname_prepare_lookup() functions.
Fixes: 1ae98e295fa2 ("ext4: optimize match for casefolded encrypted dirs")
Signed-off-by: Luís Henriques <lhenriques@suse.de>
---
Changes since v2:
- Rephrased commit log to (hopefully!) make it more clear.
- Use ext4_fname_free_filename() instead of fscrypt_free_filename().
Although not strictly needed, it cleans up the fname struct, removing a
dangling pointer to freed memory.
Changes since v1:
- Include fix to ext4_fname_prepare_lookup() as well
- Add 'Fixes:' tag
fs/ext4/crypto.c | 4 ++++
1 file changed, 4 insertions(+)
Comments
On Thu, Aug 03, 2023 at 10:17:13AM +0100, Luís Henriques wrote: > If the filename casefolding fails, we'll be leaking memory from the > fscrypt_name struct, namely from the 'crypto_buf.name' member. > > Make sure we free it in the error path on both ext4_fname_setup_filename() > and ext4_fname_prepare_lookup() functions. > > Fixes: 1ae98e295fa2 ("ext4: optimize match for casefolded encrypted dirs") > Signed-off-by: Luís Henriques <lhenriques@suse.de> > --- > Changes since v2: > - Rephrased commit log to (hopefully!) make it more clear. > - Use ext4_fname_free_filename() instead of fscrypt_free_filename(). > Although not strictly needed, it cleans up the fname struct, removing a > dangling pointer to freed memory. > > Changes since v1: > - Include fix to ext4_fname_prepare_lookup() as well > - Add 'Fixes:' tag > > fs/ext4/crypto.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c > index e20ac0654b3f..453d4da5de52 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) > + ext4_fname_free_filename(fname); > #endif > return err; > } > @@ -51,6 +53,8 @@ int ext4_fname_prepare_lookup(struct inode *dir, struct dentry *dentry, > > #if IS_ENABLED(CONFIG_UNICODE) > err = ext4_fname_setup_ci_filename(dir, &dentry->d_name, fname); > + if (err) > + ext4_fname_free_filename(fname); > #endif > return err; > } Reviewed-by: Eric Biggers <ebiggers@google.com> - Eric
On Thu, 03 Aug 2023 10:17:13 +0100, Luís Henriques wrote: > If the filename casefolding fails, we'll be leaking memory from the > fscrypt_name struct, namely from the 'crypto_buf.name' member. > > Make sure we free it in the error path on both ext4_fname_setup_filename() > and ext4_fname_prepare_lookup() functions. > > > [...] Applied, thanks! [1/1] ext4: fix memory leaks in ext4_fname_{setup_filename,prepare_lookup} commit: 7ca4b085f430f3774c3838b3da569ceccd6a0177 Best regards,
diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c index e20ac0654b3f..453d4da5de52 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) + ext4_fname_free_filename(fname); #endif return err; } @@ -51,6 +53,8 @@ int ext4_fname_prepare_lookup(struct inode *dir, struct dentry *dentry, #if IS_ENABLED(CONFIG_UNICODE) err = ext4_fname_setup_ci_filename(dir, &dentry->d_name, fname); + if (err) + ext4_fname_free_filename(fname); #endif return err; }