From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (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 276E31A76D0; Mon, 7 Jul 2025 23:29:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751930975; cv=none; b=Va6G1utD0Xf0Um9DZjGK1HxpgADsiXPtytIsJ5vruX5TUjVn0vmgW06MTX3oHy3PIrqGGYfzlAmYGMSx8JIK9Gx+Iooxo5WYbep6n0IwEtvHzdONN4ODCo1BBxKkjmoI6zkK3E+9FgT1hb4h+SctNLO5sjEXBY/gnfbGIqUY5fg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751930975; c=relaxed/simple; bh=tDfslSGThUSSeDw6MEDGAodzhrzY37bUiuz93OXBkP4=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=hWfIuaBOirky8LfvOg52jK3LcUdOhw3WivLUu7kvJXDvxV4dnkwY3qZ87rpmbTWSb+z8tzrNSz6T5DcsjVn6hjJRigLjNB0QK+uX3vAQ6OWTWXkk8FDRlw/3DaWPZ5ql7k8wFQUzW3ETX2fYZoFVdyuqg1jjR/oiQlQBKmDJ5Kw= 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=f6oYTr5b; arc=none smtp.client-ip=209.85.215.173 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="f6oYTr5b" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-b34a8f69862so3005946a12.2; Mon, 07 Jul 2025 16:29:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751930973; x=1752535773; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=E2q/+ZmwOZVJfPSae1Ojo1PnKlFTAiIjYB1Ogh0Ew14=; b=f6oYTr5bdFeHm2JKwrHCYK0p1b/J0NHdVsfZOVbOPNLVwmMD7PmvhZ4cUaAdiM6spv e0s0ogS1/lGYtUvyeQNl0ZCtIRfgM0ha5tfnYcJI8DtbMPksY1tI/yYOd25p/84QfOl7 ATx7indAF77cTeahDrAc47kZgNnozs1yw4JRFkHbHnXDkCiqoe4JgGBufecs5DTU/w2t TFdA5mtz9CMHUZ8UBQ6LiPIQ3w0XPgM39+f2PV6CGGxqd7U/GMwnVV5tyH8ODamcS09Q vNT00mKh8Ah1HMDY5IOhTB+285bRA+m2mQAeHNWtbCq8ReevbWyYDmevh8WdidXOYH0K xchg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751930973; x=1752535773; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=E2q/+ZmwOZVJfPSae1Ojo1PnKlFTAiIjYB1Ogh0Ew14=; b=D92qyw9f6PBhZKNcMVDAqAqFt5L79QoNHJKgkPhWiNzCqA5lqSy8KjqyykM2n02paj zzGWQ8g94IkW8VOHdIgHhNnCoc/GbV5rwkqj/zQfM2CgIZ7MIx6klRRORZEVksrL2FiD dk6PvfJmU8T2vo8FIelQ+k5al/At4nKPVvnOgbP3/U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received: by 2002:a05:6a20:43a1:b0:218:17c4:248c with SMTP id adf61e73a8af0-2260b2953dfmr21552737637.22.1751930973280; Mon, 07 Jul 2025 16:29:33 -0700 (PDT) Received: from ?IPv6:2620:10d:c096:14a::647? ([2620:10d:c090:600::1:6ad]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b38ee450a61sm9882340a12.8.2025.07.07.16.29.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jul 2025 16:29:32 -0700 (PDT) Message-ID: <2fb0a354ec117d36a24fe37a3184c1d40849ef1a.camel@gmail.com> Subject: Re: [syzbot] [bpf?] WARNING in reg_bounds_sanity_check From: Eduard Zingerman To: Paul Chaignon Cc: syzbot , andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org, linux-kernel@vger.kernel.org, martin.lau@linux.dev, netdev@vger.kernel.org, sdf@fomichev.me, song@kernel.org, syzkaller-bugs@googlegroups.com, yonghong.song@linux.dev Date: Mon, 07 Jul 2025 16:29:30 -0700 In-Reply-To: References: <68649190.a70a0220.3b7e22.20e8.GAE@google.com> <865f2345eaa61afbd26d9de0917e3b1d887c647d.camel@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2 (3.56.2-1.fc42) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Tue, 2025-07-08 at 00:30 +0200, Paul Chaignon wrote: [...] > This is really nice! I think we can extend it to detect some > always-true branches as well, and thus handle the initial case reported > by syzbot. > > - if a_min =3D=3D 0: we don't deduce anything > - bits that may be set in 'a' are: possible_a =3D or_range(a_min, a_max) > - bits that are always set in 'b' are: always_b =3D b_value & ~b_mask > - if possible_a & always_b =3D=3D possible_a: only true branch is possibl= e > - otherwise, we can't deduce anything > > For BPF_X case, we probably want to also check the reverse with > possible_b & always_a. So, this would extend existing predictions: - [old] always_a & always_b -> infer always true - [old] !(possible_a & possible_b) -> infer always false - [new] if possible_a & always_b =3D=3D possible_a -> infer true (but make sure 0 is not in possible_a) And it so happens, that it covers example at hand. Note that or_range(1, (u64)-1) =3D=3D (u64)-1, so maybe tnum would be sufficient, w/o the need for or_range(). The part of the verifier that narrows the range after prediction: regs_refine_cond_op: case BPF_JSET | BPF_X: /* reverse of BPF_JSET, see rev_opcode() */ if (!is_reg_const(reg: reg2, subreg32: is_jmp32)) swap(reg1, reg2); if (!is_reg_const(reg: reg2, subreg32: is_jmp32)) break; val =3D reg_const_value(reg: reg2, subreg32: is_jmp32); ... reg1->var_off =3D tnum_and(a: reg1->var_off, b: tn= um_const(value: ~val)); ... break; And after suggested change this part would be executed only if tnum bounds can be changed by jset. So, this eliminates at-least a sub-class of a problem.