lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YbdFOvHedDCVZ04A@kernel.org>
Date:   Mon, 13 Dec 2021 10:06:02 -0300
From:   Arnaldo Carvalho de Melo <acme@...nel.org>
To:     Miaoqian Lin <linmq006@...il.com>
Cc:     Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...hat.com>,
        Namhyung Kim <namhyung@...nel.org>,
        Ian Rogers <irogers@...gle.com>,
        Andi Kleen <ak@...ux.intel.com>,
        linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] perf expr: Fix missing check for return value of
 hashmap__new

Em Sun, Dec 12, 2021 at 06:25:02AM +0000, Miaoqian Lin escreveu:
> The hashmap__new() function may return ERR_PTR(-ENOMEM) when malloc
> fails, add IS_ERR checking for ctx->ids.
> 
> Signed-off-by: Miaoqian Lin <linmq006@...il.com>

Thanks, applied.

As a follow up you may consider using ids__new() instead:

struct hashmap *ids__new(void)
{
        return hashmap__new(key_hash, key_equal, NULL);
}

And I noticed that the users of ids__new() are not using IS_ERR() on its
return in tools/perf/tests/expr.c, e.g.:

static int test_ids_union(void)
{
        struct hashmap *ids1, *ids2;

        /* Empty union. */
        ids1 = ids__new();
        TEST_ASSERT_VAL("ids__new", ids1);
        ids2 = ids__new();
        TEST_ASSERT_VAL("ids__new", ids2);

This needs converting to TEST_ASSERT_VAL_IS_ERR() probably after
introducing it, I haven't checked if this variation exists.

- Arnaldo

> ---
>  tools/perf/util/expr.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c
> index 1d532b9fed29..c94c9ea30d1a 100644
> --- a/tools/perf/util/expr.c
> +++ b/tools/perf/util/expr.c
> @@ -299,6 +299,10 @@ struct expr_parse_ctx *expr__ctx_new(void)
>  		return NULL;
>  
>  	ctx->ids = hashmap__new(key_hash, key_equal, NULL);
> +	if (IS_ERR(ctx->ids)) {
> +		kfree(ctx);
> +		return NULL;
> +	}
>  	ctx->runtime = 0;
>  
>  	return ctx;
> -- 
> 2.17.1

-- 

- Arnaldo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ