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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38406C433EF for ; Fri, 8 Apr 2022 03:35:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BACA86B0071; Thu, 7 Apr 2022 23:35:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5BAC6B0072; Thu, 7 Apr 2022 23:35:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A23476B0074; Thu, 7 Apr 2022 23:35:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 90D236B0071 for ; Thu, 7 Apr 2022 23:35:06 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 748E620C4F for ; Fri, 8 Apr 2022 03:35:06 +0000 (UTC) X-FDA: 79332295812.01.FC87E7F Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf05.hostedemail.com (Postfix) with ESMTP id D99E6100005 for ; Fri, 8 Apr 2022 03:35:05 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id be5so825234plb.13 for ; Thu, 07 Apr 2022 20:35:05 -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=c5Z2BjAgFDB5ffwCfSBrzazo1i97nTuEbiqPvTikdzI=; b=QPooFwjpoVXbBo/yF32DprJzh2jp8GfVrl5P9+XT9kwTzYYENmJk4xw0GGFBLWj/Iq GMhv/UezKT4E2kmvUMBZ4s/gc5wmri/JW6SUyt7euSt6rL7PjvTNoV+CBCKgYPmo4lxL 2X59eAzIg2u3BRkGPGEQ+PR9JbFlCxYZ3dboI= 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=c5Z2BjAgFDB5ffwCfSBrzazo1i97nTuEbiqPvTikdzI=; b=pHlT2CF3ZlccZqnRVw4gjqu4mcuSpbCHtrnU4Ud4smR3KJiwur0SpvSw2icL4BWK3W IjtGOVh4rOPw4YBnnHXoFaKwF1gsyIFnQAnrf/4f7sjiJFeIhQd7CJN+yftJWuUvgVy3 p9abI+p4LEV70cNlgpRg3nqFuxH8LwBimHUWcIoEnVIpHi31N2LsCBber+pP/qVLELlE XIlF8WvmOGj5Q8eluYoJ36vpC+YrJK8PNHxLLOOCmfhVPv0c0u+d0EVzgzqOF2R7L/lD LYKWhz8medNtFJJpSK/hqMEvrtjj0CCXDLIfD4YFXon3nXEUiv21ImbXsc8mlHbD7iP7 aPvA== X-Gm-Message-State: AOAM531LUr6/UQpvBTqJ5ZfnISgAAUrzfJoQzB9+6mzhnckewxV10bMB BgLUslwmYOEdZjk20fXlZ1vb2w== X-Google-Smtp-Source: ABdhPJziwzJ1ICU9SwuFvDJ7vjL/gv5LeD8177ZammEm6ZOExt3vp3NvbLGxStbnXY0bF3kA1O1j3A== X-Received: by 2002:a17:90b:4a06:b0:1c7:2020:b5b9 with SMTP id kk6-20020a17090b4a0600b001c72020b5b9mr19354192pjb.58.1649388904769; Thu, 07 Apr 2022 20:35:04 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id c8-20020a17090a558800b001ca81981f51sm10266434pji.44.2022.04.07.20.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 20:35:04 -0700 (PDT) Date: Thu, 7 Apr 2022 20:35:03 -0700 From: Kees Cook To: Dan Williams Cc: Greg KH , Arnd Bergmann , Ingo Molnar , Matthew Wilcox , Russell King , Andrew Morton , Linux Kernel Mailing List , Linux MM Subject: Re: [PATCH v4] /dev/mem: Revoke mappings when a driver claims the region Message-ID: <202204072030.43D5BFDB@keescook> References: <159009507306.847224.8502634072429766747.stgit@dwillia2-desk3.amr.corp.intel.com> <202005211950.D56130B81@keescook> <202204061243.FB134CA4B1@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D99E6100005 X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=QPooFwjp; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf05.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.175 as permitted sender) smtp.mailfrom=keescook@chromium.org X-Stat-Signature: sfiyojtstzf5eqe19hw9ug53ge8tx3zk X-HE-Tag: 1649388905-408226 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Apr 07, 2022 at 04:43:10PM -0700, Dan Williams wrote: > On Thu, Apr 7, 2022 at 11:47 AM Dan Williams wrote: > > > > On Wed, Apr 6, 2022 at 12:46 PM Kees Cook wrote: > > > > > > *thread necromancy* > > > > It's alive! > > > > > > > > Hi Dan, > > > > > > I'm doing a KSPP bug scrub and am reviewing > > > https://github.com/KSPP/linux/issues/74 again. > > > > > > Do you have a chance to look at this? I'd love a way to make mmap() > > > behave the same way as read() for the first meg of /dev/mem. > > > > You want 0-reads or SIGBUS when attempting to access the first 1MB? > > > > Because it sounds like what you want is instead of loudly failing with > > -EPERM in drivers/char/mem.c::mmap_mem() you want it to silently > > succeed but swap in the zero page, right? Otherwise if it's SIGBUS > > then IO_STRICT_DEVMEM=y + marking that span as IORESOURCE_BUSY will > > "Do the Right Thing (TM).". > > In other words, if IO_STRICT_DEVMEM is enabled then the enforcement is > already there at least for anything marked IORESOURCE_BUSY. So if > tools are ok with that protection today, maybe there is no need to do > the zero page dance. I.e. legacy tools the read(2) /dev/mem below 1MB > get zeroes, and apparently no tools were mmap'ing below 1MB otherwise > they would have complained by now? At least Fedora is shipping > IO_STRICT_DEVMEM these days: > > https://src.fedoraproject.org/rpms/kernel/blob/rawhide/f/kernel-x86_64-fedora.config#_2799 When I try to mmap a RAM area <1MiB, mmap succeeds (range_is_allowed() is non-zero), so I don't think IO_STRICT_DEVMEM would trip anything using mmap on /dev/mem there. I am only reading 0s from there, though, but I don't see what's all happening. I thought maybe it was just literally unused, but even with CONFIG_PAGE_POISONING=y booted with page_poison=1, I still read 0s (not 0xaa), but I'd like to understand _why_ (i.e. I can't tell if it is accidentally safe, intentionally safe, or my test is bad.) For example: # cat /proc/iomem 00000000-00000fff : Reserved 00001000-0009fbff : System RAM 0009fc00-0009ffff : Reserved 000a0000-000bffff : PCI Bus 0000:00 000c0000-000c99ff : Video ROM ... If I mmap page 0, it's rejected (non-RAM). If I mmap page 1, it works, but it's all 0s. (Which is what I'd like, but I don't see where this is happening.) Hmmm. -- Kees Cook