Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4669444pxb; Tue, 31 Aug 2021 10:23:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwADlNJ5UUHqbFSshc/ZMhMie5xVifbbeV3bSCn/zXqIqBKCIERJWuXeOksMn/jXeIxqMCH X-Received: by 2002:a05:6602:2436:: with SMTP id g22mr23964469iob.109.1630430613069; Tue, 31 Aug 2021 10:23:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630430613; cv=none; d=google.com; s=arc-20160816; b=XC0I8pnJkNH14Ajb9pmUJyjrB5/HvVz87+fDhKVhQzZqZ/kEhUEfZTp05SlYMlbF+c F1yn1EjipaL8scvYbm9DXDi8mAV9PahvEf1bC7pr6BiGhXXLPZiPE+TbyfDaBEPFwsyU AqMJlfpPESppgWwEtO4tE65zpi/uRjmZkbBnDWP5ybECyBGobeXjzmY+QNWxCRd1lLDc ExrfGkQLpWTl7M4DdRhY6WVvKDywcRH4eVeq4TQ8ylmDtmE1xq2O1GkAIZmUIyDYf8jH Mty3ZO3okN6WjZ87TP4skqHHTMyWoo68pS7oxyCK6qCtmsebYb7/lVuQmaAAMLG14bwX zGjg== 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=WrEonas+JepcSOY1s7UkcRJkLLwq2Xbze1BTfCD2A34=; b=HNVIfwirG7CxjcqO+WC53No9RXLx7FX5HggYcBH20XQadzivbvENiRPEKEGMEBG/WW Afqaiw+RDuGNeD67KZLMEIMskGWtKRf9AotS+ypTlc6bOJ/3q9H+gx2omvYnIWCBkIYn d3tSXK+oJwqv2GY2HZul8FaOZM2vpJCEMgwy9daX/F0cGdNuRrtY83moU7AXt9MsXF+4 q4jBJrr9O1fPyKRLt8rJ3tZch9V/Iwt9enZCFnMCTTO+q9OA79KPHUlVD7QehCc9P4f2 BOKtvy46+kiIloryrzGLWcczZ/ONrHL0niJH7KTanSevFV4Nj+UhcFholp6cn4Haz81E WvFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FUmATkIw; 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 a21si17882601iot.52.2021.08.31.10.23.18; Tue, 31 Aug 2021 10:23:33 -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=FUmATkIw; 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 S232377AbhHaRWr (ORCPT + 99 others); Tue, 31 Aug 2021 13:22:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231862AbhHaRWq (ORCPT ); Tue, 31 Aug 2021 13:22:46 -0400 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37BDFC061760 for ; Tue, 31 Aug 2021 10:21:51 -0700 (PDT) Received: by mail-yb1-xb33.google.com with SMTP id q70so36562920ybg.11 for ; Tue, 31 Aug 2021 10:21:51 -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=WrEonas+JepcSOY1s7UkcRJkLLwq2Xbze1BTfCD2A34=; b=FUmATkIwZg5ZsdXIB4Beeo0WFBRLtX/xMW4hRtj8U9Wo67Z07U2YrBoqMyWD89anYc jsZEr/hMAxrvTFvMC8Z8Rep0v1FYAbDiZxWZvwtcd3E3rkJu/fEI9TdMwKHr1bbDR+uG HrstyAHrLttUKuChWSzh50+cnHbAvQTldLsIhAWnCQBRs8xuX9pTMDALn1e7AG1Tzrqv 9CTf/X/hTTE4PneuIB0GsckhUTCqGhd/28jqAa/6Z1Ghl1YlkghiTFTzQHBQ4qZadojQ QpfxNyuvbhGMfLmre6jfNGm/k46DQ96BSRhwvSufQ0V0iRfZBfjkohXmi+r4VNOa0Hou z5zQ== 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=WrEonas+JepcSOY1s7UkcRJkLLwq2Xbze1BTfCD2A34=; b=E2A8besAmsgurrXQcaq6sSSeJzr18wONvTiiVreED6xWCvU649xRGMFmhXnlumds1F Qc035wOUK9C3uKA1UP30LdJh87gfWnNBPV11irYH1CzQXNzR3pYqZCqGn4stdEEgGybo GeMGTMv7nYGIhCcPxQfB4pdDufHQUcf0hFlPwb9odednefIxGDSkO2jyhNwKYaPnNfpS DNHrNycIjV41qLo41RLhto+lzRpeyDfaQtHx8fR6fPC+bj1aoe6dDG7BWombJsPJXG1H T/z8LZRDrTAQ9Q91lbSvdaTNKyiEz7aNIcT15v5JjvOw+4ivqxSmGSdLSRJpqkWxr9mx 3AzA== X-Gm-Message-State: AOAM532saCaG97KxK9oqEhSlTFMm003whTHmZKVVgZmqjnW+fJ+2AN7x my9UeuvL4O+Ogy2prO4MX3EEiL2oed5wWCK3tQ5wYw== X-Received: by 2002:a25:9ac6:: with SMTP id t6mr32228595ybo.190.1630430510051; Tue, 31 Aug 2021 10:21:50 -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: Tue, 31 Aug 2021 10:21:38 -0700 Message-ID: Subject: Re: [PATCH v8 2/3] mm: add a field to store names for private anonymous memory To: Matthew Wilcox Cc: Rasmus Villemoes , Kees Cook , 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 9:59 AM Matthew Wilcox wrote: > > On Mon, Aug 30, 2021 at 09:16:14AM -0700, Suren Baghdasaryan wrote: > > 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? > > Yes, I think so. It permits all kinds of characters that might > be confusing if passed on to something else, but we can't prohibit > everything, and forbidding just these three should remove any confusion > for any parser of /proc. Little Bobby Tables thanks you. Thanks for all the feedback! I think I have enough change suggestions to resping the next revision. Will send an update later today.