Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp385461lqo; Fri, 10 May 2024 02:59:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUTXbMUls4zVxTkmDpZ4j6CusxywySTkOPkaWZurETi/2+HwnwQo1yMHU6Toz0TOWb/okkFRMsQO4iL0zgBUUUiTbps32XQHg3QxhWM9g== X-Google-Smtp-Source: AGHT+IHBOgouzCs21KoAgyso+ARKe9CHPM2n9xEFt2vPKr4o6mZI/X5pZdoe6OjI7JX8ywQAcf4h X-Received: by 2002:a50:f61e:0:b0:568:d55c:1bb3 with SMTP id 4fb4d7f45d1cf-5734d67ef0emr1489366a12.31.1715335145130; Fri, 10 May 2024 02:59:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715335145; cv=pass; d=google.com; s=arc-20160816; b=etjXx825BQ3d8/yDoLkcARQ5yI+vnPw7/XBm9uyrCCpxw2ZlGuooP2Fr8xnqcWAnI2 NHqU1G5hoATwPz92OjPjqqB4hy/o9Ioth93mgp4r9FVh9exrfZvNny9bLWmp1QeEdS+8 kg1p0H1583HxSfOJpC8uy6/0TEzh732h2Dz7lWikxTLWYoU0ggCDJLZiJTOCFYX2D//G d5t4Y3P7OwMXJFjYV6z3/ptoFZ7eBT5fcWCuycj89Yw47jGtqgt13gkphVc7MtLr0mjv 2q2yefmgwwvrnmHVfFSK4ZxkGLxGYmI6cKKGRHncLQxx9irZPKc82szbroTu0UfGV53X qLmQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=W1C/72k3CZqrqQ8uzPc/VTP/P/Rw9MPoSpFvH6FC94M=; fh=lPKFJvVb52pC2FZAsmTs3X0iL2A14rZznWkIdxXku7w=; b=fY4UnRztXYkMqQRr6sDBk+R78wPF1lgFJ4vdEOBrw4XdCBM1yfAwxsZ0I6vJEKpawD XQP05sOiMfc3cN+OMil0r8qZSl+V5XJw7GcWR5yRf/bZpgaoaLOS++Lkp8EPfLVtVV9g 398tvlbv1rfBr5lPzfiUg7UbShBBztDcVrPbS8wpeSJpYjZ9XoyGbP4MBSmkfLb0cI/l 1bLA/d1u4Nmx1UlTTwbW9P0Gkyk7HKDihXm5It3Ekmk6HEM2LLOTN3Hv4VV2AWOnwG8+ 6iNeZZCQsoVupHSIyq3xNvWXDSLEkmilUW7CxwprJfZJYL7tPx+xcy0WoFW+oRRE4QGf NIug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xdMCXLkx; 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-175557-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175557-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c362bfesi1821903a12.511.2024.05.10.02.59.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 02:59:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175557-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xdMCXLkx; 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-175557-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175557-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 am.mirrors.kernel.org (Postfix) with ESMTPS id AEC081F21E2A for ; Fri, 10 May 2024 09:59:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7033816D320; Fri, 10 May 2024 09:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="xdMCXLkx" Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (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 2196216C683; Fri, 10 May 2024 09:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715335105; cv=none; b=Wn5yPqQIeVItlZVusp+qbPPQ+DkUtpXzACC1uDPbBJzvwaqUHUiFUhS4mhDPKTtTOcZA1SpgwwruyNObSMJnoRv1J+RoFMmYW6tyWtxoUGDYDG2SniWs4mSfgGfiaCvxGEDAaoyTFBDNX1gP97wERhlQinVcIvzO1b+rv0LWvYM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715335105; c=relaxed/simple; bh=L5CtxcTyFe4ed4Z4V5GzUmwGAj4pyd/5Gw6Sce0wkyU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dXvkHuYObMySZmvQq3Nz+xN0sXY2TH52OGiHTIMzYbZE7e/FuPz3ZgKkDm3dKDSdeYgWEB6ZWnRuN6qSmSmLlqW1w7k9XR6fy5xMwRvxVL2rQHtHDharQJ50zxX+gMzdpSfqgME8Fnkpr8tWUpZHYIxkN1CzyHxiCT8R/JOSp+k= 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=xdMCXLkx; arc=none smtp.client-ip=91.218.175.180 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 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715335102; h=from:from:reply-to:subject:subject: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=W1C/72k3CZqrqQ8uzPc/VTP/P/Rw9MPoSpFvH6FC94M=; b=xdMCXLkxAwQR7/Rdu0KQ0aeqzSuPHIOOG5MO2qG3rrkiN72687KX/wrY8xYgwC3U7ZKFuY y0ex++vSNlf6eryLU9R4t9tWEz3Stbhxuw8ZjCKMMKu4pOxjVLSlzPak0+D9AqYFkC1Ems TpeYjO8C7XU9a3P9vy4GAXD0XUvYofE= From: kunwu.chan@linux.dev To: 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, Kunwu Chan Subject: [PATCH bpf-next v2 1/4] selftests/bpf: Add some null pointer checks Date: Fri, 10 May 2024 17:58:00 +0800 Message-Id: <20240510095803.472840-2-kunwu.chan@linux.dev> In-Reply-To: <20240510095803.472840-1-kunwu.chan@linux.dev> References: <20240510095803.472840-1-kunwu.chan@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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; + 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]; -- 2.40.1