From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.100 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796004336; b=Ots1alDjQSgxjbRZLn+PKnDYtxwybsCRAGayFl4GSw3kw6f7Atbt5tmfoaAhl1eSgjGh TXhwE5o5/LSvjyqpZmJ18HgTdTXiGdnxx9McwmfNk8s0L0HW2/H542a0r063MYsmcdONP 2sMtsFf738r8apnDMU8KVP/A14hbAlTd7vBOgPRiST1Rbmi+rwrC0z4ncokeetRx0z3c1 J5NK1X1hQFbst+OYTA3ipzWUh4HRJyD5doVZKT78cfD+b5REE19tRiBux/NthlWPRErQB unLHRFYt+X00DufNGIHJPIhhcLhPS69Fxa9LLbi6a6LhIH5LGs8onQOXlneYkqWg9dw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796004336; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: X-Relaying-Domain:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=EZUHNOKVxxvyPbVALTYSeXafb3a3H80gYTGVGdoKnEE=; b=Jtf+D0ut17TBn+S9BbDZDf5jAIBTS4UQcRSAM+Dq7ZDz3Axfy/u30wEBRRLhwYrrMXHk ooGeLvkKNegQVEXHkQk7u9oBXUt3ss0XH+MBbcy40AsWgbWdipEQ47Le1SOF0kZIyu33F GJUd18gjxW7vtz0EVtVvlLmWC7MzQIr3ZA8OPHgOHArQUKVVhKGLkff0EGF5fjuwJ64ad MgmJv7VPsiq37/Pcf74NDrVcLbK3BLzjNRumZCRlmBJxQ4rgfDrQJoNG2GjXWnAczxK4n aDjIUIUSsgd5sq6qZp4P5nDC/on0rfx+LwOofj+051NMgZt+wSn4frx3nSyl2JwgxiA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=andrii.net; spf=pass smtp.mailfrom=andrii.net; dkim=pass header.d=andrii.net header.i=@andrii.net header.a=rsa-sha256 header.s=gmail-2025 header.b=TgaDEGbg; arc=none smtp.remote-ip=209.85.216.100 Received: from mail-pj1-f100.google.com (mail-pj1-f100.google.com [209.85.216.100]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDC4D606A31D for ; Mon, 30 Nov 2026 02:05:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EDC4D606A31D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=andrii.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=andrii.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=andrii.net header.i=@andrii.net header.a=rsa-sha256 header.s=gmail-2025 header.b=TgaDEGbg Received: by mail-pj1-f100.google.com with SMTP id 98e67ed59e1d1-3b44bdcea8aso5755351a91.1 for ; Sun, 29 Nov 2026 18:05:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=andrii.net; s=gmail-2025; t=1796004335; x=1796609135; 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:content-type; bh=EZUHNOKVxxvyPbVALTYSeXafb3a3H80gYTGVGdoKnEE=; b=TgaDEGbg9EZgjd6HpCKMMcUktY9tPuohqD6RS5+npJzLeTnEjiSQYyD2KcSR62mbO4 Z+U2LjQzzTDPG/ndgOSpU8IgNrlu6kGk3VqBGbSD3Lzv0ErYlfC39cPFccmybZcRvoAK OuwK5s4Bbti+TSibN64CRtqC5wFLTZEtWCAoaVJ0BDtvBfc08Zr6iNnjUwChE+jgrZWv KITeQXrPSJCT7jBU3XJc7la0gx0ZpT4XZkBzG47tf7sIEOBHJTRTwXJ7N7UhXJAQQHHY 5uISak+0mDrYqPTTuAY6eLK19mXzVN4evbUij+xD0UI1GOCb+fMQi9m/Asw3fxxQ1kF+ 26Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796004335; x=1796609135; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=EZUHNOKVxxvyPbVALTYSeXafb3a3H80gYTGVGdoKnEE=; b=uBac584Ukux9l+htVN5zrlUVm/dFG5Vn4iUs7GNcH8e4KQB08CjTdPXUC3NmbALmNd xeJOxS/J31umeWV1Brte+WcOMjXryyQe2BIw9OYvjrp3RmDEwkbH7jemdw358IAr05iZ iz++BQYoDl6a2i6jtKHgPIK9wVxgN5RFSyV0QKqpGjMVdoBL0kbiXHVjYpmAcq37nsaE mFkWwbs0QDUhnx0+pmUqMVkliix9IOsWsNYiTgnWTrFHMxLGnThYvVHS1BZhVFMzmH53 ucE1ACefpxM7trrkjdzWOg1ZFiV894/L5spQc0XV2PbDrHsq3LAUTew3+cGaGBJRZfGZ CEjQ== X-Forwarded-Encrypted: i=1; AL+hErGUZI/1geyotonB9yRRvQGA2kQxmk608vJ28zNa5DPw42AdHY6imI4GAaGE/jV3EFVqPQCq2xIxzp5x0yw=@vger.kernel.org X-Gm-Message-State: APuU4Z9x5toGz5S00xu5JR+rFwAU4w+/426Dl7U09ZNlhd2vArRYvpHj 2YcnM0ZQUp/wSmkUXIZn62bK7zrKPHpFReEH/QvuYigO7QYXbQAPXaTz7h9l3fKH+ul/bkEdmrq n+h6QQnnk1SnhMM8TIiXIh5JCwKZbESancqnmmBBdGo12wmT9lD3s X-Gm-Gg: AZFdTZdIaVXlEpO0bSxuTnbiKoFZMMNzoZMcBPhh01e0Pt8CB2YU5iE4DtlXnWAPyaB u2Bg5bBV/RMt8kaj2ArDaHwhv3gFD0wPhpd2GmdETzgVmchmjKxYVUa8RigdERvWIvRZrOSz4F3 r2+uKId5X9cQKCOhRvnXgZGtIUc38nq+n0ywUBL0KgD2/r9jL0VpPUXtnANUsJGHlEYKY2L+YB7 CuicztHGHW4v6ZwgJG41DhMvuhRLqD/DgBlmmmFRtq1R6rrq3cYde44w4Hi4dCCDgBdGwpIFFHk OKrDrkglun/h9pvUbV/qC9PlDPDqfpi+qbFxovd2dprtGfKkE3fWfG2EJ7ksZCyCnub2L9L8YrD ZO8RvCyxb3UI+NM7qh5KYqyi2RFY= X-Received: by 2002:a17:90b:554e:b0:3ac:860e:1af9 with SMTP id 98e67ed59e1d1-3b41c981a67mr21876538a91.41.1796004335125; Sun, 29 Nov 2026 18:05:35 -0800 (PST) Received: from andrii.ai (mac.hestia.andrii.net. [2602:f337:ed:4865:7374:6961:204d:6163]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-3b41ac84fd5sm21885316a91.2.2026.11.29.18.05.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 29 Nov 2026 18:05:35 -0800 (PST) X-Relaying-Domain: andrii.net From: Andrii Tereshchenko To: netdev-bot+sashiko@kernel.org Cc: Steffen Klassert , Herbert Xu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Willem de Bruijn , netdev@vger.kernel.org, ipsec@lists.linux.dev, linux-kernel@vger.kernel.org, syzkaller@googlegroups.com Subject: Re: [PATCH ipsec] xfrm: policy: avoid an undefined shift when testing the auth algorithm Date: Sun, 29 Nov 2026 19:05:35 -0700 Message-ID: <715d488f-594d-4eac-950a-1aeabdecec1e@mid.andrii.net> X-Mailer: git-send-email 2.56.0 In-Reply-To: <179593186284.3146.17226586054560246501@kernel.org> References: <928a3d63-eb17-4192-8952-a9a74a89c5f9@mid.andrii.net> <179593186284.3146.17226586054560246501@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sashiko (netdev AI review) wrote: > On x86 and arm64, does this change which inbound digest_null SAs pass the > template check? [...] > Could tmpl->aalgos == ~0U also be treated as allowing any aalgo? That would > still avoid the out-of-range shift and would keep the "all auth algorithms" > meaning. Yes, it does, in one case, and "no functional change" below the --- was wrong. The test runs only when the template does not allow all algorithms (allalgs is 0). For a digest_null SA (SADB_X_AALG_NULL, 251), the old code tests bit 27 of aalgos on x86, where the compiled check is a bt on a 32-bit register (bit number modulo 32, and 251 = 7 * 32 + 27), and on arm64, where the shift count is also taken modulo 32. On 32-bit ARM, PowerPC and s390 the shift gives 0. So on x86 and arm64 a template installed with XFRM_MSG_NEWPOLICY, or as a socket policy, with bit 27 of aalgos set (in practice aalgos = ~0) and a restricted ealgos or calgos accepted inbound digest_null SAs, and with this patch it refuses them. Templates from iproute2 and PF_KEY have all three masks at ~0 (allalgs) and do not reach the shift, before or after. I would rather not give ~0 a meaning of its own, though: - aalgos is a mask of algorithm IDs, bit n for ID n, and nothing in the UAPI or the code says ~0 means more than IDs 0 to 31. The one "any algorithm" the code defines is allalgs, set in copy_templates() when all three masks are ~0. - digest_null was admitted by an out-of-range shift, so by bit 27, which names no algorithm, and only on some architectures. A template with any other mask that has bit 27 set admitted it too. - af_key.c has treated an ID outside the mask as not set since f398035f2dec ("[IPSEC]: Avoid undefined shift operation when testing algorithm ID") in 2007, and 32-bit ARM, PowerPC and s390 have always refused it here. The patch makes x86 and arm64 do the same. - digest_null gives no integrity protection. When a template restricts the algorithms, refusing an SA that no bit of the mask names is the safer reading; a policy that wants any algorithm, digest_null included, sets all three masks to ~0. Steffen, if you want the behaviour change in the git history, I'll send a v2 with the same code and the note moved above the --- in place of "no functional change". Andrii Tereshchenko