Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp354034rdf; Fri, 3 Nov 2023 02:46:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGThfk16BBnRNKLt142/jzd/v682L2rffeUmOErn/S+DQF3BgRjDPHkQD4lGdpYXVS518Hv X-Received: by 2002:a05:6a00:a17:b0:693:43b5:aaf3 with SMTP id p23-20020a056a000a1700b0069343b5aaf3mr3098712pfh.13.1699004789148; Fri, 03 Nov 2023 02:46:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699004789; cv=none; d=google.com; s=arc-20160816; b=PAFOWsDX10kiPLJMXglSkXYrORh5w4wgWFql+9vf8Jh6mJMBwnOVmnNAUoYYLcMdNF Nox9kvHvRBYaduHnflv8xkrltC/SQHAZXeCp7TvI9yZL1I1ovi+LDpzzkKuY7Ou2jSQj uJDaaFKW9y250Wd8VrVrLFWzGukveyu9G/LrWNnMvvLUm/2AfEKtlAA1/NdDIKyC8P9e 4kYKmIZK8zmIhGjlVmr6n/VayDSS3noanH56Sk+3BqF3Yz8MIhsEsfJgaKsDKfIkNiQD bcIxBUSHWaoTLmVfqkyPCg21VUgrqDbmod9+Q1PUxknsyUOxSDy+r7gEwvU+fdckFBsC 4JUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=46DUs+m+YIpYpzOCYBYUt76ZCmuGnAXzuRJLBSQ+kjE=; fh=QkTIe/ZPK5qWoUtl4ktt3mmgd1qOdCEGFRWxQosFNAA=; b=pjZhML6GHJ4rDEhb2aH3S8cbv03exWn9d4z3OaJ7u0APBPshtkoxXg/AB0zOxaHFop b6AzpVnyh28FSPFc1iR8yEak9NgeOS0b9ecqyZokcs8RqWqsErHUJOQGi1rApkRe5qAI VvUbGEkqPEAWZAedIfXh88tuBKcvlJn0QYiDmErWnGxw3hRcvzWE3GoNbZQAxjnyOoya T2kdDT3sRTiBLoD/c3MLTe1CkP2fp/Wgg1v+Cd9pOcxd/GXtcq1stsYRzzmloD4y0G+1 f9WI212ts4la+I/3QcHbi3DVUY7ACivJeWhq2SHKu5q2RSjPXRtFAiHaIYoAlYgtpyhq JONg== 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 Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id t22-20020aa79396000000b006be07ee9906si1222143pfe.99.2023.11.03.02.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 02:46:29 -0700 (PDT) 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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 7FA50801CD8C; Fri, 3 Nov 2023 02:45:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347292AbjKCJph (ORCPT + 99 others); Fri, 3 Nov 2023 05:45:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347166AbjKCJpg (ORCPT ); Fri, 3 Nov 2023 05:45:36 -0400 Received: from ganesha.gnumonks.org (ganesha.gnumonks.org [IPv6:2001:780:45:1d:225:90ff:fe52:c662]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2CE11BD; Fri, 3 Nov 2023 02:45:31 -0700 (PDT) Received: from [78.30.35.151] (port=34830 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 1qyqk1-00EAjx-Tf; Fri, 03 Nov 2023 10:45:27 +0100 Date: Fri, 3 Nov 2023 10:45:25 +0100 From: Pablo Neira Ayuso To: Florian Westphal Cc: Dan Carpenter , Jozsef Kadlecsik , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH net] netfilter: nf_tables: fix pointer math issue in nft_byteorder_eval() Message-ID: References: <15fdceb5-2de5-4453-98b3-cfa9d486e8da@moroto.mountain> <20231103091801.GA8035@breakpoint.cc> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20231103091801.GA8035@breakpoint.cc> X-Spam-Score: -1.9 (-) 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, 03 Nov 2023 02:45:46 -0700 (PDT) On Fri, Nov 03, 2023 at 10:18:01AM +0100, Florian Westphal wrote: > Dan Carpenter wrote: > > The problem is in nft_byteorder_eval() where we are iterating through a > > loop and writing to dst[0], dst[1], dst[2] and so on... On each > > iteration we are writing 8 bytes. But dst[] is an array of u32 so each > > element only has space for 4 bytes. That means that every iteration > > overwrites part of the previous element. > > > > I spotted this bug while reviewing commit caf3ef7468f7 ("netfilter: > > nf_tables: prevent OOB access in nft_byteorder_eval") which is a related > > issue. I think that the reason we have not detected this bug in testing > > is that most of time we only write one element. > > LGTM, thanks Dan. We will route this via nf.git. Thanks for your patch. One question, is this update really required? diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h index 3bbd13ab1ecf..b157c5cafd14 100644 --- a/include/net/netfilter/nf_tables.h +++ b/include/net/netfilter/nf_tables.h @@ -178,9 +178,9 @@ static inline __be32 nft_reg_load_be32(const u32 *sreg) return *(__force __be32 *)sreg; } -static inline void nft_reg_store64(u32 *dreg, u64 val) +static inline void nft_reg_store64(u64 *dreg, u64 val) { - put_unaligned(val, (u64 *)dreg); + put_unaligned(val, dreg); } static inline u64 nft_reg_load64(const u32 *sreg) because one of the goals of nft_reg_store64() is to avoid that caller casts the register to 64-bits.