Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp858155pxb; Fri, 3 Sep 2021 15:34:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZoe/dwDYYhDpk6WeefJeIkIRDF4EccXIZtZGITAwiDQsrmjS5tJbX/hIkC3q4ht8ssg27 X-Received: by 2002:a05:6402:3098:: with SMTP id de24mr1273907edb.326.1630708491850; Fri, 03 Sep 2021 15:34:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630708491; cv=none; d=google.com; s=arc-20160816; b=IGJXTxrwvDcFDTS41LOQvjttQyhhTM6NGYlYntmx9jUoWylf5eslxIOSHg0xPF95fY ROdm9IzWmv9aEi+l+mXxrK3UX82NXQPgDz5G0LnAVKkuUThb0wgDkNX2Y3ExUCobI+kZ ZxYzMEqKoL1OE9bjv7t08X+WM/J9C/6T3/KPKXQsorjziZEdKKQomCw1hNuDStsO5BST jw8M8Ytg7M/tJyY40+cT5pcFgmcUe/5X5alyjJq+/LRq1KnU4kut/jFmB1zxBaIwDYM1 j5DrcLJPepvtMLD287UGwJ4cqa39QjARJ1QChklga/1QdoM3MPBmRMHcjwY+V4quOfyS mV5Q== 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=BS6jWoL9pWSi0KXjHeej6vjUIclKhlV3mGFNGSvhg5w=; b=p56ekUono09m8yRs93eCCgsbuejdezAIpShurdMP8edZ7oSJTZAnjuxUKsY6yymBDP etAITMvxxcBbiL5VzdqjN3UEY280srRn5MEQep2hgN6wd1WiaGZn6W4nIl8/Tq6B+I7+ axu2mDb+q/dvWrrX2c4k/3l8oH3EGToucHzOuqQn+ZrhDmeEcJ7wO0Wi/GIOfOs0mny7 Oc1LKhLUqCrLDRIeMF6ON27/sCrBQLwoHXPnyFy7JJhe6vtR26NQrIiAGIbCJvGUKur0 Ug4ljxL/jo0FMRnfDJfSLTWZHfQ+etH3Gf3d2QXtKnDnykfvEIwDo1a0wiH8cKyGJjgw Iw0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lvAfLsLn; 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 v26si478055ejk.700.2021.09.03.15.34.16; Fri, 03 Sep 2021 15:34:51 -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=lvAfLsLn; 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 S1349369AbhICW3d (ORCPT + 99 others); Fri, 3 Sep 2021 18:29:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242831AbhICW3Z (ORCPT ); Fri, 3 Sep 2021 18:29:25 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6553C061757 for ; Fri, 3 Sep 2021 15:28:24 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id c6so502469pjv.1 for ; Fri, 03 Sep 2021 15:28:24 -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=BS6jWoL9pWSi0KXjHeej6vjUIclKhlV3mGFNGSvhg5w=; b=lvAfLsLnn/50KH5BhXOVM8yk6EQsU+CWCcB3ajHc68JoJFkEsFipc+RHheUz83Bfbt t+8Fh+FZC2ScHzSuqtnikr4XATusXLxd9ZaDi4YqJjYk9Vp/H1MwSsOXtB154B9cS2u5 gd4PrW561dBLiOjrX3i69lbR51p3vC5CyFNis= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=BS6jWoL9pWSi0KXjHeej6vjUIclKhlV3mGFNGSvhg5w=; b=Y38f93I+/5KI6JaOu8weDW95zt2nBNL1IdQvfISdlqyUma+3Jry36WZQdj14H0Sr/X VS1pZHK8ZbsQLcP6pXuRO072Q7/MbIQaDfw8knOX/UE2PRrK+HrQh8TXVfVpbI5GRwvb 47nNk/DG4F4MtqeX6COkOlr6nmBY/Acs/2qw3NYAeLvOwAPnB+L7lKeWzdaXDdwbelk9 msCtP6+sKSBNzGQw4+TmnWm5ZbPU3vP4kLEo9NEBZnb/bZIoo4hoWi7R04shaAxR9uS8 dW3bgDXKZJycAazR/l+/hj5YnY9JXqUd2ChzGTPTP0HtoMsrshdjpB9FUMrl9xqW1BOi rC1Q== X-Gm-Message-State: AOAM533ZgWR8/R54jlak92ih7XqkqWGv3Ciy5PyXFGu9A99x0J1XvfX1 i2Lm8xpl7rlCyYCdlkhkftoxwg== X-Received: by 2002:a17:90a:194a:: with SMTP id 10mr1071828pjh.221.1630708104224; Fri, 03 Sep 2021 15:28:24 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id j11sm359051pfa.10.2021.09.03.15.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 15:28:23 -0700 (PDT) Date: Fri, 3 Sep 2021 15:28:22 -0700 From: Kees Cook To: Suren Baghdasaryan Cc: Andrew Morton , Colin Cross , Sumit Semwal , Michal Hocko , Dave Hansen , Matthew Wilcox , "Kirill A . Shutemov" , Vlastimil Babka , Johannes Weiner , Jonathan Corbet , Al Viro , Randy Dunlap , Kalesh Singh , Peter Xu , rppt@kernel.org, Peter Zijlstra , Catalin Marinas , vincenzo.frascino@arm.com, Chinwen Chang =?utf-8?B?KOW8temMpuaWhyk=?= , Axel Rasmussen , Andrea Arcangeli , Jann Horn , apopple@nvidia.com, John Hubbard , Yu Zhao , Will Deacon , fenghua.yu@intel.com, thunder.leizhen@huawei.com, Hugh Dickins , feng.tang@intel.com, Jason Gunthorpe , Roman Gushchin , Thomas Gleixner , krisman@collabora.com, chris.hyser@oracle.com, Peter Collingbourne , "Eric W. Biederman" , Jens Axboe , legion@kernel.org, Rolf Eike Beer , Cyrill Gorcunov , Muchun Song , Viresh Kumar , Thomas Cedeno , sashal@kernel.org, cxfcosmos@gmail.com, Rasmus Villemoes , LKML , linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm , kernel-team Subject: Re: [PATCH v9 2/3] mm: add a field to store names for private anonymous memory Message-ID: <202109031522.ACDF5BA8@keescook> References: <20210902231813.3597709-1-surenb@google.com> <20210902231813.3597709-2-surenb@google.com> <202109031439.B58932AF0@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 03, 2021 at 02:56:21PM -0700, Suren Baghdasaryan wrote: > On Fri, Sep 3, 2021 at 2:47 PM Kees Cook wrote: > > > > (Sorry, a few more things jumped out at me when I looked again...) > > > > On Thu, Sep 02, 2021 at 04:18:12PM -0700, Suren Baghdasaryan wrote: > > > [...] > > > diff --git a/kernel/sys.c b/kernel/sys.c > > > index 72c7639e3c98..25118902a376 100644 > > > --- a/kernel/sys.c > > > +++ b/kernel/sys.c > > > @@ -2299,6 +2299,64 @@ int __weak arch_prctl_spec_ctrl_set(struct task_struct *t, unsigned long which, > > > > > > #define PR_IO_FLUSHER (PF_MEMALLOC_NOIO | PF_LOCAL_THROTTLE) > > > > > > +#ifdef CONFIG_MMU > > > + > > > +#define ANON_VMA_NAME_MAX_LEN 256 > > > + > > > +static inline bool is_valid_name_char(char ch) > > > +{ > > > + /* printable ascii characters, except [ \ ] */ > > > + return (ch > 0x1f && ch < 0x5b) || (ch > 0x5d && ch < 0x7f); > > > +} > > > > In the back of my mind, I feel like disallowing backtick would be nice, > > but then if $, (, and ) are allowed, it doesn't matter, and that seems > > too limiting. :) > > It's not used by the only current user (Android) and we can always > allow more chars later. However going the other direction and > disallowing some of them I think would be harder (need to make sure > nobody uses them). WDYT if we keep it stricter and relax if needed? I'd say, if we can also drop each of: ` $ ( ) then let's do it. Better to keep the obvious shell meta-characters out of this, although I don't feel strongly about it. Anything that might get confused by this would be similarly confused by binary names too: $ cat /proc/3407216/maps 560bdafd4000-560bdafd6000 r--p 00000000 fd:02 2621909 /tmp/yay`wat And it's probably easier to change a binary name than to call prctl. :P I'm good either way. What you have now is great, but if we wanted to be extra extra strict, we can add the other 4 above. -- Kees Cook