Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2717312pxv; Sun, 11 Jul 2021 23:40:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoPBys3LadHA8WH2yCpIw9L4x703xnFLgn9f9615KjWlIksGxWLRwzKnZfbsKWQXv6RsIX X-Received: by 2002:a17:906:131a:: with SMTP id w26mr27095808ejb.46.1626072032775; Sun, 11 Jul 2021 23:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626072032; cv=none; d=google.com; s=arc-20160816; b=gh1FfoRCQSZQmJiKCs5lQ54ChyBVd7AniFhYt8PowR7J61/yCreUQC6SYq6mJMYRcN xntD9j6syIqxXiodVb0ta1ugqn35BG1iKwN5ruyQyrZ0XJz2Fk59gsCumjnZ2rl+Ep2P 1xjS2IRQlVXHlAVlFjX5y7r4CM8DbjUX4cq6WJc3p2pZ7JMOSb0d0Zn/GKF6BWIH/jFu IAmfQx0PmUKlA6ZC8KgNAq42MWobSF2TsaOrIBm1v/S8/5yES4A0510UyVQvSbO5Ifhz sVUhHnm5oWII10/TJv8jskNDvEVr3W0P8JmwELW24J6HdtzZkR8LTL+ZboQfh28kaXoN nWiQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5Agea8L432Bs5fyn69Po5F3Zq6MEiWTYTk3scvOAtOM=; b=oDSlX4jiuOjpd/gZDqbiuuRJFhibCp97GJWUHWYVmmv1WmSscW7daHnmui8MVfPgjL yJOCyoxwFyBQHPhg/kPR3wk8Fecc4/WUURcE1pLIFpGGIUIQ5UdziSPEKpF+a/cwLUf6 IRKmJE8SEj46RHKEX8zCgOBae+EQX8nTRX/l+VHh3GfhLu2w3E2+5oNP8NDmrbThsn80 wLlSkwSFD9If9kz/DFvL2OWbMgiw7zkZlheqult7BVaRlwSyRDQ+eACh1aVIFOwvP3nh ZhdAdsUhyIySRO6YBIScjHqwNASrCNBkeCNQ6ix5jvcCLwjjMrhxX+wJC/omlIfk79Fw uAVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TUDpKk1B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 19si16063578ejx.529.2021.07.11.23.40.10; Sun, 11 Jul 2021 23:40:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TUDpKk1B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236918AbhGLGlR (ORCPT + 99 others); Mon, 12 Jul 2021 02:41:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:54932 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235717AbhGLGdQ (ORCPT ); Mon, 12 Jul 2021 02:33:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D531B61107; Mon, 12 Jul 2021 06:29:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071394; bh=FvwUpQ2nmy72RY4rak7jDjupjX9dGsTCsai5zJ8RPPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TUDpKk1BOWytu28BbUKq9r7yLgnyqEjODhqXmfexVik/6RtNA5zU8Sh6PrXVVdtwv LruzGK4DaUaz/6pD/4WWEN03lkM/1Ale9sjzKsSiA5/txbcAJvaN7Zf857E1gHKBPC tb86uY1WT3p5P4x4dEPtZQywr3glxqcceb+nR4QQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+0f7e7e5e2f4f40fa89c0@syzkaller.appspotmail.com, Norbert Slusarek , Thadeu Lima de Souza Cascardo , Oliver Hartkopp , Marc Kleine-Budde Subject: [PATCH 5.10 050/593] can: bcm: delay release of struct bcm_op after synchronize_rcu() Date: Mon, 12 Jul 2021 08:03:30 +0200 Message-Id: <20210712060848.631325566@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thadeu Lima de Souza Cascardo commit d5f9023fa61ee8b94f37a93f08e94b136cf1e463 upstream. can_rx_register() callbacks may be called concurrently to the call to can_rx_unregister(). The callbacks and callback data, though, are protected by RCU and the struct sock reference count. So the callback data is really attached to the life of sk, meaning that it should be released on sk_destruct. However, bcm_remove_op() calls tasklet_kill(), and RCU callbacks may be called under RCU softirq, so that cannot be used on kernels before the introduction of HRTIMER_MODE_SOFT. However, bcm_rx_handler() is called under RCU protection, so after calling can_rx_unregister(), we may call synchronize_rcu() in order to wait for any RCU read-side critical sections to finish. That is, bcm_rx_handler() won't be called anymore for those ops. So, we only free them, after we do that synchronize_rcu(). Fixes: ffd980f976e7 ("[CAN]: Add broadcast manager (bcm) protocol") Link: https://lore.kernel.org/r/20210619161813.2098382-1-cascardo@canonical.com Cc: linux-stable Reported-by: syzbot+0f7e7e5e2f4f40fa89c0@syzkaller.appspotmail.com Reported-by: Norbert Slusarek Signed-off-by: Thadeu Lima de Souza Cascardo Acked-by: Oliver Hartkopp Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- net/can/bcm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/net/can/bcm.c +++ b/net/can/bcm.c @@ -785,6 +785,7 @@ static int bcm_delete_rx_op(struct list_ bcm_rx_handler, op); list_del(&op->list); + synchronize_rcu(); bcm_remove_op(op); return 1; /* done */ } @@ -1533,9 +1534,13 @@ static int bcm_release(struct socket *so REGMASK(op->can_id), bcm_rx_handler, op); - bcm_remove_op(op); } + synchronize_rcu(); + + list_for_each_entry_safe(op, next, &bo->rx_ops, list) + bcm_remove_op(op); + #if IS_ENABLED(CONFIG_PROC_FS) /* remove procfs entry */ if (net->can.bcmproc_dir && bo->bcm_proc_read)