Message ID | 20221229075323.1394010-1-linmq006@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2285875wrt; Thu, 29 Dec 2022 00:03:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXtitjiOvtSQhJcZVsYaQ4cMuDJqQiWpl4uy2D4ZpUL2ed7betm9eqncHA2WmX5Txfg1eQ7w X-Received: by 2002:a17:90b:1110:b0:225:c6fa:97cb with SMTP id gi16-20020a17090b111000b00225c6fa97cbmr20553570pjb.21.1672301023399; Thu, 29 Dec 2022 00:03:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672301023; cv=none; d=google.com; s=arc-20160816; b=UJeaIoAcXkRbq8leVOjNKn482hV/OgQSWLJoR6+AoPkpEMaQb8hYITVSasJz8GRkP0 C73epNTQr7n5msSIgnwfqzr7JDbslBH3M5daGXJ96rv6PXfmeErBwepBBcC5R8qslFwb A45v5Uobl3TxHc4lP9OlMigZpaVVQJ7HdmkckdXWxFZFAmu8VUTyE64BvCa18Zr0J9UO QN5zS7GTZlYogNN0fWlWZzraT4sPj3rwZSDCFTBJHR3nrl5Wp6sxGWWmQW4qHY5imROA Du7352CM/7yCThOHXb1b+uzicNWXFuw5MmAcNtu6c2N3wQW8bFA0At6RghVYYRcaFCNA WYJQ== 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:subject:to:from:dkim-signature; bh=wDeSYbJRD5UIxf0kkPf6Les3H3nIVnzcLc/ji7ALnCE=; b=fp9mXxZR5WRXCWcGs7py75udC7GcWzQnv4dKXZ/sjME6AMedh7bskUvXWvtUGXt5Hl Yduen2MTNVJs5nLh7sy7oZiNy02WQ5hJIWal/EATzvFfgcsfHPIzfz4qF5H6wqp8pZ9h UsXNspG3xzBJZzu0kUVkl7CdSclcjFxDFIZmRAkMVtFK0XfmuH7+nMS6ficv59CG83jw ywm2e+Pkf3UZvV8m6Y8a2C5uGeaeGnC7EOHrnMf8LXfgoSmPac5No859vPMAp6T/XPlS OChjOkEQcxTP2RfcneZ20FLKmHoQMdEaNOjO/Kmd4fLAz+/IlU7HmkDyqJzlyKF6gieP bLxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qtpzgTHl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r23-20020a634417000000b004782ca58117si18827545pga.611.2022.12.29.00.03.25; Thu, 29 Dec 2022 00:03:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@gmail.com header.s=20210112 header.b=qtpzgTHl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233008AbiL2Hxi (ORCPT <rfc822;eddaouddi.ayoub@gmail.com> + 99 others); Thu, 29 Dec 2022 02:53:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230237AbiL2Hxe (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 29 Dec 2022 02:53:34 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B95EF585 for <linux-kernel@vger.kernel.org>; Wed, 28 Dec 2022 23:53:33 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id k19so4464896pfg.11 for <linux-kernel@vger.kernel.org>; Wed, 28 Dec 2022 23:53:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=wDeSYbJRD5UIxf0kkPf6Les3H3nIVnzcLc/ji7ALnCE=; b=qtpzgTHlnAUEX2ly37pMS8tGaRlIXK0hm2KhLHj9n1OgGC9mPJ4R3s1wEEjDXcr7v8 LH/xO2CKUW7TThMnCXMQEU9Fk5xFelRz6bQcuIWar7ylBvHdnqsKlrLT9D6avGwhi1k3 LmoOfoEoWvjBIA2cf40UqTdy6hKv1svsnmqN10EGTR7WwHtxWgAwe08tA8Sp5BiuBktj 2ju9o7VcUAj4/KeelGsnMQNp3IcuNtJuvIASxr7+eJX/yilF8MgvPSYnudnfAm3/5xvt i0tWic8Sgt7ZkiBubZUj1ckNt5qyowqTIWpqOgNKZPebk0yxzwrGsJBHf+fMUC3tgzj5 Y/2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wDeSYbJRD5UIxf0kkPf6Les3H3nIVnzcLc/ji7ALnCE=; b=zhURCT4uDETmXKC9umyxVE8I65Elkdzwr4Eu0Lznt0fVPIiHwQ89a/uAoai5CxP2l3 yZYT/PM0t1bOnGThzrwPR3Blgzw3BIebU6AmXwP2BRDXTn6bU0yFJa/9hdYnexKz3nHp nS1jZmqkzF6U0OFfn9PsTrAB8dc7eVMcoAXivCWzwDLbyl4NCmwWd2RgVR9tU4foCb/9 Klj6WxsbdNT/6S9XmNoofDL7Al56D5gz8TLA0H1NoLz14DE/xw5wUVZMKNHQcmSCfVUO d3uDDc3g6j2/WHEufyL6MSNqkajaf5mqTipkj23FaavLanVr3K7SDHHv1f55CyOpWGtx ZVpQ== X-Gm-Message-State: AFqh2kpZmVKzDkTl5yhcUy2ZYB4Q7hgy3J5Tq05eu6Aqu9J86wi5xx07 U7DQ/iAu8K+lB3iWLXj2qA0= X-Received: by 2002:a05:6a00:410b:b0:57a:9482:843b with SMTP id bu11-20020a056a00410b00b0057a9482843bmr31812196pfb.5.1672300412939; Wed, 28 Dec 2022 23:53:32 -0800 (PST) Received: from localhost.localdomain ([202.120.234.246]) by smtp.googlemail.com with ESMTPSA id x24-20020aa78f18000000b0058134d2df41sm6126235pfr.146.2022.12.28.23.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 23:53:32 -0800 (PST) From: Miaoqian Lin <linmq006@gmail.com> To: Richard Weinberger <richard@nod.at>, Anton Ivanov <anton.ivanov@cambridgegreys.com>, Johannes Berg <johannes@sipsolutions.net>, Jakub Kicinski <kuba@kernel.org>, Miaoqian Lin <linmq006@gmail.com>, "David S. Miller" <davem@davemloft.net>, Wolfram Sang <wsa+renesas@sang-engineering.com>, linux-um@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] um: vector: Fix memory leak in vector_config Date: Thu, 29 Dec 2022 11:53:21 +0400 Message-Id: <20221229075323.1394010-1-linmq006@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753534717980598910?= X-GMAIL-MSGID: =?utf-8?q?1753534717980598910?= |
Series |
um: vector: Fix memory leak in vector_config
|
|
Commit Message
Miaoqian Lin
Dec. 29, 2022, 7:53 a.m. UTC
kstrdup() return newly allocated copy of the string.
Call kfree() to release the memory when after use.
Fixes: 49da7e64f33e ("High Performance UML Vector Network Driver")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
arch/um/drivers/vector_kern.c | 1 +
1 file changed, 1 insertion(+)
Comments
Hi Miaoqian, On Thu, Dec 29, 2022 at 8:53 AM Miaoqian Lin <linmq006@gmail.com> wrote: > kstrdup() return newly allocated copy of the string. > Call kfree() to release the memory when after use. > > Fixes: 49da7e64f33e ("High Performance UML Vector Network Driver") > Signed-off-by: Miaoqian Lin <linmq006@gmail.com> Thanks for your patch! > --- a/arch/um/drivers/vector_kern.c > +++ b/arch/um/drivers/vector_kern.c > @@ -765,6 +765,7 @@ static int vector_config(char *str, char **error_out) > > parsed = uml_parse_vector_ifspec(params); > > + kfree(params); Are you sure the memory pointed to by "params" is no longer used? "parsed" seems to contain pointers pointing to (parts of) the string pointed to by "params", so it cannot be freed. > if (parsed == NULL) { > *error_out = "vector_config failed to parse parameters"; > return -EINVAL; Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
On 03/01/2023 08:00, Geert Uytterhoeven wrote: > Hi Miaoqian, > > On Thu, Dec 29, 2022 at 8:53 AM Miaoqian Lin <linmq006@gmail.com> wrote: >> kstrdup() return newly allocated copy of the string. >> Call kfree() to release the memory when after use. >> >> Fixes: 49da7e64f33e ("High Performance UML Vector Network Driver") >> Signed-off-by: Miaoqian Lin <linmq006@gmail.com> > Thanks for your patch! > >> --- a/arch/um/drivers/vector_kern.c >> +++ b/arch/um/drivers/vector_kern.c >> @@ -765,6 +765,7 @@ static int vector_config(char *str, char **error_out) >> >> parsed = uml_parse_vector_ifspec(params); >> >> + kfree(params); > Are you sure the memory pointed to by "params" is no longer used? > "parsed" seems to contain pointers pointing to (parts of) the string > pointed to by "params", so it cannot be freed. +1. I was just about to send the same comment. > >> if (parsed == NULL) { >> *error_out = "vector_config failed to parse parameters"; >> return -EINVAL; > Gr{oetje,eeting}s, > > Geert > > -- > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org > > In personal conversations with technical people, I call myself a hacker. But > when I'm talking to journalists I just say "programmer" or something like that. > -- Linus Torvalds >
On 2023/1/3 18:28, Anton Ivanov wrote: > > On 03/01/2023 08:00, Geert Uytterhoeven wrote: >> Hi Miaoqian, >> >> On Thu, Dec 29, 2022 at 8:53 AM Miaoqian Lin <linmq006@gmail.com> wrote: >>> kstrdup() return newly allocated copy of the string. >>> Call kfree() to release the memory when after use. >>> >>> Fixes: 49da7e64f33e ("High Performance UML Vector Network Driver") >>> Signed-off-by: Miaoqian Lin <linmq006@gmail.com> >> Thanks for your patch! >> >>> --- a/arch/um/drivers/vector_kern.c >>> +++ b/arch/um/drivers/vector_kern.c >>> @@ -765,6 +765,7 @@ static int vector_config(char *str, char **error_out) >>> >>> parsed = uml_parse_vector_ifspec(params); >>> >>> + kfree(params); >> Are you sure the memory pointed to by "params" is no longer used? >> "parsed" seems to contain pointers pointing to (parts of) the string >> pointed to by "params", so it cannot be freed. > > +1. > > I was just about to send the same comment. > Oh yes, thanks for spotting this. We should only perform release when uml_parse_vector_ifspec() fails (returns NULL). In this situation, 'params' is no longer used. Do you agree? Thanks, >> >>> if (parsed == NULL) { >>> *error_out = "vector_config failed to parse parameters"; >>> return -EINVAL; >> Gr{oetje,eeting}s, >> >> Geert >> >> -- >> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org >> >> In personal conversations with technical people, I call myself a hacker. But >> when I'm talking to journalists I just say "programmer" or something like that. >> -- Linus Torvalds >>
Hi Miaoqian, On Tue, Jan 3, 2023 at 1:17 PM Miaoqian Lin <linmq006@gmail.com> wrote: > On 2023/1/3 18:28, Anton Ivanov wrote: > > On 03/01/2023 08:00, Geert Uytterhoeven wrote: > >> On Thu, Dec 29, 2022 at 8:53 AM Miaoqian Lin <linmq006@gmail.com> wrote: > >>> kstrdup() return newly allocated copy of the string. > >>> Call kfree() to release the memory when after use. > >>> > >>> Fixes: 49da7e64f33e ("High Performance UML Vector Network Driver") > >>> Signed-off-by: Miaoqian Lin <linmq006@gmail.com> > >> Thanks for your patch! > >> > >>> --- a/arch/um/drivers/vector_kern.c > >>> +++ b/arch/um/drivers/vector_kern.c > >>> @@ -765,6 +765,7 @@ static int vector_config(char *str, char **error_out) > >>> > >>> parsed = uml_parse_vector_ifspec(params); > >>> > >>> + kfree(params); > >> Are you sure the memory pointed to by "params" is no longer used? > >> "parsed" seems to contain pointers pointing to (parts of) the string > >> pointed to by "params", so it cannot be freed. > > > > +1. > > > > I was just about to send the same comment. > > > Oh yes, thanks for spotting this. We should only perform release when uml_parse_vector_ifspec() fails (returns NULL). In this situation, 'params' is no longer used. Do you agree? Yes, that sounds fine to me. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c index ded7c47d2fbe..78f32005dd90 100644 --- a/arch/um/drivers/vector_kern.c +++ b/arch/um/drivers/vector_kern.c @@ -765,6 +765,7 @@ static int vector_config(char *str, char **error_out) parsed = uml_parse_vector_ifspec(params); + kfree(params); if (parsed == NULL) { *error_out = "vector_config failed to parse parameters"; return -EINVAL;