Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp650449yba; Fri, 26 Apr 2019 06:35:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqzms1iRPUBDgQxkn3IjBkpeRZUwg2r41D/XuXJDfLxxQn83yl3S4HY2cwZOq61nL2WjSDHt X-Received: by 2002:a17:902:302:: with SMTP id 2mr46543618pld.232.1556285701148; Fri, 26 Apr 2019 06:35:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556285701; cv=none; d=google.com; s=arc-20160816; b=FHEvgykEnhmTnEfm1oNwDWOQx0fRuQGvt0APVT5FygvWuEYqVGxIH96MvG06hpZaL+ nLPm0N1RneyDBZmhYUpW+S92UHSKqjev2udTSxHXOpFlRTG30wVS2mu01pnvQ0tOk51z ogvULfsawKf8EaFaKCiqCecxA0zt6j8wVkdQ105DaRM0qtgI3fJaA2wOAf/TpuY15m3J kOQkH8uf6fADXBf9QqMYQJBorYbZOxw1RLqzDy0mpIanj4pGFiUnC7gy2lFF0N15aEyb 0mgAvSfZyd+44aJJnvqk36K+GLgdWTmTPoJh9P0bXouL6Y61WYjNTsrqvH/J/dud67a6 oQGg== 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 :in-reply-to:references:mime-version:dkim-signature; bh=6tej5jESshTVv0aym01xqA2/I/b4wPINcqNXZwVn3us=; b=jyDiEp2xKpNRJQ7CRu60quMwQIrDKXva8qOhIb0QRUh2uADkvCSBLgasQ17etv3eUG WrEJtRgO4eUXsFnm8ajbQ15AYThPUo0rSDLPK2DoTA8WHI4a8W2sqCXkDI6qVNqnD6lt 4zZp3ttyzHbRD1OIj9O/bCKzmO48+Nld2yhoRV4zGZK9o3v1CUZ40jt3K2qny3J1ntF5 xn1ZBBhGq0wevH/wcVGE22MbI38AUV0JXNgLwpWfNanoKQUhTdIGy8iPaGRCTN3bNQqZ EFmfRL2RqMBa4nF3VyW4EwIdhf2OohNQyA4ymvVVahUk1/xJAfpc0VGhifPt6V2QeuMQ 1g4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="uQ/gZaik"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 23si10159017pfi.227.2019.04.26.06.34.45; Fri, 26 Apr 2019 06:35:01 -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=@google.com header.s=20161025 header.b="uQ/gZaik"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726168AbfDZNdx (ORCPT + 99 others); Fri, 26 Apr 2019 09:33:53 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:44077 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726039AbfDZNdw (ORCPT ); Fri, 26 Apr 2019 09:33:52 -0400 Received: by mail-ot1-f68.google.com with SMTP id d24so2602331otl.11 for ; Fri, 26 Apr 2019 06:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6tej5jESshTVv0aym01xqA2/I/b4wPINcqNXZwVn3us=; b=uQ/gZaikg/ajGneKizm6XgTmI0RD3bZasUlUCaqWvuv3O3tS8ZBfFwf33o0Asl/OOW seIqin7ynG3eEUvz0Znn9051GpjNVUvGNQ4mDDKShussZxDy9ruJPQOn6Wz7Fh/oNUCi xcgG6LhZ1nmD1xNwu1JVjfI7BasXG9tB9BEP2O508BRfjJwX12FOnK6RJt1sl003DSbA f562iu6AqopYyCpnmBjH17DUhjnRAcl76yE8X9WpHXz9aiZzr289L6lPKyiE2vuogHi9 klzE2XIKl+uBsNXlRksrkMYWQGfJ6Ptygkf6NRc5BXdhFsW8P4qLsAvn1JgZT4L0i/Co BC6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6tej5jESshTVv0aym01xqA2/I/b4wPINcqNXZwVn3us=; b=T/ng5PcwtzvOP3xyJSbWBcU11pRaj6TVYywlSqWf/PkAoCq6LxyZsWO1sbyhuy4OA+ 0zjEoG91S3l9yfX8MF0XNGv4So2Q/qPiydv/x3eFiG21j1SHpnEWEfZL5e7KDHtpBhXK zB+qZuFLgcbMW4CUiNrUSZgQNIuvTU+n5PFjgO3CQWmRDB7UAn3MIS46nwJ67kYdDja4 ctMqUC5nhHOINanCpSUORkb8F491iBKXRaMfRQBQrFWwJH3KylQXa7L4KPH5dWGI+Dzf 6vS9CMa2gbVj9oxRgw2YM5Lx+B7Ddy5YAT5oJTz06Bp7XfVb++nv+xMlMmuL6VmhwZUA V1Nw== X-Gm-Message-State: APjAAAWz0ABWIP0o47wFJHQN9C8r3DRt+8ylgO5CovslMBLvoSb13Ri8 KUtSHOPJsgnj/8zo4BsqqTFypasPYGCGhvUPsCRA4Q== X-Received: by 2002:a9d:7a54:: with SMTP id z20mr1752200otm.230.1556285631958; Fri, 26 Apr 2019 06:33:51 -0700 (PDT) MIME-Version: 1.0 References: <20190424211038.204001-1-matthewgarrett@google.com> <20190425121410.GC1144@dhcp22.suse.cz> <20190426053135.GC12337@dhcp22.suse.cz> In-Reply-To: <20190426053135.GC12337@dhcp22.suse.cz> From: Jann Horn Date: Fri, 26 Apr 2019 15:33:25 +0200 Message-ID: Subject: Re: [PATCH V2] mm: Allow userland to request that the kernel clear memory on release To: Michal Hocko Cc: Matthew Garrett , Linux-MM , kernel list , Matthew Garrett , Linux API 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 Fri, Apr 26, 2019 at 7:31 AM Michal Hocko wrote: > On Thu 25-04-19 14:42:52, Jann Horn wrote: > > On Thu, Apr 25, 2019 at 2:14 PM Michal Hocko wrote: > > [...] > > > On Wed 24-04-19 14:10:39, Matthew Garrett wrote: > > > > From: Matthew Garrett > > > > > > > > Applications that hold secrets and wish to avoid them leaking can use > > > > mlock() to prevent the page from being pushed out to swap and > > > > MADV_DONTDUMP to prevent it from being included in core dumps. Applications > > > > can also use atexit() handlers to overwrite secrets on application exit. > > > > However, if an attacker can reboot the system into another OS, they can > > > > dump the contents of RAM and extract secrets. We can avoid this by setting > > > > CONFIG_RESET_ATTACK_MITIGATION on UEFI systems in order to request that the > > > > firmware wipe the contents of RAM before booting another OS, but this means > > > > rebooting takes a *long* time - the expected behaviour is for a clean > > > > shutdown to remove the request after scrubbing secrets from RAM in order to > > > > avoid this. > > > > > > > > Unfortunately, if an application exits uncleanly, its secrets may still be > > > > present in RAM. This can't be easily fixed in userland (eg, if the OOM > > > > killer decides to kill a process holding secrets, we're not going to be able > > > > to avoid that), so this patch adds a new flag to madvise() to allow userland > > > > to request that the kernel clear the covered pages whenever the page > > > > reference count hits zero. Since vm_flags is already full on 32-bit, it > > > > will only work on 64-bit systems. > > [...] > > > > diff --git a/mm/madvise.c b/mm/madvise.c > > > > index 21a7881a2db4..989c2fde15cf 100644 > > > > --- a/mm/madvise.c > > > > +++ b/mm/madvise.c > > > > @@ -92,6 +92,22 @@ static long madvise_behavior(struct vm_area_struct *vma, > > > > case MADV_KEEPONFORK: > > > > new_flags &= ~VM_WIPEONFORK; > > > > break; > > > > + case MADV_WIPEONRELEASE: > > > > + /* MADV_WIPEONRELEASE is only supported on anonymous memory. */ > > > > + if (VM_WIPEONRELEASE == 0 || vma->vm_file || > > > > + vma->vm_flags & VM_SHARED) { > > > > + error = -EINVAL; > > > > + goto out; > > > > + } > > > > + new_flags |= VM_WIPEONRELEASE; > > > > + break; > > > > An interesting effect of this is that it will be possible to set this > > on a CoW anon VMA in a fork() child, and then the semantics in the > > parent will be subtly different - e.g. if the parent vmsplice()d a > > CoWed page into a pipe, then forked an unprivileged child, the child > > Maybe a stupid question. How do you fork an unprivileged child (without > exec)? Child would have to drop priviledges on its own, no? Sorry, yes, that's what I meant.