From patchwork Thu Jan 5 00:02:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13089205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60FDFC46467 for ; Thu, 5 Jan 2023 00:02:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82C728E0002; Wed, 4 Jan 2023 19:02:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7DC8D8E0001; Wed, 4 Jan 2023 19:02:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A46B8E0002; Wed, 4 Jan 2023 19:02:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5CF3B8E0001 for ; Wed, 4 Jan 2023 19:02:48 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2178C1209B4 for ; Thu, 5 Jan 2023 00:02:48 +0000 (UTC) X-FDA: 80318794416.19.A386F2B Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf23.hostedemail.com (Postfix) with ESMTP id 9E87D140009 for ; Thu, 5 Jan 2023 00:02:45 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GgBu5oQs; spf=pass (imf23.hostedemail.com: domain of 3pBO2YwYKCMc574r0ot11tyr.p1zyv07A-zzx8npx.14t@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3pBO2YwYKCMc574r0ot11tyr.p1zyv07A-zzx8npx.14t@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672876965; a=rsa-sha256; cv=none; b=a9zZRGuMVWq/BuhJ0nSjKo7f/ss0iz1pj382GlB7VOktvEOEhFQzGDcZ3GXp3f01Kve/Mg tRz5T0bl1bc6A2HyP9P2m+KEyMBFAwBI9yqk3ajWt2CcOjXy4Klr1Tf4MuVkBlNKRo6dys F/SJgSHvwhBTWeQNJ6Z/UPTje/uvLnk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GgBu5oQs; spf=pass (imf23.hostedemail.com: domain of 3pBO2YwYKCMc574r0ot11tyr.p1zyv07A-zzx8npx.14t@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3pBO2YwYKCMc574r0ot11tyr.p1zyv07A-zzx8npx.14t@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672876965; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=2FPuHPcUnxQtCWYTvyX7yM9LZ48eFw1C5/KmPQ+TvO4=; b=VWg90jVPjQhA/vGWJUF1XlevHnUEsbEowWNaSfjgHpK9/vy9vLQVx3CAh79hZx/XOirF0c KslOTFl23CHbMagqecfKKmegKJq6xJL7cevRUa00yfJZWNEXPgglOZb8L4wTESwKOikkvt Ftqjp3cnsdAmJh9F9rB1vN4xeNIrIXw= Received: by mail-yb1-f202.google.com with SMTP id 195-20020a2505cc000000b0071163981d18so35450321ybf.13 for ; Wed, 04 Jan 2023 16:02:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=2FPuHPcUnxQtCWYTvyX7yM9LZ48eFw1C5/KmPQ+TvO4=; b=GgBu5oQsImcIXo2jP7+rTsbFZ4J6GJzA5TcGdhDUJdS8FD/izShQCaTVsjwG2A0JZP ERqghA7ROAqQONt87t5EX88eZ+Z6V0HVeybU5S8v/4T38LQzdDvbQ6XpZcfg5NLS26h0 CbNdUqORwKoIeaiNwxnAwy7iVPjfZachw2mtptzLKnoO03ERtPB7QRRu+5zZaX8tLEq+ li2pWjuFKbfE2/iinlfRWPxfyEEOaMmxA+VJL/T/TT/0djDDmX2M/pEY4ZQD7LbJNmIG vf8ZgSMXsu96kFDMsiCn5VFfrsp8j/hSAgkGGTJyNgdJDd4pCXu07HKPYPq5VdXZ55T1 ZbOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=2FPuHPcUnxQtCWYTvyX7yM9LZ48eFw1C5/KmPQ+TvO4=; b=Nc+d6sJG1C+yJMtxxnpE4LSj0Sz3z9JD5D9AHBWgqG1yDW/H+fbk09kgl++2tpzjeA 7zLc6M4sQkqctcdHNqinxP0h1s+UXrkn0sXZnLP8rfBRFnOtL2pmr/5tFd3GSvgafXdv ugJlLoQdWjbUZIpSdZUyVfOEaJlfWbZehYuqMUBkBW8nlv3kvvyI60E8ogR5+oT6Z+MQ QS/bKCqA3dREhd/IrBzzI+BzRosgrAq5bIg9MdLv4jhQ0+uhwVtRMOVtsTo5NHmLJIw8 lMsczJ3WYOljCObdPj9Lv+vOZ7oI5YELG+n5wglmnpTVyJG+xW37VeFGKGuDpJ3Tvyo4 Y5Ng== X-Gm-Message-State: AFqh2koI1F5CgTgTVYuTPbMsP0/Q0RgpHVM82y5HkuuXvqabkWi3gIPF MgmzEwfmBK7wkvU3ny94Dn0ha2TJHcg= X-Google-Smtp-Source: AMrXdXsr3UK5K28malh8jXLRNrBnQiukJ1s7bXmCGqtO7t8FNwysRAsumbMS3uy9IeAkyFJH5qTFQN14A/Q= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:ed06:f432:893:3486]) (user=surenb job=sendgmr) by 2002:a81:1495:0:b0:465:d978:9724 with SMTP id 143-20020a811495000000b00465d9789724mr6360883ywu.249.1672876964792; Wed, 04 Jan 2023 16:02:44 -0800 (PST) Date: Wed, 4 Jan 2023 16:02:40 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230105000241.1450843-1-surenb@google.com> Subject: [PATCH v2 1/1] mm: fix vma->anon_name memory leak for anonymous shmem VMAs From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: hughd@google.com, hannes@cmpxchg.org, david@redhat.com, vincent.whitchurch@axis.com, seanjc@google.com, rppt@kernel.org, shy828301@gmail.com, pasha.tatashin@soleen.com, paul.gortmaker@windriver.com, peterx@redhat.com, vbabka@suse.cz, Liam.Howlett@Oracle.com, ccross@google.com, willy@infradead.org, arnd@arndb.de, cgel.zte@gmail.com, yuzhao@google.com, bagasdotme@gmail.com, suleiman@google.com, steven@liquorix.net, heftig@archlinux.org, cuigaosheng1@huawei.com, kirill@shutemov.name, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, surenb@google.com, syzbot+91edf9178386a07d06a7@syzkaller.appspotmail.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 9E87D140009 X-Stat-Signature: p8eudh6pk4aq7zedi8hj3pet4puhjf76 X-HE-Tag: 1672876965-500236 X-HE-Meta: U2FsdGVkX1+1OiDq7ecNAn3A2sA+6d+4CxPwX3Hzyg4Shs3HQt6GMOLzfKYdl4h/0gGPveCzqix+h0TXY12WiA0BWUg5cFRYTzQFiRL9HlyRE7VRQq8KKBZB88pC1b2B2Y1+CFFCnPMeYNlTt+mYuejOfRtl4G9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Iw67UoslBtPgC6gicQ391S83xgKUVeP7vpNNKW2d8gsFg8c9+MCYDf9hmFt3Ilu6B2Qw8Q0APRWmNsmkrc6+oIQMvve+cASzRmhUWcMofLrHoTUVRK97J5IfGEsOhc+LsMFUtwyD10RvnvVhrKN1GGBgxXlAE9kods/h9SoMXST119E3RVSI7wS03R76wHfTywgyfKu8yUZC9ya2LZ7AQvxvnVbrWK7weEsMlaAYucru7zfTw2NKN5SKjbpIPIHruZtBJeH 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: free_anon_vma_name() is missing a check for anonymous shmem VMA which leads to a memory leak due to refcount not being dropped. Fix this by calling anon_vma_name_put() unconditionally. It will free vma->anon_name whenever it's non-NULL. Fixes: d09e8ca6cb93 ("mm: anonymous shared memory naming") Signed-off-by: Suren Baghdasaryan Suggested-by: David Hildenbrand Reported-by: syzbot+91edf9178386a07d06a7@syzkaller.appspotmail.com Cc: David Hildenbrand Cc: Hugh Dickins Cc: Pasha Tatashin Reviewed-by: David Hildenbrand --- applies over mm-hotfixes-unstable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm tree after reverting the original version of this patch. include/linux/mm_inline.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index e8ed225d8f7c..ff3f3f23f649 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -413,8 +413,7 @@ static inline void free_anon_vma_name(struct vm_area_struct *vma) * Not using anon_vma_name because it generates a warning if mmap_lock * is not held, which might be the case here. */ - if (!vma->vm_file) - anon_vma_name_put(vma->anon_name); + anon_vma_name_put(vma->anon_name); } static inline bool anon_vma_name_eq(struct anon_vma_name *anon_name1,