Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp425203lqo; Fri, 10 May 2024 04:22:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWuleeXfykHH55Sd/ccnEX4V2qRPS6AfJ6uXann18TTeR8CswwAmLN4C1bczhv+IIkK3WfePVHTKXWTRz8uqPQkCd0H4yQQmVq8GmwS3g== X-Google-Smtp-Source: AGHT+IH/mzdLQ+eb0QfEt/WuUycEiHqbgv+SmvFrx3OBEOHb5ZDDYRKZuHeRsuF5zi2VzXA6ACiY X-Received: by 2002:a17:906:f186:b0:a59:b68d:45fb with SMTP id a640c23a62f3a-a5a2d68aa70mr161217966b.63.1715340146604; Fri, 10 May 2024 04:22:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715340146; cv=pass; d=google.com; s=arc-20160816; b=Oxj36IQ/oXLCfXEIcz4MrOxWVaBpBsOrocURH8HCNNn9TI4dD29ziD7ILE9pC1kJHH 32sSYnEH9CzLi0YKAHGVSVbldpOEl+GsnT/3cnuShJ5Y7qQXAJ6UgA1Y8m5JJlhrjEiD qZY/+mcTs1LqOWUydl2aS5lF+k73bxotWdp0vWbZsgA1GEsX5lePYuFRwGL0UkQ8rSYs 2Fn+xWyEe36Au3jhjBr9DDU0U6Oycc2q0D7c1MZ95wFYrA/bKmDgbjgm8o1RItXEq4Xr /9QT3dvro17BgYTwJCuKBXIRb+LB3VOhR8BdBdta0e9w0Sqhq+S7DRtoRJEbYcztbWPA dPRQ== 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:to:subject:cc:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=MWmzzIj153vrReKCREDUd3nnyrTLEztXauXxl6kwoTs=; fh=Icz9E8DXite47jto1J5FDKj9WwOAR7K0spywDAVWNP8=; b=wL1TcKsnK9MQIhv//dEu6s7/B5056hUMJydV44QAx4gNM8wX2YSMvbXL5Z1Psh7jeg I9tpmiHQI2/s59SW3kuA9kZqxAXjJtOFIW+QNAlxnbQCw37KvflPxnTQFNRwh4UPTN8B wuaTVoEDoWyFZ1Ol+dNbLyULzRDpRorAfO2kFd8LGJ8s0CqUCnxT1kxgTSmaqLA6SoT4 1n9kt4AT/DNUiODQ2GjRME2wLnvc1m589zQYDWICMT1toIyjshzGPm8wEOV2wFyFW4Be t+vpQesqg7PX+gnfWefQAnDkDFlnzdjtJKccCE6RdMJ6vcjJMcps6lAAq7zLLAOpKQP8 A7Xw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=UakbpR3T; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-175648-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175648-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17b21f15si194368966b.384.2024.05.10.04.22.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 04:22:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175648-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=UakbpR3T; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-175648-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175648-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 25F181F21685 for ; Fri, 10 May 2024 11:22:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0FE9C16EC03; Fri, 10 May 2024 11:20:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="UakbpR3T" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (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 7377454662; Fri, 10 May 2024 11:20:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340032; cv=none; b=BxIdXOD/kLZdPyUL0BrULxMPVeAIF9vF/isuQxVWiyJkKHPvbd5uQItNpW5jazJQEQ8zhgX+nIjBCif8ghY+f0LymWQOhmaTb9IiY+EJ6EpBB/9AagHyUaZYr+W6gY0/wqmGIACQD73ogDW5O8Drtc6yGUcWnXOKooRNrSmVuNw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340032; c=relaxed/simple; bh=SQwwA9wyysyHiNBB6w7RkMHU+mPG8xq/RDeviEh9MXk=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=W9rxC5ohYPzWO4VHFVDfRPDUWJFkHi2MbdSPTwObIjw555J3GJ9sqcuBd8qBMr46gInxElgLKfD3G4c5esZJYtj93bqM81IHuh5vHM2OqxcFE/+N9BdeNeSrUKybs/LZH5e56VcWxxgoRBHcQJRUx761t68Nz0NxQ8TZbJMMlek= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=UakbpR3T; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1715340028; bh=SQwwA9wyysyHiNBB6w7RkMHU+mPG8xq/RDeviEh9MXk=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=UakbpR3TJ28+qmztK/kRuEiv8VQ5JVn1O6Jh7oooZ9E1tiL2jCwl/mNZST9Z6PfvX 0oNJl2CdZydIeWA0a1ADrgggike+lcNMHOVGx37r3yZTtIhpAHfAczi8HYo4q6WNl7 bcBNFxKBJQT4dv/xuygREoM3eVIR36PcYwffLfgmrEhAywD5/Waps3TM4e1bH7kgwR /YcMQreBEyJ81Cn+etuDplvnpRltof+YudwKi0cN8FsDuToxBvo0hlaSaTjq3f8BH7 AAdSI7Y8XMzGt/PC5CFhQN8pTxUTsx06YD/pIyiwxLhU62uSIC5r6N9Eh0s9V9uasA 83Jpe90mllcsA== Received: from [10.193.1.1] (broslavsky.collaboradmins.com [68.183.210.73]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id C282C3782185; Fri, 10 May 2024 11:20:23 +0000 (UTC) Message-ID: Date: Fri, 10 May 2024 16:20:47 +0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: Muhammad Usama Anjum , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Kunwu Chan Subject: Re: [PATCH bpf-next v2 1/4] selftests/bpf: Add some null pointer checks To: 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 References: <20240510095803.472840-1-kunwu.chan@linux.dev> <20240510095803.472840-2-kunwu.chan@linux.dev> Content-Language: en-US From: Muhammad Usama Anjum In-Reply-To: <20240510095803.472840-2-kunwu.chan@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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. > + 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]; -- BR, Muhammad Usama Anjum