Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1308645rdb; Wed, 20 Sep 2023 05:55:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7vIbr0Pa5WNYPmwYUISdKmem1p+/mPkDe+mDqgm/KvuYOu3HZW7pDmO4t2XnqsBlT1nwj X-Received: by 2002:a17:903:22c7:b0:1c3:a2f2:b327 with SMTP id y7-20020a17090322c700b001c3a2f2b327mr2202346plg.2.1695214552105; Wed, 20 Sep 2023 05:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695214552; cv=none; d=google.com; s=arc-20160816; b=lV4ZjaOx2bCOihnxJP01A3ig6Ubgqr7xJHLVFTYbijknQUoPbf/jmsP9g1mJm0kAdG TcQBgK7SbZ75RfhLctolyT8j2ixwf8uCbvmOUeCX8/VwV0zAthAnvN1zu+syWhTboHUi 70VTsT9gzLtYaixneSr0aZ3Yjk3q3uHQ+P8wG4mDvA1+mre41pmKhc3EhA2W7RVqP+B/ PuuuTlF8FAlH9VbfJouYsnMQP9XyQ9pLzI7kYN+nSwfaZc2DWp/rY+MOBiu6hmy98sTD vImkidErYKol/egUFY2beBlRMF26a1/Js3fUubmcfnxXXmFEy+ZHjbIvQwdALustETl2 zy2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-transfer-encoding :content-id:mime-version:subject:cc:to:from:organization :dkim-signature; bh=+3yBpA5iz82pce6LfLZNujDLBSjE7ZVN1nK9Rsm3ufc=; fh=kQe84kwE5TxPvvkb4B0IYRcMTipN2dYXirw+2l8D2KU=; b=Ruf65SA3B0qx9Uh9n9/mimowJSLzEbZcr/VtlJ863Bv9q0tNIfpejS59W++eXVydR4 k6bXq77aCf42Hdt/uBu0SXccdtkIqfoCSwxQ5rv3eBeFVnIxWslrviP62Q7JsoXlT4J3 jVu6WUZd2yoXrlg5u7j+NWiSRE7ZTBX6iJeDWODfE7mB9u4+cJwzKf1el9sBPcmZ+NR/ XQiPA5GlPi7Eom1oOXUQ/+Gcuv/PldH+/+fQIjFB4cmrBYoQQeHXPUpewML9u3DeFujN ok0cyiDhzZQAgyRLNUjOCuW7zs8Nq0vOghGhA/uYAtLosGCm+HJH+cW6Pmhbt8FXlYzo Mc7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=czUj6an4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id t7-20020a1709027fc700b001b885fbe17dsi11697320plb.532.2023.09.20.05.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 05:55:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=czUj6an4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id C4E168076D0A; Wed, 20 Sep 2023 01:40:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233406AbjITIkH (ORCPT + 99 others); Wed, 20 Sep 2023 04:40:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232488AbjITIkG (ORCPT ); Wed, 20 Sep 2023 04:40:06 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CBAC90 for ; Wed, 20 Sep 2023 01:39:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695199162; 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; bh=+3yBpA5iz82pce6LfLZNujDLBSjE7ZVN1nK9Rsm3ufc=; b=czUj6an4tmC8yvo5TCg5v68hUY+mos8NhxGUIUWLHDkmIWnT0OBj7AHmXiH4nETIcsUj+1 rWY5CjoohHp5KXRSB3Mf6NPY0WnNdERIfQeXy4mNW2/4U8RztNFhJHj3p6FDT8diEjFKbd Wm+yOvWnd1VuywC6/NiPZZnAvwJvkf4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-169-whr9bxVyOA-yv0PPo12ZiA-1; Wed, 20 Sep 2023 04:39:15 -0400 X-MC-Unique: whr9bxVyOA-yv0PPo12ZiA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 139D385A5BA; Wed, 20 Sep 2023 08:39:14 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5788E2156701; Wed, 20 Sep 2023 08:39:12 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells To: netdev@vger.kernel.org cc: dhowells@redhat.com, syzbot+62cbf263225ae13ff153@syzkaller.appspotmail.com, Eric Dumazet , Willem de Bruijn , "David S. Miller" , David Ahern , Paolo Abeni , Jakub Kicinski , bpf@vger.kernel.org, syzkaller-bugs@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH net v2] ipv4, ipv6: Fix handling of transhdrlen in __ip{,6}_append_data() MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <108790.1695199151.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Wed, 20 Sep 2023 09:39:11 +0100 Message-ID: <108791.1695199151@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 20 Sep 2023 01:40:12 -0700 (PDT) Including the transhdrlen in length is a problem when the packet is partially filled (e.g. something like send(MSG_MORE) happened previously) when appending to an IPv4 or IPv6 packet as we don't want to repeat the transport header or account for it twice. This can happen under some circumstances, such as splicing into an L2TP socket. The symptom observed is a warning in __ip6_append_data(): WARNING: CPU: 1 PID: 5042 at net/ipv6/ip6_output.c:1800 __ip6_append_d= ata.isra.0+0x1be8/0x47f0 net/ipv6/ip6_output.c:1800 that occurs when MSG_SPLICE_PAGES is used to append more data to an alread= y partially occupied skbuff. The warning occurs when 'copy' is larger than the amount of data in the message iterator. This is because the requested length includes the transport header length when it shouldn't. This can b= e triggered by, for example: sfd =3D socket(AF_INET6, SOCK_DGRAM, IPPROTO_L2TP); bind(sfd, ...); // ::1 connect(sfd, ...); // ::1 port 7 send(sfd, buffer, 4100, MSG_MORE); sendfile(sfd, dfd, NULL, 1024); Fix this by deducting transhdrlen from length in ip{,6}_append_data() righ= t before we clear transhdrlen if there is already a packet that we're going to try appending to. Reported-by: syzbot+62cbf263225ae13ff153@syzkaller.appspotmail.com Link: https://lore.kernel.org/r/0000000000001c12b30605378ce8@google.com/ Signed-off-by: David Howells cc: Eric Dumazet cc: Willem de Bruijn cc: "David S. Miller" cc: David Ahern cc: Paolo Abeni cc: Jakub Kicinski cc: netdev@vger.kernel.org cc: bpf@vger.kernel.org cc: syzkaller-bugs@googlegroups.com Link: https://lore.kernel.org/r/75315.1695139973@warthog.procyon.org.uk/ #= v1 --- net/ipv4/ip_output.c | 1 + net/ipv6/ip6_output.c | 1 + 2 files changed, 2 insertions(+) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 4ab877cf6d35..9646f2d9afcf 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1354,6 +1354,7 @@ int ip_append_data(struct sock *sk, struct flowi4 *f= l4, if (err) return err; } else { + length -=3D transhdrlen; transhdrlen =3D 0; } = diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 54fc4c711f2c..6a4ce7f622e9 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1888,6 +1888,7 @@ int ip6_append_data(struct sock *sk, length +=3D exthdrlen; transhdrlen +=3D exthdrlen; } else { + length -=3D transhdrlen; transhdrlen =3D 0; } =