Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp5128347imd; Tue, 30 Oct 2018 12:24:05 -0700 (PDT) X-Google-Smtp-Source: AJdET5dGrXBewfk4bw7vsQh8IbW6beQx/8+u1RUTJ/hbtT2ip2ay4kPIZSiwwOImCq8h54ELACki X-Received: by 2002:a63:e841:: with SMTP id a1-v6mr34501pgk.4.1540927445741; Tue, 30 Oct 2018 12:24:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540927445; cv=none; d=google.com; s=arc-20160816; b=aPSgeTubs6wW039Klm2FUQZYiGpgp6gPmhkKYSivQO/q4KVk1REBw2i1jQCuiSOBC1 vXTIzzteUTFQBoHYpKz70AaeMSxlvHmtav7+g5HmPtZAaJb6AO1s9NXUmUECW7YtVMne U8Ozaqn8KLycXP11B8tfbAfQMWddd/lhZhghNOc0UQHbJtYoySGRwWmhVdqdDqSPTCd3 gInHsqXb8/+KsK/OY579nC9YD3pEx19RDqfIVfwTcZ8MNjTtJo2VkUMeHavFrr4HXnyc frcmkK3tvA+EK7RMLAe2QH8A1a1zwDLrZ7XPCh1jhPbJE+9t77oo02ihV/Bq82bkdcMb FJDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=snsTm8fAPGUfSdsnB6UIfUoFWMS1wWtbb4pqgSay4sA=; b=amM/gP+eya7DvKoIEzMpDF+PC+yUNvpiL/pFawp7vJ0Qs3vb7fT8ZpbHxz0B/on4uy JDVCzUdZ19qgsE/QZO22XK9mq4m5o/sVjFUu0ItIq4gIAsDDbihpLhiAuxnpIKq+Gebi 0GozMYIidWS+K/o1iPSnWLk5AwVvyoBSSvyr0+lBLQ1cBn95YwXuqj3/P4+MBXdRrpcS zq6BxAExTWp7jS4X9yc98eBLeTHGrGsHujRXrUxwa2iFd+1+s+ATOIi4DOMOTeN4lK9S PfCECJ4aueWR55gflpLKlRjd09rVu/nbbDSkxxcjcARS6PiZhReXENokgwTRFm8iribj FpwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=js+vjHyi; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i12-v6si24030683plt.9.2018.10.30.12.23.50; Tue, 30 Oct 2018 12:24:05 -0700 (PDT) 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=@chromium.org header.s=google header.b=js+vjHyi; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726392AbeJaEJl (ORCPT + 99 others); Wed, 31 Oct 2018 00:09:41 -0400 Received: from mail-yb1-f195.google.com ([209.85.219.195]:33213 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726287AbeJaEJk (ORCPT ); Wed, 31 Oct 2018 00:09:40 -0400 Received: by mail-yb1-f195.google.com with SMTP id i78-v6so5541788ybg.0 for ; Tue, 30 Oct 2018 12:14:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=snsTm8fAPGUfSdsnB6UIfUoFWMS1wWtbb4pqgSay4sA=; b=js+vjHyiVy7gKOcR4aV8aB6qbFEHm1tQBHbY/tnoGr1sJ0IsCxOkyAi588iqVgxxTD TmOGu3y1E6hYb+duMhWiN6w6UUykrHTIDJoGIUwZJUO/JjkT8puHgjty3vDuJLXFlBqB K/j7WHf8RIxqYMxXPYrBZLJd7iQ6TARKKl9ek= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=snsTm8fAPGUfSdsnB6UIfUoFWMS1wWtbb4pqgSay4sA=; b=OgpB5QokcpB1F0u5XTpFPyjbq+0ShulKbVctuKHk0JLHAwiBwZSbnFs2UtC0hZcbBp U6YOTGzbvG9FJUuk2rGk61zOsF0f4lzxwUC+mK6XdCN5YZhH+rP3oFHjp76+TDDCrAs8 Knkm4MNthh0l6YpqxTtO69GTAFEb5qONNMpxu1PiJAJ9v8BQXCxt+BiHGkk5du8kiAFL lyTV9j3/76lSJuKqVR08SODKJ+wNRxStDh1AfXbFlCglWkiU2IW6mp/nJIpeeouE1EGV ntgvLIAkz+Z+FpMefJNZPtrVifVbcPbTTt3bRrkSVufDCst6edd8XfwEOckz/XWyEgYS kEaw== X-Gm-Message-State: AGRZ1gIfdbv2vtMdOp22Eyfmnq4H12dcVMVrgcv3uBP0cia2jyVFc7tr VE1CFZu04wGPMDOeh1Dn+8srPYtckkc= X-Received: by 2002:a25:7e01:: with SMTP id z1-v6mr142223ybc.91.1540926895861; Tue, 30 Oct 2018 12:14:55 -0700 (PDT) Received: from mail-yw1-f53.google.com (mail-yw1-f53.google.com. [209.85.161.53]) by smtp.gmail.com with ESMTPSA id y126-v6sm5944426ywe.26.2018.10.30.12.14.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Oct 2018 12:14:54 -0700 (PDT) Received: by mail-yw1-f53.google.com with SMTP id j75-v6so5401502ywj.10 for ; Tue, 30 Oct 2018 12:14:52 -0700 (PDT) X-Received: by 2002:a81:98cb:: with SMTP id p194-v6mr3973873ywg.353.1540926891605; Tue, 30 Oct 2018 12:14:51 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:3990:0:0:0:0:0 with HTTP; Tue, 30 Oct 2018 12:14:50 -0700 (PDT) In-Reply-To: <28C8CD2A-BDC0-49A5-854E-1E18968528B8@amacapital.net> References: <20181023213504.28905-1-igor.stoppa@huawei.com> <20181023213504.28905-11-igor.stoppa@huawei.com> <20181026092609.GB3159@worktop.c.hoisthospitality.com> <20181028183126.GB744@hirez.programming.kicks-ass.net> <40cd77ce-f234-3213-f3cb-0c3137c5e201@gmail.com> <20181030152641.GE8177@hirez.programming.kicks-ass.net> <0A7AFB50-9ADE-4E12-B541-EC7839223B65@amacapital.net> <20181030175814.GB10491@bombadil.infradead.org> <28C8CD2A-BDC0-49A5-854E-1E18968528B8@amacapital.net> From: Kees Cook Date: Tue, 30 Oct 2018 12:14:50 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 10/17] prmem: documentation To: Andy Lutomirski Cc: Matthew Wilcox , Nadav Amit , Peter Zijlstra , Igor Stoppa , Mimi Zohar , Dave Chinner , James Morris , Michal Hocko , Kernel Hardening , linux-integrity , linux-security-module , Igor Stoppa , Dave Hansen , Jonathan Corbet , Laura Abbott , Randy Dunlap , Mike Rapoport , "open list:DOCUMENTATION" , LKML , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 30, 2018 at 11:51 AM, Andy Lutomirski wrote: > > >> On Oct 30, 2018, at 10:58 AM, Matthew Wilcox wrote: >> >> On Tue, Oct 30, 2018 at 10:06:51AM -0700, Andy Lutomirski wrote: >>>> On Oct 30, 2018, at 9:37 AM, Kees Cook wrote: >>> I support the addition of a rare-write mechanism to the upstream kernel. >>> And I think that there is only one sane way to implement it: using an >>> mm_struct. That mm_struct, just like any sane mm_struct, should only >>> differ from init_mm in that it has extra mappings in the *user* region. >> >> I'd like to understand this approach a little better. In a syscall path, >> we run with the user task's mm. What you're proposing is that when we >> want to modify rare data, we switch to rare_mm which contains a >> writable mapping to all the kernel data which is rare-write. >> >> So the API might look something like this: >> >> void *p = rare_alloc(...); /* writable pointer */ >> p->a = x; >> q = rare_protect(p); /* read-only pointer */ >> >> To subsequently modify q, >> >> p = rare_modify(q); >> q->a = y; >> rare_protect(p); > > How about: > > rare_write(&q->a, y); > > Or, for big writes: > > rare_write_copy(&q, local_q); > > This avoids a whole ton of issues. In practice, actually running with a special mm requires preemption disabled as well as some other stuff, which Nadav carefully dealt with. This is what I had before, yes: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=kspp/write-rarely&id=9ab0cb2618ebbc51f830ceaa06b7d2182fe1a52d It just needs the switch_mm() backend. -- Kees Cook