Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3467188imu; Sun, 11 Nov 2018 15:46:25 -0800 (PST) X-Google-Smtp-Source: AJdET5c+sxL8mesyPofsodCI4pQuiNPdiwshZmy6PcwPSJkiXWyyjSULjHCi4P82yaL0IoZJtEVu X-Received: by 2002:a62:401:: with SMTP id 1-v6mr17586620pfe.156.1541979985197; Sun, 11 Nov 2018 15:46:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541979985; cv=none; d=google.com; s=arc-20160816; b=qyqaJY/l/XJwXR0WvD7t6pAGIbAoLPV2ooWjUQ0MgGWkTYvidFc6pLPeRh5wg0BgYz dsMAsbl3NXjbi6agyVXKE+Oj9naKx5WPe/+Clu4xmMFvtJ591ltmX8EKuhBcUmPIDqIe WjV8GAmfv/ZR/a58ipf1n7nuasIdBgqBWoLzQKRF5MPKkAL2O86ZguE0FiKSNjIkanPT swmvaMfzFcqjr9inLh98A0fFGgw15KQz3gR7UjBGOhfj1qQtlwkymxZA6bE07ZE9DTCM HQFn0GpUwpANdYEP+SeOL5TXGu3eEOQl/kQ6c5tbn62QKTHzzTov9n3T0skbfWGbAhrT T1ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vR5mpDoQwEnoMEk9C6W1KC/No4KP04QBn9LXXRzEAAk=; b=i+w5sTZ4JUgMgtxIN3coAc1Rj0utzoF1+SLwYKPWtJ8Es0qBtD2aX5bjeOfBSPE7Ev V/s97TJoJzbRlmDsqpHUdRR7RD0Vbfj5BG4AJBgCSnr8cm7l+1GFSYod4iKptoOJwrVO EkfERvtjOH5fy2YojMdZS9XFQWRicRxBzmuEbj9Ut/OlzHk+nwGMeJd4Yz8f7f87FTED xlsxcamhggBX3V0ab/EYLl6Xn5VmO88yc4XD6lYegcyHMJWQwhtj3DzOWJuk9WP7WhEw U06v107Cc5i/OPqoLYnzo0jgRJnMFFx1yjRKE0qtA7cq+VDeTQRXM4QuKOWlrftUnqWT PD1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xHEAxdyW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3-v6si15683718plb.291.2018.11.11.15.46.10; Sun, 11 Nov 2018 15:46:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xHEAxdyW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387655AbeKLJgE (ORCPT + 99 others); Mon, 12 Nov 2018 04:36:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:39818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387401AbeKLITF (ORCPT ); Mon, 12 Nov 2018 03:19:05 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4AF6B21508; Sun, 11 Nov 2018 22:29:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975349; bh=oR1LGesLeY46cJUrAhC2Hjj5E2UKOWnlqk9J3zu2nak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xHEAxdyWxSHN+1iVVNqv/kjg8nPs2Y/ngF6q5I1osk+J0cxK2x5z3Lo9EKW27o1Vj R7tFUCjK3C4ESM7c9rtaFDVkHi2SB9eoGJfChVeYSwLXhAWG6ewt+WOaWLJaxRPV1x gqFw/5ez0PQYgR+K9LhcShuhlOK48laeKOFkjxcs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Colascione , "Joel Fernandes (Google)" , Alexei Starovoitov , Chenbo Feng Subject: [PATCH 4.19 360/361] bpf: wait for running BPF programs when updating map-in-map Date: Sun, 11 Nov 2018 14:21:47 -0800 Message-Id: <20181111221702.268411766@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daniel Colascione commit 1ae80cf31938c8f77c37a29bbe29e7f1cd492be8 upstream. The map-in-map frequently serves as a mechanism for atomic snapshotting of state that a BPF program might record. The current implementation is dangerous to use in this way, however, since userspace has no way of knowing when all programs that might have retrieved the "old" value of the map may have completed. This change ensures that map update operations on map-in-map map types always wait for all references to the old map to drop before returning to userspace. Signed-off-by: Daniel Colascione Reviewed-by: Joel Fernandes (Google) Signed-off-by: Alexei Starovoitov Signed-off-by: Chenbo Feng Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/syscall.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -741,6 +741,17 @@ err_put: return err; } +static void maybe_wait_bpf_programs(struct bpf_map *map) +{ + /* Wait for any running BPF programs to complete so that + * userspace, when we return to it, knows that all programs + * that could be running use the new map value. + */ + if (map->map_type == BPF_MAP_TYPE_HASH_OF_MAPS || + map->map_type == BPF_MAP_TYPE_ARRAY_OF_MAPS) + synchronize_rcu(); +} + #define BPF_MAP_UPDATE_ELEM_LAST_FIELD flags static int map_update_elem(union bpf_attr *attr) @@ -831,6 +842,7 @@ static int map_update_elem(union bpf_att } __this_cpu_dec(bpf_prog_active); preempt_enable(); + maybe_wait_bpf_programs(map); out: free_value: kfree(value); @@ -883,6 +895,7 @@ static int map_delete_elem(union bpf_att rcu_read_unlock(); __this_cpu_dec(bpf_prog_active); preempt_enable(); + maybe_wait_bpf_programs(map); out: kfree(key); err_put: