Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp14466423pxu; Tue, 5 Jan 2021 02:15:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJw65ayOlIGHp6BuOok4r1OjwVZdVMazRjhTL/25hzDaQ5Th79hKLrMY+Y/wI+H5APIoqc1+ X-Received: by 2002:a05:6402:1383:: with SMTP id b3mr73638450edv.100.1609841723868; Tue, 05 Jan 2021 02:15:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609841723; cv=none; d=google.com; s=arc-20160816; b=UWelEUVBXIUOJfteOYKpsSe+9uHNjLNgzeYAZhBlKoAzc9xDHv5frTUydbF+kPQwFw 0BcFLG8N1osiVn7dx/gLwyo9aNpUflcSWgkdMypvpNzX/czbrGwj9Lkn8PkYT6ruDzLg 9g34v5x4YlMRJqJywwPqQ2PkHvc8C+dcJSxfa2X7u9tKX9RBi34VYqI1E/b7V7AgFB+7 W0SO2zvhLAoPFHPhnpBV5YWztP0DM+p1AlKM0LN7gcE2riK7V3wDU+KQg/S3FPvfQpST D3U5qLrix150VyGLvDZAeVmh+R728yYNSsWz+eussCW3GFsN6Tf+gHVhSbnmsNxwlExJ jrRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=PNFOPR4/kpgTbmUASEbxRMKXikcpxs+NfIWPhzi7LtU=; b=w712wMjuguiMb6fYoNr5mtlz/FExqBAMGGogoySK9xJUR0hrS3z2PQOq/RcNDJI1Bt aVq56rYcCBPqrsHfoImXMI0IpIpTV7f2RTpsf8QBBuAU6BPreybsn+dtJJExAcALn9M/ mj/T7BE8GjrDjnnj5o5ZHjNUNk8Qm4rK9OeW6L+bQF8QaBkCTOUfYa0bg4A75z71iXFk AnOfgDC8nUdatanrmO8e6x5iXELT1tjxDMaWlUnrcA/fS1QYFIKy3qNiZT6el37F4l1s xfWGFmtQnj9R+Sf0uNoy6TxWFnTwM5BI4m5sBPNAOmWFzkcntKd0iwidN1S1HvPFzEXA ctug== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k18si33450155eds.42.2021.01.05.02.15.01; Tue, 05 Jan 2021 02:15:23 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728717AbhAEKL6 (ORCPT + 99 others); Tue, 5 Jan 2021 05:11:58 -0500 Received: from www262.sakura.ne.jp ([202.181.97.72]:55376 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728357AbhAEKL5 (ORCPT ); Tue, 5 Jan 2021 05:11:57 -0500 Received: from fsav110.sakura.ne.jp (fsav110.sakura.ne.jp [27.133.134.237]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 105AB3Yg011941; Tue, 5 Jan 2021 19:11:03 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav110.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav110.sakura.ne.jp); Tue, 05 Jan 2021 19:11:03 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav110.sakura.ne.jp) Received: from [192.168.1.9] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 105AB37V011938 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Tue, 5 Jan 2021 19:11:03 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Subject: Re: Does uaccess_kernel() work for detecting kernel thread? To: Christoph Hellwig Cc: Al Viro , "Eric W. Biederman" , Jens Axboe , Kees Cook , LKML References: <0bcc0c63-31a3-26fd-bccb-b28af0375c34@i-love.sakura.ne.jp> <20201223075307.GA4185@lst.de> <239a6775-c514-e752-2520-16668b8bc344@i-love.sakura.ne.jp> <20210105075946.GC30414@lst.de> From: Tetsuo Handa Message-ID: <3f6d88e6-6c0f-c954-25b0-df97263ca4bc@i-love.sakura.ne.jp> Date: Tue, 5 Jan 2021 19:11:03 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210105075946.GC30414@lst.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/01/05 16:59, Christoph Hellwig wrote: > On Wed, Dec 23, 2020 at 07:11:38PM +0900, Tetsuo Handa wrote: >> due to commit 5e6e9852d6f76e01 ("uaccess: add infrastructure for kernel >> builds with set_fs()") and follow up changes. Don't we need to change this >> "uaccess_kernel()" with "(current->flags & PF_KTHREAD)" ? > > No. The real problem here is that when a this funtion is called Called by "who" ? Called by "a userspace process" ? Called by "a kernel thread" ? Called by "an io_uring service thread" ? > under > set_fs it allows kernel memory access for all user pointers, and due to > the indirection in the playload allows reading or changing kernel > memory. A kthread does not have that issue. If this uaccess_kernel() is intended to reject calling this function from "a userspace process", uaccess_kernel() is failing to reject because uaccess_kernel() is always "false" for x86. If this uaccess_kernel() is intended to reject calling this function from "a kernel thread", uaccess_kernel() is failing to reject because uaccess_kernel() is always "false" for x86. If this uaccess_kernel() is intended to reject calling this function from "an io_uring service thread", uaccess_kernel() is failing to reject because uaccess_kernel() is always "false" for x86. What does uaccess_kernel() in sg_check_file_access() (and uhid_char_write(), ib_safe_file_access(), bpfilter_process_sockopt() etc.) want to check? > >>>> For another example, if uaccess_kernel() is "false" due to CONFIG_SET_FS=n, >>>> isn't TOMOYO unexpectedly checking permissions for socket operations? >>> >>> Can someone explain WTF TOMOYO is even doing there? A security module >>> has absolutely no business checking what context it is called from, but >>> must check the process credentials instead. >>> >> >> TOMOYO distinguishes userspace processes and kernel threads, and grants >> kernel threads implicit permissions to perform socket operations. > > And this is the problem we need to fix. A kernel thread can't just have > implicit permissions only because it is a kernel thread. Think of e.g. > the io_uring service threads. We can use (current->flags & (PF_KTHREAD | PF_IO_WORKER)) == PF_KTHREAD like https://lkml.kernel.org/r/dacfb329-de66-d0cf-dcf9-f030ea1370de@schaufler-ca.com does in order to exclude e.g. the io_uring service threads, can't we?