Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp240209rwb; Sun, 25 Sep 2022 19:41:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7JOU7/LnfBBojppziXccVyomxB2dUc9/p9SELg6qNGtqtEHtFiX19dzK/9LMvkX1sbFxYa X-Received: by 2002:a17:907:dac:b0:782:95fa:545c with SMTP id go44-20020a1709070dac00b0078295fa545cmr12817020ejc.277.1664160116883; Sun, 25 Sep 2022 19:41:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664160116; cv=none; d=google.com; s=arc-20160816; b=vDCJcX8MeJc9/IbTNHXkLYlppz1SHDhDW6kUed+9tiKXamJ8PLqE3LOFuOtP74R5Qf a6oHHyX+yl/jgjHO7i+vC+2Y4Y+dUEJ8R0inpDoZaUVsCzVaLeP3kmJe3nq0Ed0VzXpT ofXy7ZHOr5XndCUadUFzic2hHciB4a1tH1LZ9OZqL2DnDEdgLJvaffjPOIXcxqwGbfxd s3hVdytrfpaufAxzMFtDoqYUQOfb2HFdHZbRblwkGNlK8CDATYBUPwyvJXpOuFxBXNcJ KzEC3aVf38s2TReK3DHOEuym8uVu6y/1GpJF2yomJiG4gbHnaQKoFHv70R3K3HetjCtq CTKw== 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:dkim-signature; bh=rNfKV091B020Efc+YRWSdOa5mhQUV0Kl4OyiKcHkZ9Q=; b=FIo1HaTYcGvqfddmbKi1LmPIraEZF8w4D4iMpsDXAEfJhlPxEa4WLMWRZPYvMM74WL 2Qylgr+tvtnDLcmUx0Ucz2X7TitMtYwGRu7rBr1Neogeecf98V2OCcwrdJptZauXN384 RN8qJBzdPiuWa7Md7woWBcV4UC/h/Vv1+VnxeKvrURYp/8s/9Og+1xZxKkMdXR+9oXQi BQF3gL8+50Nz8UmeqBK86BYbPWCceSD9SdbkTyNOjW8SoN7HXqfRzbR0SVkktD4VkwEu IdCZZwFPWPC4ZePViR0yxrl0nf0tG2Y5Smmv4zK/fxczzAh54kt7Ew+EwZ8bPpN/fwTZ Qsgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kh1BUFDj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b20-20020a056402279400b0043be6506057si16016043ede.182.2022.09.25.19.41.30; Sun, 25 Sep 2022 19:41:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kh1BUFDj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232589AbiIZCje (ORCPT + 99 others); Sun, 25 Sep 2022 22:39:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232575AbiIZCj1 (ORCPT ); Sun, 25 Sep 2022 22:39:27 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B151638A6 for ; Sun, 25 Sep 2022 19:39:25 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id p14so2392138pjd.3 for ; Sun, 25 Sep 2022 19:39:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=rNfKV091B020Efc+YRWSdOa5mhQUV0Kl4OyiKcHkZ9Q=; b=kh1BUFDjkrLOhsENJ07K39+e7g1gEH4tc3sMPWx+sF3myjmnrJjs/Tx3sY8M4PaCUo oIJmzH7gjKTkasxkN/feO5ML/XlyTNFcju7NaZmfuNzK0D6eW02grt1GrxXFVe5OEnGE mm0bEdnQTbysRH54a1XnMMvqrTSmMCwvKJuao= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=rNfKV091B020Efc+YRWSdOa5mhQUV0Kl4OyiKcHkZ9Q=; b=b24BxgUUxO5TepXXEdYFDqRTRuAwhV7PzL0OC1H1zXuoprl1eCZ0+LpXzG44FVQnry si/BI7/NoW4ntOMkO7BCM2jgA0xyEt5jnxsmfHqpvF9ehzwheapLn/v/EIIB8MwwdyeI JYVEhbK62mvVR82z2xZaUZNepiYhvAGq5E12n6qrnmwb8Q3Kn8BDuZnx/78d72P+O36y XWITQ4SQnwFe5HJgMve+c9hDvGJSCL3e/I8Na9GqDGxi2HymISQrBxw9O4VGFkDEQ1ur chGg1z4i6OYP+vanAekq7fqS/uva3nhuRSfSyBqJZDgYz/xekvGjNdO+7drrKN2DhN4y ShNQ== X-Gm-Message-State: ACrzQf1XcvU42ibu8r05jFTR4fhJfLdTUMaWJwDExVbIG+j63X7+eAii tw+CfBZojliCxbYVcBNPzXox3w== X-Received: by 2002:a17:902:f389:b0:178:9bd4:b72e with SMTP id f9-20020a170902f38900b001789bd4b72emr19464384ple.140.1664159965206; Sun, 25 Sep 2022 19:39:25 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id p4-20020a622904000000b0054d1a2ee8cfsm10666756pfp.103.2022.09.25.19.39.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Sep 2022 19:39:24 -0700 (PDT) Date: Sun, 25 Sep 2022 19:39:23 -0700 From: Kees Cook To: Eric Dumazet Cc: Jamal Hadi Salim , syzbot , David Miller , Jiri Pirko , Jakub Kicinski , LKML , netdev , Paolo Abeni , syzkaller-bugs , Cong Wang Subject: Re: [syzbot] WARNING in u32_change Message-ID: <202209251935.0469930C@keescook> References: <000000000000a96c0b05e97f0444@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 25, 2022 at 10:34:37AM -0700, Eric Dumazet wrote: > Sure, please look at: > > commit 54d9469bc515dc5fcbc20eecbe19cea868b70d68 > Author: Kees Cook > Date: Thu Jun 24 15:39:26 2021 -0700 > > fortify: Add run-time WARN for cross-field memcpy() > [...] > Here, we might switch to unsafe_memcpy() instead of memcpy() I would tend to agree. Something like: diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 4d27300c287c..21e0e6206ecc 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -1040,7 +1040,9 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, } #endif - memcpy(&n->sel, s, sel_size); + unsafe_memcpy(&n->sel, s, sel_size, + /* A composite flex-array structure destination, + * which was correctly sized and allocated above. */); RCU_INIT_POINTER(n->ht_up, ht); n->handle = handle; n->fshift = s->hmask ? ffs(ntohl(s->hmask)) - 1 : 0; This alloc/partial-copy pattern is relatively common in the kernel, so I've been considering adding a helper for it. It'd be like kmemdup(), but more like kmemdup_offset(), which only the object from a certainly point is copied. -- Kees Cook