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 61DEDC432BE for ; Sat, 28 Aug 2021 21:48:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 42CE660E99 for ; Sat, 28 Aug 2021 21:48:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232563AbhH1Vsu (ORCPT ); Sat, 28 Aug 2021 17:48:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230253AbhH1Vst (ORCPT ); Sat, 28 Aug 2021 17:48:49 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AB6FC061756 for ; Sat, 28 Aug 2021 14:47:58 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id k78so16613587ybf.10 for ; Sat, 28 Aug 2021 14:47:58 -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=rpFNOvvpFZbbZ8OM3mIkAwJTup8tfISROOVfntRP9pg=; b=MzSuWBFZvekJz7MBaisKxWQ6esuYjymMLZ3IrbKj/oha3c6TmcvZtOeOIvOrR0wk2r MI9IE8qYkuhDL3mVBGpQokgXbf1Sv32wrg2D7tpw1KBPbBl3CB8uFDsLUOjqrUV/iwMY nqabwDzlrPvZEeWxcCs7/3Ir1zqLdAbIh9MRwdZPG8JpUj8Hgp78xJfy875BU05RAcIj nK52sQVxzEGZiKl8GtQxwYiDr9brpS4Dzsrj5U+TxePlIxTM2Hr4e/T7peehxfrkda/c 0J+Z1AYZjUNYWGlJ90k16GfxTYfDUZ2hpZCjn43GkToyMAk89/Ye7WqaU1WQLL5TKU9d 3Q+g== 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=rpFNOvvpFZbbZ8OM3mIkAwJTup8tfISROOVfntRP9pg=; b=tljI7w751TY7CbqK1doOFJvXq+yclPCRskKEAb3rtFgX9Z1wfLcmliufalP9YUBXCJ cWpKw/oK9BpSZiCVsPIsQPYQ7KIv8dp3EnaJ9FizC1B5zcDKmg0g74KDAeuOCex1iR2V rNic7meTLY15ffLdzXxFzquXZ0HekRZHSOCzPovpJ6w8QBGyCQLHGj4Gb/1So8g8fh+F LmvQuACxszKf0CP0x+GgqeHpltItDUXGdzOrSGMkhZdOv+QSWaY+MT5oKsXm4yG1aQjF uQ6I44wdu3D3z2+Ryj6n4hxiqTXbVNVsTwqlqV/icEUuRU9EvGJGSQGZIiIn4s+WEAmU br8w== X-Gm-Message-State: AOAM531awW8SOZq8AksRatOshzxk/Hv0ynIRqC4xVL1ueNExOvMRlc7h XY4zXzhpNEscE1BR1TeSHEY8cA6QcHtCM2Oog6X02g== X-Google-Smtp-Source: ABdhPJxLFe0ifBzSQIBXioyPixIsF51tIx7RKGeEqpYwiC2QLvRLZlCjMTzoqzh4c2B6Q8LmDm2C5NX/wjFcIV7kVNY= X-Received: by 2002:a25:810c:: with SMTP id o12mr14569991ybk.250.1630187277699; Sat, 28 Aug 2021 14:47:57 -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: <202108272228.7D36F0373@keescook> From: Suren Baghdasaryan Date: Sat, 28 Aug 2021 14:47:46 -0700 Message-ID: Subject: Re: [PATCH v8 2/3] mm: add a field to store names for private anonymous memory To: Kees Cook Cc: 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, eb@emlix.com, Muchun Song , Viresh Kumar , thomascedeno@google.com, sashal@kernel.org, cxfcosmos@gmail.com, linux@rasmusvillemoes.dk, 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-fsdevel@vger.kernel.org On Fri, Aug 27, 2021 at 10:52 PM Kees Cook wrote: > > On Sat, Aug 28, 2021 at 02:47:03AM +0100, Matthew Wilcox wrote: > > On Fri, Aug 27, 2021 at 12:18:57PM -0700, Suren Baghdasaryan wrote: > > > + anon_name = vma_anon_name(vma); > > > + if (anon_name) { > > > + seq_pad(m, ' '); > > > + seq_puts(m, "[anon:"); > > > + seq_write(m, anon_name, strlen(anon_name)); > > > + seq_putc(m, ']'); > > > + } > > Maybe after seq_pad, use: seq_printf(m, "[anon:%s]", anon_name); Good idea. Will change. > > > > > ... > > > > > + 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 > > 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? > > 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); Did you mean "%*pE" as in https://www.kernel.org/doc/html/latest/core-api/printk-formats.html#raw-buffer-as-an-escaped-string ? > if (escaped) { > kfree(name); > return -ENOMEM; > } > kfree(name); > name = escaped; > > -- > Kees Cook