Received: by 10.223.185.116 with SMTP id b49csp1104179wrg; Fri, 23 Feb 2018 12:01:28 -0800 (PST) X-Google-Smtp-Source: AH8x226d3vPGq2rxl7rK8nrAAqCEyt53RC2ZTvsdymTBsaIfVkuP/+2Fmin55fImg0pg9EypnZQw X-Received: by 10.101.91.133 with SMTP id i5mr2251988pgr.20.1519416088656; Fri, 23 Feb 2018 12:01:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519416088; cv=none; d=google.com; s=arc-20160816; b=xy2bzpRlDhK8a9a/IvYncerBlZaFmGUCAfiz7iTvIuEHMAUx/DLBEkW0gEoPCHCncd cdM7++ZTXdV4wXyYQODyWK3FUH2LcPBKfPE/ohmuswd6DklPQhzyLcp+3KuUGI/9OSH7 5v38Zaehb+PDjfpHUJevmVUCY8JOOXtS5lHnrDOVYHBsB+j6cM60X5OiurNZQG77DNo2 RKhzLMErxMRRx4u+RXKXsDaVur48OxbCRIahy38Sq9tPKkfR/He/1nRCfYX3p6gmcWu/ Nr584DFPsg5ZTkS1y38b2q2tXxamFzq6XcKY6KFXZP+Ocp4KVGdTZ3WCUFi+kdHUUvx4 7eQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=GQvhA8kQse/e4VxLx10sMU7AMr/AgMMjIB2W0+VOFxw=; b=V36wqr4kluz+IxhV1hLyJwd2CbtFhPzCM2rNI0b+e46LRabgtGUQGNSRPLqqFgmCLz NNJZiFydau83J4ho4ZUMnHaVRCfVU/CXaKp2GxKRy+f35lGqubXo0cgsJuD4h43RiquO XJAaYcZLwkK8fbWqRVEkb30Yb1xYhkyJUiITASyXbtYXgCbl4JdsFEvsx+f0HnASlCAC Ch+/HzfjArIXy4pgp8hKs4cyHKBaRFA80kvxkjEjEvmWOuqSXO8GhB2BZOS9ELqj3weu G4/ZmWdfpUxG6s2859DCXLNX2jnpRJ5zJustjViX/NaHYwuWJ2W5/Wc+66Lk/Z5oDyvg nVSA== 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 p68si2316489pfk.8.2018.02.23.12.01.14; Fri, 23 Feb 2018 12:01:28 -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; 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 S933393AbeBWSnr (ORCPT + 99 others); Fri, 23 Feb 2018 13:43:47 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42312 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932953AbeBWSno (ORCPT ); Fri, 23 Feb 2018 13:43:44 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 49FD710BE; Fri, 23 Feb 2018 18:43:43 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Petr Vandrovec , Paolo Abeni , "David S. Miller" Subject: [PATCH 4.9 036/145] dn_getsockoptdecnet: move nf_{get/set}sockopt outside sock lock Date: Fri, 23 Feb 2018 19:25:42 +0100 Message-Id: <20180223170729.553321509@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170724.669759283@linuxfoundation.org> References: <20180223170724.669759283@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable 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: Greg Kroah-Hartman --- 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 @@ -1337,6 +1337,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; } @@ -1444,15 +1450,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; @@ -1500,6 +1497,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; @@ -1513,6 +1516,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; } @@ -1578,26 +1595,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); @@ -1629,6 +1626,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) {