From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA702C433DF for ; Thu, 20 Aug 2020 12:27:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A40E220738 for ; Thu, 20 Aug 2020 12:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597926428; bh=Fs+JoK8/M8yAb9+zWAqCpaVCtCSJyL1vmeAN0FStg2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=t8xlm8XEAR/It6HMXzkP5095fY39KAvdPBoEKWHR5L4pkUisRZBNbNwxDCgb7KBy5 U7tCd41cs+xCQlPPEMV7jNrSZZZOtDwX9Wy5dWUmsWWoMduwi40F0TPwC9q2ZTNdEr IcBfvDMTS3HSj/bVWs/KvUptHFOTNpbMLXN0RLkU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729643AbgHTM1G (ORCPT ); Thu, 20 Aug 2020 08:27:06 -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;