From patchwork Fri Dec 3 06:26:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanchengbin X-Patchwork-Id: 1563117 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee2:21ea]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J52sF5j7Kz9t1r for ; Fri, 3 Dec 2021 17:26:25 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee2:21ea]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4J52s847GVz4xYy for ; Fri, 3 Dec 2021 17:26:20 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4J52s83wPCz4xbC; Fri, 3 Dec 2021 17:26:20 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4J52s83s93z4xYy for ; Fri, 3 Dec 2021 17:26:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378575AbhLCG3n (ORCPT ); Fri, 3 Dec 2021 01:29:43 -0500 Received: from szxga01-in.huawei.com ([45.249.212.187]:32870 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232133AbhLCG3m (ORCPT ); Fri, 3 Dec 2021 01:29:42 -0500 Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4J52rx1Tq0zcbJx; Fri, 3 Dec 2021 14:26:09 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Fri, 3 Dec 2021 14:26:17 +0800 Received: from [10.174.176.102] (10.174.176.102) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Fri, 3 Dec 2021 14:26:17 +0800 Message-ID: <622dc317-a9cb-2541-b357-a868d31a9605@huawei.com> Date: Fri, 3 Dec 2021 14:26:16 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: [PATCH 1/6] e2fsck: set s->len=0 if malloc() fails in alloc_string() From: zhanchengbin To: Theodore Ts'o CC: , , References: <37c58382-9714-7e99-6c4d-01b78cfdbd26@huawei.com> In-Reply-To: <37c58382-9714-7e99-6c4d-01b78cfdbd26@huawei.com> X-Originating-IP: [10.174.176.102] X-ClientProxiedBy: dggpeml500001.china.huawei.com (7.185.36.227) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org In alloc_string(), when malloc fails, len in the string structure should be 0. Signed-off-by: zhanchengbin Signed-off-by: Zhiqiang Liu --- e2fsck/logfile.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/e2fsck/logfile.c b/e2fsck/logfile.c index 63e9a12f..f2227ad5 100644 --- a/e2fsck/logfile.c +++ b/e2fsck/logfile.c @@ -32,6 +32,8 @@ static void alloc_string(struct string *s, int len) { s->s = malloc(len); /* e2fsck_allocate_memory(ctx, len, "logfile name"); */ + if (s->s == NULL) + s->len = 0; s->len = len; s->end = 0; } From patchwork Fri Dec 3 06:27:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanchengbin X-Patchwork-Id: 1563118 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee2:21ea]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J52ty4jHmz9t1r for ; Fri, 3 Dec 2021 17:27:54 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee2:21ea]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4J52ty3v64z4xYy for ; Fri, 3 Dec 2021 17:27:54 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4J52ty3r74z4xZ4; Fri, 3 Dec 2021 17:27:54 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4J52ty3lZKz4xYy for ; Fri, 3 Dec 2021 17:27:54 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234195AbhLCGbR (ORCPT ); Fri, 3 Dec 2021 01:31:17 -0500 Received: from szxga08-in.huawei.com ([45.249.212.255]:29084 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232133AbhLCGbQ (ORCPT ); Fri, 3 Dec 2021 01:31:16 -0500 Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4J52ql6FqWz1DJlq; Fri, 3 Dec 2021 14:25:07 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Fri, 3 Dec 2021 14:27:51 +0800 Received: from [10.174.176.102] (10.174.176.102) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Fri, 3 Dec 2021 14:27:51 +0800 Message-ID: <10e7ffbc-2d79-f970-a55a-a219ebd32f24@huawei.com> Date: Fri, 3 Dec 2021 14:27:50 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: [PATCH 2/6] lib/ss: check whether argp is null before accessing it in ss_execute_command() From: zhanchengbin To: Theodore Ts'o CC: , , References: <37c58382-9714-7e99-6c4d-01b78cfdbd26@huawei.com> In-Reply-To: <37c58382-9714-7e99-6c4d-01b78cfdbd26@huawei.com> X-Originating-IP: [10.174.176.102] X-ClientProxiedBy: dggpeml500001.china.huawei.com (7.185.36.227) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org In ss_execute_command(), we should check whether argp is null before accessing it, otherwise the null potinter dereference error may occur. Signed-off-by: zhanchengbin Signed-off-by: Zhiqiang Liu --- lib/ss/execute_cmd.c | 2 ++ 1 file changed, 2 insertions(+) i = really_execute_command(sci_idx, argc, &argp); diff --git a/lib/ss/execute_cmd.c b/lib/ss/execute_cmd.c index d443a468..b6e4a5dc 100644 --- a/lib/ss/execute_cmd.c +++ b/lib/ss/execute_cmd.c @@ -171,6 +171,8 @@ int ss_execute_command(int sci_idx, register char *argv[]) for (argp = argv; *argp; argp++) argc++; argp = (char **)malloc((argc+1)*sizeof(char *)); + if (argp == NULL) + return (SS_ET_COMMAND_NOT_FOUND); for (i = 0; i <= argc; i++) argp[i] = argv[i]; From patchwork Fri Dec 3 06:28:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanchengbin X-Patchwork-Id: 1563119 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee2:21ea]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J52w80HCVz9t1r for ; Fri, 3 Dec 2021 17:28:56 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee2:21ea]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4J52w76bGYz4xZ4 for ; Fri, 3 Dec 2021 17:28:55 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4J52w76Xswz4xbC; Fri, 3 Dec 2021 17:28:55 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4J52w76TpTz4xZ4 for ; Fri, 3 Dec 2021 17:28:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378575AbhLCGcS (ORCPT ); Fri, 3 Dec 2021 01:32:18 -0500 Received: from szxga01-in.huawei.com ([45.249.212.187]:32871 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232133AbhLCGcS (ORCPT ); Fri, 3 Dec 2021 01:32:18 -0500 Received: from dggpeml500022.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4J52vx1Pwxzcbp2; Fri, 3 Dec 2021 14:28:45 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Fri, 3 Dec 2021 14:28:53 +0800 Received: from [10.174.176.102] (10.174.176.102) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Fri, 3 Dec 2021 14:28:53 +0800 Message-ID: <71ed1c9e-7e23-9f73-e7b9-55810963f4f3@huawei.com> Date: Fri, 3 Dec 2021 14:28:52 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: [PATCH 3/6] lib/support: check whether inump is null before accessing it in quota_set_sb_inum() From: zhanchengbin To: Theodore Ts'o CC: , , References: <37c58382-9714-7e99-6c4d-01b78cfdbd26@huawei.com> In-Reply-To: <37c58382-9714-7e99-6c4d-01b78cfdbd26@huawei.com> X-Originating-IP: [10.174.176.102] X-ClientProxiedBy: dggpeml500001.china.huawei.com (7.185.36.227) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org In quota_set_sb_inum(), we should check whether inump is null before accessing it, otherwise the null potinter dereference error may occur. Signed-off-by: zhanchengbin Signed-off-by: Zhiqiang Liu --- lib/support/mkquota.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/support/mkquota.c b/lib/support/mkquota.c index 6f4a0b90..482e3d91 100644 --- a/lib/support/mkquota.c +++ b/lib/support/mkquota.c @@ -99,7 +99,8 @@ void quota_set_sb_inum(ext2_filsys fs, ext2_ino_t ino, enum quota_type qtype) log_debug("setting quota ino in superblock: ino=%u, type=%d", ino, qtype); - *inump = ino; + if (inump != NULL) + *inump = ino; ext2fs_mark_super_dirty(fs); } From patchwork Fri Dec 3 06:29:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanchengbin X-Patchwork-Id: 1563120 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee2:21ea]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J52xB4t7xz9t1r for ; Fri, 3 Dec 2021 17:29:50 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4J52xB499lz4xZ4 for ; Fri, 3 Dec 2021 17:29:50 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4J52xB45S8z4xbC; Fri, 3 Dec 2021 17:29:50 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4J52xB3w6yz4xZ4 for ; Fri, 3 Dec 2021 17:29:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378576AbhLCGdN (ORCPT ); Fri, 3 Dec 2021 01:33:13 -0500 Received: from szxga03-in.huawei.com ([45.249.212.189]:29150 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232133AbhLCGdL (ORCPT ); Fri, 3 Dec 2021 01:33:11 -0500 Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4J52tp6ns9zXdWj; Fri, 3 Dec 2021 14:27:46 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Fri, 3 Dec 2021 14:29:47 +0800 Received: from [10.174.176.102] (10.174.176.102) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Fri, 3 Dec 2021 14:29:46 +0800 Message-ID: <861a4e77-66dc-2c0d-46b9-0af2666a988a@huawei.com> Date: Fri, 3 Dec 2021 14:29:46 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: [PATCH 4/6] e2fsprogs: call ext2fs_badblocks_list_free() to free list in exception branch From: zhanchengbin To: Theodore Ts'o CC: , , References: <37c58382-9714-7e99-6c4d-01b78cfdbd26@huawei.com> In-Reply-To: <37c58382-9714-7e99-6c4d-01b78cfdbd26@huawei.com> X-Originating-IP: [10.174.176.102] X-ClientProxiedBy: dggpeml500001.china.huawei.com (7.185.36.227) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org In the exception branch, not call ext2fs_badblocks_list_free() to free list, it will cause memory leak. Signed-off-by: zhanchengbin Signed-off-by: Zhiqiang Liu --- misc/dumpe2fs.c | 1 + resize/resize2fs.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c index 3f4fc4ed..ef6d1cb8 100644 --- a/misc/dumpe2fs.c +++ b/misc/dumpe2fs.c @@ -338,6 +338,7 @@ static void list_bad_blocks(ext2_filsys fs, int dump) if (retval) { com_err("ext2fs_badblocks_list_iterate_begin", retval, "%s", _("while printing bad block list")); + ext2fs_badblocks_list_free(bb_list); return; } if (dump) { diff --git a/resize/resize2fs.c b/resize/resize2fs.c index 73174be0..740cec48 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -1781,11 +1781,11 @@ static errcode_t block_mover(ext2_resize_t rfs) fs->inode_blocks_per_group, &rfs->itable_buf); if (retval) - return retval; + goto errout; } retval = ext2fs_create_extent_table(&rfs->bmap, 0); if (retval) - return retval; + goto errout; /* * The first step is to figure out where all of the blocks From patchwork Fri Dec 3 06:30:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanchengbin X-Patchwork-Id: 1563121 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J52y33s2nz9t1r for ; Fri, 3 Dec 2021 17:30:35 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4J52y337lBz4xR5 for ; Fri, 3 Dec 2021 17:30:35 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4J52y335hPz4xbC; Fri, 3 Dec 2021 17:30:35 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4J52y32x5hz4xR5 for ; Fri, 3 Dec 2021 17:30:35 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378580AbhLCGd6 (ORCPT ); Fri, 3 Dec 2021 01:33:58 -0500 Received: from szxga01-in.huawei.com ([45.249.212.187]:32872 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232133AbhLCGd4 (ORCPT ); Fri, 3 Dec 2021 01:33:56 -0500 Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4J52xq72VGzcbdx; Fri, 3 Dec 2021 14:30:23 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Fri, 3 Dec 2021 14:30:32 +0800 Received: from [10.174.176.102] (10.174.176.102) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Fri, 3 Dec 2021 14:30:32 +0800 Message-ID: Date: Fri, 3 Dec 2021 14:30:31 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: [PATCH 5/6] e2fsck: check whether ldesc is null before accessing it in end_problem_latch() From: zhanchengbin To: Theodore Ts'o CC: , , References: <37c58382-9714-7e99-6c4d-01b78cfdbd26@huawei.com> In-Reply-To: <37c58382-9714-7e99-6c4d-01b78cfdbd26@huawei.com> X-Originating-IP: [10.174.176.102] X-ClientProxiedBy: dggpeml500001.china.huawei.com (7.185.36.227) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org In end_problem_latch(), ldesc need check not NULL before dereference. Signed-off-by: zhanchengbin --- e2fsck/problem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/e2fsck/problem.c b/e2fsck/problem.c index f454dcb7..fd814f9e 100644 --- a/e2fsck/problem.c +++ b/e2fsck/problem.c @@ -2394,6 +2394,8 @@ int end_problem_latch(e2fsck_t ctx, int mask) int answer = -1; ldesc = find_latch(mask); + if (!ldesc) + return answer; if (ldesc->end_message && (ldesc->flags & PRL_LATCHED)) { clear_problem_context(&pctx); answer = fix_problem(ctx, ldesc->end_message, &pctx); From patchwork Fri Dec 3 06:31:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanchengbin X-Patchwork-Id: 1563122 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J52yt0RXsz9t1r for ; Fri, 3 Dec 2021 17:31:18 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4J52ys6rM2z4xR5 for ; Fri, 3 Dec 2021 17:31:17 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4J52ys6nc3z4xbC; Fri, 3 Dec 2021 17:31:17 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4J52ys6kP0z4xR5 for ; Fri, 3 Dec 2021 17:31:17 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378582AbhLCGek (ORCPT ); Fri, 3 Dec 2021 01:34:40 -0500 Received: from szxga02-in.huawei.com ([45.249.212.188]:16339 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378580AbhLCGek (ORCPT ); Fri, 3 Dec 2021 01:34:40 -0500 Received: from dggpeml500026.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4J52y90JwLz91bg; Fri, 3 Dec 2021 14:30:41 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggpeml500026.china.huawei.com (7.185.36.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Fri, 3 Dec 2021 14:31:15 +0800 Received: from [10.174.176.102] (10.174.176.102) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Fri, 3 Dec 2021 14:31:14 +0800 Message-ID: <7bd86fda-90f1-601f-05b2-b247b5dd6bed@huawei.com> Date: Fri, 3 Dec 2021 14:31:14 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: [PATCH 6/6] lib/ext2fs: call ext2fs_free_mem() to free &io->name in exception branch From: zhanchengbin To: Theodore Ts'o CC: , , References: <37c58382-9714-7e99-6c4d-01b78cfdbd26@huawei.com> In-Reply-To: <37c58382-9714-7e99-6c4d-01b78cfdbd26@huawei.com> X-Originating-IP: [10.174.176.102] X-ClientProxiedBy: dggpeml500001.china.huawei.com (7.185.36.227) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org In the exception branch,if we donot call ext2fs_free_mem() to free &io->name, memory leak will occur. Signed-off-by: zhanchengbin Signed-off-by: Zhiqiang Liu --- lib/ext2fs/test_io.c | 2 ++ lib/ext2fs/undo_io.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/ext2fs/test_io.c b/lib/ext2fs/test_io.c index 480e68fc..6843edbc 100644 --- a/lib/ext2fs/test_io.c +++ b/lib/ext2fs/test_io.c @@ -248,6 +248,8 @@ static errcode_t test_open(const char *name, int flags, io_channel *channel) return 0; cleanup: + if (io && io->name) + ext2fs_free_mem(&io->name); if (io) ext2fs_free_mem(&io); if (data) diff --git a/lib/ext2fs/undo_io.c b/lib/ext2fs/undo_io.c index eb56f53d..0d4915cb 100644 --- a/lib/ext2fs/undo_io.c +++ b/lib/ext2fs/undo_io.c @@ -788,6 +788,8 @@ cleanup: free(data->tdb_file); if (data && data->real) io_channel_close(data->real); + if (io && io->name) + ext2fs_free_mem(&io->name); if (data) ext2fs_free_mem(&data); if (io)