Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17926489ybl; Thu, 2 Jan 2020 14:58:31 -0800 (PST) X-Google-Smtp-Source: APXvYqx7XRxWMHzmebH262APGXc0CgkqMOG4zeKUy9wkspNNP/0yx9jC6kczMNgDsGQt6p9QAhqc X-Received: by 2002:a9d:7519:: with SMTP id r25mr84808018otk.284.1578005909854; Thu, 02 Jan 2020 14:58:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578005909; cv=none; d=google.com; s=arc-20160816; b=O7BYszvD1bZ98ZDyiR7kKakNQJSaYjv2K7TAeZI5UYNOelcAAE35EwfOyLjTX4m41J dH/qL/VMTTXvmN2wb6bDpogR8sgIhR9oeJaciNiOiykAjY8l3IalKgZDQxPPZA//DJ/U dOIMgleCQa9OfyU3rlI7InLED+bN6Kd5S8hcZqrgsPLElv6j2L75+72ATAJUq2/RZEFe gSkSw3/VNFhzT2+gUYYZTzRRknwFAQ30uq9c4HXVUYNkzf2OlBDGJ3MxqKU70+55srkW /ln4T7uSG6vCgqErmLrtntWM0z4usuZ7kkxelPqowFIKGQEkrQRPEcGVqgq8jzPEbZSp FYvA== 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=qIOn3HDbBbgdKarwrB4gKu+a3GNRi3BoJ2X0olTwZZY=; b=zhG3lWNOJel8Qa2yrn3Ix2RBw5NptbBqm5g+VuMZF6rEQ2kfWczEku/pkVS5n1mbWu vEuKBM40lBtljt9Mw3W14a/CmT2K/AyVhbTeP1yHPgZS3MB0LaVbk3DoGpra3YAHuQaP eaMsbpLqgvlZfzDa2BANbf8aah3EVzkw1rWFVttahsniDa2Ur4aPGJH3PqeokuVJWWu+ mi+XaBagoymYHX/FcwMlM+2fDCGxuGy8qtAYX1oaGXIUNLlkD1tZJYZn4yGTJHS6xcJw v4XuVyeX9ISX7cG4pc3bRauNouucoPLxtAfOUHlCYkbpIBN+Ii5Ls6knHxju7HePMBrR BqVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gsxLaqif; 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 l26si28334315oti.152.2020.01.02.14.58.17; Thu, 02 Jan 2020 14:58:29 -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; dkim=pass header.i=@kernel.org header.s=default header.b=gsxLaqif; 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 S1728343AbgABWRW (ORCPT + 99 others); Thu, 2 Jan 2020 17:17:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:59700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726781AbgABWRS (ORCPT ); Thu, 2 Jan 2020 17:17:18 -0500 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 4CBCF227BF; Thu, 2 Jan 2020 22:17:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003437; bh=vGEiSPzPvuEHzZI+F9IqVYZ3YL+4aIjczUHdbVUGx8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gsxLaqif0RXDmT0zzCDGZbaLch1dkaPMDkrwAfZpcmpiuAcMznMoRlxhbnVltqDda ALIRhQ9d7fM23GEKl5ltZtm6LI9CWESOl56aEaYUbwmfSbdIGmyxJyKd/MLBm3nrdQ pYEB9dzQ5/o9g3CqrnA58CG4c8UNJP1a6o+YQjvc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tetsuo Handa , syzbot , James Morris Subject: [PATCH 5.4 143/191] tomoyo: Dont use nifty names on sockets. Date: Thu, 2 Jan 2020 23:07:05 +0100 Message-Id: <20200102215844.863867281@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102215829.911231638@linuxfoundation.org> References: <20200102215829.911231638@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: Tetsuo Handa commit 6f7c41374b62fd80bbd8aae3536c43688c54d95e upstream. syzbot is reporting that use of SOCKET_I()->sk from open() can result in use after free problem [1], for socket's inode is still reachable via /proc/pid/fd/n despite destruction of SOCKET_I()->sk already completed. At first I thought that this race condition applies to only open/getattr permission checks. But James Morris has pointed out that there are more permission checks where this race condition applies to. Thus, get rid of tomoyo_get_socket_name() instead of conditionally bypassing permission checks on sockets. As a side effect of this patch, "socket:[family=\$:type=\$:protocol=\$]" in the policy files has to be rewritten to "socket:[\$]". [1] https://syzkaller.appspot.com/bug?id=73d590010454403d55164cca23bd0565b1eb3b74 Signed-off-by: Tetsuo Handa Reported-by: syzbot Reported-by: James Morris Signed-off-by: Greg Kroah-Hartman --- security/tomoyo/realpath.c | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) --- a/security/tomoyo/realpath.c +++ b/security/tomoyo/realpath.c @@ -218,31 +218,6 @@ out: } /** - * tomoyo_get_socket_name - Get the name of a socket. - * - * @path: Pointer to "struct path". - * @buffer: Pointer to buffer to return value in. - * @buflen: Sizeof @buffer. - * - * Returns the buffer. - */ -static char *tomoyo_get_socket_name(const struct path *path, char * const buffer, - const int buflen) -{ - struct inode *inode = d_backing_inode(path->dentry); - struct socket *sock = inode ? SOCKET_I(inode) : NULL; - struct sock *sk = sock ? sock->sk : NULL; - - if (sk) { - snprintf(buffer, buflen, "socket:[family=%u:type=%u:protocol=%u]", - sk->sk_family, sk->sk_type, sk->sk_protocol); - } else { - snprintf(buffer, buflen, "socket:[unknown]"); - } - return buffer; -} - -/** * tomoyo_realpath_from_path - Returns realpath(3) of the given pathname but ignores chroot'ed root. * * @path: Pointer to "struct path". @@ -279,12 +254,7 @@ char *tomoyo_realpath_from_path(const st break; /* To make sure that pos is '\0' terminated. */ buf[buf_len - 1] = '\0'; - /* Get better name for socket. */ - if (sb->s_magic == SOCKFS_MAGIC) { - pos = tomoyo_get_socket_name(path, buf, buf_len - 1); - goto encode; - } - /* For "pipe:[\$]". */ + /* For "pipe:[\$]" and "socket:[\$]". */ if (dentry->d_op && dentry->d_op->d_dname) { pos = dentry->d_op->d_dname(dentry, buf, buf_len - 1); goto encode;