Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2437848pxb; Sat, 28 Aug 2021 14:55:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywE2ZTLQXZ6cLjjrH5Z6qlwPLwIdG3dYFwR3szXv93EhQFyDHkmGYPUhs86e4GZrhKh2De X-Received: by 2002:a17:906:401:: with SMTP id d1mr17270562eja.242.1630187711748; Sat, 28 Aug 2021 14:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630187711; cv=none; d=google.com; s=arc-20160816; b=aGvUF2yoUjjD+IZ06GorRsNtNgQSuQV0Kud2UJ3o9GBRKLw0Qegk7U++VEGAqaw7x/ IFktM1ryDyZfS5BgfkLuk+Mc0RzchXYodFha/6T+aYVYqId63LBLlYIRAxPWvRkCoNPa iRFut0WNdfxirTSSoZIClMk0Z7hALrmGIREWtIF0zgOfCgEt4bkAXnb7OTZGw+X+o4OR tv+d58EkIkG4D22FGxaYj8KNPj1C7wf1mF9y+mBybb2YNTBz/IszbIsOfA8lmtYxTTUV OJ9BcX4DtGG9yJOtanSPM5rNNvimz5qMPP4kZ1D3VcrWYZMMcz8DS8mmS5pp9FgEuFZ4 UDEw== 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=rpFNOvvpFZbbZ8OM3mIkAwJTup8tfISROOVfntRP9pg=; b=JiVSzm6Ob1TT8Tq365Mf2nR3++tdbLgaY6FvPXK+1sG8JjP0XGaV5vnFFzLF+pJ9nb O2s+Smto8yHOxl7WsyzEwa0nlRPbWc2CVp9L/uHr/u0rMUP9fxQugns1eUGPnje8qz0e ruZjFsgbIJ9vFn2ds+SRXNSNtoMDDaGZLj70Ils56Prgd8KoCEhuW6hx4gAu3ITZw6S/ mR51JVTT0xkusO/t51H4QsrVhkYnmJpj4oBCgHcOG8reFcCGMjz0ppcvF0+wpOgpQ+r7 z8iEdaiHtw0Q15Y4wUVhH7bAvpW2E238TrDFuZsLfFeiBQnNNkr2sFmvf6mhL1US+XcK ZBFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=MzSuWBFZ; 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 y8si4265375edw.184.2021.08.28.14.54.48; Sat, 28 Aug 2021 14:55:11 -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=MzSuWBFZ; 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 S232561AbhH1Vsu (ORCPT + 99 others); Sat, 28 Aug 2021 17:48:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232475AbhH1Vst (ORCPT ); Sat, 28 Aug 2021 17:48:49 -0400 Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B14F2C0613D9 for ; Sat, 28 Aug 2021 14:47:58 -0700 (PDT) Received: by mail-yb1-xb2f.google.com with SMTP id z5so19869620ybj.2 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=FygmC9DeO10zaImDxMR8GnYMPYOIpspyTWQ7h0HeauY/tyASfk4PmW6B6kW1OapUzN t6mF0ZRkyVuY3sjbamOqS0AEL7vCyLLX/TaNH6kqa2EDRHnIiSYT3wuV/I9Ieff2sHZY j8wBLSGJR9nGkB6R/7UCz2QnAxMQisT8tKftbKrg4VX6Q2e0Cli4rZf1NsGk4SzIEuyf e0SF6HLzpvIv088h7taaVCe5ELXreGtZtv6B9ZYB/gc+ZKK261ZNscfZgDSG8CuOGa9Q 01eXH7/UTJofQTXOd4uyFQmnDOkhbAngvBt32qB4hHwo7c8iAGRVs3tONedHb5pDGnTi HiaQ== X-Gm-Message-State: AOAM531YoNlpZ9VTjnErAH3e3OlhbnNUdClxp3/4534j4f+jav2mFSqx vZYukvEcBh7oDRK+3GtmsIEFzMRA/HLZTi8cN/aa8Q== 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-kernel@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