From patchwork Fri Mar 3 08:33:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 13158406 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D811C7EE2F for ; Fri, 3 Mar 2023 08:33:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbjCCIdg (ORCPT ); Fri, 3 Mar 2023 03:33:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbjCCIde (ORCPT ); Fri, 3 Mar 2023 03:33:34 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2C1E2D4C for ; Fri, 3 Mar 2023 00:33:33 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 6392E2299D; Fri, 3 Mar 2023 08:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677832412; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QXwSmFG6VXjVI6JJAGflb1UwkSfDosHgaPU3ut0vnks=; b=ZXMuo2UKKTyb39GpV7++hhW7+I7THTrQpastlOvYSPkQfzwbhsxhnib1B7pHtP+mkFEi5d Oqj7y7gII69SZ3SWRqK76Y2KyU49SKK8iduQy+hhmr+AA25/v8gYphiv1A6SCvvaoTmy+j /DV04qOwverKPfdRPQUR1uufP/dNr98= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677832412; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QXwSmFG6VXjVI6JJAGflb1UwkSfDosHgaPU3ut0vnks=; b=5jmY76BWxl4aQmgw+BTc/dBdNvsKr3Qnixd/JyBAsigQoVN9/yjveB/d+WW9M+zR/xFH6N X3Bm5CXKb1AJTxCg== Received: from localhost.localdomain (colyli.tcp.ovpn1.nue.suse.de [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id 3025D2C141; Fri, 3 Mar 2023 08:33:30 +0000 (UTC) From: Coly Li To: jes@trained-monkey.org Cc: linux-raid@vger.kernel.org, Coly Li Subject: [PATCH 1/6] util.c: code cleanup for parse_layout_faulty() Date: Fri, 3 Mar 2023 16:33:18 +0800 Message-Id: <20230303083323.3406-2-colyli@suse.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303083323.3406-1-colyli@suse.de> References: <20230303083323.3406-1-colyli@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org Resort the code lines in parse_layout_faulty() to make it more comfortable, no logic change. Signed-off-by: Coly Li Reviewed-by: Paul Menzel --- util.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/util.c b/util.c index 7fc881bf..b0b7aec4 100644 --- a/util.c +++ b/util.c @@ -421,12 +421,15 @@ int parse_layout_10(char *layout) int parse_layout_faulty(char *layout) { + int ln, mode; + char *m; + if (!layout) return -1; + /* Parse the layout string for 'faulty' */ - int ln = strcspn(layout, "0123456789"); - char *m = xstrdup(layout); - int mode; + ln = strcspn(layout, "0123456789"); + m = xstrdup(layout); m[ln] = 0; mode = map_name(faultylayout, m); if (mode == UnSet) From patchwork Fri Mar 3 08:33:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 13158407 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B80CC64EC4 for ; Fri, 3 Mar 2023 08:33:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229868AbjCCIdm (ORCPT ); Fri, 3 Mar 2023 03:33:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229850AbjCCIdh (ORCPT ); Fri, 3 Mar 2023 03:33:37 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2407014EAF for ; Fri, 3 Mar 2023 00:33:36 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id AFAC22299C; Fri, 3 Mar 2023 08:33:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677832414; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2I+Who3dVeWNwZoM5OltjMZpO4CJYuMNV8koUEN3Chs=; b=boFt2UQKm7ihvSXktkimUcr19w0sfJDIoas74OAjeZuUVvOjWIW+LUbcKE11cUQPCIdOJI Ef0pJROpQ2nKeOl36hMQtdTfVzysoftzWXAdqqZFeg+m5cTw6JGhVxPX4fNxyczExTQruz mmmEZ8mUnmB/ZgC+CmjG++BcPA9iqxk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677832414; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2I+Who3dVeWNwZoM5OltjMZpO4CJYuMNV8koUEN3Chs=; b=a5Ye5vLtMXhr/eIXsj2JOhD2YR51FnS7JGOjomeTLTTH8UpFVbjMyFI3BSkzbB19Bo5421 2rSFJgEVI8m+emDg== Received: from localhost.localdomain (colyli.tcp.ovpn1.nue.suse.de [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id CC5272C141; Fri, 3 Mar 2023 08:33:32 +0000 (UTC) From: Coly Li To: jes@trained-monkey.org Cc: linux-raid@vger.kernel.org, Wu Guanghao , Mariusz Tkaczyk , Coly Li Subject: [PATCH 2/6] util.c: fix memleak in parse_layout_faulty() Date: Fri, 3 Mar 2023 16:33:19 +0800 Message-Id: <20230303083323.3406-3-colyli@suse.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303083323.3406-1-colyli@suse.de> References: <20230303083323.3406-1-colyli@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org From: Wu Guanghao char *m is allocated by xstrdup but not free() before return, will cause a memory leak Signed-off-by: Wu Guanghao Acked-by: Mariusz Tkaczyk Acked-by: Coly Li --- util.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util.c b/util.c index b0b7aec4..9f1e1f7c 100644 --- a/util.c +++ b/util.c @@ -432,6 +432,8 @@ int parse_layout_faulty(char *layout) m = xstrdup(layout); m[ln] = 0; mode = map_name(faultylayout, m); + free(m); + if (mode == UnSet) return -1; From patchwork Fri Mar 3 08:33:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 13158408 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55F4FC678D4 for ; Fri, 3 Mar 2023 08:33:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229850AbjCCIdm (ORCPT ); Fri, 3 Mar 2023 03:33:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229886AbjCCIdl (ORCPT ); Fri, 3 Mar 2023 03:33:41 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB3201027F for ; Fri, 3 Mar 2023 00:33:38 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id C7A8020382; Fri, 3 Mar 2023 08:33:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677832416; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iqmQPr0U5NDHGeFXAGA2tVhQ0Oe5zBXzOz62yxjpU/4=; b=IwO82K5UuutjnTUVAsdepUd8viOzaZ6AhlHGAo15y7rlRvuXlOxOYh6gWuSzuQNtPRiY2q EHQpK7INZHrTDetABJj0W1lbObdQXk1uHHs66//p1Io+AyWwHfNaRPuOXAv0GtaTRm7tzz c58ZESVDfOqF142kKYw2ii99F6+D4pM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677832416; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iqmQPr0U5NDHGeFXAGA2tVhQ0Oe5zBXzOz62yxjpU/4=; b=/mEyOKx8xu3dKrL8vKIus/6B4kVRq/tqFhtlWR3pvTrq38vKEKNMsGNIQxfIof4eX3gwI+ epzPYlmLmJqYbjCA== Received: from localhost.localdomain (colyli.tcp.ovpn1.nue.suse.de [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id 213652C141; Fri, 3 Mar 2023 08:33:34 +0000 (UTC) From: Coly Li To: jes@trained-monkey.org Cc: linux-raid@vger.kernel.org, Wu Guanghao , Mariusz Tkaczyk , Coly Li Subject: [PATCH 3/6] Detail.c: fix memleak in Detail() Date: Fri, 3 Mar 2023 16:33:20 +0800 Message-Id: <20230303083323.3406-4-colyli@suse.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303083323.3406-1-colyli@suse.de> References: <20230303083323.3406-1-colyli@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org From: Wu Guanghao char *sysdev = xstrdup() but not free() in for loop, will cause memory leak Signed-off-by: Wu Guanghao Acked-by: Mariusz Tkaczyk Acked-by: Coly Li --- Detail.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Detail.c b/Detail.c index ce7a8445..4ef26460 100644 --- a/Detail.c +++ b/Detail.c @@ -303,6 +303,7 @@ int Detail(char *dev, struct context *c) if (path) printf("MD_DEVICE_%s_DEV=%s\n", sysdev, path); + free(sysdev); } } goto out; From patchwork Fri Mar 3 08:33:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 13158409 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E2A9C7EE32 for ; Fri, 3 Mar 2023 08:33:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229886AbjCCIdn (ORCPT ); Fri, 3 Mar 2023 03:33:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229962AbjCCIdl (ORCPT ); Fri, 3 Mar 2023 03:33:41 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3039A1554A for ; Fri, 3 Mar 2023 00:33:40 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id E2E4420384; Fri, 3 Mar 2023 08:33:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677832418; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nStWt9LyPd5i2JdOC1LgHiMs5zmzXfXoEFEz3VKzKSg=; b=hkChUcicGz5HmMLDIXby0CxAgBV3dzFn91DkHdyMHaRJeI3VUpC0KWP3mnAYmKim9M78ZW uq3vdMUa/ARhH2chQaVBWZXnoOR5c4xv8ob28AcfD4hxd8zxtr/KrqIb73afaitdBYoWZK VzBD17hoPj5elSLLUmc4d+6dQnBOjnI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677832418; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nStWt9LyPd5i2JdOC1LgHiMs5zmzXfXoEFEz3VKzKSg=; b=qdyNIDrc//aJUS7vNh0lA7VzN0VjNE4Ms3NAuCXsDgc80qItAMAQNyot8VcLICPUGWWkfe H6W5cxfnDEE0Z+Cw== Received: from localhost.localdomain (colyli.tcp.ovpn1.nue.suse.de [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id 3CAB92C141; Fri, 3 Mar 2023 08:33:37 +0000 (UTC) From: Coly Li To: jes@trained-monkey.org Cc: linux-raid@vger.kernel.org, Wu Guanghao , Mariusz Tkaczyk , Coly Li Subject: [PATCH 4/6] isuper-intel.c: fix double free in load_imsm_mpb() Date: Fri, 3 Mar 2023 16:33:21 +0800 Message-Id: <20230303083323.3406-5-colyli@suse.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303083323.3406-1-colyli@suse.de> References: <20230303083323.3406-1-colyli@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org From: Wu Guanghao In load_imsm_mpb() there is potential double free issue on super->buf. The first location to free super->buf is from get_super_block() <== load_and_parse_mpb() <== load_imsm_mpb(): 4514 if (posix_memalign(&super->migr_rec_buf, MAX_SECTOR_SIZE, 4515 MIGR_REC_BUF_SECTORS*MAX_SECTOR_SIZE) != 0) { 4516 pr_err("could not allocate migr_rec buffer\n"); 4517 free(super->buf); 4518 return 2; 4519 } If the above error condition happens, super->buf is freed and value 2 is returned to get_super_block() eventually. Then in the following code block inside load_imsm_mpb(), 5289 error: 5290 if (!err) { 5291 s->next = *super_list; 5292 *super_list = s; 5293 } else { 5294 if (s) 5295 free_imsm(s); 5296 close_fd(&dfd); 5297 } at line 5295 when free_imsm() is called, super->buf is freed again from the call chain free_imsm() <== __free_imsm(), in following code block, 4651 if (super->buf) { 4652 free(super->buf); 4653 super->buf = NULL; 4654 } This patch sets super->buf as NULL after line 4517 in load_imsm_mpb() to avoid the potential double free(). (Coly Li helps to re-compose the commit log) Signed-off-by: Wu Guanghao Reviewed-by: Mariusz Tkaczyk Acked-by: Coly Li --- super-intel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/super-intel.c b/super-intel.c index 89fac626..4a3da847 100644 --- a/super-intel.c +++ b/super-intel.c @@ -4515,6 +4515,7 @@ static int load_imsm_mpb(int fd, struct intel_super *super, char *devname) MIGR_REC_BUF_SECTORS*MAX_SECTOR_SIZE) != 0) { pr_err("could not allocate migr_rec buffer\n"); free(super->buf); + super->buf = NULL; return 2; } super->clean_migration_record_by_mdmon = 0; From patchwork Fri Mar 3 08:33:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 13158410 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 917B4C64EC4 for ; Fri, 3 Mar 2023 08:33:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbjCCIdt (ORCPT ); Fri, 3 Mar 2023 03:33:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229969AbjCCIdp (ORCPT ); Fri, 3 Mar 2023 03:33:45 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 573B11027F for ; Fri, 3 Mar 2023 00:33:42 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 0B32320386; Fri, 3 Mar 2023 08:33:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677832421; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KndKLdJIWK5FsuiK84M52PIMaqJZtY5y1+nTPnb7hTc=; b=fNqdr9rsrjjpD9vyIaZukloHVzwapwslndMnmcmI+uOMLItlIyN781yJaer75cLS1s9AA3 IK5qUUVx/ArXQdM8RzJAKQh+AC6Aw8myh6h4hFmOulFckAzFWMuphwXUlyTQM2pthGeUhS V7iDVWrVCxVZ+2DbP5DBMrCEiJdsQ6w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677832421; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KndKLdJIWK5FsuiK84M52PIMaqJZtY5y1+nTPnb7hTc=; b=ZZIviXzhx4kHI4rwKg4RtEOF7ONsJEg9caAMBGMHtpZqYTYeUplnjDYIvvYYIBEKEC477c Gw33MDV67CgeaGCw== Received: from localhost.localdomain (colyli.tcp.ovpn1.nue.suse.de [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id 584EC2C141; Fri, 3 Mar 2023 08:33:39 +0000 (UTC) From: Coly Li To: jes@trained-monkey.org Cc: linux-raid@vger.kernel.org, Wu Guanghao , Mariusz Tkaczyk , Coly Li Subject: [PATCH 5/6] super-intel.c: fix memleak in find_disk_attached_hba() Date: Fri, 3 Mar 2023 16:33:22 +0800 Message-Id: <20230303083323.3406-6-colyli@suse.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303083323.3406-1-colyli@suse.de> References: <20230303083323.3406-1-colyli@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org From: Wu Guanghao If disk_path = diskfd_to_devpath(), we need free(disk_path) before return, otherwise there will be a memory leak Signed-off-by: Wu Guanghao Reviewed-by: Mariusz Tkaczyk Acked-by: Coly Li --- super-intel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/super-intel.c b/super-intel.c index 4a3da847..e155a8ae 100644 --- a/super-intel.c +++ b/super-intel.c @@ -713,12 +713,12 @@ static struct sys_dev* find_disk_attached_hba(int fd, const char *devname) for (elem = list; elem; elem = elem->next) if (path_attached_to_hba(disk_path, elem->path)) - return elem; + break; if (disk_path != devname) free(disk_path); - return NULL; + return elem; } static int find_intel_hba_capability(int fd, struct intel_super *super, From patchwork Fri Mar 3 08:33:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 13158411 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90528C678D4 for ; Fri, 3 Mar 2023 08:34:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229912AbjCCIeE (ORCPT ); Fri, 3 Mar 2023 03:34:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230161AbjCCIdr (ORCPT ); Fri, 3 Mar 2023 03:33:47 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79DED19F1B for ; Fri, 3 Mar 2023 00:33:44 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 24B0C20388; Fri, 3 Mar 2023 08:33:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677832423; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UHysmSY16jNd7M5xVj60PNU0yvKD7xNuPUq8eJZEHeY=; b=xUMqbJnXmpF+hGFK0NWpSVJ5ZVanYWf8G+ifj2ovmumRCQqVrYX3IDaRsBBGptSMAFOAEA ku4E5S7LjtpwVhOwfPDtedexp8NAcjlI4ssngPcz1rMln5bRbYjpt4+NbiqhqzYDHkh/NU 1kMBQaAHqzCJmtAqdOoTje9bWjKeepk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677832423; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UHysmSY16jNd7M5xVj60PNU0yvKD7xNuPUq8eJZEHeY=; b=aefkx14ikLAh2zapGCLHSHkUbO/bT3wOCK0dAbUPtyJMsWR6YfQSg0dCTmWPccp3d2u7ut 2g9Y7EQkQ2cPl5Cw== Received: from localhost.localdomain (colyli.tcp.ovpn1.nue.suse.de [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id 738E62C141; Fri, 3 Mar 2023 08:33:41 +0000 (UTC) From: Coly Li To: jes@trained-monkey.org Cc: linux-raid@vger.kernel.org, Wu Guanghao , Mariusz Tkaczyk , Coly Li Subject: [PATCH 6/6] super-ddf.c: fix memleak in get_vd_num_of_subarray() Date: Fri, 3 Mar 2023 16:33:23 +0800 Message-Id: <20230303083323.3406-7-colyli@suse.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303083323.3406-1-colyli@suse.de> References: <20230303083323.3406-1-colyli@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org From: Wu Guanghao sra = sysfs_read() should be free before return in get_vd_num_of_subarray() Signed-off-by: Wu Guanghao Acked-by: Mariusz Tkaczyk Acked-by: Coly Li --- super-ddf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/super-ddf.c b/super-ddf.c index 309812df..b86c6acd 100644 --- a/super-ddf.c +++ b/super-ddf.c @@ -1592,15 +1592,20 @@ static unsigned int get_vd_num_of_subarray(struct supertype *st) sra = sysfs_read(-1, st->devnm, GET_VERSION); if (!sra || sra->array.major_version != -1 || sra->array.minor_version != -2 || - !is_subarray(sra->text_version)) + !is_subarray(sra->text_version)) { + if (sra) + sysfs_free(sra); return DDF_NOTFOUND; + } sub = strchr(sra->text_version + 1, '/'); if (sub != NULL) vcnum = strtoul(sub + 1, &end, 10); if (sub == NULL || *sub == '\0' || *end != '\0' || - vcnum >= be16_to_cpu(ddf->active->max_vd_entries)) + vcnum >= be16_to_cpu(ddf->active->max_vd_entries)) { + sysfs_free(sra); return DDF_NOTFOUND; + } return vcnum; }