Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp731269pxb; Wed, 1 Sep 2021 08:48:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZjfz3GReHSZHEZiR7l8rfBPECiXDk2bUgr+Wmc+J0q9E6p5YLI9BHs/swGcExBc/R4Q+k X-Received: by 2002:a05:6402:221b:: with SMTP id cq27mr257458edb.374.1630511296017; Wed, 01 Sep 2021 08:48:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630511296; cv=none; d=google.com; s=arc-20160816; b=GSKtF3v4B2NjMGT/ujmJmX4N9cof3Z05fszmQREwKWwmQIS6WPpuO3vAS3+rt0EdoU ZV3FsFLtzBa1yj4nWAC2CM+2wWZzWo4eklkebv+JdqyC+5AZqUQp4Ylslq8AnDjlqu2F EzkB4hnmM2IiG28s9Z04YGcn8GVkU2qAZH7rvbpRGY/VXx/uYt6ol3bH0wrIMlLTfFu7 Rw3sV5qIIOigfA4XEEtVGKwyLzfcBMmhEiqC4bVvsjDf6l3K7Ukt2gW7fnMIkVxIUjyf 4+4W3LQfO+2/faZmHADYCbwtGiSDdWDqybQkREZpWCH2PnNcbSPvKVbnOG7kntvh8VnR 7XSA== 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=8aCBEJKtdvAJtrTrGgodt4LUm0+Z7gqZfpmD/VmzxRk=; b=cvmm0ivtyexcq9YUj82iqZvovyGtmBLY7mC1OOVcWg1S7YCX3BlPZ3b/5oknnCrJlq OwrguXuroyuQSFg5vuE8AB94Wu8WO4AvM5I2nb2WqqGK0E9IO3jcwAR8UBvGsSYyDwhR pTE50apzDhj0SLw+waRfuFyKtadp9UBH43N9lhS0RUU6q/dwJMZn3ADQEGvt04wM1rG4 QD0h0VlOPFuK3Y3XRTURz1OemIU6zi9vR1V4kG24V79CZgRVY0PEQqABtY1vIFA8f6ml aTCZS0KRwUVaehrh7NA/YXThN/+oWOfXrB3DU5rlhObpwhFtaaXehQcUX1rODnU1lAPz Zijw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=R1ryQlLr; 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 fj2si82768ejc.474.2021.09.01.08.47.07; Wed, 01 Sep 2021 08:48:15 -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=R1ryQlLr; 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 S244935AbhIAPnj (ORCPT + 99 others); Wed, 1 Sep 2021 11:43:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343705AbhIAPnh (ORCPT ); Wed, 1 Sep 2021 11:43:37 -0400 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E291C061760 for ; Wed, 1 Sep 2021 08:42:41 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id q70so5892619ybg.11 for ; Wed, 01 Sep 2021 08:42:41 -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=FWPg+3kVuWZvb5AdMrtrpvF46Xg9U9LGKHMxi+JXg11ad1Y8qGQiFGo0NdUAVMdCvZ RwxYuHk1ibObGdurOqsaeSOzhwfoynmjEdEp39R+JqI/78H3aNDAztAqqI2jEFCwNT7g 9wUWp1k9tJLNyrjkyckJX5qj0q4L4E0h9NiE+q/3/ocl2Rp4MNKTd2h0wVlx6QX8gr6A O1gF632+bFqMP8vYW9jXFJonQs6c3FKBD7SsBI2whPUECxpQ9x8ONabn54wl2++8B5Xu y7dG3Xw17Vh9Gr2vXBJQw9lLbd/kJBl5ffE0dPquMXOxJ5CPHCjHA0mAp2rCJIgQpk0/ kS7w== X-Gm-Message-State: AOAM533s5pbNLX1oPxO/XzaJQs1suBh/dFNlc443x+rChxQqOj5VrZOp uXTifpjvJQcEEgxQGdKTL1OEw73OFetg0YjAjv20Hg== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. >