Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp747028rwo; Wed, 2 Aug 2023 03:39:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlFFKiObW6Tf2HWvOYaquEDsLFGVv1j2TLyQHown4vOowdSh4XW5MDbg3uMWOtt9x5kp6t1w X-Received: by 2002:a17:907:a079:b0:99b:4378:a5aa with SMTP id ia25-20020a170907a07900b0099b4378a5aamr4654104ejc.49.1690972769092; Wed, 02 Aug 2023 03:39:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690972769; cv=none; d=google.com; s=arc-20160816; b=D+4hdoRD+uFnivmhoaYmHyK8w4rtxwTetkRBrnw0soc3N87XFwbFTtdBjOboz3diha wo6WJUh5Ov2d7H+SLawulztY3SKXVFAXviQjbQpfd8y2sdh/F44A9uWMwrerPwAYJGl9 HK59tcjieIzyjkBPqetQB4riG08LCOQhd7PXAnAXNwspF1aiHNTXXkMcODV5Tn6achx4 qGipQ0XBz0dn2ManwHFxkk0iMIWAgs75sV62/8wib0QGrcbIqIDg2LoZoXRVJWR8Bo4W 2ojeMHvawW6hU2zgxnFUy4UQF6epN6uZZygck9sPsnDv/+s0gRKbFnHWI9v51UmYp7ct LkNw== 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=oG99N9wn1Zwsv4UxpgLJDybTYUZ52WwqDECex34X2Ok=; fh=Podj8p+K1fkxTRmxRPx4mxr3QsttTSduPMq2N9o6PM8=; b=ZK49Pq2kwRFe50oioSHJ7aOXur9AxaFEQ98DNcLTXyU747vHykfcEl+HeeXzSRhxpW dm6A487yL9iORWZH3HHX9lyb7fuVWDxISKj1LlgO5+b2R5WiByg/68Duavt3gsODxKSf 6qzv/c7WwtEFrHSisfoB3ojEkfBF4BS3nPI4nd3JJENO+HP+n8yj3rG3cChB6IQ83/mw 0F/RJAfvHW/2nY1Fdh1slaRGc+PS/Lk/F4oMc/nsYJApkgSeq7e/Aujh5lY6SyBQE38C M6lTwZIRpCIJm9jarv6KAfQDxdgE+Gje8GtOS9ji0AvHlwh6jFYMVSKiGH30ZL4djPrA k1dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=1jYsc+Xy; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=53er0okG; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b12-20020a170906038c00b00993a68a3af8si10834508eja.568.2023.08.02.03.38.59; Wed, 02 Aug 2023 03:39:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=1jYsc+Xy; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=53er0okG; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 S231703AbjHBJti (ORCPT + 99 others); Wed, 2 Aug 2023 05:49:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230396AbjHBJth (ORCPT ); Wed, 2 Aug 2023 05:49:37 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACF8FE57; Wed, 2 Aug 2023 02:49:36 -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 5F9C51F749; Wed, 2 Aug 2023 09:49:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1690969775; 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=oG99N9wn1Zwsv4UxpgLJDybTYUZ52WwqDECex34X2Ok=; b=1jYsc+Xy79TkLiVn8FyhO/kCudhhFlmkevXic8bQl4pI+sEVJzTa3j5QpCtwOF4vWXNci5 ycr/pF6rZEggWoev1UZWk4lp8ZVcy7hRYujImA6kHsfHNkNMfUiGAiWdwMdtUiYjlW5374 JWL1c+dngQvLpEOHaydpH+yOrfT03j0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1690969775; 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=oG99N9wn1Zwsv4UxpgLJDybTYUZ52WwqDECex34X2Ok=; b=53er0okG6zAS0kRbBncgS1qtXng3Y93tUmR9bxJXqjXIilpziX+PEA5fSnqfQ/b+DnPjcS ckvf68sWHKpFBACw== 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 E48FB13909; Wed, 2 Aug 2023 09:49:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id fpPoNK4mymRycAAAMHmgww (envelope-from ); Wed, 02 Aug 2023 09:49:34 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id a355a2d3; Wed, 2 Aug 2023 09:49:34 +0000 (UTC) From: =?UTF-8?q?Lu=C3=ADs=20Henriques?= To: Theodore Ts'o , Andreas Dilger , Daniel Rosenberg , Eric Biggers Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Lu=C3=ADs=20Henriques?= Subject: [PATCH v2] ext4: fix memory leaks in ext4_fname_{setup_filename,prepare_lookup} Date: Wed, 2 Aug 2023 10:49:31 +0100 Message-Id: <20230802094931.18215-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: X-Mailing-List: linux-ext4@vger.kernel.org If casefolding the filename fails, we'll be leaking fscrypt_buf name. Make sure we free it in the error paths of 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 --- 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..3c05c7f3415b 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; } @@ -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) + fscrypt_free_filename(&name); #endif return err; }