From patchwork Wed Apr 24 01:28:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 13640927 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D7C06112 for ; Wed, 24 Apr 2024 01:28:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713922130; cv=none; b=FThUdUJwh/Bnm5tsCjzoUbzWMXa94t728LPHu+Qu0GWuAFlvUruKJYSUtM23UqXxjdIcT2DBJDOSysDDWabn1zDyotamzhIKLGGClRyoDcEXbZBS18YR5QYQbxfFeMtz1OnXCGR4m2KZaaQ7o+MTbsIzqjXEiJg880u9MpMtf3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713922130; c=relaxed/simple; bh=9J26TE/6MUBkHwCplZk2OjBOWWngkfcaPvczZgQTHDU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=B60wbaF4eREs+3aCzZkxwDuaH+81GDNNkv3q5HM52vvXEFnXB7kK1FB8QPHaVq3AC/fVKBHzwBcgIeLZ/N/fmir4Y3W9r+BHkVMw9I2F/LnSx/IJABv4uSC1C2IEPWEx4Vny6BCnbGUIFug3mpwKaXbI/hpvJ5u3TePLkECvnwk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ch+3bABi; arc=none smtp.client-ip=209.85.167.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ch+3bABi" Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3bbbc6b4ed1so4097047b6e.2 for ; Tue, 23 Apr 2024 18:28:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713922128; x=1714526928; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7H94wLOmtbonKp8Hw+9xTGITfBs3ZyZURRtQOSpiQtA=; b=ch+3bABi5KJY7cWrKd1piLP2EOxAaYuxOTu45NOzAKqy6YLL6UIA3D6kOAUvRHAZdN B3VPENfjbEBZp9AqYGWYKFetuJk6Izma8kSFv/0hZ+jjeCp8bGF6QZZrktg66CAwFPoX lnNEJgWESYC3cVC7StvEL+phgIoM1QcJkGTe6p87Izb0zxRDp7W4FxhU+2OQ92SDVsoc eCbIpsLVsSaGaSGHKpDzmd034M9b71jfVMWZkT3rRExYn/DO9q4TwO/wfVIy62b+c4XK +DQCazSf0rpyBsIskal9PySKyfrg8r5zuGzvd/0Xo6C/fuKNeRJkhKSCDL52uI8/ksdl Prng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713922128; x=1714526928; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7H94wLOmtbonKp8Hw+9xTGITfBs3ZyZURRtQOSpiQtA=; b=JNDe4j8g58BDe+q8jgr7tmkniiAcVWdNQO7zSBcBdiv9Nl0zLLzZIli9FU4DDzmaPO sgXb2qvOaJPZIK2AlM17CzpOHORJB9aYsL6gCUEXDt4CpmU9QN8ovzPkEWAmtT5gdxG8 BBeolB7CrELhQoZWcscQToNcKEsKsNzNF3XobP3QyixQK+6ZHqgIanTjPokfBLER3OqD T4D4DIVmiGPurT4WhgkZSWzcscivam+Xl4/ASgTCJIvlW8RkhdLyLdLbCt+MgCm58hJD dnJpDd2xYqasxD/rFaB4yFmv7DU8piW+yAdIsizlUK3jfAqHHqUPaF2YPR5OyqIX6BSl Y2Kg== X-Gm-Message-State: AOJu0YzH6q4b+h+W/P4R4QKNfJJdQI6n67XLv3KcSFGy/e6+cthGANYQ wFWiOzxM1sWUEDZXm1FCAeXlTlikfs0CxVBC7k+gQonaZZGVvvHru6PtkA== X-Google-Smtp-Source: AGHT+IEfxtvSqEESc5wBQaw3eo7cTgtqqV1OwMjnGC5oCoTpPreQCGGgH5A2JBTrsrfY7Y66FljwLA== X-Received: by 2002:a05:6870:348e:b0:232:f9e0:e4c7 with SMTP id n14-20020a056870348e00b00232f9e0e4c7mr1135256oah.48.1713922128260; Tue, 23 Apr 2024 18:28:48 -0700 (PDT) Received: from badger.vs.shawcable.net ([2604:3d08:9880:5900:1fa0:b3a5:f828:f414]) by smtp.gmail.com with ESMTPSA id fk24-20020a056a003a9800b006ed9d839c4csm10271007pfb.4.2024.04.23.18.28.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 18:28:47 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com, yonghong.song@linux.dev, jemarch@gnu.org, thinker.li@gmail.com, Eduard Zingerman Subject: [PATCH bpf-next 1/5] bpf: mark bpf_dummy_struct_ops.test_1 parameter as nullable Date: Tue, 23 Apr 2024 18:28:17 -0700 Message-Id: <20240424012821.595216-2-eddyz87@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240424012821.595216-1-eddyz87@gmail.com> References: <20240424012821.595216-1-eddyz87@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Test case dummy_st_ops/dummy_init_ret_value passes NULL as the first parameter of the test_1() function. Mark this parameter as nullable to make verifier aware of such possibility. Otherwise, NULL check in the test_1() code: SEC("struct_ops/test_1") int BPF_PROG(test_1, struct bpf_dummy_ops_state *state) { if (!state) return ...; ... access state ... } Might be removed by verifier, thus triggering NULL pointer dereference under certain conditions. Reported-by: Jose E. Marchesi Signed-off-by: Eduard Zingerman --- net/bpf/bpf_dummy_struct_ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/bpf/bpf_dummy_struct_ops.c b/net/bpf/bpf_dummy_struct_ops.c index 25b75844891a..8f413cdfd91a 100644 --- a/net/bpf/bpf_dummy_struct_ops.c +++ b/net/bpf/bpf_dummy_struct_ops.c @@ -232,7 +232,7 @@ static void bpf_dummy_unreg(void *kdata) { } -static int bpf_dummy_test_1(struct bpf_dummy_ops_state *cb) +static int bpf_dummy_ops__test_1(struct bpf_dummy_ops_state *cb__nullable) { return 0; } @@ -249,7 +249,7 @@ static int bpf_dummy_test_sleepable(struct bpf_dummy_ops_state *cb) } static struct bpf_dummy_ops __bpf_bpf_dummy_ops = { - .test_1 = bpf_dummy_test_1, + .test_1 = bpf_dummy_ops__test_1, .test_2 = bpf_dummy_test_2, .test_sleepable = bpf_dummy_test_sleepable, }; From patchwork Wed Apr 24 01:28:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 13640928 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 486EB6FC2 for ; Wed, 24 Apr 2024 01:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713922131; cv=none; b=uAg4WVj+GXyvphIBYUTzcgBpUuFlfqoY2lL9wEk/BZm9dowxPQVhgr9Ijw6XA7zXm0nBqh44MwSdjoWm5o6PmfpxP/JGWxacI9T/J6VS3jc7fWiDYk67paVev5Nd695jWJv/MF4GdqC8cem9hUxfIvk0tE0hB6gLBFHH4kvN/5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713922131; c=relaxed/simple; bh=Nwkgt3kRLR7hbWESbpleJdPHGyNN9y3gJVWWefNDWEk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BS1kKStnUbgxbLclU+8DWR0Vp3c8L9dC/nZixbqhZRLWl/eUrCn/LfohDhmGr7NAodBsnF5iZBc58uuR5i9nRDzY9GsXR+3k4JVzqTQaTqqjCSFa82dHnFwV736SfiLIQngqr4AXUjfoUUYLxPr5RRDsox/SFyLTXABLFNn5iUc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=J1jL1YBo; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J1jL1YBo" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6ee12766586so369643b3a.0 for ; Tue, 23 Apr 2024 18:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713922129; x=1714526929; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tGom8NiuBuJrUn6+QQCpbHJYsvp6s+pmTnv9noWy96k=; b=J1jL1YBoO7mp1TYmKuT+Q9rZtAudP4bSxuAURaa2tg5IbJFUm4dthUJnArqvDZz1dP gCaK6oO1KPe//k70lCfkCt/XM0Zsmpz8ez0qUG3h6R6eBl4kI/d9ZdiGFdK1F0f+fB92 Q6BUpA08Ao4Zjjaql8ilhYFx9stNkRhK/a7YUJBLQVhjQxfpt3FSGyaRT0YIJCGTQ0oN iqUDKgUTwLx63oVOJwNwkTGB42resW7EAvsjEf1bPr453OGwKMgwRLMl9rv1dA5RuQRb 6uPeNTXqa+aHLLaXV4xPoDHT053rVMUijvYVQgRDY5tepaYwOZxQucqtQ4F3FmXJE3UX I3rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713922129; x=1714526929; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tGom8NiuBuJrUn6+QQCpbHJYsvp6s+pmTnv9noWy96k=; b=iLNwrUbQXIT6HYBnnYIPFeVIZaf/9mJytYuJ4aRTGRUBqVjM0tRRs9b3Guf56zRABg vDr8F/Wx81VfBQ6ZBTDLMAyxF4gpIDS3BNwAMv9nLYUOItPlH1Tccc9NZd22xRiOf4br fWmRRhcQ+qKYXgUsv/bSu/wxSwYKPSHbxQAR2C9FdAdUTbXiPDDJw1zdFia8jnorrjSg tbPKHdHfcSNxcRfVqS5oul7WtE3MAbaOhZ9CdhC6DQbl42DUXADd34oM4y9t0xJZb2LG 5/DL97UQfzmcIUydFdOrQuxFoscw/X2BQ2qCFed2ebsVvo9mb2Xv0ZsZ7BPJhz6eOF71 Obdg== X-Gm-Message-State: AOJu0YyGSpMEX+utowCYd28V3+zGACirTF4UR8nbDhJ/eaC1vo7Hqd8r l5PvcN28wtVjYSolgpV6tAK9VcXm3qZ4XRcPz6ez5eVdmm/kjpHxY4Xheg== X-Google-Smtp-Source: AGHT+IFSOalnDEKncN+1ptDFvmrUKldllCQ3osF0i1Vpbh/m6VsxYIi+OhjsEZvu9aMFnsIsKP/G4Q== X-Received: by 2002:a05:6a00:2283:b0:6ed:5f9e:39d7 with SMTP id f3-20020a056a00228300b006ed5f9e39d7mr5681482pfe.5.1713922129247; Tue, 23 Apr 2024 18:28:49 -0700 (PDT) Received: from badger.vs.shawcable.net ([2604:3d08:9880:5900:1fa0:b3a5:f828:f414]) by smtp.gmail.com with ESMTPSA id fk24-20020a056a003a9800b006ed9d839c4csm10271007pfb.4.2024.04.23.18.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 18:28:48 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com, yonghong.song@linux.dev, jemarch@gnu.org, thinker.li@gmail.com, Eduard Zingerman Subject: [PATCH bpf-next 2/5] selftests/bpf: adjust dummy_st_ops_success to detect additional error Date: Tue, 23 Apr 2024 18:28:18 -0700 Message-Id: <20240424012821.595216-3-eddyz87@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240424012821.595216-1-eddyz87@gmail.com> References: <20240424012821.595216-1-eddyz87@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net As reported by Jose E. Marchesi in off-list discussion, GCC and LLVM generate slightly different code for dummy_st_ops_success/test_1(): SEC("struct_ops/test_1") int BPF_PROG(test_1, struct bpf_dummy_ops_state *state) { int ret; if (!state) return 0xf2f3f4f5; ret = state->val; state->val = 0x5a; return ret; } GCC-generated LLVM-generated ---------------------------- --------------------------- 0: r1 = *(u64 *)(r1 + 0x0) 0: w0 = -0xd0c0b0b 1: if r1 == 0x0 goto 5f 1: r1 = *(u64 *)(r1 + 0x0) 2: r0 = *(s32 *)(r1 + 0x0) 2: if r1 == 0x0 goto 6f 3: *(u32 *)(r1 + 0x0) = 0x5a 3: r0 = *(u32 *)(r1 + 0x0) 4: exit 4: w2 = 0x5a 5: r0 = -0xd0c0b0b 5: *(u32 *)(r1 + 0x0) = r2 6: exit 6: exit If the 'state' argument is not marked as nullable in net/bpf/bpf_dummy_struct_ops.c, the verifier would assume that 'r1 == 0x0' is never true: - for the GCC version, this means that instructions #5-6 would be marked as dead and removed; - for the LLVM version, all instructions would be marked as live. The test dummy_st_ops/dummy_init_ret_value actually sets the 'state' parameter to NULL. Therefore, when the 'state' argument is not marked as nullable, the GCC-generated version of the code would trigger a NULL pointer dereference at instruction #3. This patch updates the test_1() test case to always follow a shape similar to the GCC-generated version above, in order to verify whether the 'state' nullability is marked correctly. Reported-by: Jose E. Marchesi Signed-off-by: Eduard Zingerman --- .../selftests/bpf/progs/dummy_st_ops_success.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/dummy_st_ops_success.c b/tools/testing/selftests/bpf/progs/dummy_st_ops_success.c index 1efa746c25dc..cc7b69b001aa 100644 --- a/tools/testing/selftests/bpf/progs/dummy_st_ops_success.c +++ b/tools/testing/selftests/bpf/progs/dummy_st_ops_success.c @@ -11,8 +11,17 @@ int BPF_PROG(test_1, struct bpf_dummy_ops_state *state) { int ret; - if (!state) - return 0xf2f3f4f5; + /* Check that 'state' nullable status is detected correctly. + * If 'state' argument would be assumed non-null by verifier + * the code below would be deleted as dead (which it shouldn't). + * Hide it from the compiler behind 'asm' block to avoid + * unnecessary optimizations. + */ + asm volatile ( + "if %[state] != 0 goto +2;" + "r0 = 0xf2f3f4f5;" + "exit;" + ::[state]"p"(state)); ret = state->val; state->val = 0x5a; From patchwork Wed Apr 24 01:28:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 13640929 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16FBD748A for ; Wed, 24 Apr 2024 01:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713922132; cv=none; b=nAteJBlX6cBHT/ZpNwbSkypPQ8hlZxwl5ZeNzirCuJH2GqM9XeM4hgu1Hww3jQcOi566pTx+O3ZhZ1YaVBCyLfvOqoixVHK/i9H0vtqTsEzkmNr/uaxo9xV4MgU4FUKMdzkqbWzO06uhuKcz+uVXce7Wqxf0aADhQc5CBrQYq3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713922132; c=relaxed/simple; bh=lt/4KEcxgi+dKSugUo/CCet1gqH6ovg9L/1Flx+HRXQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HKtblzYnxED/b71NcebXVpyI4glyp2u67R9Yud0DExNnycIPYSghnjLO9LwoTf1QFtRYW47c7LI6SaCRWEZLwdFuNd3ukwCIzaJEGSC/wZ0BqfLi3LZgb3k0TXs4vCa+xjlT6pNVVkZ6Kov5rq2RciIY1m0YQm7LvIKSIAXIWQw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eLsyMWyY; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eLsyMWyY" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-6f043f9e6d7so6665791b3a.3 for ; Tue, 23 Apr 2024 18:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713922130; x=1714526930; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c88AZSJbjLbncPcEf4x9ksfVi3C2muY6xU8IDwdukyU=; b=eLsyMWyYMYDDw7yxNjNGhnio05VBpImBvAAV5rYLC5hNmzfh1zEtAG2Jxqna/kJ/O5 nlhpuiDURgdtkD1EvxT8bF9cYofq4hNXbdoSxygw8Dtji5WNLcgMHZ6SBhFlnJ8ZTZJe MPUdDzpHkrthH1M+o/nKfnQY/cdTJwRgayOX9duE0knd1XZT1sRDdyT4hc3GZdFKuxHg oHAdjleL82TOo2fXhfAy1G1WRHyJlSwBNrZU4FTKdu1LgQ4pz6iDR1lvwk9i27vIkHSc K3wl66SdVAiQ25s/Oglhnaq58vsk6JTrlD01dAVUMFPNZjWw49w61rgW3pDm5XQ5brQ0 IwcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713922130; x=1714526930; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c88AZSJbjLbncPcEf4x9ksfVi3C2muY6xU8IDwdukyU=; b=C18bsyOAElPf4MvL+fxqWtLdE4U7wMEunCxKw8fgTbhhTzRJde/sHIOcKVPZK59Lh+ L2LXV7aU8LT5dset2Vyu8NtJHv9819Egce5aPpxOUazJkNvwMp6ILM+inx0DJNbZf2gW p+mY37N41CIuYcbb8UI9vn+1tIwvFfxLqZCxFrcnG0z2dB5PZA8jxsKneMA5JYEUCiqS PQSHX8dZghIWDyYHvOZb/7S3USlrXqPcp865YAV5qLw4gP+fjNRjazR7mnBaMbw2NcYZ k2XQEBNVHkbv6DH7CNtMsrrDdE98k2AhVsddhjIDH5c6yClO87e3n562glVTXeC55e75 S+Rw== X-Gm-Message-State: AOJu0Yywhaa1Pnx26d/xuJmPSGDoZ/pDZcs8gZ0nqynXInR8+pSEDGAq M9anBShGpHWaMbRMznCJGOY6W6EJHPz+M99QhGJTiyV47Oj7/Xa6luW1Ew== X-Google-Smtp-Source: AGHT+IH64742sJcngCd9nDwpmR+R9gQ3XqAE85uzPYbwX29ssCfCBBi3kPYZO43+SQtd2ENG0aFLBg== X-Received: by 2002:a05:6a00:194b:b0:6ef:a0fe:c478 with SMTP id s11-20020a056a00194b00b006efa0fec478mr1616306pfk.34.1713922130242; Tue, 23 Apr 2024 18:28:50 -0700 (PDT) Received: from badger.vs.shawcable.net ([2604:3d08:9880:5900:1fa0:b3a5:f828:f414]) by smtp.gmail.com with ESMTPSA id fk24-20020a056a003a9800b006ed9d839c4csm10271007pfb.4.2024.04.23.18.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 18:28:49 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com, yonghong.song@linux.dev, jemarch@gnu.org, thinker.li@gmail.com, Eduard Zingerman Subject: [PATCH bpf-next 3/5] selftests/bpf: do not pass NULL for non-nullable params in dummy_st_ops Date: Tue, 23 Apr 2024 18:28:19 -0700 Message-Id: <20240424012821.595216-4-eddyz87@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240424012821.595216-1-eddyz87@gmail.com> References: <20240424012821.595216-1-eddyz87@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net dummy_st_ops.test_2 and dummy_st_ops.test_sleepable do not have their 'state' parameter marked as nullable. Update dummy_st_ops.c to avoid passing NULL for such parameters, as the next patch would allow kernel to enforce this restriction. Signed-off-by: Eduard Zingerman --- tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c | 7 +++++-- tools/testing/selftests/bpf/progs/dummy_st_ops_success.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c b/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c index f43fcb13d2c4..dd926c00f414 100644 --- a/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c +++ b/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c @@ -98,7 +98,8 @@ static void test_dummy_init_ptr_arg(void) static void test_dummy_multiple_args(void) { - __u64 args[5] = {0, -100, 0x8a5f, 'c', 0x1234567887654321ULL}; + struct bpf_dummy_ops_state st = { 7 }; + __u64 args[5] = {(__u64)&st, -100, 0x8a5f, 'c', 0x1234567887654321ULL}; LIBBPF_OPTS(bpf_test_run_opts, attr, .ctx_in = args, .ctx_size_in = sizeof(args), @@ -115,6 +116,7 @@ static void test_dummy_multiple_args(void) fd = bpf_program__fd(skel->progs.test_2); err = bpf_prog_test_run_opts(fd, &attr); ASSERT_OK(err, "test_run"); + args[0] = 7; for (i = 0; i < ARRAY_SIZE(args); i++) { snprintf(name, sizeof(name), "arg %zu", i); ASSERT_EQ(skel->bss->test_2_args[i], args[i], name); @@ -125,7 +127,8 @@ static void test_dummy_multiple_args(void) static void test_dummy_sleepable(void) { - __u64 args[1] = {0}; + struct bpf_dummy_ops_state st; + __u64 args[1] = {(__u64)&st}; LIBBPF_OPTS(bpf_test_run_opts, attr, .ctx_in = args, .ctx_size_in = sizeof(args), diff --git a/tools/testing/selftests/bpf/progs/dummy_st_ops_success.c b/tools/testing/selftests/bpf/progs/dummy_st_ops_success.c index cc7b69b001aa..ec0c595d47af 100644 --- a/tools/testing/selftests/bpf/progs/dummy_st_ops_success.c +++ b/tools/testing/selftests/bpf/progs/dummy_st_ops_success.c @@ -34,7 +34,7 @@ SEC("struct_ops/test_2") int BPF_PROG(test_2, struct bpf_dummy_ops_state *state, int a1, unsigned short a2, char a3, unsigned long a4) { - test_2_args[0] = (unsigned long)state; + test_2_args[0] = state->val; test_2_args[1] = a1; test_2_args[2] = a2; test_2_args[3] = a3; From patchwork Wed Apr 24 01:28:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 13640930 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31D15BE58 for ; Wed, 24 Apr 2024 01:28:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713922133; cv=none; b=CZH5gG0xaJ2KzLHRvXkp5rb1SzjUuw0PDsuJ7z6S+TM+GDYTuJR4/iirgzc8liBXulT0PZTfwlIk4c2y+GQeNJKyixQVPmS2/L5zF4A8PFJfdLkRWLaimksQqi1CW0i6mpXFRcgLy8fu+po+0Ax/flR62grR5D8CNakQ0CWR7WA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713922133; c=relaxed/simple; bh=XNTFwPXq/zIkKx/7/jSsPYtHd3EJEu4EHGglxp4R8r4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pkCW+226Jz5Wa+3tTtpLrYcx05xGbEF0AS5dyjGGVtWl2O1K6g4pQt0h4byqBmsnEgfV2E79b8+Mv6fdUWu97IGjFKooSGp1Wi8M2giUIWfjShVx/UPGcAcJTfYsFrh0PORd4SAMATIqsRaE+xjUFHbWVjCcKUG9Ftp6AFegpZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lLkwYxqe; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lLkwYxqe" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6effe9c852eso5390407b3a.3 for ; Tue, 23 Apr 2024 18:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713922131; x=1714526931; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bWRdC3oo/A3o44C4yupF67pCknfH6xg5tY+ELJrIY7g=; b=lLkwYxqeoIE0tkAEAsb8Sll+zrcW6NEpzko3gM050VXTbV6xq9mE5DhGHDsuYZXBgm YyEWV/h89Dis+E/8ILLwOKwMhu8IFb0tYdF9cC89iPFv/vArm/8zWFcg2CaIuRfTJyH0 ElzQaT3EZHRiXs8AM7y19LlIKilObPOU0cJ+ImKUGJ/2S+P70oPN0kAAcbtm7chreKX2 w1cmt84f8PO5IOLqAibmCKbNcmYOIEXBUREgwSovspqEHro9pWhAqLKDRdF1282JnOLl H6fqWcsU5dZMBuMexO4Hm8j8t0V+tCHroYg9JfjzCC9X7RLn82sLlMztLfdhmMiLV/Fq Yzlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713922131; x=1714526931; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bWRdC3oo/A3o44C4yupF67pCknfH6xg5tY+ELJrIY7g=; b=YMPiFrhL9ajbBc3tfEb/FXV7nj13/7E3Btsj07KqrEkLbK4iAB3k2X/0hBrUB4cvLk Oweq/gsjs0cqdb5FV9exyEST0v1ZJRVq3Zv1PvMO87Vy62svWjT3LRnJO5CdmYmg0vyU PDKss/VYV90GdX/NZYyWvT6qfUAhTn57szYO3wzHbbm5mbfDnvWfFIicp/HpwWsOeySP BqutMjJnSs29QFX4IBuFwshSMWV/Bi0Mzh20n8b0cNH0lhLD6MWMXtIfGazPrh3ChKF2 XqUN8T7KVWEpqFCZpFqF8QhWETdwFNM8nDM6rtiWyVHc8R/JhnhXWC3mFBkvpaRNA0pH d6yA== X-Gm-Message-State: AOJu0YzdiwwQbxJVOXNHfS59lOG/zuuyW6lmSPnYa69+olqO5EyxwPf8 neVoSz4/9jIJyqwIm9vGmf0JFnzHhFm8AYs6SDjIGwsO1OP7SBHvToEwqw== X-Google-Smtp-Source: AGHT+IGZRMs1xa68wB2IhzBIEqSv7YTp/HflRTneLVcX168AU6WDwsBYxPdmEoAHcO3TD37AfCUduw== X-Received: by 2002:a05:6a00:1823:b0:6f0:c9b8:e8f9 with SMTP id y35-20020a056a00182300b006f0c9b8e8f9mr1409515pfa.33.1713922131260; Tue, 23 Apr 2024 18:28:51 -0700 (PDT) Received: from badger.vs.shawcable.net ([2604:3d08:9880:5900:1fa0:b3a5:f828:f414]) by smtp.gmail.com with ESMTPSA id fk24-20020a056a003a9800b006ed9d839c4csm10271007pfb.4.2024.04.23.18.28.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 18:28:50 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com, yonghong.song@linux.dev, jemarch@gnu.org, thinker.li@gmail.com, Eduard Zingerman , Kui-Feng Lee Subject: [PATCH bpf-next 4/5] bpf: check bpf_dummy_struct_ops program params for test runs Date: Tue, 23 Apr 2024 18:28:20 -0700 Message-Id: <20240424012821.595216-5-eddyz87@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240424012821.595216-1-eddyz87@gmail.com> References: <20240424012821.595216-1-eddyz87@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net When doing BPF_PROG_TEST_RUN for bpf_dummy_struct_ops programs, reject execution when NULL is passed for non-nullable params. For programs with non-nullable params verifier assumes that such params are never NULL and thus might optimize out NULL checks. Suggested-by: Kui-Feng Lee Signed-off-by: Eduard Zingerman --- net/bpf/bpf_dummy_struct_ops.c | 51 +++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/net/bpf/bpf_dummy_struct_ops.c b/net/bpf/bpf_dummy_struct_ops.c index 8f413cdfd91a..891cdf61c65a 100644 --- a/net/bpf/bpf_dummy_struct_ops.c +++ b/net/bpf/bpf_dummy_struct_ops.c @@ -79,6 +79,51 @@ static int dummy_ops_call_op(void *image, struct bpf_dummy_ops_test_args *args) args->args[3], args->args[4]); } +static const struct bpf_ctx_arg_aux *find_ctx_arg_info(struct bpf_prog_aux *aux, int offset) +{ + int i; + + for (i = 0; i < aux->ctx_arg_info_size; i++) + if (aux->ctx_arg_info[i].offset == offset) + return &aux->ctx_arg_info[i]; + + return NULL; +} + +/* There is only one check at the moment: + * - zero should not be passed for pointer parameters not marked as nullable. + */ +static int check_test_run_args(struct bpf_prog *prog, struct bpf_dummy_ops_test_args *args) +{ + const struct btf_type *func_proto = prog->aux->attach_func_proto; + + for (u32 arg_no = 0; arg_no < btf_type_vlen(func_proto) ; ++arg_no) { + const struct btf_param *param = &btf_params(func_proto)[arg_no]; + const struct bpf_ctx_arg_aux *info; + const struct btf_type *t; + int offset; + + if (args->args[arg_no] != 0) + continue; + + /* Program is validated already, so there is no need + * to check if t is NULL. + */ + t = btf_type_skip_modifiers(bpf_dummy_ops_btf, param->type, NULL); + if (!btf_type_is_ptr(t)) + continue; + + offset = btf_ctx_arg_offset(bpf_dummy_ops_btf, func_proto, arg_no); + info = find_ctx_arg_info(prog->aux, offset); + if (info && (info->reg_type & PTR_MAYBE_NULL)) + continue; + + return -EINVAL; + } + + return 0; +} + extern const struct bpf_link_ops bpf_struct_ops_link_lops; int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr, @@ -87,7 +132,7 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr, const struct bpf_struct_ops *st_ops = &bpf_bpf_dummy_ops; const struct btf_type *func_proto; struct bpf_dummy_ops_test_args *args; - struct bpf_tramp_links *tlinks; + struct bpf_tramp_links *tlinks = NULL; struct bpf_tramp_link *link = NULL; void *image = NULL; unsigned int op_idx; @@ -109,6 +154,10 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr, if (IS_ERR(args)) return PTR_ERR(args); + err = check_test_run_args(prog, args); + if (err) + goto out; + tlinks = kcalloc(BPF_TRAMP_MAX, sizeof(*tlinks), GFP_KERNEL); if (!tlinks) { err = -ENOMEM; From patchwork Wed Apr 24 01:28:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 13640931 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-oa1-f52.google.com (mail-oa1-f52.google.com [209.85.160.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DB2DCA7D for ; Wed, 24 Apr 2024 01:28:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713922134; cv=none; b=Bq3WaDp/OkqK3NJ4EUoTe4SY0nn3RaoFWB5Uj1hYwAgNJXH63WayUumGUTdEFBft61gkOCu8nZn1GL9+1MY6ygcXq1CDrMcy5dj+QtXoDI47kzVdciTmL0gEsN0o8W+dvFrmVA28vpdVwAgnGU9TvHoZ1rowY8Lwk43oSJ2rhvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713922134; c=relaxed/simple; bh=Tdj8PEmhBw//fpzzqQ3cqJbR9zPcqXUGzRE5ORM6SGE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=URg331a6MUyFsrvkB0/UMxrb0ZepxFtzOHXIQK9sDdjVsdC8yjNX/10mNDcJxy6JkRJhMQk4ETQo8GlQSwhDc0+LtjW5wMQDWMhObSioBdPvzmFoz0HWv7y7V6A1qiaekxFYQIzzB0pzfjeIXf08MHHMNtTBSdlsrsS8uHKpBUs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mB+aYc3v; arc=none smtp.client-ip=209.85.160.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mB+aYc3v" Received: by mail-oa1-f52.google.com with SMTP id 586e51a60fabf-2228c4c5ac3so3544553fac.0 for ; Tue, 23 Apr 2024 18:28:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713922132; x=1714526932; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O5pj7SymkM183LlMpcQuiaA71zx4yWKamRf7W07OAQc=; b=mB+aYc3vDhX2OepIJLrijAdQGiNoWErPKW+906iiHAZFzgo9ckyRZdbRvGuLqG/yEV WxzFfBbvdCFtZTrA0yq0j8V6/bcHkRH1ZHEe3HNGNvSm0tKVmRl663V1mVZ2z3mrUYxk YNc9c5LRgX8IC7K7J35QopeMKEUlkhTYuAHAYgHTmMSmuZiM4HhGMiPAbP8bHcZrvImv Bwi3HLzFSnrnv7vv0Xl3UDQKPimpMkUW3A7BC9vTWtkCc6+WPWToybddXewXFj/iQts3 VgGShiCkcvcnv/mtDc8kfFNwcjCEpNkI+Ry/GD8KnmL+hb1doXptjCkKpVo59fKwXJiv gmPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713922132; x=1714526932; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O5pj7SymkM183LlMpcQuiaA71zx4yWKamRf7W07OAQc=; b=VTwITzcnwKMfd1umUfYYfvxHy88B6WZ3vuSrLnv31627omJ0jY4MJSpcaHQovq5pIk gcsYQqSJqOadM4jC1BuYzdw6BTC1VI2muIpd2lW/u1UJiOTxm/5CzWkRFD07hKefpWR8 FwCmbK+JvaKtnlWI2GZSDs0Bc68JxfCrEMX2K8x/5AKOTmG6CYBZjg3cCCjJ2ScZntRG n6BiFE2nKZr789HTczn8ITvYuEUHsimhnchbfzxtdfP5OTH+WWuBeGdyp2WqgDR7SOWd pPFkRNX9/9KvXMeFKeUG3phnVjWQVcIYHpchqu0Fu0qvyXZdE8otlUj6309nMjyzxLUA A/3w== X-Gm-Message-State: AOJu0Yzf7/RQS/FZIWkuSIDXafmPU2Kvx7U/jfnGxkSFqpJ5pf0yLl+E u9STpgXP33keyvdLyWjawEQY4Eqf6z1sp6tC2SPFi8Ih1c/CzAELDfL8ew== X-Google-Smtp-Source: AGHT+IEOqqexFuVHrPFNcZx9igSN/t37QTx62Ck8bqCrNE/ZDhLcCZoVXMl5jBcasJAoglGovOXqRQ== X-Received: by 2002:a05:6870:968e:b0:22a:1ce4:c0cf with SMTP id o14-20020a056870968e00b0022a1ce4c0cfmr1233836oaq.55.1713922132280; Tue, 23 Apr 2024 18:28:52 -0700 (PDT) Received: from badger.vs.shawcable.net ([2604:3d08:9880:5900:1fa0:b3a5:f828:f414]) by smtp.gmail.com with ESMTPSA id fk24-20020a056a003a9800b006ed9d839c4csm10271007pfb.4.2024.04.23.18.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 18:28:51 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com, yonghong.song@linux.dev, jemarch@gnu.org, thinker.li@gmail.com, Eduard Zingerman Subject: [PATCH bpf-next 5/5] selftests/bpf: dummy_st_ops should reject 0 for non-nullable params Date: Tue, 23 Apr 2024 18:28:21 -0700 Message-Id: <20240424012821.595216-6-eddyz87@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240424012821.595216-1-eddyz87@gmail.com> References: <20240424012821.595216-1-eddyz87@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Check if BPF_PROG_TEST_RUN for bpf_dummy_struct_ops programs rejects execution if NULL is passed for non-nullable parameter. Signed-off-by: Eduard Zingerman --- .../selftests/bpf/prog_tests/dummy_st_ops.c | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c b/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c index dd926c00f414..d3d94596ab79 100644 --- a/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c +++ b/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c @@ -147,6 +147,31 @@ static void test_dummy_sleepable(void) dummy_st_ops_success__destroy(skel); } +/* dummy_st_ops.test_sleepable() parameter is not marked as nullable, + * thus bpf_prog_test_run_opts() below should be rejected as it tries + * to pass NULL for this parameter. + */ +static void test_dummy_sleepable_reject_null(void) +{ + __u64 args[1] = {0}; + LIBBPF_OPTS(bpf_test_run_opts, attr, + .ctx_in = args, + .ctx_size_in = sizeof(args), + ); + struct dummy_st_ops_success *skel; + int fd, err; + + skel = dummy_st_ops_success__open_and_load(); + if (!ASSERT_OK_PTR(skel, "dummy_st_ops_load")) + return; + + fd = bpf_program__fd(skel->progs.test_sleepable); + err = bpf_prog_test_run_opts(fd, &attr); + ASSERT_EQ(err, -EINVAL, "test_run"); + + dummy_st_ops_success__destroy(skel); +} + void test_dummy_st_ops(void) { if (test__start_subtest("dummy_st_ops_attach")) @@ -159,6 +184,8 @@ void test_dummy_st_ops(void) test_dummy_multiple_args(); if (test__start_subtest("dummy_sleepable")) test_dummy_sleepable(); + if (test__start_subtest("dummy_sleepable_reject_null")) + test_dummy_sleepable_reject_null(); RUN_TESTS(dummy_st_ops_fail); }