Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1929975pxb; Fri, 27 Aug 2021 23:00:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzemI6pkXaYRvZ6Dwdvh+Ykcx4PM1a/qroZo1W1e7cgpx6E5h+bIi8ko29kE6G+LS14AWuF X-Received: by 2002:a05:6602:3404:: with SMTP id n4mr10229411ioz.45.1630130442212; Fri, 27 Aug 2021 23:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630130442; cv=none; d=google.com; s=arc-20160816; b=HU4LzTmUZjuPVd3tCu5Cs7xelr8nknk2SbJ1QjyhGUJMWQBmkBTyzHAl4mpjZnWs7p ptbemqdaDpJQ/RIyLMZI/5iMRFcyJK875nGbJ50fAa9FDvFQ6NVVv5jabON7/504pkyi 0Ii+rdOhCd6s27zPa0KnDIjcfWyRp4/IQYIZXiVvRmMMS58ne5HFe0miU8MwSL2m64cT GU57zeoUcx3mQf273yne5b574swM4maSWWEGCtip87Jds6nJow7OJiN/vU371/lxsHoN 1CSWcYBZaznpLjZ0Jcms1m1Y+yYvWt8PLfgdH/drP9oQBmo/tf8+m2jb0Ow/XILYmO15 EtEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Z+HuhAltfukR5DxGM9D9CIqPHDVhtycCenUu1P74d+E=; b=RrdR9TnXHAAXoflZtAV4eDPPlXKmt1ZD5yGZ66z967t6MV25zskil+sWkIF2Nmd8iA G+PuPg4AwjAYe/PRaKDxMSyPiShvJD5CB2wWUOzmxJ6EIPDd/9cL94ZJaeTv05Finncn scmmQYaWsy0OTaL8T5h/ZaiwdI4tKyO6K7Btqh8571LMv5KwqGs3VhipS8+H31BeNDh+ rcsfhCUW7kA5APpFzDwyt9ykp4KGnY00+o6my37KeTrFVzQlFqSUa6IvGm2Nv2K+wfyt 61ZrJ6FcnIMLDaJw+ACRNiYKqgw+8C+ZiHUCY4RU7/ZduX7SKoRhxgVlYgnkWRM7FDRz sutw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bdORIgQR; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s21si7695566jar.42.2021.08.27.23.00.04; Fri, 27 Aug 2021 23:00:42 -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=@chromium.org header.s=google header.b=bdORIgQR; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229555AbhH1Fx2 (ORCPT + 99 others); Sat, 28 Aug 2021 01:53:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231617AbhH1Fx1 (ORCPT ); Sat, 28 Aug 2021 01:53:27 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 249EAC061796 for ; Fri, 27 Aug 2021 22:52:37 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id r13so7200969pff.7 for ; Fri, 27 Aug 2021 22:52:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Z+HuhAltfukR5DxGM9D9CIqPHDVhtycCenUu1P74d+E=; b=bdORIgQRO5qTEimiwy5kQivohDvUrEODFuEj423+D/FNgtSgGvj8uD9iZHQrUldlSS O63NVS+iWTa88tkTbrR4TJWYtTf9ibq33RPNQj6JqBAhpbCCwSeYv8urfqL0N15UKfTx L+o3L2rl2wmR1kzngsKz5V8FbDNbRcZBFP+eY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Z+HuhAltfukR5DxGM9D9CIqPHDVhtycCenUu1P74d+E=; b=W9m1wl9HTLQNxVSp1vYfCk/b17Mu9d/iy5zENXM5+/iX41/iBi3i2T6W605O06JwNb teuN3BN078iz6/YLQeaMTeqWXMeFyYqWnAzj/SM41s48ugs4bvTCWuc7hlw3hP3Ruhbn WmoCWnryEwinGeeayEyM0eH1tqGTjOa53eu7bR2FKvuql8KC6bKu9BqarMbEoJE71E7m aesd5luKeWPtzkq4x8xQQlMaBGS203shO/K0gB5brg56n4y0R4Prd3wEC5zFwdyzLApK HaJaVcdCxTapsgGk5d42F7D+iTwprz8NBgqbptymsrZU5aKuND0jOEr/BhcdZu6Znvoz /G3A== X-Gm-Message-State: AOAM53071wgrES0FMNoRLxKXfxKsOYhdYY1pj8DhhqMnzwbuSfT7ED/K snqJGQmuPSpen/Z5KjOeZ0lyKg== X-Received: by 2002:aa7:9218:0:b0:3ef:5618:6b02 with SMTP id 24-20020aa79218000000b003ef56186b02mr12092111pfo.45.1630129956591; Fri, 27 Aug 2021 22:52:36 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y19sm8342507pfr.137.2021.08.27.22.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Aug 2021 22:52:36 -0700 (PDT) Date: Fri, 27 Aug 2021 22:52:33 -0700 From: Kees Cook To: Matthew Wilcox Cc: Suren Baghdasaryan , akpm@linux-foundation.org, ccross@google.com, sumit.semwal@linaro.org, mhocko@suse.com, dave.hansen@intel.com, kirill.shutemov@linux.intel.com, vbabka@suse.cz, hannes@cmpxchg.org, corbet@lwn.net, viro@zeniv.linux.org.uk, rdunlap@infradead.org, kaleshsingh@google.com, peterx@redhat.com, rppt@kernel.org, peterz@infradead.org, catalin.marinas@arm.com, vincenzo.frascino@arm.com, chinwen.chang@mediatek.com, axelrasmussen@google.com, aarcange@redhat.com, jannh@google.com, apopple@nvidia.com, jhubbard@nvidia.com, yuzhao@google.com, will@kernel.org, fenghua.yu@intel.com, thunder.leizhen@huawei.com, hughd@google.com, feng.tang@intel.com, jgg@ziepe.ca, guro@fb.com, tglx@linutronix.de, krisman@collabora.com, chris.hyser@oracle.com, pcc@google.com, ebiederm@xmission.com, axboe@kernel.dk, legion@kernel.org, eb@emlix.com, songmuchun@bytedance.com, viresh.kumar@linaro.org, thomascedeno@google.com, sashal@kernel.org, cxfcosmos@gmail.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com Subject: Re: [PATCH v8 2/3] mm: add a field to store names for private anonymous memory Message-ID: <202108272228.7D36F0373@keescook> References: <20210827191858.2037087-1-surenb@google.com> <20210827191858.2037087-3-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); > > ... > > > + 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:(.*)\]$| 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); if (escaped) { kfree(name); return -ENOMEM; } kfree(name); name = escaped; -- Kees Cook