From nobody Tue Dec 2 02:32:13 2025 Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (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 4DDCE3358DB for ; Wed, 19 Nov 2025 22:42:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763592177; cv=none; b=qcjbCCM0vIILoWom0nKZD1CB0PwtAdrUyjSgD/G4LGrU0MbqWPRpAKvqYFd3dUqwwXT+w77VLq5kQ2niJM/LX0k86X4IbZdHKqgk7Hs383L20z/jzS+WTkkmuLu+3wo7jUb7S9aHih9azeufVCzCzglA2k+dKEY/onHOugkt4bE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763592177; c=relaxed/simple; bh=gAsQ1BSMJqiVR8shfZtZyu7x2+PjqZJQokKQtFZDbhs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F/LWMzYeqO3GPf54BmH4lBVbuBpma1X+5Rs9kgXsiecK8WLbr83l6iE7an2luPBFnKkZhMsDDI1Vpn/KsErlkk7CEexZlLcnUSwNHEHE4a+0CUduE9dmGliMlUpp2gu0dOe2h95c/zKyX7CfsH30ziLZpV0jquSb5VTSq7VRQBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=runbox.com; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b=YJTQK6bP; arc=none smtp.client-ip=185.226.149.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=runbox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b="YJTQK6bP" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vLqt2-006kxq-4O for linux-kernel@vger.kernel.org; Wed, 19 Nov 2025 23:42:52 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector1; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=lcMHhp25wy5nbuDPLhTDVdMWQ5rl0c1LdhaGtzxA1uQ=; b=YJTQK6bPVL5ryK/U8U+yc5/0S7 X2CDQZgd2Bl2hh7/DQY1DYXJ87uCIBxyP1QRtS2cpgwfmAjGQ6hMpMccxcUZAiHiAP96Kk5ogAcEM OJ3uRc9DCQEZhb9aAvZY8hHJ0s9C/1tkkiL6JFWPSOA8OeNhrK/rMAPlHBouHj0rePAnaJLyNtcHs 5CicLzrQSL1kdLnhVCuPSPlyvbYGJ4WrwPuFzHE2IdmLkd6PJsyMTcv8wOAdMWcZwmkRFviTaP6jC lIYEZRBAdWWYfUrjqJ+WT0QrJSQB97sj8ieuLRllDiyxDGklAEI6Qnp+YEyEY8k72wtR7bFPvQ0Dy q1sS0gkA==; Received: from [10.9.9.74] (helo=submission03.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vLqt1-0000Dw-QT; Wed, 19 Nov 2025 23:42:51 +0100 Received: by submission03.runbox with esmtpsa [Authenticated ID (1493616)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1vLqsk-00Fos6-Hk; Wed, 19 Nov 2025 23:42:34 +0100 From: david.laight.linux@gmail.com To: linux-kernel@vger.kernel.org, bpf@vger.kernel.org Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , David Laight Subject: [PATCH 34/44] bpf: use min() instead of min_t() Date: Wed, 19 Nov 2025 22:41:30 +0000 Message-Id: <20251119224140.8616-35-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251119224140.8616-1-david.laight.linux@gmail.com> References: <20251119224140.8616-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight min_t(unsigned int, a, b) casts an 'unsigned long' to 'unsigned int'. Use min(a, b) instead as it promotes any 'unsigned int' to 'unsigned long' and so cannot discard significant bits. In this case the 'unsigned long' value is small enough that the result is ok. Detected by an extra check added to min_t(). Signed-off-by: David Laight --- kernel/bpf/core.c | 4 ++-- kernel/bpf/log.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index d595fe512498..4f9808ea51fb 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -1081,7 +1081,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image= _ptr, bpf_fill_ill_insns(hdr, size); =20 hdr->size =3D size; - hole =3D min_t(unsigned int, size - (proglen + sizeof(*hdr)), + hole =3D min(size - (proglen + sizeof(*hdr)), PAGE_SIZE - sizeof(*hdr)); start =3D get_random_u32_below(hole) & ~(alignment - 1); =20 @@ -1142,7 +1142,7 @@ bpf_jit_binary_pack_alloc(unsigned int proglen, u8 **= image_ptr, bpf_fill_ill_insns(*rw_header, size); (*rw_header)->size =3D size; =20 - hole =3D min_t(unsigned int, size - (proglen + sizeof(*ro_header)), + hole =3D min(size - (proglen + sizeof(*ro_header)), BPF_PROG_CHUNK_SIZE - sizeof(*ro_header)); start =3D get_random_u32_below(hole) & ~(alignment - 1); =20 diff --git a/kernel/bpf/log.c b/kernel/bpf/log.c index f50533169cc3..01dc13aaa785 100644 --- a/kernel/bpf/log.c +++ b/kernel/bpf/log.c @@ -79,7 +79,7 @@ void bpf_verifier_vlog(struct bpf_verifier_log *log, cons= t char *fmt, /* check if we have at least something to put into user buf */ new_n =3D 0; if (log->end_pos < log->len_total) { - new_n =3D min_t(u32, log->len_total - log->end_pos, n); + new_n =3D min(log->len_total - log->end_pos, n); log->kbuf[new_n - 1] =3D '\0'; } =20 --=20 2.39.5