Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp580313pxb; Wed, 22 Sep 2021 08:33:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYVL0Fdq9fwFJmHV9cg+unUyat4tPhhVua7kXW92nkl+Apk5sOx/xUBCSrdL3gwU+Wykv8 X-Received: by 2002:a50:f145:: with SMTP id z5mr268325edl.4.1632324793365; Wed, 22 Sep 2021 08:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632324793; cv=none; d=google.com; s=arc-20160816; b=1KehsQPjZKbushBBHDk05MVRzyRXrUVJ2JLUyxyebQEJlXhLTTbiSWo/nfR0K78sww RVfsMJjuGF1zGoA8WyO5CRaMNJ6QFmMSbYEfJjwzl8qRCNqWrPFXhVvp8SGnc1VsNZM0 gF1AlVFSUzCwtN9OUkQKvzXbiHbyvtAyIgreS6vwQTfni3Ym3Cw+o9lDmji/wHx9Drrq X/MuRwyiCDP1etaeOuoehWi6cYc867nxzKxM9l+1ZESLcgSXfbumnvz1ps4fpprmuE2J eZT1r+S/AW1yBNE6IoMvAET0YjWM7X7jofOSZeTBR4Ut6XkIFlbjWBVbDboJ4vUkol9O /k4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=uG8kbMDq3wWFr/zeapZnykzvzoN7SSQeT88JzB5wbWE=; b=K8Wfs98Ifd28pJNuWtTFhpbEwn+eltTGeNFkla8i8NwyN3gw1bZMDkpfyGlkobltUH zk+Ktq8T1CcgIRMl6H3BrEDUI1AMoFv3nd8hyArWdLatG2jlTCaH/caxVI0N1lEqsbtG u7wMlymAtlXk6f7ayeP9wD9nFm77aJkq1mC9UsPLZOeutB3hodd4P6bb6rhR7Gs+qYtv P5p2ukuYEq8T64LIP42moxjw0zknllymjKXdKyMsacaRteBUHf3DaGWrGIuuf9931l9B bWzzBIpQepgyJ86RVf2s/QZN4nhGDAzyZXjX1lyj6L36jgnAEznb2YCYQYCkCOL3Yaor yOrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PmZIAxL0; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e4si3176763ejs.733.2021.09.22.08.32.48; Wed, 22 Sep 2021 08:33: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=@chromium.org header.s=google header.b=PmZIAxL0; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236447AbhIVPcO (ORCPT + 99 others); Wed, 22 Sep 2021 11:32:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236443AbhIVPcN (ORCPT ); Wed, 22 Sep 2021 11:32:13 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C49CBC061756 for ; Wed, 22 Sep 2021 08:30:43 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id q23so3003195pfs.9 for ; Wed, 22 Sep 2021 08:30:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=uG8kbMDq3wWFr/zeapZnykzvzoN7SSQeT88JzB5wbWE=; b=PmZIAxL0qI0ZUjgkEKbm/alrr9/0KQGVptK74f5bXbBYVa7zokeLn8N3pGkUV55CfI DAGkFnpsgbZc2MGiCPciF6VSHahGpJCkzssEe0ITNqYGY5viUeYZaDEcpNNsKG7uJoF0 ZvfoUXuemAsGMxl15kJkc+y3OXSGOclJt5wXc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=uG8kbMDq3wWFr/zeapZnykzvzoN7SSQeT88JzB5wbWE=; b=IWJtNAq6LtGlII4+PU79qssmt4MAw0ba9lVyvUqYg1M9wGuvRQfrzCSyOcs/piw+UE bdQLzV3Az5AJBVpjqTkgSrnzBKJLAiGB1vpR+/VkPnFmmoywmR5NkbaRAhJuIEkq5Ewm 8qSt+3glwGrJo0ijRdeg8uuAZ+8j1zRhTrOgSqjyVnSkyqMOndMkL6sJ+5W4hdeo49K3 z8elOpJIRBMAWMm6QeO3oqwxvqa1hcy2Uw1Ob98roRG6NduweKRuNcjFRkT7NRTFR74Y blphgsV3voQE0NdQSSHyWguRT/j2xbbd1ASg2OVL5j3A8thvxj9vG+evbiRZpdeDpuMp 7AQw== X-Gm-Message-State: AOAM533MknsZofbKCRLkPP6R/ktK83BQI+t4rAYUagb6hdr12buShlDk tevdPShBuVR/KBtDc0H09EBAcw== X-Received: by 2002:a63:480b:: with SMTP id v11mr183763pga.413.1632324643268; Wed, 22 Sep 2021 08:30:43 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id k29sm2941045pfp.200.2021.09.22.08.30.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 08:30:41 -0700 (PDT) Date: Wed, 22 Sep 2021 08:30:40 -0700 From: Kees Cook To: "Eric W. Biederman" , Peter Collingbourne Cc: Jann Horn , Catalin Marinas , Will Deacon , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Thomas Gleixner , Andy Lutomirski , Andrew Morton , Masahiro Yamada , Sami Tolvanen , YiFei Zhu , Colin Ian King , Mark Rutland , Frederic Weisbecker , Viresh Kumar , Andrey Konovalov , Gabriel Krisman Bertazi , Balbir Singh , Chris Hyser , Daniel Vetter , Chris Wilson , Arnd Bergmann , Dmitry Vyukov , Christian Brauner , Alexey Gladkov , Ran Xiaokai , David Hildenbrand , Xiaofeng Cao , Cyrill Gorcunov , Thomas Cedeno , Marco Elver , Alexander Potapenko , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Evgenii Stepanov Subject: Re: [PATCH] kernel: introduce prctl(PR_LOG_UACCESS) Message-ID: <202109220755.B0CFED9F5@keescook> References: <20210922061809.736124-1-pcc@google.com> <87k0j8zo35.fsf@disp2133> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87k0j8zo35.fsf@disp2133> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 22, 2021 at 09:23:10AM -0500, Eric W. Biederman wrote: > Peter Collingbourne writes: > > > This patch introduces a kernel feature known as uaccess logging. > > With uaccess logging, the userspace program passes the address and size > > of a so-called uaccess buffer to the kernel via a prctl(). The prctl() > > is a request for the kernel to log any uaccesses made during the next > > syscall to the uaccess buffer. When the next syscall returns, the address > > one past the end of the logged uaccess buffer entries is written to the > > location specified by the third argument to the prctl(). In this way, > > the userspace program may enumerate the uaccesses logged to the access > > buffer to determine which accesses occurred. > > [...] > > 3) Kernel fuzzing. We may use the list of reported kernel accesses to > > guide a kernel fuzzing tool such as syzkaller (so that it knows which > > parts of user memory to fuzz), as an alternative to providing the tool > > with a list of syscalls and their uaccesses (which again thanks to > > (2) may not be accurate). > > How is logging the kernel's activity like this not a significant > information leak? How is this safe for unprivileged users? This does result in userspace being able to "watch" the kernel progress through a syscall. I'd say it's less dangerous than userfaultfd, but still worrisome. (And userfaultfd is normally disabled[1] for unprivileged users trying to interpose the kernel accessing user memory.) Regardless, this is a pretty useful tool for this kind of fuzzing. Perhaps the timing exposure could be mitigated by having the kernel collect the record in a separate kernel-allocated buffer and flush the results to userspace at syscall exit? (This would solve the copy_to_user() recursion issue too.) I'm pondering what else might be getting exposed by creating this level of probing... kernel addresses would already be getting rejected, so they wouldn't show up in the buffer. Hmm. Jann, any thoughts here? Some other thoughts: Instead of reimplementing copy_*_user() with a new wrapper that bypasses some checks and adds others and has to stay in sync, etc, how about just adding a "recursion" flag? Something like: copy_from_user(...) instrument_copy_from_user(...) uaccess_buffer_log_read(...) if (current->uaccess_buffer.writing) return; uaccess_buffer_log(...) current->uaccess_buffer.writing = true; copy_to_user(...) current->uaccess_buffer.writing = false; How about using this via seccomp instead of a per-syscall prctl? This would mean you would have very specific control over which syscalls should get the uaccess tracing, and wouldn't need to deal with the signal mask (I think). I would imagine something similar to SECCOMP_FILTER_FLAG_LOG, maybe SECCOMP_FILTER_FLAG_UACCESS_TRACE, and add a new top-level seccomp command, (like SECCOMP_GET_NOTIF_SIZES) maybe named SECCOMP_SET_UACCESS_TRACE_BUFFER. This would likely only make sense for SECCOMP_RET_TRACE or _TRAP if the program wants to collect the results after every syscall. And maybe this won't make any sense across exec (losing the mm that was used during SECCOMP_SET_UACCESS_TRACE_BUFFER). Hmmm. -Kees [1] https://git.kernel.org/linus/d0d4730ac2e404a5b0da9a87ef38c73e51cb1664 -- Kees Cook