From patchwork Sat Feb 8 15:42:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 1235312 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48FGdx4Mfyz9sRQ for ; Sun, 9 Feb 2020 02:43:01 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727558AbgBHPnB convert rfc822-to-8bit (ORCPT ); Sat, 8 Feb 2020 10:43:01 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:51943 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727546AbgBHPnB (ORCPT ); Sat, 8 Feb 2020 10:43:01 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-350-45redfCwPh-WpmZuHuWcIg-1; Sat, 08 Feb 2020 10:42:57 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D037C8014D1; Sat, 8 Feb 2020 15:42:55 +0000 (UTC) Received: from krava.redhat.com (ovpn-204-79.brq.redhat.com [10.40.204.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD4225C28F; Sat, 8 Feb 2020 15:42:52 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Yonghong Song , Song Liu , Martin KaFai Lau , Jakub Kicinski , David Miller , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , John Fastabend , Jesper Dangaard Brouer Subject: [PATCH 10/14] bpf: Re-initialize lnode in bpf_ksym_del Date: Sat, 8 Feb 2020 16:42:05 +0100 Message-Id: <20200208154209.1797988-11-jolsa@kernel.org> In-Reply-To: <20200208154209.1797988-1-jolsa@kernel.org> References: <20200208154209.1797988-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: 45redfCwPh-WpmZuHuWcIg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org When bpf_prog is removed from kallsyms it's on the way out to be removed, so we don't care about lnode state. However the bpf_ksym_del will be used also by bpf_trampoline and bpf_dispatcher objects, which stay allocated even when they are not in kallsyms list, hence the lnode re-init. The list_del_rcu commentary states that we need to call synchronize_rcu, before we can change/re-init the list_head pointers. Signed-off-by: Jiri Olsa --- kernel/bpf/core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 73242fd07893..66b17bea286e 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -676,6 +676,13 @@ void bpf_ksym_del(struct bpf_ksym *ksym) spin_lock_bh(&bpf_lock); __bpf_ksym_del(ksym); spin_unlock_bh(&bpf_lock); + + /* + * As explained in list_del_rcu, We must call synchronize_rcu + * before changing list_head pointers. + */ + synchronize_rcu(); + INIT_LIST_HEAD_RCU(&ksym->lnode); } static bool bpf_prog_kallsyms_candidate(const struct bpf_prog *fp)