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 83788C432BE for ; Wed, 1 Sep 2021 15:42:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2C76A60F3A for ; Wed, 1 Sep 2021 15:42:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2C76A60F3A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id B472A6B006C; Wed, 1 Sep 2021 11:42:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD0418D0002; Wed, 1 Sep 2021 11:42:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BF338D0001; Wed, 1 Sep 2021 11:42:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0244.hostedemail.com [216.40.44.244]) by kanga.kvack.org (Postfix) with ESMTP id 8D4DE6B006C for ; Wed, 1 Sep 2021 11:42:41 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 4C98A1822BC6B for ; Wed, 1 Sep 2021 15:42:41 +0000 (UTC) X-FDA: 78539422122.26.6AA898D Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) by imf14.hostedemail.com (Postfix) with ESMTP id 050596001988 for ; Wed, 1 Sep 2021 15:42:40 +0000 (UTC) Received: by mail-yb1-f181.google.com with SMTP id v26so3806076ybd.9 for ; Wed, 01 Sep 2021 08:42:40 -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=8aCBEJKtdvAJtrTrGgodt4LUm0+Z7gqZfpmD/VmzxRk=; b=R1ryQlLrLKGt/v8//Q9rGKUHdcgBDrp6/sYQ33GTCTpJ5Un4Skro0oOst3pFa2vmzj 0eRJUNhpZce5+8lwfZ3e5akFkVTbhP2ghPnNi3hUABx/JlqLQyuA6pychIwvcmbqln/i CR26ejZI3VeSRhRM2ycMIXajd+c3VGOQ2S/iLnA4ZhA/O55klYq5+MCnjcsfecphzRSV K+FMeY8OE+XpUXLB0I9AXogd+d0Qsn72gxpzdG4UJzafkOgNmMXj8X19Dr+JH9GElsrS 5pfGbfXWHsUfRVe70ybV7MTIxJza2dg/DX/SJDyL+6atpZIIKQxhh4+KI9jfDbMYpqSP CcdA== 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=8aCBEJKtdvAJtrTrGgodt4LUm0+Z7gqZfpmD/VmzxRk=; b=lcY98i9Cat0Vk2UnMr7qUUk2XBnMS03IFjgXSWg1T2i/RrZKgn6FYRmfyzErtPlAWI dxHjapPgmvkZgXMbPSP9iV0QORXtLA7tMT72hSicnAH2hN6n3m/13Rd8fsNS1jaqgFvz DoCxA5Ywxfa5SEJ9d1z6z5S1NPjI4Ao53QOAoU9jLsDwjBMYX3vwPjrEKxHSAMRyxxjZ YLeojVFHpqWOvEGlpNJHalhU9jKmXrR06DflX8gvHWu8B+yWoVlpDZ9ofJt+Xjlgtjhp GMX9a9cW3EhCmAENxNSTCWDifW28jFDTtRS9aJY663FMmS4GImOQPJeB1CwGr2jL1veS EYBA== X-Gm-Message-State: AOAM533oU5pFEuHhx97bl/EF3m2wlhU97lnkjqE24FGIocaMTKYjbHhQ 48W5RC843q39NErXRKykmwWZa9WzUSHrICje8AOo7w== X-Google-Smtp-Source: ABdhPJwgQPH0nvbXpOtJyJ8qfGoULlT527Pv1mAagLgarkJHCp5SC7DsgZ+zIsArG/MC/YiqIV0K+Xpv+P7vOkdmGkQ= X-Received: by 2002:a25:9ac6:: with SMTP id t6mr189907ybo.190.1630510960178; Wed, 01 Sep 2021 08:42:40 -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:42:29 -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" X-Rspamd-Queue-Id: 050596001988 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=R1ryQlLr; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of surenb@google.com designates 209.85.219.181 as permitted sender) smtp.mailfrom=surenb@google.com X-Rspamd-Server: rspam01 X-Stat-Signature: fd5bu64yud9jqz17qs1uf8kqtbm7iprh X-HE-Tag: 1630510960-112915 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Sep 1, 2021 at 1:10 AM 'Michal Hocko' via kernel-team wrote: > > On Fri 27-08-21 12:18:57, Suren Baghdasaryan wrote: > [...] > > +static void replace_vma_anon_name(struct vm_area_struct *vma, const char *name) > > +{ > > + if (!name) { > > + free_vma_anon_name(vma); > > + return; > > + } > > + > > + if (vma->anon_name) { > > + /* Should never happen, to dup use dup_vma_anon_name() */ > > + WARN_ON(vma->anon_name == name); > > What is the point of this warning? I wanted to make sure replace_vma_anon_name() is not used from inside vm_area_dup() or some similar place (does not exist today but maybe in the future) where "new" vma is a copy of "orig" vma and new->anon_name==orig->anon_name. If someone by mistake calls replace_vma_anon_name(new, orig->anon_name) and new->anon_name==orig->anon_name then they will keep pointing to the same name pointer, which breaks an assumption that ->anon_name pointers are not shared among vmas even if the string is the same. That would eventually lead to use-after-free error. After the next patch implementing refcounting, the similar situation would lead to both new and orig vma pointing to the same anon_vma_name structure without raising the refcount, which would also lead to use-after-free error. That's why the above comment asks to use dup_vma_anon_name() if this warning ever happens. I can remove the warning but I thought the problem is subtle enough to put some safeguards. > > > + > > + /* Same name, nothing to do here */ > > + if (!strcmp(name, vma->anon_name)) > > + return; > > + > > + free_vma_anon_name(vma); > > + } > > + vma->anon_name = kstrdup(name, GFP_KERNEL); > > +} > -- > Michal Hocko > SUSE Labs > > -- > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. >