Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1847253lql; Wed, 13 Mar 2024 09:42:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX6c3yJtXy4T15H+JWxZ1uhdv+AAXJE1EPj+KEqmIQkju9aEco2E8+ZBdNw3INfPw90oHOGXiO3v+KmnI+/loR6DZvV3lD7wzHsKx41mQ== X-Google-Smtp-Source: AGHT+IE/NkBsVIv2ANdLTqX6w1uqnV8W5Diuda88DB1+x/HLaQ6TetK+rgVyoePRgQddEcjiAeBr X-Received: by 2002:a05:6358:5906:b0:17b:ee29:40a with SMTP id g6-20020a056358590600b0017bee29040amr598728rwf.6.1710348130659; Wed, 13 Mar 2024 09:42:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710348130; cv=pass; d=google.com; s=arc-20160816; b=rn5YUOihGauMdEZED3kskwaDBPIMPTMwMnFZXLKihv46ZUv9OAN7zcWLYeusCyvu3z TzTi0uo53sdiEnt7kJx57lv/JP5d6htnvjlHNMYQvWs9IFNdtV0eJzoz4WG/W7PFY9s5 czZ6QbOJe/7sNQHnUtcrjAfwn0RmuTOg8XFNumptfzFwWUlrktjViHlPjoh3Wz+eune3 XhRTG6e/W8M+heuBAzp9VgvotPBvtsOeOcquqe7uJzyhOSsvscfJ5k0fe1uyNRqTBXIL Ov6UJFGT1QpJgOK6n9EEhGzJytLzuab8p6dl/0gLzBjHvsHW+8WxuB++wJLXhns4kzlf 1fgg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=w9rbUtGgNGDvXslml94XX68j77x5l0xCpxZjZqFi74A=; fh=8BCRhSjjitfkgvC2+9aeZGi+53AP2zOCkXMCsmUKX8U=; b=F6bJwW0ASSpxV59DiNZgykGMh2mIwT9ORDJgPUIFhIeM/eGHX2NpgvooYD6ukPHhBu cPIgPHlUz5FkOvZ6xUS0PwhDWuPEYC/Cg6yELumUivgc1M9fuXNzqLTqfDCYWhi6X9ol pEKZM6WztcgUsmw/2rGnjDPkNIWTbkbf0ltyscnu/0UDjRUjFCqbTQIRpgu1xwcJWWkz cJArDRQE9kI0H3HzTWtccmN/GfYJR8c1en886t+aAFAGmZG4L3GXhc+dgXFQdFO1Zerb KqMaS9ispgihFZYF9Ym5s2U+O8Rjo7aiV3+S6pYA2QqQfQPANvp0+m6aK+sylddi+QfD v8nw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f5M8AEvl; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101780-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101780-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p29-20020a63951d000000b005d849f5352csi9409727pgd.795.2024.03.13.09.42.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 09:42:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101780-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f5M8AEvl; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101780-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101780-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 44E8028ED60 for ; Wed, 13 Mar 2024 16:42:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6B6350A88; Wed, 13 Mar 2024 16:33:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="f5M8AEvl" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D65D1627FF; Wed, 13 Mar 2024 16:33:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710347608; cv=none; b=IaifTku2hU4ESqFgXAlW/YaCiTGu2EsTxbnNsnOJEJcBxAlc/Ru4FuU19j9fvPHs8gavN/DNcGq+WOeU2SUa3rs+0Sjd1YU9eZn2jzX3bNRSvdHcfd55WC61BPZSwc07suLROc4E5YBXIwepGpXS/iV1MuA2DaeYQz32FFmX8fk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710347608; c=relaxed/simple; bh=3UekCyyDHThKiG9v+4KxnUS74Ovcmcs7JvlE63gLlaQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ES+Tm2E8lfv/QPxAeV52Aqc9eG87HZnD9WZ5fgUegVJK94CVkjEoEstuVR4CR/J2oNIe2+fuTUsHQB3VuVDziCHwWU9PVPZmnKGpWDxpATxDYCFfP6wao/BGOX0gnz6rYqVuBK2WIq3t/SDwJVOt05uAgEmSQrKUqTPViXqhGr8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f5M8AEvl; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 091D8C433F1; Wed, 13 Mar 2024 16:33:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710347608; bh=3UekCyyDHThKiG9v+4KxnUS74Ovcmcs7JvlE63gLlaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f5M8AEvlCd6qcJgVf2cTMiscevbIC0ro1vyqtgoM50L5OIjeYztRDXQiDiyLPjJK1 Zu8MDEgXSOOI7V9Q6RvMOlCghpT/cJl73B2LBUBPa6bX7nMA+GuLpLs3f7PK/fbjgK kAXkGfsu7HWpQ7LtdIliOgxtXYOjm/gubRuYNACCuvz7fn37MIcH0PGTubP1q2KZUl bGsoDV00FSNQzXnqKwmYgbBtn8idzWKii3oq5Q5jXzYTnsz4gF66v3TDg3LdSRcLmi kDWxocZprN0JY6w09pVb9vqvnkqIRg1A9R0EMY135SId88bjloqzOo4qAmaz90wJFP GFQsxfieuTFTA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Lena Wang , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 6.7 41/61] netfilter: nf_conntrack_h323: Add protection for bmp length out of range Date: Wed, 13 Mar 2024 12:32:16 -0400 Message-ID: <20240313163236.613880-42-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240313163236.613880-1-sashal@kernel.org> References: <20240313163236.613880-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.7.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-6.7.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 6.7.10-rc1 X-KernelTest-Deadline: 2024-03-15T16:32+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Lena Wang [ Upstream commit 767146637efc528b5e3d31297df115e85a2fd362 ] UBSAN load reports an exception of BRK#5515 SHIFT_ISSUE:Bitwise shifts that are out of bounds for their data type. vmlinux get_bitmap(b=75) + 712 vmlinux decode_seq(bs=0xFFFFFFD008037000, f=0xFFFFFFD008037018, level=134443100) + 1956 vmlinux decode_choice(base=0xFFFFFFD0080370F0, level=23843636) + 1216 vmlinux decode_seq(f=0xFFFFFFD0080371A8, level=134443500) + 812 vmlinux decode_choice(base=0xFFFFFFD008037280, level=0) + 1216 vmlinux DecodeRasMessage() + 304 vmlinux ras_help() + 684 vmlinux nf_confirm() + 188 Due to abnormal data in skb->data, the extension bitmap length exceeds 32 when decoding ras message then uses the length to make a shift operation. It will change into negative after several loop. UBSAN load could detect a negative shift as an undefined behaviour and reports exception. So we add the protection to avoid the length exceeding 32. Or else it will return out of range error and stop decoding. Fixes: 5e35941d9901 ("[NETFILTER]: Add H.323 conntrack/NAT helper") Signed-off-by: Lena Wang Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_conntrack_h323_asn1.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/netfilter/nf_conntrack_h323_asn1.c b/net/netfilter/nf_conntrack_h323_asn1.c index e697a824b0018..540d97715bd23 100644 --- a/net/netfilter/nf_conntrack_h323_asn1.c +++ b/net/netfilter/nf_conntrack_h323_asn1.c @@ -533,6 +533,8 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f, /* Get fields bitmap */ if (nf_h323_error_boundary(bs, 0, f->sz)) return H323_ERROR_BOUND; + if (f->sz > 32) + return H323_ERROR_RANGE; bmp = get_bitmap(bs, f->sz); if (base) *(unsigned int *)base = bmp; @@ -589,6 +591,8 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f, bmp2_len = get_bits(bs, 7) + 1; if (nf_h323_error_boundary(bs, 0, bmp2_len)) return H323_ERROR_BOUND; + if (bmp2_len > 32) + return H323_ERROR_RANGE; bmp2 = get_bitmap(bs, bmp2_len); bmp |= bmp2 >> f->sz; if (base) -- 2.43.0