Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2429129rdb; Fri, 8 Dec 2023 07:56:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFaLxiOfn6XVlE2egAQrROLFS6vf9ikkiQAnK4iIYJPnPXFj21KYx7tuTlxk8ZaBtdchgY7 X-Received: by 2002:a05:6a20:3ca0:b0:190:e5a:830e with SMTP id b32-20020a056a203ca000b001900e5a830emr224193pzj.46.1702051016802; Fri, 08 Dec 2023 07:56:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702051016; cv=none; d=google.com; s=arc-20160816; b=X6JA7+ohFcAqFEC5KRvaZjUouMMPZ0es1ZWcaMIf5ThIdSlQBsbh8kIC7B3y8TE55x 47zWRwFRGkFRiT1fNLBTZ+b794rls+mQO/s1rHwArRDsAPXK9a7UBntgs/vHrUoEMnAQ ZxF4d7UJPUy52mQQ5daQ81QeR3Hny5yQn8rMGjyOw/tc9IIdxLJEpw1x/c8k9GTg7zLE +78jF2yTTLJuFJ6//qJgMT7GJH7YbUXfEQ11Bd8URPEmFMt4JXPskqMvWVIVwE/F7Oqw ejdgAw5LP5FV6Ie2tYU704eQtZQL/yLfpAaGtJku6sdMDyFrj2RH3E7MPk4F6UchfcYj iahg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=lTA3Rj+ZPCv58l/tGJ+XHI4ES76KJiNlfiKFHihinkI=; fh=HoBJoQSi17TtNeYPMa6uWii9jFtba6IhJH2Ott6JMD8=; b=efPrYJrVdYlzJc6DoUL52jfTjKEzUSm3QYguIZAzLIyOeX9dqqo8i/WX5RmYXttVuD Ezrq/FG6/1r/j4nQpSktbtXBjBMqZSMB+MWR6B69ZJt40l5o82UxX1FIlqvPNbkfteix CCWbkd4dOiH+yoqE5zb9IfSXRliXhWLcTa4bMDsu27GKWG0H2PPPR5aqPywHsA49pyyH wdzKOzvJ7QvMX2ImpKhzH9BGqTumHqK8jbFqqdiuKX8yerVixQDqOEub411CdC05Miae mduje9v4XkTbQ5khu55EPer3B5SNNqz0wQOVTyybv8tKKrKoe8xVpPyfLMQ6wevGSsz+ IRjA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id k1-20020a6568c1000000b005b96c4292basi1697760pgt.29.2023.12.08.07.56.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 07:56:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 6674B825F1E5; Fri, 8 Dec 2023 07:56:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233606AbjLHP4j convert rfc822-to-8bit (ORCPT + 99 others); Fri, 8 Dec 2023 10:56:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233584AbjLHP4i (ORCPT ); Fri, 8 Dec 2023 10:56:38 -0500 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A3BA10CF for ; Fri, 8 Dec 2023 07:56:44 -0800 (PST) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-272-xAJojC2tP_KYEh9QIaiPUQ-1; Fri, 08 Dec 2023 15:56:41 +0000 X-MC-Unique: xAJojC2tP_KYEh9QIaiPUQ-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 8 Dec 2023 15:56:27 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Fri, 8 Dec 2023 15:56:27 +0000 From: David Laight To: 'Al Viro' CC: "linux-arch@vger.kernel.org" , "gus Gusenleitner Klaus" , Al Viro , "Thomas Gleixner" , lkml , "Ingo Molnar" , "bp@alien8.de" , "dave.hansen@linux.intel.com" , "x86@kernel.org" , "David S. Miller" , "dsahern@kernel.org" , "kuba@kernel.org" , Paolo Abeni , Eric Dumazet Subject: RE: [RFC][PATCHES v2] checksum stuff Thread-Topic: [RFC][PATCHES v2] checksum stuff Thread-Index: AQHaJyGyb9WP/snuGU2gdqpp5IxoMLCcGsYAgADCXYCAAmhtsIAALqUAgAATlYA= Date: Fri, 8 Dec 2023 15:56:27 +0000 Message-ID: References: <20231019063925.GX800259@ZenIV> <20231019080615.GY800259@ZenIV> <20231021071525.GA789610@ZenIV> <20231021222203.GA800259@ZenIV> <20231022194020.GA972254@ZenIV> <20231205022100.GB1674809@ZenIV> <602ab11ffa2c4cc49bb9ecae2f0540b0@AcuMS.aculab.com> <20231206224359.GR1674809@ZenIV> <46711b57a62348059cfe798c8acea941@AcuMS.aculab.com> <20231208141712.GA1674809@ZenIV> In-Reply-To: <20231208141712.GA1674809@ZenIV> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Fri, 08 Dec 2023 07:56:54 -0800 (PST) From: Al Viro > Sent: 08 December 2023 14:17 > > On Fri, Dec 08, 2023 at 12:04:24PM +0000, David Laight wrote: > > I've just read RFC 792 and done some experiments. > > The kernel ICMP checksum code is just plain broken. > > > > RFC 792 is quite clear that the checksum is the 16-bit ones's > > complement of the one's complement sum of the ICMP message > > starting with the ICMP Type. > > > > The one's complement sum of 0xfffe and 0x0001 is zero (not the 0xffff > > It is not. FYI, N-bit one's complement sum is defined as > > X + Y <= MAX_N_BIT ? X + Y : X + Y - MAX_N_BIT, > > where MAX_N_BIT is 2^N - 1. If that is true (I did bump into that RFC earlier) I can't help feeling that someone has decided to call an 'adc sum' 1's compliment! I've never used a computer with native 1's compliment integers (only sign over-punch) so I'm not really sure what might be expected to happen when you wrap from +MAXINT (+32767) to -MAXINT (-32767). > You add them as natural numbers. If there is no carry and result > fits into N bits, that's it. If there is carry, you add it to > the lower N bits of sum. > > Discussion of properties of that operation is present e.g. in > RFC1071, titled "Computing the Internet Checksum". > > May I politely suggest that some basic understanding of the > arithmetics involved might be useful for this discussion? Well 0x0000 is +0 and 0xffff is -0, mathematically they are (mostly) equal. Most code validating checksums just sums the buffer and expects 0xffff. RFC 768 (UDP) aays: If the computed checksum is zero, it is transmitted as all ones (the equivalent in one's complement arithmetic). An all zero transmitted checksum value means that the transmitter generated no checksum (for debugging or for higher level protocols that don't care). RFC 8200 (IPv6) makes the zero checksum illegal. So those paths (at least) really need to initialise the chechsum to 1 and then increment after the invert. I bet that ICMP response (with id == 0 and seq == 0) is the only place it is possible to get an ip-checksum of a zero buffer. So it will be pretty moot for copy+checksum with can return 0xffff (or lots of other values) for an all-zero buffer. In terms of copy+checksum returning an error, why not reduce the 32bit wcsum once (to 17 bits) and return -1 (or ~0u) on error? Much simpler than your patch and it won't have the lurking problem of the result being assigned to a 32bit variable. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)