Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp164434rdb; Thu, 1 Feb 2024 05:22:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEi8sHT5BPY6qmWIHPhV2zTO8FphTjKk8ZMGkYWmF8ougjFIjbo9OaRgQcGARjhoAFWgeHb X-Received: by 2002:a05:6870:40c1:b0:218:e4c3:e34 with SMTP id l1-20020a05687040c100b00218e4c30e34mr2229042oal.55.1706793741955; Thu, 01 Feb 2024 05:22:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706793741; cv=pass; d=google.com; s=arc-20160816; b=HpmYLmdMuJJO7LxKwmVf+VYdyDchRIFnsD98Qh1ry2g5nPJVOgGfwdatCN2jbiZmSh OlMcQbFEVzbW0s5pIwr3g0qYscaXxGEJ0QT+E5VSNNIeipRDAKWFjG3gdA7ve/nb9NC8 E7rvxeeGhrNgk2VwSdMykqz7xAGYgupKPa1l1oTUtifsQ5vJzG4h3TwJ/m/Jhr8m+ziq Jcf+/GJZnbHwVnR8YUo+b6pdR69ARUjDuVyDTBnt6B7KiHjcCL3UZNAevG6d9TQNM7yc 7YgAA8VkJ337L3G78hjZE/J0vOcg57GxuqtcP1dhOI8fk1+l3ZqIZT4I91GgdLFc13/z IkFQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=bWvMf7BoFybjL6lpw2SsO4Njprr22Jd416PNaqzE/uw=; fh=d4Yv365X/L9bXW4nT1qP+FKnV4m4AYkcI/TwhjjFlrc=; b=HrcdSBY1N3EVrcdek6SU2KTtU7L8zG5FU7T4T+tHvoFrTlj/+wVvDyAAacMOomSjdj eKGMAvF3fhU5/ev682UGZLGefQ3YyZ+3H9XG31WfBTSRI08FAgBeyWj1F3YkZ40nY07M +FdgzHCHFBS/5sb8kePIdM7KNlqNF1yZtw0Y3clAgw+LbLOUzZxvJAgEMvDV+ILhc21r 97HmQXhWppj451dWQo6ZUeaz9M6jQhG43G6DJT63Vf47xoLL4xqnO+xmCB63f3EFzZu6 3pZvsZJplWA3Oy2KM2jAyatoPH/phFTgOFvVYzZPWze+2PU3yLYo3VdVq5egkfTy4iPl Pr3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-48182-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48182-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCW7sOisDXE2ZL7dbH5ji9fd5UFL1AqrTQuZeyEIlZZKfoMXmyFU2lB/JyBDyq1mn8PSveBqoKpB39z6KW4J2ehmCpt8YdBe85VspeF4KA== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id s186-20020a6377c3000000b005d8baa20a39si9924471pgc.312.2024.02.01.05.22.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 05:22:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48182-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-48182-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48182-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5D335B2753A for ; Thu, 1 Feb 2024 13:01:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D6658665E; Thu, 1 Feb 2024 13:00:48 +0000 (UTC) Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net (zg8tmtyylji0my4xnjqumte4.icoremail.net [162.243.164.118]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 37AE52135B; Thu, 1 Feb 2024 13:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.164.118 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706792447; cv=none; b=AUobfvaTUI9vj2NmEoOXjWbhWBpxz4D+6JD3zgHHfpRf73T7YZIWQGG/TAOnAK34TMkhvhgCcp1vXtonTMvTlTsDuJADkUf11nKuqP5OLWgAVx3OT3AHnQMZwDdtTQIsW4dmNnKBdYDGjZVnWmGgKQSxPxYiToUfuLZzCtXjSoQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706792447; c=relaxed/simple; bh=KGwHBmWrAATKZPHoOixC25AHQc2bWnaKnUFnY/2WAO0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=RNXvXgnOFDYuEBk0efhpnRmBHSaohDhUK+rEX2EhlXFwpDTqdDcFZbOjE5sY9lVZJsFaalAiWh5IRdCdy9zr+PV8BqugYaOBXBqwXZkv2C+fzKSoMC7iWEmJtAUPr3ouVX+J6opnzr3cJPS6QboMuz7+7ZR6S5oGFkF1BnmaUqw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn; spf=pass smtp.mailfrom=zju.edu.cn; arc=none smtp.client-ip=162.243.164.118 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zju.edu.cn Received: from luzhipeng.223.5.5.5 (unknown [60.177.98.222]) by mail-app3 (Coremail) with SMTP id cC_KCgCXezX0lbtlXt3jAA--.1379S2; Thu, 01 Feb 2024 21:00:37 +0800 (CST) From: Zhipeng Lu To: alexious@zju.edu.cn Cc: Desmond Cheong Zhi Xi , Viacheslav Dubeyko , Andrew Morton , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] hfs: fix a memleak in hfs_find_init Date: Thu, 1 Feb 2024 21:00:24 +0800 Message-Id: <20240201130027.3058006-1-alexious@zju.edu.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cC_KCgCXezX0lbtlXt3jAA--.1379S2 X-Coremail-Antispam: 1UD129KBjvdXoW7GFy5Cw43Kw45Jw48Gr1UGFg_yoWDGwb_Za 1xu3s2gw1kur9xA34avF9YqFWDGa929r4xWr47tF18K39a9a4xGFs2qr95AryfWF12kryx JryUJ3yF93ZxXjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb4xFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j 6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWU AVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14 v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkG c2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4U MIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUSNtxUUU UU= X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ In every caller of hfs_find_init, `ptr` won't be freed when hfs_find_init fails, but will be freed when somewhere after hfs_find_init fails. This suggests that hfs_find_init should proberly free `ptr` in its own error-handling to prevent `ptr` from leaking. In particular, When the switch statment goes to default and return an error, `ptr` should be freed. Fixes: b3b2177a2d79 ("hfs: add lock nesting notation to hfs_find_init") Signed-off-by: Zhipeng Lu --- Changelog: v2: Improve commit message to be more clear. --- fs/hfs/bfind.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/hfs/bfind.c b/fs/hfs/bfind.c index ef9498a6e88a..7aa3b9aba4d1 100644 --- a/fs/hfs/bfind.c +++ b/fs/hfs/bfind.c @@ -36,6 +36,7 @@ int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd) mutex_lock_nested(&tree->tree_lock, ATTR_BTREE_MUTEX); break; default: + kfree(fd->search_key); return -EINVAL; } return 0; -- 2.34.1