Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp5821911rwb; Wed, 9 Aug 2023 09:31:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHBCJCKdZyZ0DiGkGbRzmALNlAf7ymwxgUqPmsn/w1PCOteGP6Xpsn+jomLq52N8iYW+Jro X-Received: by 2002:a05:6a00:3981:b0:66f:7076:a5b4 with SMTP id fi1-20020a056a00398100b0066f7076a5b4mr4092760pfb.7.1691598691715; Wed, 09 Aug 2023 09:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691598691; cv=none; d=google.com; s=arc-20160816; b=r4ByUIThUuD4bAHbVEsvsTvmtWzVQ7ux7lyl5zDgH72uoZbz1nJ9gPErMyWVDejK5x TlX8QEGsn+VSW20TL72MyYqoBrIdtH8TkA5ovT7hy3JdJ5UD7rcHt38sb0KCRVvR5+Cq eRI4hjHdZVwRsEen2l2O1wPVhvNCcMW+P4qSAkYUusTEb2xFN0TkL4P1MlQKy1nqHALE HFOMGkIu4kgra54sjvoJBYynooAGQrnk1yqbuplbGjHrQYpZuVywNt9b296vJ1lsGGJi z/XJZGNWQGWd/lWrCkxfo55SXvGVfgXNN5pDoSSD5VlmBP9Dsw0LF+toMxKZhEgRGGTT r+JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SsgNs8WP7Va7/HPmzzpveitPd422Cl33ClfKs6muCY8=; fh=bDMhawaV3Z1J7PJ3BxdcqcGpBnHFiMOpzHEfKROCXg0=; b=KxL9nu5H3nlA32jnKFyHVEBo8i4Bbts49bCV4HyNovH2lnJMp6MM7kxfHFWadYEcWZ blFCReXYYskVVYx4VHzL6tIHGZbH4ZAp455grw8Ac909q9FSNetrFfaRTfTZ8PUVANUz 85EIFpLJgmN4MAk5HtCkZUzyuQZi9malIbHVGnWA+3R0Tp/9c1ykJqC7Rrj32k9njBEA sAUn5J9xO3F31/VK0u539tArnrqewggZsX4tyosYZiaLxTSK6m5jS5BlXGfALwR+5G+K O6St0CLpyzZLXixdiNSFwe6JGNIqhaXmqMFZeaorb/jSKcj23IKKgS3Yok6LV6K8WclP 16eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=DHFk60Fg; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o17-20020a637e51000000b00564bea180dbsi8862868pgn.181.2023.08.09.09.31.18; Wed, 09 Aug 2023 09:31:31 -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=@amazon.com header.s=amazon201209 header.b=DHFk60Fg; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230260AbjHIP41 (ORCPT + 99 others); Wed, 9 Aug 2023 11:56:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231299AbjHIP40 (ORCPT ); Wed, 9 Aug 2023 11:56:26 -0400 Received: from smtp-fw-52005.amazon.com (smtp-fw-52005.amazon.com [52.119.213.156]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4402D2698; Wed, 9 Aug 2023 08:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1691596567; x=1723132567; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SsgNs8WP7Va7/HPmzzpveitPd422Cl33ClfKs6muCY8=; b=DHFk60Fga6jL5POkjcp2KhSALBJofqV3R2ze8tdgMKXbCLLsRwLEsdGh OFEQyS7RqIhFeEWNAq3m54u3wJ/2ck1dEw3KjPnJwLEmLnCP4GUlJwAz5 Zg6F17GaIglCDcCIXtbDTDhB3XYCSBsNeR3YO577gbFUCSAWNJFX/z5Br s=; X-IronPort-AV: E=Sophos;i="6.01,159,1684800000"; d="scan'208";a="597758339" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1d-m6i4x-153b24bc.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-52005.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2023 15:56:04 +0000 Received: from EX19MTAUWB001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1d-m6i4x-153b24bc.us-east-1.amazon.com (Postfix) with ESMTPS id 400C7C1540; Wed, 9 Aug 2023 15:55:59 +0000 (UTC) Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB001.ant.amazon.com (10.250.64.248) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Wed, 9 Aug 2023 15:55:50 +0000 Received: from 88665a182662.ant.amazon.com (10.106.100.32) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.30; Wed, 9 Aug 2023 15:55:46 +0000 From: Kuniyuki Iwashima To: CC: , , , , , , , , , , , Subject: Re: [PATCH bpf-next] net: Fix slab-out-of-bounds in inet[6]_steal_sock Date: Wed, 9 Aug 2023 08:55:38 -0700 Message-ID: <20230809155538.67000-1-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.106.100.32] X-ClientProxiedBy: EX19D036UWB004.ant.amazon.com (10.13.139.170) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,T_SPF_PERMERROR autolearn=no 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 From: Lorenz Bauer Date: Wed, 9 Aug 2023 16:08:31 +0100 > On Wed, Aug 9, 2023 at 3:39 PM Martin KaFai Lau wrote: > > > > On 8/9/23 1:33 AM, Lorenz Bauer wrote: > > > Kumar reported a KASAN splat in tcp_v6_rcv: > > > > > > bash-5.2# ./test_progs -t btf_skc_cls_ingress > > > ... > > > [ 51.810085] BUG: KASAN: slab-out-of-bounds in tcp_v6_rcv+0x2d7d/0x3440 > > > [ 51.810458] Read of size 2 at addr ffff8881053f038c by task test_progs/226 > > > > > > The problem is that inet[6]_steal_sock accesses sk->sk_protocol without > > > accounting for request sockets. I added the check to ensure that we only > > > every try to perform a reuseport lookup on a supported socket. > > > > > > It turns out that this isn't necessary at all. struct sock_common contains > > > a skc_reuseport flag which indicates whether a socket is part of a > > > > Does it go back to the earlier discussion > > (https://lore.kernel.org/bpf/7188429a-c380-14c8-57bb-9d05d3ba4e5e@linux.dev/) > > that the sk->sk_reuseport is 1 from sk_clone for TCP_ESTABLISHED? It works > > because there is sk->sk_reuseport"_cb" check going deeper into > > reuseport_select_sock() but there is an extra inet6_ehashfn for all TCP_ESTABLISHED. > > Sigh, I'd forgotten about this... > > For the TPROXY TCP replacement use case we sk_assign the SYN to the > listener, which creates the reqsk. We can let follow up packets pass > without sk_assign since they will match the reqsk and convert to a > fullsock via the usual route. At least that is what the test does. I'm > not even sure what it means to redirect a random packet into an > established TCP socket TBH. It'd probably be dropped? > > For UDP, I'm not sure whether we even get into this situation? Doesn't > seem like UDP sockets are cloned from each other, so we also shouldn't > end up with a reuseport flag set erroneously. > > Things we could do if necessary: > 1. Reset the flag in inet_csk_clone_lock like we do for SOCK_RCU_FREE I think we can't do this as sk_reuseport is inherited to twsk and used in inet_bind_conflict(). > 2. Duplicate the cb check into inet[6]_steal_sock or 3. Add sk_fullsock() test ?