Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1948101rwo; Thu, 3 Aug 2023 02:17:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlFxZ6PFeAO7aa+gfs48j3Fs2tTQPCAqHP/ZJ2Hg5RAKIXaRSGOSHjzMuUGuoFrIw9cP7QTJ X-Received: by 2002:a17:906:20de:b0:99b:d698:152e with SMTP id c30-20020a17090620de00b0099bd698152emr7629451ejc.42.1691054237848; Thu, 03 Aug 2023 02:17:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691054237; cv=none; d=google.com; s=arc-20160816; b=n8F49Q6491a6iHqY7O61+B2x3Mew198PmHXS1JS/VdABuSIxwlA5NeO5/u+xBtAKrB u3pavDm1C1tYY2quhOpfnSGlpyWYN/iBob1zUYD7MR6KjZeB3WVcd+psl9iEvwSjXkVY nUANutWUR1S9WhDf3k9J1Hl5U9O3Kw9QgZJbo9VdUrqd5VNNUPFZJKZ5XWpD5JlJHV56 gGpkGy6kpbXkOTrLaXkNQOOJgLkmIaXuJftKKHW2h388xFSn/syGx23VSnSSxDO2NLGY MsCLGJfiV177UGIPzWx+JmF+orD+0ZrSBHsRFGRcqISBHGAqyH1pXeQAtvJ0T6Lprvcl frqA== 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:references:in-reply-to:subject:cc:to:from :dkim-signature:dkim-signature; bh=3n1Xwcb4VZeSgb4cQeQ3gMUuZkzy82ywXtFnmXwXFLo=; fh=FxDRQh+RjIvklnMJ8b+6wBZMm8mkpBzYau2TMeNUgag=; b=GEGjO9HdqqsaTrOMML+4ZyzhNP9MkpzkPC6OybyBxcFV+SaVyXLwwB2yt5fHX+/JxQ txolB8xga8imIQU6dQygqRYZrkhrvxXfRZFl9ItGYNaDVMZpwbzrXuPIcRZZD9nAyBBu pu+SvQjAoknuNJVLfOodJd+UbfK2KwAA1CZTT3jq4boZdPBkZvU9vwwjpyl+qp2CD3qe RO6hix1n0Pxdn4MRd/jbazS0OL7K2+8YYBKkRy3uSEd0Sr0hxluMrvLcyLPTS9daeznC gtIAzCSzDx735ILPgKNRdrHMs1Ri0JBg3n0HrMtyfU6duUIoBQ2/UF2ho0jfAdIYyEuu YQUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=UTFScJUN; dkim=neutral (no key) header.i=@suse.de; 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 p12-20020a170906228c00b0099bcc677cf2si11215985eja.726.2023.08.03.02.16.45; Thu, 03 Aug 2023 02:17:17 -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=UTFScJUN; dkim=neutral (no key) header.i=@suse.de; 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 S234408AbjHCI6Y (ORCPT + 99 others); Thu, 3 Aug 2023 04:58:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234857AbjHCI6T (ORCPT ); Thu, 3 Aug 2023 04:58:19 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6526EE58; Thu, 3 Aug 2023 01:58:18 -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 2371B219AE; Thu, 3 Aug 2023 08:58:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1691053097; 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: in-reply-to:in-reply-to:references:references; bh=3n1Xwcb4VZeSgb4cQeQ3gMUuZkzy82ywXtFnmXwXFLo=; b=UTFScJUNTHA/ifu6d7I8Bq1rCz1+plajC7GH+WD/DO1z/vFGnMb4O85CvXzOf7iUBQoBdm iaNG0J0ovupOZmkh9NlWiM7Lx9LwvbXVmxqXiBB1a/Izdau4Aoo7JFn5upnHve5PTIFaX2 qFpQK9XeHkJcPhkSabvlgNgbLjIiv84= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1691053097; 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: in-reply-to:in-reply-to:references:references; bh=3n1Xwcb4VZeSgb4cQeQ3gMUuZkzy82ywXtFnmXwXFLo=; b=OIvL1Hzv0YURFLHqO/DkC7i9CiIrVmFyWvH098+HiozNcz5F0fViL/PnMvxmJAuJgHHqPy sVNUo8sQ9LNvdIDw== 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 B3E50134B0; Thu, 3 Aug 2023 08:58:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id DF/gKChsy2TFYwAAMHmgww (envelope-from ); Thu, 03 Aug 2023 08:58:16 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id 66f404ce; Thu, 3 Aug 2023 08:58:15 +0000 (UTC) From: =?utf-8?Q?Lu=C3=ADs_Henriques?= To: Eric Biggers Cc: Theodore Ts'o , Andreas Dilger , Daniel Rosenberg , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] ext4: fix memory leaks in ext4_fname_{setup_filename,prepare_lookup} In-Reply-To: <20230803041918.GA1218@sol.localdomain> (Eric Biggers's message of "Wed, 2 Aug 2023 21:19:18 -0700") References: <20230802094931.18215-1-lhenriques@suse.de> <20230803041918.GA1218@sol.localdomain> Date: Thu, 03 Aug 2023 09:58:15 +0100 Message-ID: <87sf90v6xk.fsf@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: X-Mailing-List: linux-ext4@vger.kernel.org Eric Biggers writes: > On Wed, Aug 02, 2023 at 10:49:31AM +0100, Lu=C3=ADs Henriques wrote: >> If casefolding the filename fails, we'll be leaking fscrypt_buf name. > > fscrypt_buf =3D> fscrypt_name > >> 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, >> struct fscrypt_name name; >> int err; >> >> err =3D fscrypt_setup_filename(dir, iname, lookup, &name); >> if (err) >> return err; >> >> ext4_fname_from_fscrypt_name(fname, &name); >> >> #if IS_ENABLED(CONFIG_UNICODE) >> err =3D 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, struc= t dentry *dentry, >> struct fscrypt_name name; >> int err; >> >> err =3D fscrypt_prepare_lookup(dir, dentry, &name); >> if (err) >> return err; >> >> ext4_fname_from_fscrypt_name(fname, &name); >> >> #if IS_ENABLED(CONFIG_UNICODE) >> err =3D ext4_fname_setup_ci_filename(dir, &dentry->d_name, fname); >> + if (err) >> + fscrypt_free_filename(&name); >> #endif >> return err; >> } > > This works, but it's a bit weird that the freeing happens on the original= struct > fscrypt_name after it has already been "moved" to the struct ext4_filenam= e by > ext4_fname_from_fscrypt_name(). That leaves a dangling pointer in the st= ruct > ext4_filename. Maybe you should call ext4_fname_free_filename() instead,= even > though it would do some unnecessary work? That makes sense, specially because fname is a parameter and it's probably a good idea to clean-up everything before returning an error. Thanks. Cheers, --=20 Lu=C3=ADs