Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp286812rdb; Thu, 19 Oct 2023 04:46:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF23RxlPLtP3+5IpUoFP8JxZiBcMyBdmBFRKGXMcHH7pOTcG3wiNEZLNdZxqu8E5VEo88fM X-Received: by 2002:a17:902:f550:b0:1c5:ff18:98af with SMTP id h16-20020a170902f55000b001c5ff1898afmr2334265plf.4.1697715967545; Thu, 19 Oct 2023 04:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697715967; cv=none; d=google.com; s=arc-20160816; b=cWweCQHLegiYHQpP814FVmB1rUXC+nX8MB7E0dy9y7nnsdD6PBBh6Ndi2ZuwYh0Wfm 82O2A0t9CdBbDisxzLcXdnAPd3J1O4HryjMRqKlKlWaALei8EGjAq/vwa+NXtQ+We8jW fGvtUw7Kkg8Sf6EC/mGBasROJ9Q63dw6BYjoLiTFOwuFoh0D1RCW+3blsBm08iHKgcsE 9AT/ia12PPyeunQpigmmkKIQIs/Omogin9Qv622plXi/f9IuX5AX7ww6TneTawKO+1sK UUSiB1EE9fQF5CtAFArCI1NziQp+MynOhBupzeddM2REL1N3BkTJ09Lk/cYSrz/5Elpl Z/Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=2WkIseThtqqkqJdqE76wGJCr8yEVr/2wrAgKQK4g43g=; fh=tmiuXp5IZ9m4jEJHO0iwTQSGy3OJEfYeEWXgpPaoUbA=; b=zOnONWvSHLs//hDNhk/g43xWA8C5qGdffADRMkwRWRmgT/ZMkh+YAjKWbJsdHJR2h6 vETv30QotPmrafgnUYyuCseyS4T9stBt6yUFkczJ0OTFCKLhxMrm1bK+pKUL6f6pEWKK WRqyFzmqG429rfepHomxRFE7s28oD2qM6832oLbk9MU+1MOuOQsl8BKoOzR9nXJGtz6Y 4HhNsrqyM5IBD7uGzb3x6fkVdepG/+JgNva8cYhvAyVm/Z+BLtixL7vGkH8xJVMP9AUp +fjQQvmhFFqGD01b6sSG1655LwadIw7DlY7KVOCs01QpFXwERJtwnycgGcwFKqbz6pkd uagQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NjRZD3mg; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id n5-20020a170903110500b001bbc138af04si2182555plh.158.2023.10.19.04.46.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 04:46:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NjRZD3mg; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 4FCDD826EB90; Thu, 19 Oct 2023 04:46:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345393AbjJSLp5 (ORCPT + 99 others); Thu, 19 Oct 2023 07:45:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233048AbjJSLpz (ORCPT ); Thu, 19 Oct 2023 07:45:55 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2F0E12F for ; Thu, 19 Oct 2023 04:45:50 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697715948; 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: in-reply-to:in-reply-to:references:references; bh=2WkIseThtqqkqJdqE76wGJCr8yEVr/2wrAgKQK4g43g=; b=NjRZD3mgYBR/EeYyoe4q65yYpso4lxg0KgDFPHilF0RYDXjKDhqU8FeZfOsOEt3twtFiqq oYftZPR4msfIsNnK+PABDSKJrOekIANn8dJMCsYhy+jIuxq7lPy11CnwPihF33NgF6pWi1 alfZFbPzPKPuK4UM+ELlV67ZS9Zs0VESm8mhui0cyr4Dan2GztLfNc7pbExTncsL5Kdkve 3oLgYopkLvnlwdPRvSUQxN9KeTNI6OkG3xj7hTg1zR+H2NlMm5ezXsN4JOaW8CkKVCfz9Z OQasGawJBpDiLJuBmtnfDCE2MrbAe8GyWwaAwf6A+2PBN6ttEYq5z0IPEiR3Xg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697715948; 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: in-reply-to:in-reply-to:references:references; bh=2WkIseThtqqkqJdqE76wGJCr8yEVr/2wrAgKQK4g43g=; b=CBE2B6CtltTOfcFiZ4T3D7y7eohi+GshuTdABTLDmANJeP7xhi9+UFECSVAe3QkRSz+4/p 0rUNX+ie5qTzGUAw== To: Al Viro , gus Gusenleitner Klaus Cc: Al Viro , lkml , Ingo Molnar , "bp@alien8.de" , "dave.hansen@linux.intel.com" , "x86@kernel.org" , "David S. Miller" , "dsahern@kernel.org" , "edumazet@google.com" , "kuba@kernel.org" , Paolo Abeni Subject: Re: AW: [PATCH] amd64: Fix csum_partial_copy_generic() In-Reply-To: <20231019063925.GX800259@ZenIV> References: <20231018154205.GT800259@ZenIV> <20231019050250.GV800259@ZenIV> <20231019061427.GW800259@ZenIV> <20231019063925.GX800259@ZenIV> Date: Thu, 19 Oct 2023 13:45:48 +0200 Message-ID: <87wmvi3ker.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.8 required=5.0 tests=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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 19 Oct 2023 04:46:04 -0700 (PDT) On Thu, Oct 19 2023 at 07:39, Al Viro wrote: > On Thu, Oct 19, 2023 at 07:14:27AM +0100, Al Viro wrote: >> > > Here's our situation: >> > > Our device gets pinged by a third party manufacturer robot controller. >> > > We have updated the kernel in our device to 5.15 from 4.9, the robot >> > > controller is kept unchanged. At 4.9, our device's ping reply is accepted >> > > by the robot controller, at 5.15 it's not. >> > > >> > > Wireshark shows a bad checksum warning: >> > > 'Checksum: 0x0000 incorrect, should be 0xffff' >> > > >> > >> > Lovely. I think I see what's going on, give me a few to think about it... >> >> The real source of trouble was switching csum_and_copy_{to,from}_user() >> to reporting faults as 0. And yes, it's broken. Bugger... > > I really hate the idea of bringing back the old horrors and splitting > _nocheck and _user variants ;-/ Especially since we don't care (and > never had, really) where in the EFAULT case had the damn thing faulted > and what csum had it managed to accumulate prior to that point. > > The only callers are csum_and_copy_..._iter() and they discard > the entire iovec segment if fault happens; all users of > csum_and_copy_from_iter() are actually discarding everything in > that case (reverting iterator to the point where it had been > prior to the call). > > And they are all thread-synchronous. Hell, it's tempting to steal > a thread flag, clear it before the call of those suckers, set it in > exception handlers in those and check in csum_and_copy_..._iter() > after the call... Let me see how ugly something of that sort would > be... Eew. That's horrible. The checksum is strictly 16bit. __wsum is 32bit (for whatever reason). So you can differentiate between error and valid checksum easily by using bit 16-31 as indicator for fail or success, no? Something like the incomplete below. Thanks, tglx --- --- a/arch/x86/lib/csum-copy_64.S +++ b/arch/x86/lib/csum-copy_64.S @@ -194,6 +194,9 @@ SYM_FUNC_START(csum_partial_copy_generic .Lende: testq %r10, %r10 js .Lwas_odd + +.Lsuccess: + orl $0xFF00, %eax .Lout: movq 0*8(%rsp), %rbx movq 1*8(%rsp), %r12 @@ -247,7 +250,7 @@ SYM_FUNC_START(csum_partial_copy_generic .Lwas_odd: roll $8, %eax - jmp .Lout + jmp .Lsuccess /* Exception: just return 0 */ .Lfault: