Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1864725lqo; Mon, 13 May 2024 00:01:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV3AhmivNjJ0xDg8tfiF97/mbwHnsLkALP9sq2b8OmWjPp0j0V9Gy+8C89dbIId/LS6SQaQqA7g3AzS74FxFjo7JMu+Zx2JL/Da5TOJ3g== X-Google-Smtp-Source: AGHT+IHdI3aYJPIvYAlA339xKgJSNL7qmFljMua9Pls+9p1s4Z9y/29rRzScb4o9QBofbSvRrjF8 X-Received: by 2002:a05:6214:4487:b0:69b:5889:8eff with SMTP id 6a1803df08f44-6a168212cfemr114194136d6.43.1715583672787; Mon, 13 May 2024 00:01:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715583672; cv=pass; d=google.com; s=arc-20160816; b=Cbj85/RyTi488hO2oaRub+cDnWxJEZOJEV4Lab/alyQ4KroghYKYw+bFnoSiwA7RpH ALnQY7i8oKhaa1OzZTKrmsIvwAasGWCiwn6nVTbgwevUpwS3nK9vHNiHEKjbrf64EV1O 6o9fWy2Nvd7YvX5HXwyzPTr0ZcHdgAkBsQtmCNry+vgYasFCPOHSHTAs+39J0MNDPF2G uPqPOJAzm3VdWvc/vdj9I40xbghWqSTu593fYoW4plVXLGnpqxY1eGUXwyzqGMdhg7Ju PgY/hjim0N3LX6ecaUZMSp/WuGZrAHsGgLvtj2gk3TaE4C+W25GANy0zdgJ8Rsugr/Oc wmuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=zuM1ivPBry8hvT+SMqe+Wim0oUpETn/fwoja6E4kiSE=; fh=x4KFvNNYW4lz9isqgjgm4gL1dUAEeYXHfezcae3BKG0=; b=b1naOzgv+GWmKsduChiHcFMf+q+r7izGvHIp6zIkYgAumwrv4zzSE8/xkwxV4FzmgJ nAM3NfOyX5ByqVeJacMNiFVxNwhaJrdr3FSzTx3wsjdgFzr5iHr/BEaEO6phuA2cufNA Sk/3seg3MHmiioscS6Ll1HT4og9WZAulHpeIIDkTw28TGprlNPXS21N+BdVHnfRZmeNY 6e9hriLS+o90g8zAJPYJ4rCr6dUY6MYlU5wIVjzEOw8X9Y+6Zul66Z5UwzQi4/wvJyRb 6jrPgvnF+kmoWs4GAIY2mqHAyTOIBbUm4ZVAmz7Jy07O43yzzQ3iCMinJQq0sS5v6eU2 jQwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=DL1O4sdP; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-177232-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177232-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f2b66d7si92048186d6.347.2024.05.13.00.01.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 00:01:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177232-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=DL1O4sdP; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-177232-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177232-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 576F71C2106B for ; Mon, 13 May 2024 07:01:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 800B9146A74; Mon, 13 May 2024 07:01:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="DL1O4sdP" Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30C3C1465AD for ; Mon, 13 May 2024 07:01:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715583667; cv=none; b=iKeZ32HXwXJn7wVyvtru1BuzVaRh1UYTD7iCXTXvaYUvyXJvaUEks9dAr1gAqFztYPd3Pw5Rv4vy5vFWAkhjIdq7wDU5DSNbO0z7OO/ouGS+E1ObDULtcfS+yiRTmUe6shxQKUtu+tHHcM8fXitJxzNUuvMQLn+w1d2te5UMZPc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715583667; c=relaxed/simple; bh=FNglutKOMNf4oIKy8z3CJ0ag4Xtd06wdi78Qz0/sjP4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=vBhk2jLqcXKgeBt6ydsU/hM9IO6V6EUQp5OwYZ08gmQSQTyErqDX06Os/z4aRIAKutAI3mRSiJLWKRv5WQ9KfQGPY3iqZG5jdupnNgMfQuywk75NXkTOjWAsc4dYquZJGyJ+m0IBPMauUS2rrqxLDvS+WjHq1wvu5KIKs3jhf2g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=DL1O4sdP; arc=none smtp.client-ip=91.218.175.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715583662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zuM1ivPBry8hvT+SMqe+Wim0oUpETn/fwoja6E4kiSE=; b=DL1O4sdP9UfM9V2ARELSgsO1X5MSdx7mxbW/hLANEG8uSQPn8nxDnmNGMYBvvb2yju/8Gh xDWPOaCrYAUuIW4TJi/7MkSQeekKER3ZUAzZKE4a71d1rTuCl2l64jfOpaHOz/9EKPIlpc EVOLVTM9a+uqRnSxS/F0mh8A6Vxvv+A= Date: Mon, 13 May 2024 15:00:30 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next v2 1/4] selftests/bpf: Add some null pointer checks To: Muhammad Usama Anjum , kunwu.chan@linux.dev, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, shuah@kernel.org, kunwu.chan@hotmail.com Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240510095803.472840-1-kunwu.chan@linux.dev> <20240510095803.472840-2-kunwu.chan@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kunwu Chan In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 2024/5/10 19:20, Muhammad Usama Anjum wrote: > On 5/10/24 2:58 PM, kunwu.chan@linux.dev wrote: >> From: Kunwu Chan >> >> There is a 'malloc' call, which can be unsuccessful. >> This patch will add the malloc failure checking >> to avoid possible null dereference. >> >> Signed-off-by: Kunwu Chan >> --- >> tools/testing/selftests/bpf/test_progs.c | 7 +++++++ >> 1 file changed, 7 insertions(+) >> >> diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c >> index 89ff704e9dad..ecc3ddeceeeb 100644 >> --- a/tools/testing/selftests/bpf/test_progs.c >> +++ b/tools/testing/selftests/bpf/test_progs.c >> @@ -582,6 +582,11 @@ int compare_stack_ips(int smap_fd, int amap_fd, int stack_trace_len) >> >> val_buf1 = malloc(stack_trace_len); >> val_buf2 = malloc(stack_trace_len); >> + if (!val_buf1 || !val_buf2) { >> + err = -ENOMEM; > Return from here instead of going to out where free(val_buf*) is being called. I think it's no harm.  And Unify the processing at the end to achieve uniform format. >> + goto out; >> + } >> + >> cur_key_p = NULL; >> next_key_p = &key; >> while (bpf_map_get_next_key(smap_fd, cur_key_p, next_key_p) == 0) { >> @@ -1197,6 +1202,8 @@ static int dispatch_thread_send_subtests(int sock_fd, struct test_state *state) >> int subtest_num = state->subtest_num; >> >> state->subtest_states = malloc(subtest_num * sizeof(*subtest_state)); >> + if (!state->subtest_states) >> + return -ENOMEM; >> >> for (int i = 0; i < subtest_num; i++) { >> subtest_state = &state->subtest_states[i]; -- Thanks, Kunwu.Chan