Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1254998pxa; Thu, 20 Aug 2020 06:53:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcldJiv4YARa0dR41glgeli9udYSw5IZFMvkUFmQsT8xxG5wi2ENT+fgyDiG1TKy12AP5N X-Received: by 2002:aa7:c0d3:: with SMTP id j19mr2902095edp.157.1597931593536; Thu, 20 Aug 2020 06:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597931593; cv=none; d=google.com; s=arc-20160816; b=06I6jT1MUNtYI54zQ3s7i3R5Bvf1eWqyorBKkXyiCqvqrA1CL+GdrYG4DVDnBXnPly h2aD9zZJJX8U2lj3HQzmYREUZrGuS45OF0fZsZxQNM0tunevTJTgxOOfBt33kxtsS3JF wUzdHQ9H29TMRMjsJ324SLvLAEsk5V9k3WzS3q5NsYC1/lSOAYcI0zo+R7OJMW00IhjX 4lQFH2qqbqtA7yVUeBQWFuXyyaF3uieenXtNUAhRa+n3w7mhmVYvwzzmM8xfjFT2DPWC QUzmTN/NZyXOi7zYiXnSJteMcvqtJYefhsqD+KjvLPxqMM6i3oQ5nyLo8C04OkLZZW9g xFjw== 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=nW+cE225GQjI+XAtONdxK6A3KD/kemmBXxT4vRRn/XQ=; b=aiGCcL4wAD7WnFTmXhzX2zlhX8MSjZju0io59slAwx9F++X4h4mTACjtW77gmvFcRX YqvxJ6slKj9wTHBoR941akfm2vJgjms8EA2BYWTH3+GDTi4F6HnQ4nuX7uOSTGxSCGzL XyYCH8KwlIh5u1PYv1Lzi1Ay3Wq8xOWXeMmXHrUihLOnMiopOdGCxSJBDOEcVsDImXpN i12xFdQfDbyKL2t82TOb4DZXZB13kxg7s11QSQhVX/17XGbmWGkR2Cnz/3/KB4tP2H1C 9GYhaJxddurS7CgpZ4Z4mFYeKO3bEp7eRVQ5JJC9KU4+eXwm/c++z6GTvrXMofp4CgIi XWmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FWkWSYqS; 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 yc19si1208675ejb.710.2020.08.20.06.52.49; Thu, 20 Aug 2020 06:53:13 -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=FWkWSYqS; 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 S1727863AbgHTNtb (ORCPT + 99 others); Thu, 20 Aug 2020 09:49:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:35816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728000AbgHTJ1h (ORCPT ); Thu, 20 Aug 2020 05:27:37 -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 3BE8422CE3; Thu, 20 Aug 2020 09:27:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915656; bh=Yk52xVjzl3lAymU1zsn6uxuxbvhhei1pzaYt+K+ZPc8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FWkWSYqSznKvZoQRr9f1Xiq/qZN3Et5oaQvXM4gmGGPRaIZ322M7C0/f2rQGFUWMP oV4+qUrv4CDjMZYcYl6v/MCO9Odv0s3cUTgjJ6AcEU6YyMr9trwKs3aookWE274ytL w/CA2YKLFdnq0FEGpxKWnMWKR4GSPg3dNDMpQK9A= 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 5.8 062/232] net/compat: Add missing sock updates for SCM_RIGHTS Date: Thu, 20 Aug 2020 11:18:33 +0200 Message-Id: <20200820091615.798111470@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@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 @@ -891,6 +891,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) @@ -898,6 +900,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 @@ -309,6 +309,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 @@ -2842,6 +2842,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;