From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.bufferbloat.net (Postfix) with ESMTPS id ABDDB3B29E for ; Tue, 7 Jul 2020 06:57:56 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594119476; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y5EnoUm440JYgQkBnt9MLy17ni9YmA7k7Hw8wKo4OHM=; b=FfcHg/Zf44tZ7J+tYlbYFlqoAyBHmWvMZ5qOJGqA2YGp/kha+S9n0H7LPZQtTK73wPuhPV dXE+wCN2D7Bink97dFZW3ZXjib1qq/lD35ElRyF+zlbGEHtabKLKusazJSlInz+vGl9z/5 I/yMpxWcm6RediWpsVKFCs+M+tPu4Lg= Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-80-A2XVT7i1POOcwfq4AOi80w-1; Tue, 07 Jul 2020 06:57:54 -0400 X-MC-Unique: A2XVT7i1POOcwfq4AOi80w-1 Received: by mail-pf1-f198.google.com with SMTP id a8so3873723pff.3 for ; Tue, 07 Jul 2020 03:57:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version:content-transfer-encoding; bh=H2LYwh1VdKHxkxER4SLeQdN4bGqkhcDbcHO7KIziy8U=; b=myvRrAGeeqDfeFIXssP0j6l2/mWgoFUyYO5po2AI6CG1yxYbOLjlpgLXqkXuWzAjYt NhNG/C3DYiIkj4t/vpkSOYB01AGEeD62vxhqpSHKNqhb80mmzUSUwCk2YmT2knPHIdQo RyMCfAD3wLHNI7clWqHV7qm54AUnnyI6l6Ckse6Knz6wm29AyF0J6ho6TqP2I1rO9+/w x6gly7YalyV+Oojg+DV9bfaTtWf8NA5FZn05byTIixLDJLqVrfqs8/AVYW23aB14wLlQ bavq/7rLaUwX3sSFL6frbdPc2lSulCSpGq3RNA/swz29rsKtK8qqw2WhleatQpwCBahS ebbw== X-Gm-Message-State: AOAM532r9EsNqHvt5mq/I9g7RL0vs214CmF5ahw7blFF87pZRKoF76cB NKVanNSFAnN+bqwfQdprU6gl971TrSP8T6Ipd1QOgliCukq7vezJ/8D4SU9iAsIbO27mysXVsV3 qxSr+gHnMoNrJYQctIKk88A== X-Received: by 2002:a65:6416:: with SMTP id a22mr19519031pgv.392.1594119473584; Tue, 07 Jul 2020 03:57:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/9IIl501a1fdtLWVOnvj8Zt0/yDhup0dmp5XfHtfzAaK6AUC7ght54TQiL5R5uxU3hdneyQ== X-Received: by 2002:a65:6416:: with SMTP id a22mr19518985pgv.392.1594119472610; Tue, 07 Jul 2020 03:57:52 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id k189sm21462268pfd.175.2020.07.07.03.57.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 03:57:51 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 83CC11804ED; Tue, 7 Jul 2020 12:57:47 +0200 (CEST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Toshiaki Makita , davem@davemloft.net Cc: netdev@vger.kernel.org, cake@lists.bufferbloat.net, Davide Caratti , Jiri Pirko , Jamal Hadi Salim , Cong Wang , Daniel Borkmann In-Reply-To: <234d54c2-5b34-7651-5e57-490bee9920ae@gmail.com> References: <20200706122951.48142-1-toke@redhat.com> <234d54c2-5b34-7651-5e57-490bee9920ae@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett Date: Tue, 07 Jul 2020 12:57:47 +0200 Message-ID: <87d057lhhw.fsf@toke.dk> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=toke@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Cake] [PATCH net] vlan: consolidate VLAN parsing code and limit max parsing depth X-BeenThere: cake@lists.bufferbloat.net X-Mailman-Version: 2.1.20 Precedence: list List-Id: Cake - FQ_codel the next generation List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jul 2020 10:57:56 -0000 Toshiaki Makita writes: > On 2020/07/06 21:29, Toke H=C3=B8iland-J=C3=B8rgensen wrote: >> Toshiaki pointed out that we now have two very similar functions to extr= act >> the L3 protocol number in the presence of VLAN tags. And Daniel pointed = out >> that the unbounded parsing loop makes it possible for maliciously crafte= d >> packets to loop through potentially hundreds of tags. >>=20 >> Fix both of these issues by consolidating the two parsing functions and >> limiting the VLAN tag parsing to an arbitrarily-chosen, but hopefully >> conservative, max depth of 32 tags. As part of this, switch over >> __vlan_get_protocol() to use skb_header_pointer() instead of >> pskb_may_pull(), to avoid the possible side effects of the latter and ke= ep >> the skb pointer 'const' through all the parsing functions. >>=20 >> Reported-by: Toshiaki Makita >> Reported-by: Daniel Borkmann >> Fixes: d7bf2ebebc2b ("sched: consistently handle layer3 header accesses = in the presence of VLANs") >> Signed-off-by: Toke H=C3=B8iland-J=C3=B8rgensen >> --- > ... >> @@ -623,13 +597,12 @@ static inline __be16 __vlan_get_protocol(struct sk= _buff *skb, __be16 type, >> =09=09=09vlan_depth =3D ETH_HLEN; >> =09=09} >> =09=09do { >> -=09=09=09struct vlan_hdr *vh; >> +=09=09=09struct vlan_hdr vhdr, *vh; >> =20 >> -=09=09=09if (unlikely(!pskb_may_pull(skb, >> -=09=09=09=09=09=09 vlan_depth + VLAN_HLEN))) >> +=09=09=09vh =3D skb_header_pointer(skb, vlan_depth, sizeof(vhdr), &vhdr= ); > > Some drivers which use vlan_get_protocol to get IP protocol for checksum = offload discards > packets when it cannot get the protocol. > I guess for such users this function should try to get protocol even if i= t is not in skb header? > I'm not sure such a case can happen, but since you care about this, you k= now real cases where > vlan tag can be in skb frags? skb_header_pointer() will still succeed in reading the data, it'll just do so by copying it into the buffer on the stack (vhdr) instead of moving the SKB data itself around... -Toke