Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3730913pxb; Mon, 30 Aug 2021 09:19:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw24MWZfXJ0H3T9Rxck7UfDTC3cHS26zIFeFJEUyiqSkNXWJ643XvuhI0D4thz8DQtRfg/u X-Received: by 2002:a17:906:1789:: with SMTP id t9mr25881442eje.61.1630340340588; Mon, 30 Aug 2021 09:19:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630340340; cv=none; d=google.com; s=arc-20160816; b=FP8SlFWARyUJsclKB6Fho09isv6naVdk4N5SQx/XTzZf3mExfzbZpXhEHbacdCoWbq ZCnBFaKCXyOwupwfHAFlN3okv/WqZs5bjXFua+37VPD6gBHkDuDQxAhYALuROcCTy2DI wV/BNoXkZFxBwBUh623kHISbwBetuw0G1DTBsMPOVPoUDeodvGtHkOGpkeDkTCqZVEcM X32HvqetB+5xnW2tPksJsVIY3yUDZxMWKFmFsrCkk64gXNUTxbe1f2TDCrnPpNOfldHC izDILgcKUpsHeVSEbsZb8Y0AwAfWmU6YScTGEPrVBw2kkILPr+u1Kh9EfVs5L4vDC844 FEuQ== 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=939bu+vC3jVVcLM9PeqTLcUxKeTQvKl0T/UCGWNALp8=; b=wg7oAnbRBcA2HsLRaDiXba1D5vx0ToFx9x3kXTHRh1k5NO4bfVMS93ehfdzw85wHLQ HTRuj0YjwZ6UqLVPpfNmss0RfGOoL5nBqW6Cp3Mg0XoF8OaNCqb9BXn6Jn08HMP5KDxB XFK/uybK1VgnDuqcKp3Lagwe20e0XjsO8llC44lR77U9pTwKg8mrTGZYC3YlS81SKBPm Q9o9ZxJY5jdyk2g3G4RKP87wPfqwWMWqxPxSjYBZkLuVbdso3IGVFpdTLAHoRrpic78t wJ2WyajpxjUTbvy09qp9iWLU4jX7ddmkyRH7ELqythlTjEDBRCYdxWC9PUobNGu8A5E3 iW1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ITcI2RF5; 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 j7si15650314edt.402.2021.08.30.09.18.26; Mon, 30 Aug 2021 09:19:00 -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=20161025 header.b=ITcI2RF5; 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 S237761AbhH3QRV (ORCPT + 99 others); Mon, 30 Aug 2021 12:17:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237767AbhH3QRU (ORCPT ); Mon, 30 Aug 2021 12:17:20 -0400 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3F14C061760 for ; Mon, 30 Aug 2021 09:16:26 -0700 (PDT) Received: by mail-yb1-xb34.google.com with SMTP id z18so29199363ybg.8 for ; Mon, 30 Aug 2021 09:16:26 -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=939bu+vC3jVVcLM9PeqTLcUxKeTQvKl0T/UCGWNALp8=; b=ITcI2RF50tbf5jpbW8hW2EUztHNlrwGsnfhzC6mjwauuNvS7Ua57LXmxQsEnU6SN4T lto0AKR9E+HNrA9uKZlePPX15hLOkKucpln1AUjIYkD7r7xSa3cKuEc7anPJF1svsnfO i6BGb2efCdpIl7cKmaMjc0QMbb/duELn6Xi+FOJIky16dA00UFatdp/+ivybREcLter0 eVp/pctX4PieOXuJmI7pr65UDYdEmRdtGBnMrUvXdskwjfGi+hEO4yAY2WV23PIUXpod 3Xz7s5C5n7uMdSMZy2ShvmwViZLPojKgRtCfw/fWgP7Z7fPUiarooICeuhOQppGopW13 13yw== 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=939bu+vC3jVVcLM9PeqTLcUxKeTQvKl0T/UCGWNALp8=; b=mqG/Zv3htjir8Qx68bWruRP4Qjg6k5Rgtrmws1wGPEYccY/W+7Jxcpi/RUVkR3ruEM nzYH6NKC3jeMeicBs91LdcGaHy8dQm9IUNGe3EZAvgGP2zhs4eZh1NAEo/DrnthtdFUR Mf+roM9WRlEAlIBh3byAfxIrbDtQ6OwlSoGJDsX8fCjKKxtpWByFstUVTKSDiwLNGffP 0Hj5xIVBi1J11rPVxwVKDwqtz0kXzqd7UREdFplp0xYGBSo+hcUh6k5q5ZUv9C/iyPel R/zr463SanK4rAo7Rmwb1D2PBoM0dm1S03J2GpFxzOwaUniPe3DaBiXqoQnrLvH8R/wu dMmA== X-Gm-Message-State: AOAM533TLkL1B9w8vTkjv89JzqB0jCzgpp19TMEFbDsxFLtASkZVWK2a MAEW3oFWhBDHZk+HJMiQ9131VLYfdEsX+VzovgaVfA== X-Received: by 2002:a25:2f84:: with SMTP id v126mr23529062ybv.397.1630340185705; Mon, 30 Aug 2021 09:16:25 -0700 (PDT) MIME-Version: 1.0 References: <20210827191858.2037087-1-surenb@google.com> <20210827191858.2037087-3-surenb@google.com> <202108272228.7D36F0373@keescook> In-Reply-To: From: Suren Baghdasaryan Date: Mon, 30 Aug 2021 09:16:14 -0700 Message-ID: Subject: Re: [PATCH v8 2/3] mm: add a field to store names for private anonymous memory To: Rasmus Villemoes Cc: Kees Cook , Matthew Wilcox , Andrew Morton , Colin Cross , Sumit Semwal , Michal Hocko , Dave Hansen , "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 , Muchun Song , Viresh Kumar , Thomas Cedeno , sashal@kernel.org, cxfcosmos@gmail.com, 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 Mon, Aug 30, 2021 at 1:12 AM Rasmus Villemoes wrote: > > On 28/08/2021 23.47, Suren Baghdasaryan wrote: > > On Fri, Aug 27, 2021 at 10:52 PM Kees Cook wrote: > >> > >>>> + case PR_SET_VMA_ANON_NAME: > >>>> + name = strndup_user((const char __user *)arg, > >>>> + ANON_VMA_NAME_MAX_LEN); > >>>> + > >>>> + if (IS_ERR(name)) > >>>> + return PTR_ERR(name); > >>>> + > >>>> + for (pch = name; *pch != '\0'; pch++) { > >>>> + if (!isprint(*pch)) { > >>>> + kfree(name); > >>>> + return -EINVAL; > >>> > >>> I think isprint() is too weak a check. For example, I would suggest > >>> forbidding the following characters: ':', ']', '[', ' '. Perhaps > > Indeed. There's also the issue that the kernel's ctype actually > implements some almost-but-not-quite latin1, so (some) chars above 0x7f > would also pass isprint() - while everybody today expects utf-8, so the > ability to put almost arbitrary sequences of chars with the high bit set > could certainly confuse some parsers. IOW, don't use isprint() at all, > just explicitly check for the byte values that we and up agreeing to > allow/forbid. > > >>> isalnum() would be better? (permit a-zA-Z0-9) I wouldn't necessarily > >>> be opposed to some punctuation characters, but let's avoid creating > >>> confusion. Do you happen to know which characters are actually in use > >>> today? > >> > >> There's some sense in refusing [, ], and :, but removing " " seems > >> unhelpful for reasonable descriptors. As long as weird stuff is escaped, > >> I think it's fine. Any parser can just extract with m|\[anon:(.*)\]$| > > > > I see no issue in forbidding '[' and ']' but whitespace and ':' are > > currently used by Android. Would forbidding or escaping '[' and ']' be > > enough? > > how about allowing [0x20, 0x7e] except [0x5b, 0x5d], i.e. all printable > (including space) ascii characters, except [ \ ] - the brackets as > already discussed, and backslash because then there's nobody who can get > confused about whether there's some (and then which?) escaping mechanism > in play - "\n" is simply never going to appear. Simple rules, easy to > implement, easy to explain in a man page. Thanks for the suggestion, Rasmus. I'm all for keeping it simple. Kees, Matthew, would that be acceptable? > > >> > >> For example, just escape it here instead of refusing to take it. Something > >> like: > >> > >> name = strndup_user((const char __user *)arg, > >> ANON_VMA_NAME_MAX_LEN); > >> escaped = kasprintf(GFP_KERNEL, "%pE", name); > > I would not go down that road. First, it makes it much harder to explain > the rules for what are allowed and not allowed. Second, parsers become > much more complicated. Third, does the length limit then apply to the > escaped or unescaped string? > > Rasmus