From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 450DCC432BE for ; Mon, 30 Aug 2021 16:16:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C377C60F57 for ; Mon, 30 Aug 2021 16:16:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C377C60F57 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 5EE626B0071; Mon, 30 Aug 2021 12:16:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5775F6B0072; Mon, 30 Aug 2021 12:16:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F2076B0073; Mon, 30 Aug 2021 12:16:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0202.hostedemail.com [216.40.44.202]) by kanga.kvack.org (Postfix) with ESMTP id 2DE736B0071 for ; Mon, 30 Aug 2021 12:16:27 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E287F18034A5D for ; Mon, 30 Aug 2021 16:16:26 +0000 (UTC) X-FDA: 78532249572.24.B233762 Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) by imf26.hostedemail.com (Postfix) with ESMTP id 9D89720019D3 for ; Mon, 30 Aug 2021 16:16:26 +0000 (UTC) Received: by mail-yb1-f175.google.com with SMTP id e63so10349134yba.7 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=oI7GQG0ggnHPtT1yBMgirHageIFyENRTRnUrGt8GqqT2gn9V3xp7F0YK0iWLcBbcmG uY1DAAv2TlzwbEz6J3b2xOrT7k1mcGpG1Poa/hAXVOfYbYJfy9tSNDdE0f8vBrgs8DVH S7rjP8d3LYgmaZKyxaPm5HZlGv3l5ReML116Zj4cyq2XusFQJUHM3ZGsCqRK6Y+AI2Kv C3Pe0Agq1lirU2JVOsLMl0FrtSS3Mw7aK/dlowDHHFVsMmzz4HzPgaP9bHNZwon2gctX lcRzjHwttHJDyIZ/fW7bK7JWwt5vlJzXPBqDhziZvHBN/g7be0kWAjXZ+9/HD396UyUc B4pQ== X-Gm-Message-State: AOAM531ZjYIWuTTQmFESeBIH7t1mEyTOSWDHph5iCRiTWNl46xzMoZQn v7XwbD3gbwG4tvFr6Iq/AroEBIqevcXB6S2EI2O28w== X-Google-Smtp-Source: ABdhPJxpO4KRrWzp9HPBWsZPHteLt3ldMMBKdPlVWSrBRAgXZx0fVjGjzTe9UARBxOQ2FzMofCcoEJhTK10UQiuzOkM= 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" Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=ITcI2RF5; spf=pass (imf26.hostedemail.com: domain of surenb@google.com designates 209.85.219.175 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: 13j7ohr9az4za5at6cpg5wg9b3o8gcib X-Rspamd-Queue-Id: 9D89720019D3 X-Rspamd-Server: rspam04 X-HE-Tag: 1630340186-286136 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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