From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A3403B9943 for ; Fri, 10 Jul 2026 07:30:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783668615; cv=none; b=g5IcWhxmEA4aYjaTNqJHacoqzjOSwcPuZ2vBYgraqNI+SB42tSGdxsQbDqaVdbvfPU5Ctr2QGMDYxtebbC53yIaAKhLhgfs9emTb3TdbSZhIic/tA8ClaiSmNAibWQn67LUk9/8u8EhHxoISJTrTx1prADNnpzVBFwGll+CYfoA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783668615; c=relaxed/simple; bh=zr0eTI4V8nWj/xhm6o2uVl0JaNkGbq+yEhAbgXFLUGk=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=tdW9g7j4ELEwBgDL3kytmkYX0VBjX2Ni+7Rs9UxnjlB2fqKuUXYMjsqH8tZl60C1rtqlQaLP82qAT5ssiZ/Wt+7juxe4lm3X1md3/1FpTV1fZILkJd7n6U24catNzEm6QD1nVcbR0K3dv4jqAeUx8vao+SDo1ibnZ6HgEv1fuis= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bMY2Spr2; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bMY2Spr2" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-8487b7b3fc8so191256b3a.3 for ; Fri, 10 Jul 2026 00:30:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783668613; x=1784273413; darn=vger.kernel.org; h=content-type:mime-version:user-agent:references:in-reply-to:subject :cc:to:from:message-id:date:from:to:cc:subject:date:message-id :reply-to:content-type; bh=WATSgPtpfbLi/5qPX6bFc80cfd3JKyi/QUuUgx4rANk=; b=bMY2Spr2lHggjUa1eLJ1oVF1KmEPyuu0JFo977XJ9phuNhwWzpUnHb4cC4pdvkz+i2 kXank65YkmjbceLSv7lfscrC/oAjuQc5MQj3+Irhd6ItadxCBWI6IdvZ+pSx8aGTHy/3 DjJR4I8wzIgeGc8FKY/10r+U4lTmqsM3q6VkM8t3H9GiZOyhpNgavnwzQyD+a6tcx8i1 7nEUpDQkFocwYk31YOxHpxng45+niKQOqWndniV7Ojqy+vfJbraHdqSwO1NjKa8wn0Rc CD6H7wsLp0XLL02j2FmiN4EQ1pI7ffGNgR+GWFxbNSZuNEUjKAskKVSPB5rVNl18mWwI 9Lzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783668613; x=1784273413; h=content-type:mime-version:user-agent:references:in-reply-to:subject :cc:to:from:message-id:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=WATSgPtpfbLi/5qPX6bFc80cfd3JKyi/QUuUgx4rANk=; b=tSujMZXm2s+rZQDKaUz4sVzAjV0SOJKcSut/L3DILw3heXuzxXkVrWXdZy2ud7OMNX XXqsSG2i3CBTbMnVzP/X3kvrxGZRmwluG7fHMNrKV7Qz566sLqDuXoFJlLlrzlvYCp1X lAHSncjdvIgwkt2Z/JvRmwqNsCYzuJnLTDPKNRrIOlnVNa5LH1Pc5W9XpOB1tTdlqTx4 IkyjV0/d7A6ixaG18/lUU48ens4Enl/PzjM9Iap6cQITGbghJSJNVUIFHrL6M0wljhVU zV5x2a+EIzpLkSFBLNkozQmnUFTs5e8/O56ChJ9fjyYrUugTKfiC0hAe0fIJ3MC2+iRL o31A== X-Gm-Message-State: AOJu0YyAu6UJVzOWbT6uTeY3hLvEJmDArkQbbV200+cEp3GxnHlWzziJ cdgoxbiI0C92/HutwxA0SzKzipYB7paX0/wFAl94oi0agS8+pFlUlVaZ X-Gm-Gg: AfdE7cm4Agy9c7RCvrgj59CjY8UaoLteFGgpJMcrG3uuWLCorOh7VsCYEoHesz2VldX xCoVr7Vq9nVT6wQQun6Qwo2dwEdnRHolr8pWk6YiG5G7nH1QY7at+CxtwSTrrVJB4tW4n/2lsvf mbAdevamCQwdrNlPNEfnVHN+8o1s2NTMwmq64yWLH77GQD2nZAmoN/1jbGBsoSfpNTIVqufGGbt pZVlgx9gHCKCrb6FL+fTxysINZ+evFmaP71rGDqZvolv5nVo0NZKbO5MjW/tQP41IcIy5Gh1wVD 4+vE/ipTosRxIkDL1H+cfayrXCZXtVYRyhTdjbZrSzHOJ96eNHABoOXvi381izPYV4H2Yoyi+Di +XuUBcAehhabtpjWrgjAs05oeU+Aw8s3tHDf2TDs33Z2/3Rdpl8BCib2ckB39bF4eZUJCCaGDtu QIlz2efWY8Yo0dxRJ9hifebV1G5kdIONSkyINhHO9uO3kdbzODbIAoGekm3u1Snqz0fPabWQCKh 5rLQu4LGlMWrtcOHl6+xrtNRmtvvhYh9g== X-Received: by 2002:a05:6a00:8f0b:b0:846:22ea:e171 with SMTP id d2e1a72fcca58-84842fde6bcmr9857234b3a.3.1783668613389; Fri, 10 Jul 2026 00:30:13 -0700 (PDT) Received: from mars.local.gmail.com (221x241x217x81.ap221.ftth.ucom.ne.jp. [221.241.217.81]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-847f6d7a98asm9738725b3a.42.2026.07.10.00.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 00:30:11 -0700 (PDT) Date: Fri, 10 Jul 2026 16:30:08 +0900 Message-ID: From: Hajime Tazaki To: akpm@linux-foundation.org, liam@infradead.org, ljs@kernel.org, vbabka@kernel.org, jannh@google.com, pfalcato@suse.de, linux-mm@kvack.org, geert@linux-m68k.org Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: nommu: free unused resources when mremap shrinks the vma In-Reply-To: <20260710054648.924005-1-thehajime@gmail.com> References: <20260710054648.924005-1-thehajime@gmail.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII On Fri, 10 Jul 2026 14:46:48 +0900, Hajime Tazaki wrote: > > When shrinking a VMA via mremap, the bounds are modified directly: > mm/nommu.c:do_mremap() { > ... > vma->vm_end = vma->vm_start + new_len; > ... > } > This shrink the VMA without updating its bounds in the maple tree. > If the maple tree (mm->mm_mt) still contains the old bounds, a user > process could access the freed portion. The stale maple tree would > incorrectly return the shrunk VMA for an address past its new vm_end. > > This commit fixes this issue by calling vmi_shrink_vma() when shrink > happens. Additionally, if a file-backed map is to be shrunk, it reports > -EINVAL like do_munmap() does. > > The issue is reported by Sashiko review, linked below. > > Link: https://sashiko.dev/#/patchset/20260702012546.665383-1-thehajime@gmail.com > Link: https://sashiko.dev/#/patchset/20260710021028.892645-1-thehajime%40gmail.com > Signed-off-by: Hajime Tazaki I think the original issue reported by Sashiko is addressed, but found another existing issue, which might take a bit to look into detail (e.g., currently under nommu we cannot map (actually kernel_read()) /dev/zero, vma_set_anonymous() isn't called for /dev/zero on nommu, etc). So I will address this in a different patch, not in this one. -- Hajime