Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2236572imm; Thu, 7 Jun 2018 07:30:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLQR8ztRTpD1iFK8Thnw+XzhoAa1o94IaC/OPQehKj+GHIDY+Uru2zQMy9Yv7lcg6V7bSgE X-Received: by 2002:a17:902:5501:: with SMTP id f1-v6mr2328514pli.108.1528381836972; Thu, 07 Jun 2018 07:30:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528381836; cv=none; d=google.com; s=arc-20160816; b=lFk8BvvApebfEMZeE3VyQuhNuyJJGSb5QEeeekMr4oTfYlTXmJ+tx3OJFNaHh0mFjJ WPTEE++7jBF0u4WMNOSTJiU+5OJGKH46KXYY3lRfvQSPiz6yqjE+ooYdxg5BUUT3h80/ qoeB/xyGovLc3xj9YvXxOQtILegTzGaASuSX+7qYJJfzakhHPBqz7SDxJt7tuDcxArTR Rgfxn2AyjiUAb0YfRWCMjokcaLcstiGe17Qu9jMiufM3PqeeHWATaYHqHOG1TR+zEIq/ G+eZZQQdV/EjFLfIb62dGD69vFZO9WLpz9z0TwH+cWnFqlo5AuOjLAj2inoMfOG/k4Qy JzXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=WszvS8VR3Wqv/0T8NY7TwwmWlAzbgs2sIwZTH2m34FA=; b=YwG19QQ0Sj3BN0BccpmLo6KGaTxb17O/MeSunUqIXLyPpLU/ct4lH0Ppb4uHRETC87 BXyj/VGlE/OhZf5XG096WcxvcbXzuCqxuUHm+Q9yZAtdMjTGa4W7PbxRulGPmffz5G1k jZjcbWQojOD3ColHI0zO0IOYJgwW/6obIAWuoGlHduEtGVzrIFY6G+CWoFCB94zVTH1E 4KnQ6kNbht1ItepcHXRQNweSbBpu3OYBWthhIESUHhe/8vZHQ28VzqCCsavQq8lIvHEL KQCbmcBxas0Uz6MnPz5hWnJQkdKEsSUxg2lDYT1QZPuksqS1L9X9aF9CejpeG6OuwR43 OZ7g== ARC-Authentication-Results: i=1; mx.google.com; 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 p8-v6si53369849plk.441.2018.06.07.07.30.22; Thu, 07 Jun 2018 07:30:36 -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; 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 S933683AbeFGO3K (ORCPT + 99 others); Thu, 7 Jun 2018 10:29:10 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40212 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932915AbeFGO3H (ORCPT ); Thu, 7 Jun 2018 10:29:07 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbb-0005hO-KP; Thu, 07 Jun 2018 15:09:35 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb8-00034p-9L; Thu, 07 Jun 2018 15:09:06 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Paolo Abeni" , "David S. Miller" , "Petr Vandrovec" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 252/410] dn_getsockoptdecnet: move nf_{get/set}sockopt outside sock lock In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Paolo Abeni commit dfec091439bb2acf763497cfc58f2bdfc67c56b7 upstream. After commit 3f34cfae1238 ("netfilter: on sockopt() acquire sock lock only in the required scope"), the caller of nf_{get/set}sockopt() must not hold any lock, but, in such changeset, I forgot to cope with DECnet. This commit addresses the issue moving the nf call outside the lock, in the dn_{get,set}sockopt() with the same schema currently used by ipv4 and ipv6. Also moves the unhandled sockopts of the end of the main switch statements, to improve code readability. Reported-by: Petr Vandrovec BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=198791#c2 Fixes: 3f34cfae1238 ("netfilter: on sockopt() acquire sock lock only in the required scope") Signed-off-by: Paolo Abeni Signed-off-by: David S. Miller Signed-off-by: Ben Hutchings --- net/decnet/af_decnet.c | 62 ++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 29 deletions(-) --- a/net/decnet/af_decnet.c +++ b/net/decnet/af_decnet.c @@ -1336,6 +1336,12 @@ static int dn_setsockopt(struct socket * lock_sock(sk); err = __dn_setsockopt(sock, level, optname, optval, optlen, 0); release_sock(sk); +#ifdef CONFIG_NETFILTER + /* we need to exclude all possible ENOPROTOOPTs except default case */ + if (err == -ENOPROTOOPT && optname != DSO_LINKINFO && + optname != DSO_STREAM && optname != DSO_SEQPACKET) + err = nf_setsockopt(sk, PF_DECnet, optname, optval, optlen); +#endif return err; } @@ -1443,15 +1449,6 @@ static int __dn_setsockopt(struct socket dn_nsp_send_disc(sk, 0x38, 0, sk->sk_allocation); break; - default: -#ifdef CONFIG_NETFILTER - return nf_setsockopt(sk, PF_DECnet, optname, optval, optlen); -#endif - case DSO_LINKINFO: - case DSO_STREAM: - case DSO_SEQPACKET: - return -ENOPROTOOPT; - case DSO_MAXWINDOW: if (optlen != sizeof(unsigned long)) return -EINVAL; @@ -1499,6 +1496,12 @@ static int __dn_setsockopt(struct socket return -EINVAL; scp->info_loc = u.info; break; + + case DSO_LINKINFO: + case DSO_STREAM: + case DSO_SEQPACKET: + default: + return -ENOPROTOOPT; } return 0; @@ -1512,6 +1515,20 @@ static int dn_getsockopt(struct socket * lock_sock(sk); err = __dn_getsockopt(sock, level, optname, optval, optlen, 0); release_sock(sk); +#ifdef CONFIG_NETFILTER + if (err == -ENOPROTOOPT && optname != DSO_STREAM && + optname != DSO_SEQPACKET && optname != DSO_CONACCEPT && + optname != DSO_CONREJECT) { + int len; + + if (get_user(len, optlen)) + return -EFAULT; + + err = nf_getsockopt(sk, PF_DECnet, optname, optval, &len); + if (err >= 0) + err = put_user(len, optlen); + } +#endif return err; } @@ -1577,26 +1594,6 @@ static int __dn_getsockopt(struct socket r_data = &link; break; - default: -#ifdef CONFIG_NETFILTER - { - int ret, len; - - if (get_user(len, optlen)) - return -EFAULT; - - ret = nf_getsockopt(sk, PF_DECnet, optname, optval, &len); - if (ret >= 0) - ret = put_user(len, optlen); - return ret; - } -#endif - case DSO_STREAM: - case DSO_SEQPACKET: - case DSO_CONACCEPT: - case DSO_CONREJECT: - return -ENOPROTOOPT; - case DSO_MAXWINDOW: if (r_len > sizeof(unsigned long)) r_len = sizeof(unsigned long); @@ -1628,6 +1625,13 @@ static int __dn_getsockopt(struct socket r_len = sizeof(unsigned char); r_data = &scp->info_rem; break; + + case DSO_STREAM: + case DSO_SEQPACKET: + case DSO_CONACCEPT: + case DSO_CONREJECT: + default: + return -ENOPROTOOPT; } if (r_data) {