From patchwork Fri Mar 3 16:21:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 13158980 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 27601C64EC4 for ; Fri, 3 Mar 2023 16:21:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbjCCQVs (ORCPT ); Fri, 3 Mar 2023 11:21:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229893AbjCCQVp (ORCPT ); Fri, 3 Mar 2023 11:21:45 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8769014235 for ; Fri, 3 Mar 2023 08:21:42 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 46C1A22CE6; Fri, 3 Mar 2023 16:21:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677860501; 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=54SgTPAd3VoihteNQuzvqd9msT4mLQmq9AcwcnzXCcI=; b=aKvSXppf3lbnd6TDiGFSwoq0G73xh5+Bdys6POmncORdTdHbH1MvNqO6y50sR8DeW9XQ4U chJkdDJMevlpKr1YS2Ww0Tpgy0CMO6c29CeIj7jkms5ZdWbANQ/DMjJMG6bvJgAh1AlkNa YxAlYbA7G9x+SQ8c572L9bXxRYwC8GE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677860501; 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=54SgTPAd3VoihteNQuzvqd9msT4mLQmq9AcwcnzXCcI=; b=OgVXK2A63yOBSIfw+MIi4RCTe8Wq13XGwHisOsbDBurbLKC4vXOG3doAZp4H+GKA8VreKK Tg2oFDwjzuKwkhBg== Received: from localhost.localdomain (unknown [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id 949282C141; Fri, 3 Mar 2023 16:21:39 +0000 (UTC) From: Coly Li To: jes@trained-monkey.org Cc: linux-raid@vger.kernel.org, mariusz.tkaczyk@linux.intel.com, pmenzel@molgen.mpg.de, Coly Li Subject: [PATCH v2 1/6] util.c: reorder code lines in parse_layout_faulty() Date: Sat, 4 Mar 2023 00:21:30 +0800 Message-Id: <20230303162135.45831-2-colyli@suse.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303162135.45831-1-colyli@suse.de> References: <20230303162135.45831-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 16:21:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 13158982 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 E38FCC64EC4 for ; Fri, 3 Mar 2023 16:21:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230389AbjCCQVv (ORCPT ); Fri, 3 Mar 2023 11:21:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230220AbjCCQVt (ORCPT ); Fri, 3 Mar 2023 11:21:49 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E78213D79 for ; Fri, 3 Mar 2023 08:21:44 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id A049720530; Fri, 3 Mar 2023 16:21:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677860503; 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=lGA0wVo+1+KPrHhrnz8O15WLQeftPGn+Qz+0+w1O1Xf3Tz2QnHQnKqGwwbk9knlMD4YfHQ lUneVZCWnRcittmxrxPh47Z8ubtMfs7VXTw9IYDKdFxVkORkfUrUKqD4BVMxiEX8rPjSRd ENo89uWJGxCMtHryDxCgmp8+Co43OP8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677860503; 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=4uURTNO5XWaSDNvXkrx5W8rPDattfcBN8pD+kWmJbVvPlxPZgZazzyl9tKXzuK8zYJLXpd /S58XQs6FW7wdPAw== Received: from localhost.localdomain (unknown [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id AECFA2C141; Fri, 3 Mar 2023 16:21:41 +0000 (UTC) From: Coly Li To: jes@trained-monkey.org Cc: linux-raid@vger.kernel.org, mariusz.tkaczyk@linux.intel.com, pmenzel@molgen.mpg.de, Wu Guanghao , Coly Li Subject: [PATCH v2 2/6] util.c: fix memleak in parse_layout_faulty() Date: Sat, 4 Mar 2023 00:21:31 +0800 Message-Id: <20230303162135.45831-3-colyli@suse.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303162135.45831-1-colyli@suse.de> References: <20230303162135.45831-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 16:21:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 13158981 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 C77DCC7EE2F for ; Fri, 3 Mar 2023 16:21:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229993AbjCCQVt (ORCPT ); Fri, 3 Mar 2023 11:21:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbjCCQVs (ORCPT ); Fri, 3 Mar 2023 11:21:48 -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 45E42BBBA for ; Fri, 3 Mar 2023 08:21:47 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 01B992052F; Fri, 3 Mar 2023 16:21:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677860506; 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=xU2FFodT2YCNqUH3H9lJVkmoqE9FJWsML2LXkiaIaVNq0/oIlHZ9g/7PnMKp5AfTgZ5CzR XWSTQDb6MR8dejD15UmyrJ9wu2c1QwkuPlJ0XMTTJ8jUZqo4beAc76z6XRELeaGWy24yrN n8OHbK7ZnTKsf+TGDLiWRctDPAMxe9c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677860506; 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=au962Zjpf9+e+SwVQby2KX01wmyyCP0Pd7JMWvx6g1dLLfHTSVdo9BZj0AzR5Qb9kB17CH VzR5Cfyi5ccgmUAw== Received: from localhost.localdomain (unknown [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id 145B12C141; Fri, 3 Mar 2023 16:21:43 +0000 (UTC) From: Coly Li To: jes@trained-monkey.org Cc: linux-raid@vger.kernel.org, mariusz.tkaczyk@linux.intel.com, pmenzel@molgen.mpg.de, Wu Guanghao , Coly Li Subject: [PATCH v2 3/6] Detail.c: fix memleak in Detail() Date: Sat, 4 Mar 2023 00:21:32 +0800 Message-Id: <20230303162135.45831-4-colyli@suse.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303162135.45831-1-colyli@suse.de> References: <20230303162135.45831-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 16:21:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 13158983 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 974FFC7EE2D for ; Fri, 3 Mar 2023 16:21:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230407AbjCCQVw (ORCPT ); Fri, 3 Mar 2023 11:21:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230304AbjCCQVu (ORCPT ); Fri, 3 Mar 2023 11:21:50 -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 925A522A32 for ; Fri, 3 Mar 2023 08:21:49 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 4C20620531; Fri, 3 Mar 2023 16:21:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677860508; 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=0tTfT7TwtQ/eQQ3NO6BoxNOBKivw/kP9WX9b8TdG4ACVxEdHzVn+0LMZ+W95jmKv0HfgYj ZF7z1foosByohAEmpPJpSRUOPk2n0X4WfLMBH92/BORQKkaByj0BX8KjzNyFiN0Cuo8EEj aKCQaJS+cmQTVqp5dPobVWTfGmtrt4Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677860508; 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=O86a0ATD67hg6WJ0tYNRGEw88sOJoY236bDQ/YxdQVyzy1epHKksRPGHwwzid8N4Bhqbzt GdM5YgUAz7HwC7Dw== Received: from localhost.localdomain (unknown [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id 69A4C2C141; Fri, 3 Mar 2023 16:21:46 +0000 (UTC) From: Coly Li To: jes@trained-monkey.org Cc: linux-raid@vger.kernel.org, mariusz.tkaczyk@linux.intel.com, pmenzel@molgen.mpg.de, Wu Guanghao , Coly Li Subject: [PATCH v2 4/6] isuper-intel.c: fix double free in load_imsm_mpb() Date: Sat, 4 Mar 2023 00:21:33 +0800 Message-Id: <20230303162135.45831-5-colyli@suse.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303162135.45831-1-colyli@suse.de> References: <20230303162135.45831-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 16:21:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 13158984 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 17D72C64EC4 for ; Fri, 3 Mar 2023 16:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230511AbjCCQWA (ORCPT ); Fri, 3 Mar 2023 11:22:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230424AbjCCQVx (ORCPT ); Fri, 3 Mar 2023 11:21:53 -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 E2B2014480 for ; Fri, 3 Mar 2023 08:21:51 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id A0A5A22C01; Fri, 3 Mar 2023 16:21:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677860510; 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=JC8WUKJ6XtxmpCWeq2mk4yl/UmxH7ZzPdNsfkNFWnlbGHv16qUmHeH+cL2ZPMWIlfYM/Sh PjN5IL+stfL4+hP0BPBdLUAGEfeiD1z/vb2rQRNDuBm/l6GmAANM41AqXUl1gm2phal4VR jXZI3KdqUnMuJdHQNgbP7jOWlydkLzM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677860510; 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=FiapPISoeXS2xm2BxnIzSMLMsHtWm/vz/UkfXdNYkXUDyTerlHtHGJEMDaWb7yBrbHvYFk LRs833Sta9UG6QAQ== Received: from localhost.localdomain (unknown [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id B4AB32C141; Fri, 3 Mar 2023 16:21:48 +0000 (UTC) From: Coly Li To: jes@trained-monkey.org Cc: linux-raid@vger.kernel.org, mariusz.tkaczyk@linux.intel.com, pmenzel@molgen.mpg.de, Wu Guanghao , Coly Li Subject: [PATCH v2 5/6] super-intel.c: fix memleak in find_disk_attached_hba() Date: Sat, 4 Mar 2023 00:21:34 +0800 Message-Id: <20230303162135.45831-6-colyli@suse.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303162135.45831-1-colyli@suse.de> References: <20230303162135.45831-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 16:21:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 13158985 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 80E51C7EE2D for ; Fri, 3 Mar 2023 16:22:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230220AbjCCQWB (ORCPT ); Fri, 3 Mar 2023 11:22:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230393AbjCCQV6 (ORCPT ); Fri, 3 Mar 2023 11:21:58 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46A815C10A for ; Fri, 3 Mar 2023 08:21:54 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id F319B20532; Fri, 3 Mar 2023 16:21:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677860513; 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=GyB6CW0x57QkjrgyKFKw/r5fFMd7GBf/rFSs2BuI5VlDKKve+Usw0ThWKFgHa3wScNwW3Z +l2IWA9py0pqap0t7Ty6NOChl39vU1MgHNjx7jL2QMbigwmgRs155CSaepwVcMabpNBsz2 NQR4im2PtVr/6UH01KtHIH/8KIn6Vow= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677860513; 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=D46n/w6jPbkp0Ldf8z8dzzVEofQiaL3hATQMne+TfknGExU/Px2SVHXnmsw/+5X5Ywntfr ++wKqYvvv8qg3QAQ== Received: from localhost.localdomain (unknown [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id 13EFC2C141; Fri, 3 Mar 2023 16:21:50 +0000 (UTC) From: Coly Li To: jes@trained-monkey.org Cc: linux-raid@vger.kernel.org, mariusz.tkaczyk@linux.intel.com, pmenzel@molgen.mpg.de, Wu Guanghao , Coly Li Subject: [PATCH v2 6/6] super-ddf.c: fix memleak in get_vd_num_of_subarray() Date: Sat, 4 Mar 2023 00:21:35 +0800 Message-Id: <20230303162135.45831-7-colyli@suse.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303162135.45831-1-colyli@suse.de> References: <20230303162135.45831-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; }