Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2080230imw; Tue, 5 Jul 2022 22:51:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tBC4vLzzFYGA4P795dlMpIKECAOt8/40AZZYDLJz9bNSkCmQGcrCiFdIQnP1Hm0JJDlyTy X-Received: by 2002:a05:6402:492:b0:437:4b50:d616 with SMTP id k18-20020a056402049200b004374b50d616mr50351541edv.43.1657086701180; Tue, 05 Jul 2022 22:51:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657086701; cv=none; d=google.com; s=arc-20160816; b=Tusy9YzHvRQ+7cFMYaN1tz9qWnKFpU0WJ0LOI2xR36JCCxwHYT5uKHdRN5E2m5CVuy UJmt6QvIM3gkcL8fbPhH/7gAHDr2oti+N/x/wnuY+I0hwgFy79gjRdUXJFKdkqiu9bLh psS0GyXumqqYsQ887bgZbVpQt1R8qIMwx53wt9m5LQoIwC2VgNq4zZETpC5DKcKVnT/P B8+ZJ+18W76Ad3s/Dm0FiWKAiBW8ipNOFdDR+7dpF5CLTM5aWh8hmWR2mMS9hJB2GFSH W2ma7RsST0+Op5e89ZuTjHB0IFRDvz3FRnh5J7s4OWKinLJm6+7o93O6j/CdKqgAHEZc vOew== 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=IKJsdEUef1a6JNTlcaG4PZoYPj0UhfWISm/SkdIazRE=; b=t44eHklFyRL6Ex/a867CJ22qoUdN6vXaeGILX2SbVBPsDZ6UHDcdYmBDB81Js/uXJ3 dvlSW9FFiDLSuAW/qxtYUL8SRYeR1U8VSP4iSK1crBofqJggXqoUTiE79qqKR6N12srT Hy0hYKnaC4R7uF06p2uSUjOblJahUAUPavqsYHk1JkHDxD8OUTnd6XFcnTzCS4XUa1JD Wnfx76g1/L2MVbQyabbQz1tR5gKg6bQs7hQco23MKcqKfBwZMypbJXtpsn8PIoNl0cSk j7sDS9z6xFygZPYEJ+QWP8Nwj31bYpqMCiiN+EDgXbAblriNsEBOmghyLN9hjLTQwC2i TjfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=hZu4c8FQ; 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 ho15-20020a1709070e8f00b0072a6bc9ae69si23022921ejc.980.2022.07.05.22.51.15; Tue, 05 Jul 2022 22:51:41 -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=hZu4c8FQ; 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 S231740AbiGFFZH (ORCPT + 99 others); Wed, 6 Jul 2022 01:25:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231659AbiGFFZB (ORCPT ); Wed, 6 Jul 2022 01:25:01 -0400 Received: from smtp-fw-9103.amazon.com (smtp-fw-9103.amazon.com [207.171.188.200]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B6D921818; Tue, 5 Jul 2022 22:24:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1657085096; x=1688621096; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IKJsdEUef1a6JNTlcaG4PZoYPj0UhfWISm/SkdIazRE=; b=hZu4c8FQESYhdtawnuNOkenTCy20gx0beTlu3xh1j0kUhDnjg25FpFye kHO4LiFtNwvE5BrVDXR2kUmB8dECpRPQb/T+s/Z1VLqUR97vsAEIvFUGM cQ9JrRB8/EcrPrE66DEMlArQH6D2kMO/Z0y0w0eD2NfNXyF9vMRbNj9JI k=; X-IronPort-AV: E=Sophos;i="5.92,248,1650931200"; d="scan'208";a="1031201962" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-pdx-2c-388992e0.us-west-2.amazon.com) ([10.25.36.214]) by smtp-border-fw-9103.sea19.amazon.com with ESMTP; 06 Jul 2022 05:24:55 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-pdx-2c-388992e0.us-west-2.amazon.com (Postfix) with ESMTPS id 9129987690; Wed, 6 Jul 2022 05:24:55 +0000 (UTC) Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Wed, 6 Jul 2022 05:24:54 +0000 Received: from 88665a182662.ant.amazon.com (10.43.162.55) 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.9; Wed, 6 Jul 2022 05:24:51 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Luis Chamberlain , Kees Cook , Iurii Zaikin CC: Kuniyuki Iwashima , Kuniyuki Iwashima , , , Paul Moore Subject: [PATCH v1 net 13/16] cipso: Fix a data-race around cipso_v4_cache_bucketsize. Date: Tue, 5 Jul 2022 22:21:27 -0700 Message-ID: <20220706052130.16368-14-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220706052130.16368-1-kuniyu@amazon.com> References: <20220706052130.16368-1-kuniyu@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.43.162.55] X-ClientProxiedBy: EX13D18UWA004.ant.amazon.com (10.43.160.45) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 While reading cipso_v4_cache_bucketsize, it can be changed concurrently. So, we need to add READ_ONCE(). Then we can set proc_dointvec_lockless() as the handler to mark it safe. Fixes: 446fda4f2682 ("[NetLabel]: CIPSOv4 engine") Signed-off-by: Kuniyuki Iwashima --- CC: Paul Moore --- Documentation/networking/ip-sysctl.rst | 2 +- net/ipv4/cipso_ipv4.c | 12 ++++++------ net/ipv4/sysctl_net_ipv4.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst index 9f41961d11d5..0e58001f8580 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -1085,7 +1085,7 @@ cipso_cache_enable - BOOLEAN cipso_cache_bucket_size - INTEGER The CIPSO label cache consists of a fixed size hash table with each hash bucket containing a number of cache entries. This variable limits - the number of entries in each hash bucket; the larger the value the + the number of entries in each hash bucket; the larger the value is, the more CIPSO label mappings that can be cached. When the number of entries in a given hash bucket reaches this limit adding new entries causes the oldest entry in the bucket to be removed to make room. diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c index 62d5f99760aa..0600e9b06e1a 100644 --- a/net/ipv4/cipso_ipv4.c +++ b/net/ipv4/cipso_ipv4.c @@ -296,13 +296,13 @@ static int cipso_v4_cache_check(const unsigned char *key, int cipso_v4_cache_add(const unsigned char *cipso_ptr, const struct netlbl_lsm_secattr *secattr) { - int ret_val = -EPERM; - u32 bkt; - struct cipso_v4_map_cache_entry *entry = NULL; + int bkt_size = READ_ONCE(cipso_v4_cache_bucketsize); struct cipso_v4_map_cache_entry *old_entry = NULL; - u32 cipso_ptr_len; + struct cipso_v4_map_cache_entry *entry = NULL; + u32 bkt, cipso_ptr_len; + int ret_val = -EPERM; - if (!cipso_v4_cache_enabled || cipso_v4_cache_bucketsize <= 0) + if (!cipso_v4_cache_enabled || bkt_size <= 0) return 0; cipso_ptr_len = cipso_ptr[1]; @@ -322,7 +322,7 @@ int cipso_v4_cache_add(const unsigned char *cipso_ptr, bkt = entry->hash & (CIPSO_V4_CACHE_BUCKETS - 1); spin_lock_bh(&cipso_v4_cache[bkt].lock); - if (cipso_v4_cache[bkt].size < cipso_v4_cache_bucketsize) { + if (cipso_v4_cache[bkt].size < bkt_size) { list_add(&entry->list, &cipso_v4_cache[bkt].list); cipso_v4_cache[bkt].size += 1; } else { diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index 0287d55f9230..5cd32b33bbac 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -527,7 +527,7 @@ static struct ctl_table ipv4_table[] = { .data = &cipso_v4_cache_bucketsize, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dointvec_lockless, }, { .procname = "cipso_rbm_optfmt", -- 2.30.2