Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10201044ybi; Wed, 24 Jul 2019 18:14:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyD0ceb1+IVw/6O/lzNdqtMKK3QMScUlVnIwa+0duvwndvhOCGjckT9riaGbtDVNeppZROy X-Received: by 2002:a17:902:b68f:: with SMTP id c15mr89314904pls.104.1564017248719; Wed, 24 Jul 2019 18:14:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564017248; cv=none; d=google.com; s=arc-20160816; b=no3uLxJffEpIYuO5O4pqnlKfNWupf9vvj02vH/epDyovN5lTJ2YTbNdlJgoyYAWoM6 rlGNW6xFAPTSTSD+IJqNVK7r7g3QEJzZOJQsXdzDCnx8p7FFajoalpiRG+yCFVWhMC7P J/gVyLY5H8KQMuQ8fGZuJurpl7prNvAxShv+nV+hJxhgNjFy4rSMiT6TXZ6bhY1TDiAi q9X5P+PczlsB07wAG62GVC45eDtnaXCPVlY7B56NyTNWtw8LePgy2pOEWFSfwQ/0ZKR1 iSogFfbC78dBuXzua20LOpf2Fj1Rmiyb0yG9Z0aSw9qkMBN3MMGs2+urmuPI29FlDIPQ ei0w== 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=bwzTuKAtwedldIZCkmoC66y56/2pJsc54zsp/HBys4k=; b=0Re5sEmyfmnKrp7eokajjO1VDXO+vkA4om61h0CflA5nxmHLSTSg4ZBl5UG34GF/cV VmjkSuz9v9WvHJ33+HVzNjj2UzE+Qzvt5W6OFss5cfWMitNNxvQjDdvRfpdNe960dlq4 lgOkc+fvfn0o6dgaxW7JKkrpu5Hace4UQY4PXuPiS8epfrL3MdvN3fVVqAgo41EYPBat 0vTZTznql457adqotE+qj/w5bVoHn98HOymlcexWlxNf/kXUQ+bkHRTKduuYYGe4iwg7 u12PKfbglCI4OjmRzF+yR7DKABhTGa1q4owZxejV/wTgR5Q6yvrRKryw95e1YTsAOKtX FZbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w4pMqA6l; 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 g5si13988365pjp.71.2019.07.24.18.13.41; Wed, 24 Jul 2019 18:14:08 -0700 (PDT) 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=w4pMqA6l; 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 S2387872AbfGXTeR (ORCPT + 99 others); Wed, 24 Jul 2019 15:34:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:56506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389076AbfGXTeP (ORCPT ); Wed, 24 Jul 2019 15:34:15 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 DA51422ADA; Wed, 24 Jul 2019 19:34:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996853; bh=y4Hveut3whjPHnXS7J7Iv+kNDpfOgraFr9FfzoJxKgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w4pMqA6llbMDj/UAAeuxav8eNaSQcoNHcn9SroDtbOxZukugQ78OcYgg2C2H0XX5x QCodqmnbtt676AfaCFDj+SHQqhgGPq9zbPsgMfJXiq0YLliVcZAW+yHfdC8FLzuzsi eEq/fj1qGUikDvLmYGLyjGEHQQigvSNJ5+/Gkc5o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Taehee Yoo , "David S. Miller" , Sasha Levin Subject: [PATCH 5.2 238/413] gtp: fix suspicious RCU usage Date: Wed, 24 Jul 2019 21:18:49 +0200 Message-Id: <20190724191752.356603780@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 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 [ Upstream commit e198987e7dd7d3645a53875151cd6f8fc425b706 ] gtp_encap_enable_socket() and gtp_encap_destroy() are not protected by rcu_read_lock(). and it's not safe to write sk->sk_user_data. This patch make these functions to use lock_sock() instead of rcu_dereference_sk_user_data(). Test commands: gtp-link add gtp1 Splat looks like: [ 83.238315] ============================= [ 83.239127] WARNING: suspicious RCU usage [ 83.239702] 5.2.0-rc6+ #49 Not tainted [ 83.240268] ----------------------------- [ 83.241205] drivers/net/gtp.c:799 suspicious rcu_dereference_check() usage! [ 83.243828] [ 83.243828] other info that might help us debug this: [ 83.243828] [ 83.246325] [ 83.246325] rcu_scheduler_active = 2, debug_locks = 1 [ 83.247314] 1 lock held by gtp-link/1008: [ 83.248523] #0: 0000000017772c7f (rtnl_mutex){+.+.}, at: __rtnl_newlink+0x5f5/0x11b0 [ 83.251503] [ 83.251503] stack backtrace: [ 83.252173] CPU: 0 PID: 1008 Comm: gtp-link Not tainted 5.2.0-rc6+ #49 [ 83.253271] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 83.254562] Call Trace: [ 83.254995] dump_stack+0x7c/0xbb [ 83.255567] gtp_encap_enable_socket+0x2df/0x360 [gtp] [ 83.256415] ? gtp_find_dev+0x1a0/0x1a0 [gtp] [ 83.257161] ? memset+0x1f/0x40 [ 83.257843] gtp_newlink+0x90/0xa21 [gtp] [ 83.258497] ? __netlink_ns_capable+0xc3/0xf0 [ 83.259260] __rtnl_newlink+0xb9f/0x11b0 [ 83.260022] ? rtnl_link_unregister+0x230/0x230 [ ... ] Fixes: 1e3a3abd8b28 ("gtp: make GTP sockets in gtp_newlink optional") Signed-off-by: Taehee Yoo Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/gtp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 01fc51892e48..61f19e66be55 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -289,12 +289,14 @@ static void gtp_encap_destroy(struct sock *sk) { struct gtp_dev *gtp; - gtp = rcu_dereference_sk_user_data(sk); + lock_sock(sk); + gtp = sk->sk_user_data; if (gtp) { udp_sk(sk)->encap_type = 0; rcu_assign_sk_user_data(sk, NULL); sock_put(sk); } + release_sock(sk); } static void gtp_encap_disable_sock(struct sock *sk) @@ -796,7 +798,8 @@ static struct sock *gtp_encap_enable_socket(int fd, int type, goto out_sock; } - if (rcu_dereference_sk_user_data(sock->sk)) { + lock_sock(sock->sk); + if (sock->sk->sk_user_data) { sk = ERR_PTR(-EBUSY); goto out_sock; } @@ -812,6 +815,7 @@ static struct sock *gtp_encap_enable_socket(int fd, int type, setup_udp_tunnel_sock(sock_net(sock->sk), sock, &tuncfg); out_sock: + release_sock(sock->sk); sockfd_put(sock); return sk; } -- 2.20.1