Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp934944pxb; Wed, 1 Sep 2021 13:06:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdUxRxv+uw+FfAv4ECrfQfffBDJtS13RVoGyBvEI5+r3Tv4l14W8TzrlJJyG9k19e6/tp6 X-Received: by 2002:a17:906:2ac1:: with SMTP id m1mr1371048eje.518.1630526816402; Wed, 01 Sep 2021 13:06:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630526816; cv=none; d=google.com; s=arc-20160816; b=h7LzY8YMEB/N/kWgfmlqsjVW0e1FltcDhI4V7d22Vj9oTFkw4uK2R4DCePTLW8AUle 3BNrlM81ogktxe+QtGMDDRFkrdeN9KMJxwsryQ6zaIrABHpqscRhZsyekDueIgGBJ3ha HVm0NA2AZ4N6k6agwJVthBf2ZgLgZ3mIgJEwbjDmK2JMPdT02AXdT2Tu8t5Zi3I0NcpW U37yQOT67rGP/NDyCsXJxhojwmNwlb9fAq08XtJ18rwASqtno0agP10f1uV+VKAIeH4w 11IxvvSyzWfo3SAdMu3T0B3+vhanwLPAS1rVbRXMX4zUht0+J0W7DNEXrnlgdIDdWBaA CpuA== 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=+GlOqsOpw3zZfxlN+CxYu9jIfOzsHv5cSyt625Vybl8=; b=px0RDiYqdEN9B/q500cX7K170Apbjrl7DuiSkDOSSue39S6ezPGHmG4qEZO0acSNtF tzXXrulbeSSwlnNBvyGLectRCHvywBI4dQ0MRwD08hAef+7hCM4iowrSJwz+JvGbUU40 DgtYFs+NBsOcJZ1H4FIIb6ylAuE4iR5fTvoNmtRwuxBTfKoC0rSo+ekpxDwgEqcg1Jr8 QBo9Xxdir4Q1YV1XX/njYi3LbNMdZP9GGcBpyfuvf+ykbLlAdlrXRkysCYgO/FIVJTSL S9aw/RDKsNSeU/8wheFjAcvHE0aqJOsiFbtiuxzTFQkV2Iwt8w2L07yeHyfOrlH11QiX PN3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pouVvtou; 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 t14si459153eds.412.2021.09.01.13.06.25; Wed, 01 Sep 2021 13:06:56 -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=pouVvtou; 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 S244326AbhIAP3o (ORCPT + 99 others); Wed, 1 Sep 2021 11:29:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244284AbhIAP3n (ORCPT ); Wed, 1 Sep 2021 11:29:43 -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 A2E33C061764 for ; Wed, 1 Sep 2021 08:28:46 -0700 (PDT) Received: by mail-yb1-xb2f.google.com with SMTP id n126so5862617ybf.6 for ; Wed, 01 Sep 2021 08:28:46 -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=+GlOqsOpw3zZfxlN+CxYu9jIfOzsHv5cSyt625Vybl8=; b=pouVvtouO9DCggJX7QWS3tCOWjs/IVuHjqBQMcHhQ0STgWiOvIiZCSSrNXAY5ld81f LZ1tSIspJ93Le8JyfMvoJul1UlvtVWAf3Ztf2FqwZPU6rjLOwLaDy2z27rSUE5xeXbjs QLUk6yb4SBxpBWd9Ak1A2Z/ZZchEHnkRsFFSh7Hp74C0IIwTPtxicZvUFOz24o01Dwqu 8PTDkYunv439Eipf41iI9fhCJBZN/ubgyxj1LESHmh5f7wxAPOm5SEwzYAHjC/qqTKZI 18CwG0LwTneoTDEOQIHDU1N8oo2XrfLx49c7cxf2mvzUQ4wXyPFrbnQvKkLWtZ6b5kWg 4+1w== 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=+GlOqsOpw3zZfxlN+CxYu9jIfOzsHv5cSyt625Vybl8=; b=KVLPtEPEDoLelVydDa2RGI5awutmWDdwoIP4NmVQ1Cscs+v5OpBhzDSzcahkbAnmmd U0cCpdsRrnlgYqVqqNfkoq9ra72vevdLknk2+1jw2X3Uk1U159SukI7ZlcsH6DN7aAEN RlUhLaqOt+0fK7pWpHGObk/2EjFWD62EG4hbW0fRnEPkzhYzf7kIF3UkJ1t1s50IGzod Yr3ynCv4cKVLxelL2S9YLoFttBzjU896r6Nb1hzps9H+8oMmOWwixFzLecaOPzBYq0hl /iVMiu0+f2N5j/wLDplIeJR7ESSMhBlKKcoX3Gz5IUZwKKiKqGvPrTi3UvNILp77Vx9j rPMA== X-Gm-Message-State: AOAM530/SI7kQw0XRsNFuVLGGsgNqMl+8JAPFuEDpju1++KO55vEQaO+ +5jynbL6ocDiH/RLXX/czEAnUJyHhlS+0WrzWoJa8Q== X-Received: by 2002:a25:4757:: with SMTP id u84mr23681yba.397.1630510125588; Wed, 01 Sep 2021 08:28:45 -0700 (PDT) MIME-Version: 1.0 References: <20210827191858.2037087-1-surenb@google.com> <20210827191858.2037087-3-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Wed, 1 Sep 2021 08:28:34 -0700 Message-ID: Subject: Re: [PATCH v8 2/3] mm: add a field to store names for private anonymous memory To: Michal Hocko Cc: Andrew Morton , Colin Cross , Sumit Semwal , Dave Hansen , Kees Cook , Matthew Wilcox , "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, Rasmus Villemoes , 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 Wed, Sep 1, 2021 at 1:09 AM 'Michal Hocko' via kernel-team wrote: > > On Fri 27-08-21 12:18:57, Suren Baghdasaryan wrote: > [...] > > Userspace can set the name for a region of memory by calling > > prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, start, len, (unsigned long)name); > > Setting the name to NULL clears it. > > Maybe I am missing this part but I do not see this being handled > anywhere. It's handled in replace_vma_anon_name(). When name==NULL we call free_vma_anon_name() which frees and resets anon_name pointer. Except that, as you noticed, the check after strndup_user() will prevent NULL to be passed here. I forgot to test this case after conversion to strndup_user() and missed this important point. Thanks for pointing it out. Will fix and retest. > > [...] > > @@ -3283,5 +3283,16 @@ static inline int seal_check_future_write(int seals, struct vm_area_struct *vma) > > return 0; > > } > > > > +#ifdef CONFIG_ADVISE_SYSCALLS > > +int madvise_set_anon_name(struct mm_struct *mm, unsigned long start, > > + unsigned long len_in, const char *name); > > +#else > > +static inline int > > +madvise_set_anon_name(struct mm_struct *mm, unsigned long start, > > + unsigned long len_in, const char *name) { > > + return 0; > > +} > > +#endif > > You want to make this depend on CONFIG_PROC_FS. Ack. > > [...] > > +#ifdef CONFIG_MMU > > + > > +#define ANON_VMA_NAME_MAX_LEN 64 > > + > > +static int prctl_set_vma(unsigned long opt, unsigned long addr, > > + unsigned long size, unsigned long arg) > > +{ > > + struct mm_struct *mm = current->mm; > > + char *name, *pch; > > + int error; > > + > > + switch (opt) { > > + 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); > > unless I am missing something NULL name would lead to an error rather > than a name clearing as advertised above. Correct, I missed that. Will fix. > > > + > > + for (pch = name; *pch != '\0'; pch++) { > > + if (!isprint(*pch)) { > > + kfree(name); > > + return -EINVAL; > > + } > > + } > > + > > + mmap_write_lock(mm); > > + error = madvise_set_anon_name(mm, addr, size, name); > > + mmap_write_unlock(mm); > > + kfree(name); > > + break; > > + default: > > + error = -EINVAL; > > + } > > + > > + return error; > -- > Michal Hocko > SUSE Labs > > -- > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. >