Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp878043pxb; Thu, 30 Sep 2021 20:46:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0gBJTo0pJeZdxd/8+xFsZG3IL8EcYwcqdabIeZmdqrvSTkdZT7YaBm5cgiAgcyezPLotC X-Received: by 2002:a05:6402:16d8:: with SMTP id r24mr11463460edx.47.1633059983120; Thu, 30 Sep 2021 20:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633059983; cv=none; d=google.com; s=arc-20160816; b=AVdQG5BMkjJOX/KspAqMc/rNp3kZ4APksQaY4TD1XT5xNNSFKLtXnA1vDDsVMunaWQ suIeVNI7TPjCDzmMbI5V8XhmGlJNCGqsb7wn9HjXZzpEOT2ETUOZtdC4vbi10hwAEW3B uf+xOvrVNbbt1eDT6xMorJBJZnMcgRGvfGCp1g9kxkTtL1UGRnoPX2Q7Qkf2ZK4QtaVH lItdXc9SFGlnEWynDWMj8n3v5tzHWVVCd8UNd+TEpilky1GjLONCvpafm3Chjn8EOMS/ YNZG4FBQ4U0ysMI9K6p1SaOsK6MbgpgTZpIDZZSJ43qg1fNeWR/TmJSC1YffNbDkjaOK sEDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=nUyg5XpqEcjYRAILgiFJJzvxtqym2vAvVPMoISCLLDM=; b=u0h0pfHFHZ/rBQ4V7uEZcyMKS7hRV+K3F78wrr+Tz+vMLgIH5UI9ThCF21O1EVQtRe 0QXmbSuKGeZHXN2iINDTiNeN7vOPbbJtRKJU9LTTKnEH4GZexLc2m3W3s2GhHfUiY5XG wZRsobO5p8jP9M/AkinUtpXB5uRz7ik87ugrtXNgvF+4QMIjxVK0gWpVPUE252iZRnRR UnUgWJrzwRAB1BpzAvkKzQa/LiAtcvP2TtMCGB16K/U+B2jYRFKLSxNHvOGWDmICRHXd JpciJUhVr38RSs9w2Ub6Q88zYVg219LU7OBIvr0g7AGBIjS7ZE3TcM7ErS+YLucDx3Xs EHEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=WSQqQNNa; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ia24si6337636ejc.453.2021.09.30.20.45.58; Thu, 30 Sep 2021 20:46:23 -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=@google.com header.s=20210112 header.b=WSQqQNNa; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230389AbhJADqW (ORCPT + 99 others); Thu, 30 Sep 2021 23:46:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230487AbhJADqW (ORCPT ); Thu, 30 Sep 2021 23:46:22 -0400 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFC93C06176C for ; Thu, 30 Sep 2021 20:44:38 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id z5so17749983ybj.2 for ; Thu, 30 Sep 2021 20:44:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nUyg5XpqEcjYRAILgiFJJzvxtqym2vAvVPMoISCLLDM=; b=WSQqQNNaNU6sKZN/vcVig76MwzWnqgyH3Y4g0q3bhSkAt+RLn8RiLo9wYfPmdxHEwj Ng8YvHClCtVSVSAlLJD7bFcHsn+Mw6Qh5uOBvYc84llJZCKuAdCRumGL9aV7ROzSVNoX zirkUMQUH0UsWfjfwIIuFEvQ5VJvlPVKeUYG791Ing+efx25wLB+Id73SD2iHg2OvmTz Du7tMGJLrwlhyzbwCZxrUiHX+uGM3N+Uq+mX6x8CcaSZaSQ/9ckaZzVNWy7/m5xwlPfO Ji+FZCzzvSsOgww9JvFT2qwCaP3NlgC1vAVpZ1vnahhCM7JpRWh6MSStXgxBI+Rfb4u7 /awA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nUyg5XpqEcjYRAILgiFJJzvxtqym2vAvVPMoISCLLDM=; b=shKn5j7xhfiJVZ+ZkfzMLffSE5ioScIh0e9XzB6484rMj1MzVTOAS8g4zPVlFZnwdM FnvSjFpLBbo7f559hCSuAk8iDWWDXE68Dvq6wZh5IWfyr4mwdIT7byiSwpHbiRHl0JRO LGV3qRlmHYWrrNsyfS+/8eUzVAF/nmfrSW37ZQaqk3Y2nmp7XAoxrRFo2V8LdqX3ZIp5 N76YuHtH5jhhJrgQCY2+bMgJBNIO5x2SYVZ9Z0956SEjYDE+WFw4wxFewXuXWuyD2Jcx 2ici6/v9mRQPEc1Qkl9qRO5T7Y21mLdk+Lf7a0Ds+JsK/GQiWhWJErtHEDIVrDwrbyMJ 9cdQ== X-Gm-Message-State: AOAM530ko4VqYS1Pr0PjgMYyz708ExRZ8EnnAq2LzG2kZ0GUuF48XX8U 2lKbfqBM/NmeT7/BCLUmKw2WOwrZvNo8OoMz/fDMcA== X-Received: by 2002:a25:8411:: with SMTP id u17mr3282073ybk.376.1633059876528; Thu, 30 Sep 2021 20:44:36 -0700 (PDT) MIME-Version: 1.0 References: <20210902231813.3597709-1-surenb@google.com> <20210902231813.3597709-2-surenb@google.com> <202109031439.B58932AF0@keescook> <202109031522.ACDF5BA8@keescook> In-Reply-To: <202109031522.ACDF5BA8@keescook> From: Suren Baghdasaryan Date: Thu, 30 Sep 2021 20:44:25 -0700 Message-ID: Subject: Re: [PATCH v9 2/3] mm: add a field to store names for private anonymous memory To: Kees Cook 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, =?UTF-8?B?Q2hpbndlbiBDaGFuZyAo5by16Yym5paHKQ==?= , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 3, 2021 at 3:28 PM Kees Cook wrote: > > 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. While testing v10 I found one case when () are used in the name "dalvik-main space (region space)". So I can add ` and $ to the restricted set but not ( and ). Kees, would you be happy with: static inline bool is_valid_name_char(char ch) { return ch > 0x1f && ch < 0x7f && !strchr("\\`$[]", ch); } ? > > -- > Kees Cook