From patchwork Thu Jan 16 05:51:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonghong Song X-Patchwork-Id: 13941301 Received: from 66-220-155-178.mail-mxout.facebook.com (66-220-155-178.mail-mxout.facebook.com [66.220.155.178]) (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 457E629A1 for ; Thu, 16 Jan 2025 05:51:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.220.155.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737006701; cv=none; b=RN2y+wDPSQrV8fWH4cTlpVSRr9mXYrm+LwKmwNUs/RrljXEkfZX7e4jTqNC5rlfTFyoR3KgHogXpO33rX3YM+xEa+QeRdPVAyLeAUKQ5mZTGtcU9hcFNfu3VltPnqADpJUySegDBOJndF5NLrP5DHswPSsmK0dEeaMQR/M3rM+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737006701; c=relaxed/simple; bh=6f//Jd0B/1dhzHrhochm+DlN+51m5p6dKMAXl6g/o1E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=a5wZPC7XIRFoCBZ/Vjmg6WQEe4BniWKrRNVaPvzFOVDoOXHjONWV/iKypPF78Hom0xo6+a9R7f6E+etJVCzjNhGoRUWLbhdKocD3RW32zif/HogxYfCZe/yIcBItkQU/ugpoaNGzsBNtg7hjCrJcDlNHKPbcM2lDxYFpIZTUxjo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev; spf=fail smtp.mailfrom=linux.dev; arc=none smtp.client-ip=66.220.155.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=linux.dev Received: by devbig309.ftw3.facebook.com (Postfix, from userid 128203) id 0200ED032429; Wed, 15 Jan 2025 21:51:23 -0800 (PST) From: Yonghong Song To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , kernel-team@fb.com, Martin KaFai Lau Subject: [PATCH bpf-next 0/3] bpf: Allow 'may_goto 0' instruction Date: Wed, 15 Jan 2025 21:51:23 -0800 Message-ID: <20250116055123.603790-1-yonghong.song@linux.dev> X-Mailer: git-send-email 2.43.5 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 Emil Tsalapatis from Meta reported such a case where 'may_goto 0' insn is generated by clang-19 compiler and this caused verification failure since 'may_goto 0' is rejected by verifier. In fact, 'may_goto 0' insn is actually a no-op and it won't hurt verification. The only side effect is that the verifier will convert the insn to a sequence of codes like /* r10 - 8 stores the implicit loop count */ r11 = *(u64 *)(r10 -8) if r11 == 0x0 goto pc+2 r11 -= 1 *(u64 *)(r10 -8) = r11 With this patch set 'may_goto 0' insns are allowed in verification which also removes those insns. Yonghong Song (3): bpf: Allow 'may_goto 0' instruction bpf: Remove 'may_goto 0' instruction selftests/bpf: Add some tests related to 'may_goto 0' insns kernel/bpf/verifier.c | 41 +++++++- .../selftests/bpf/prog_tests/verifier.c | 4 + .../selftests/bpf/progs/verifier_may_goto_1.c | 97 +++++++++++++++++++ .../selftests/bpf/progs/verifier_may_goto_2.c | 28 ++++++ 4 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/verifier_may_goto_1.c create mode 100644 tools/testing/selftests/bpf/progs/verifier_may_goto_2.c