Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp791201lqg; Sat, 2 Mar 2024 01:49:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV2rPW82sn7ox/VLo3m0Lyrc4i42vEB5KRCFq6vuu0Kw7DjmTbqp8v/kh2AuWVfRTtGKnQxR/NTfq85YLiKGNnMJsixLeymMcsAO8djFg== X-Google-Smtp-Source: AGHT+IEyYKfKlczRaDEpWEcKSB6qQDZn8atcvpp8tgW7ZgU5XTBpQKox8NA4tA/JC17cOf3NY5F/ X-Received: by 2002:a05:6a00:2289:b0:6e4:8d81:50b with SMTP id f9-20020a056a00228900b006e48d81050bmr4759414pfe.31.1709372957960; Sat, 02 Mar 2024 01:49:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709372957; cv=pass; d=google.com; s=arc-20160816; b=VFYzsejZMAhykpqbQ1Z+akrEhHUw88vuaQ9iPJn5FPocxaEAbb06ZN3f0LgMXiG03P e22PDsBpwSfJ6tu23mhm72HGIiW6fU931rnGz1U3YcLZWlK96rPwvLUqQtduhA7IAS5G J+h8k1lJcuhReHLlLWeD+/4rGkFckG63wNwpfp3BbMVrR4EnXsl2ECuzbQ1vHr++abx6 fnNBUUlrHsGAhdYkwlZ/vXNJ0/Ji8bqNtkw4lW8x/t935ncIZR1eAs8/yjFa31yeDj4X sMpHvXDPY0iidorU9kqE2yUYw2isNMcv4tasAJbWf15Bk665ilj/kSb39dX01YT+E7/9 CtQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date; bh=Del2aBMIlSKRJA3JzuAaWlTYHBhmYus5/c2jRAPkdxM=; fh=U9Hi9zo/P0gzwa8g0zviiJ6zDdpdFTNF1K71IxHRsGU=; b=NjvWyOYy5byR7Izum03mhX8lpRE1YG2yFvhA9vnb6CL/0H2Q65fn4TTP7rPYRnUqsP qeNCG5JxmkU+YpCho+FR5I4bgQG/Uga/ntT+ncEn1VQnTfCrGd8ePBriOY36B1XsDy1Q 3NkVA7tZsbftTZZpUY9FrHR5NhHP7dljcw2yjCyvIwsC9ylAAMjSXBfWhHEHzw4IWb6T WWQpKiDwaxFxg/u2QoFSUtwc2MpA4/c/45UIpX26U+6zkAh7VGMW+rjWVgSFrnCAbYqW Lh5sYtloa/MLbUKjI3hAVx2sOwBeviugXNpxgh+kmFI3WjJjx9N8qNTK2IaYkhthXuCN Pqew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gnumonks.org); spf=pass (google.com: domain of linux-kernel+bounces-89403-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89403-linux.lists.archive=gmail.com@vger.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 c18-20020a634e12000000b005c65c11ad09si5144188pgb.768.2024.03.02.01.49.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Mar 2024 01:49:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89403-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; arc=pass (i=1 spf=pass spfdomain=gnumonks.org); spf=pass (google.com: domain of linux-kernel+bounces-89403-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89403-linux.lists.archive=gmail.com@vger.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 5DFFE2849D4 for ; Sat, 2 Mar 2024 09:49:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9E4515E80; Sat, 2 Mar 2024 09:49:05 +0000 (UTC) Received: from ganesha.gnumonks.org (ganesha.gnumonks.org [213.95.27.120]) (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 282D513FF1; Sat, 2 Mar 2024 09:49:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.95.27.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709372945; cv=none; b=DyLQbiaoWU9my1nDqiq9yFU3EFAS+5RBBuIuqGWm000hCNrPzex/g9RWOInCSl07a6ws8RmpLgHrKcu9fVWN/ckV7+V80Ljd2J2HyJSzviNrmy7N50KTlaP3x0mz6e3H2vS6q8g+bgBKJQSidCqZXz9e1ywISRm5F/GPY0ZRCYQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709372945; c=relaxed/simple; bh=25G4CnMZXN8FjED1jmnlV5PfqYFZXUzZOn0xZchUcf0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=axpWTQ06GsJfn4cBBO75rJwADEFXtlfUzNbPWnQtC+U+lZUSdh3oS/09MmbEgr1NWscTQbUJVStIUy2oyGwJCSDVoGNX9dmJVkByUu1oKfht97qow+U2krP4H9BD1P8znMVGtPwjtgYztWbjifvnPqKl6rO4PvjlOHS7KY3+fVc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org; spf=pass smtp.mailfrom=gnumonks.org; arc=none smtp.client-ip=213.95.27.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gnumonks.org Received: from [78.30.41.52] (port=40434 helo=gnumonks.org) by ganesha.gnumonks.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rgLz7-008oxI-F4; Sat, 02 Mar 2024 10:48:51 +0100 Date: Sat, 2 Mar 2024 10:48:47 +0100 From: Pablo Neira Ayuso To: Lena Wang =?utf-8?B?KOeOi+WonCk=?= Cc: "fw@strlen.de" , "davem@davemloft.net" , "kadlec@netfilter.org" , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "netfilter-devel@vger.kernel.org" Subject: Re: [PATCH net v2] netfilter: Add protection for bmp length out of range Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Score: -1.9 (-) On Fri, Mar 01, 2024 at 03:12:24PM +0000, Lena Wang (王娜) wrote: > From: Lena Wang > > 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 get_bitmap uses the > length to make a shift operation. It will change into negative > after several loop. > > UBSAN load can detect a negative shift as an undefined behaviour > and reports an exception. > > So we should add the protection to avoid the length exceeding 32. > If it exceeds it will return out of range error and stop decoding > ras message. > > Signed-off-by: Lena Wang > --- > v2: > - add length protecton for another get_bitmap call. > - update commit message to trim stacktrace. > --- > --- > 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 e697a824b001..540d97715bd2 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; Could you possibly place this in get_bitmap()? IIRC these are the only two calls to this function. Thanks. > 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.18.0