Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp385554lqo; Fri, 10 May 2024 02:59:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVU8y256th5QMB2MrsV7wCIUohbGmBZpGbjyn92QsMdiUfzlQSVdIXqJaKBCDj3FkLTRHwvHloWFcseIdD7f0JM6ewvt/cKWcNuS8sNqw== X-Google-Smtp-Source: AGHT+IHHZGCRZ046oWDf4HSkXqfvIIoT0vhsRuYrpbTVMbmFZzIFttGo4E9nwWF1wmaHL1l3by1U X-Received: by 2002:a50:8d50:0:b0:572:689f:6380 with SMTP id 4fb4d7f45d1cf-5734d597df2mr2160527a12.3.1715335162282; Fri, 10 May 2024 02:59:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715335162; cv=pass; d=google.com; s=arc-20160816; b=i2dgPpVwQ/fQw+OuWJKeYJQyToSq25u1+omBCuTDlzmkQkSKgA9B2uKnyWvRjw2a1x GT5R4qDkOgRXdvZlajlB+nZabPnY59f4O4msSZv3W5QjRP9H/AZHjRkuY0ofXeossuRm D83LLzJGIfwhLWQXe05+CkNmgBJT0UrLSNTOr9NgnpTB9LEXtzxqSoKgkW5ALtk0eY7i jLWHpWrak9cZNzZhKz/RZx8bh55xtdu+gSwZBeZQNR3lGDhnA8rTjsIA7qS9I1AEUdzo zOKtQ/IhLsFEYJZBdchLSbZMv4s0NMxTPvOVLGw/CQ1P+xAgjgmkhSmfL75ZZDwoVzZQ O7KA== 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=Z20fNZGFCqGAeDIBxhPRlb7sk072IN18zBHdKwtlyTE=; fh=lPKFJvVb52pC2FZAsmTs3X0iL2A14rZznWkIdxXku7w=; b=dycMuX/S7U2apsVOySaiGRIJv64gvf12a9EKG554rdipdZX/7sN+/cb8CV2sxDU49J SpnmVsAcY0RRPcMBssCyzL6nUHgt56zakkNNFfXS7I/Ym64fRAY+nXN37QIfm/7NagLA qx5Dy9dQYFdJIDs8cMuw5LyT6BZfGkmYnAZ0LzXT/DeGwvPdQ0oeWes1zqFUM52ZuZKx hnEc6NcWXTtuHxYvpNgntsJvE+30S8+od+TwMFEPUMiM7PwmGquF/edkHC8hf8SUzdYs os+mbGrvXyhqIe7roe5gjLonmp3jlwV/KqfNKydGAMSmW8IGNvy6nTO0UtGmv4GjXnBr otEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=htYbeuAc; 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-175558-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175558-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c372da0si1744875a12.580.2024.05.10.02.59.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 02:59:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175558-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=@linux.dev header.s=key1 header.b=htYbeuAc; 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-175558-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175558-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 0821C1F219FC for ; Fri, 10 May 2024 09:59:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7CFD165FC4; Fri, 10 May 2024 09:58:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="htYbeuAc" Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (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 7776816D4C6 for ; Fri, 10 May 2024 09:58:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715335109; cv=none; b=GM3Ynyshuv3kTfki9S7/HJp8EuhXdezA4GpuGS1TKOp2wzBDXrUpmipeJzAngaScaQz1lJq44gHAGJ9rnyqMUS+zInZvNBJSU96s20MIdDfGyAprtP9SplD8F96e0Sc6Aokfx2ECdR2CFhx8OEuv5+1ZrgvSSds1F1QQSg0KM48= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715335109; c=relaxed/simple; bh=z9zdge8Uw/xViOY7Q1RU4YYXc81cHoFE1Mhbnb/H+ZY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Eliv/vyX832C7kE0gQu8i6ZqlUKeddYGSZ4QxxOGfAPiUROvA+RDCwxsSriKtRWYsi1C3ap3IbyC9hJCHRK7XLLd2WHNQBDwYZ+psWdbyCAY6vUtSOzvO8qT5PjWHFmMqM52T7i6TLiYLQL1T7OQnVgtni0cu1sbGLFrTfVRIe0= 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=htYbeuAc; arc=none smtp.client-ip=91.218.175.189 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=1715335106; 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=Z20fNZGFCqGAeDIBxhPRlb7sk072IN18zBHdKwtlyTE=; b=htYbeuAcAhLYNZklnby0O8snwbvSM2rqf1jrXvpgaHB0B7rL1lgx3uw05t7RXWYKXc7NX3 2/e8C/A6UqN+4iHfcgVshknDf93Z5ZB6T0zQ8Uokd4RvTf/UC8hsL0YKNZuOmNDaqT5GBg WgEAowPbAmYACMAdheVLgSjQoSU+TIU= 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 2/4] selftests/bpf/sockopt: Add a null pointer check for the run_test Date: Fri, 10 May 2024 17:58:01 +0800 Message-Id: <20240510095803.472840-3-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. Add the malloc failure checking to avoid possible null dereference and give more information about test fail reasons. Signed-off-by: Kunwu Chan --- tools/testing/selftests/bpf/prog_tests/sockopt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt.c b/tools/testing/selftests/bpf/prog_tests/sockopt.c index 5a4491d4edfe..bde63e1f74dc 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockopt.c +++ b/tools/testing/selftests/bpf/prog_tests/sockopt.c @@ -1100,6 +1100,12 @@ static int run_test(int cgroup_fd, struct sockopt_test *test, bool use_io_uring) } optval = malloc(test->get_optlen); + if (!optval) { + log_err("Failed to allocate memory"); + ret = -1; + goto close_sock_fd; + } + memset(optval, 0, test->get_optlen); socklen_t optlen = test->get_optlen; socklen_t expected_get_optlen = test->get_optlen_ret ?: -- 2.40.1