Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1199808pxa; Thu, 20 Aug 2020 05:27:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfyatJLBLKGAoERY1+TQAEG2a8baFhkJ6JkKbvYTsBi4FBu7ULrLOxX77z0OPSqFuCaF/u X-Received: by 2002:a17:906:2e51:: with SMTP id r17mr2969411eji.308.1597926474342; Thu, 20 Aug 2020 05:27:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597926474; cv=none; d=google.com; s=arc-20160816; b=l216jruEpoQG0QtJU3GdorsLQKJAhonCXQNPa8pVYjCt0ijErOEGcmE2BdGTyr94E6 h8ZY1ND2UmaRcfC53y1kjB68x541u4imeWG3hJoARMRmAANzzXRE/eLJK1JeFAwuoQ7a Lsw8qlsPJVrybH5YcfzIlAMmQ4v4UtCg5NcYLZsLnmcTXb+cO90M1fAnM7l/MVn5htGd AbifMBuFs4C8NRvjfMNtOlEraUM3Zm4OwB848eInw26EmvIq0/ioFEUomDFw9g38dUgS oxUpOEcPK/rGnvNnN+sqkBfhSMfjDvsh9mg9aKIz65/5lATbh8bJXioR1+nlV0u4qnWY X6Pg== 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=TshuYZPaiMLI8QauNNDkN48Yef8olfBx7hEjVxPa3P4=; b=Hz5ewN+vj9svgtqZVoWw4zuof+T9mCNsVNF+UhhG7ua0hVfkymD9UlRBvEFhGRGK82 HSp/sY+u4gVF0vYnbt+Fh1ZtL13k7I1GIwlHJP8Tst5bf72oOFypAt/Lch7SoQ9Ha3oy kLA8rNofYZngGstZNgbeIQsntbQhCStKmP2NohrgARPSlu4yBhXqvTL5B2EtrqABb5da mnhjQVEIabWif0xxZaLt4GIofZmo0GYvgUA3FsTjqW1qbAXzCPM/2eM85VVwqdLGixDM daw7q5oUWlZqy7f4siqTWmsLyHu3RbY9KtXJJ8Fj+YGy8fz7ljrDCaFlWBREiskC4VGL wMEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nWTEvPhv; 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=fail (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 b15si490104edt.42.2020.08.20.05.27.30; Thu, 20 Aug 2020 05:27:54 -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=@kernel.org header.s=default header.b=nWTEvPhv; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729896AbgHTM1A (ORCPT + 99 others); Thu, 20 Aug 2020 08:27:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:34260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730004AbgHTJwp (ORCPT ); Thu, 20 Aug 2020 05:52:45 -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 B77B22067C; Thu, 20 Aug 2020 09:52:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597917165; bh=Fs+JoK8/M8yAb9+zWAqCpaVCtCSJyL1vmeAN0FStg2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nWTEvPhvi78/fQ6ncuXJBCtTC6SAJXSD07mnZbVfnPWlR/MdWMfJS0ouSdezn3tLe BbnXHT9MDtQQESD1Lchuqre20pp87wJM28l9OxCdYT7eO3RkjRX70sm6m1oJUpWPtU abRT901QnR0bXWWqLIrUSQdMQijXrRPg6AIvrM3U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Sargun Dhillon , Jakub Kicinski , Christian Brauner , Kees Cook Subject: [PATCH 4.19 27/92] net/compat: Add missing sock updates for SCM_RIGHTS Date: Thu, 20 Aug 2020 11:21:12 +0200 Message-Id: <20200820091538.955608072@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091537.490965042@linuxfoundation.org> References: <20200820091537.490965042@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 From: Kees Cook commit d9539752d23283db4692384a634034f451261e29 upstream. Add missed sock updates to compat path via a new helper, which will be used more in coming patches. (The net/core/scm.c code is left as-is here to assist with -stable backports for the compat path.) Cc: Christoph Hellwig Cc: Sargun Dhillon Cc: Jakub Kicinski Cc: stable@vger.kernel.org Fixes: 48a87cc26c13 ("net: netprio: fd passed in SCM_RIGHTS datagram not set correctly") Fixes: d84295067fc7 ("net: net_cls: fd passed in SCM_RIGHTS datagram not set correctly") Acked-by: Christian Brauner Signed-off-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- include/net/sock.h | 4 ++++ net/compat.c | 1 + net/core/sock.c | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+) --- a/include/net/sock.h +++ b/include/net/sock.h @@ -845,6 +845,8 @@ static inline int sk_memalloc_socks(void { return static_branch_unlikely(&memalloc_socks_key); } + +void __receive_sock(struct file *file); #else static inline int sk_memalloc_socks(void) @@ -852,6 +854,8 @@ static inline int sk_memalloc_socks(void return 0; } +static inline void __receive_sock(struct file *file) +{ } #endif static inline gfp_t sk_gfp_mask(const struct sock *sk, gfp_t gfp_mask) --- a/net/compat.c +++ b/net/compat.c @@ -289,6 +289,7 @@ void scm_detach_fds_compat(struct msghdr break; } /* Bump the usage count and install the file. */ + __receive_sock(fp[i]); fd_install(new_fd, get_file(fp[i])); } --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2636,6 +2636,27 @@ int sock_no_mmap(struct file *file, stru } EXPORT_SYMBOL(sock_no_mmap); +/* + * When a file is received (via SCM_RIGHTS, etc), we must bump the + * various sock-based usage counts. + */ +void __receive_sock(struct file *file) +{ + struct socket *sock; + int error; + + /* + * The resulting value of "error" is ignored here since we only + * need to take action when the file is a socket and testing + * "sock" for NULL is sufficient. + */ + sock = sock_from_file(file, &error); + if (sock) { + sock_update_netprioidx(&sock->sk->sk_cgrp_data); + sock_update_classid(&sock->sk->sk_cgrp_data); + } +} + ssize_t sock_no_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags) { ssize_t res;