linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/mmap: Fix fsnotify_mmap_perm() call in vm_mmap_pgoff()
@ 2025-10-03 15:58 Kiryl Shutsemau
  2025-10-03 16:25 ` Dev Jain
  2025-10-03 16:56 ` Kiryl Shutsemau
  0 siblings, 2 replies; 4+ messages in thread
From: Kiryl Shutsemau @ 2025-10-03 15:58 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes, Liam R. Howlett
  Cc: Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	linux-mm, linux-kernel, Kiryl Shutsemau, stable, Josef Bacik,
	Amir Goldstein, Jan Kara

From: Kiryl Shutsemau <kas@kernel.org>

vm_mmap_pgoff() includes a fsnotify call that allows for pre-content
hooks on mmap().

The fsnotify_mmap_perm() function takes, among other arguments, an
offset in the file in the form of loff_t. However, vm_mmap_pgoff() has
file offset in the form of pgoff. This offset needs to be converted
before being passed to fsnotify_mmap_perm().

The conversion from pgoff to loff_t is incorrect. The pgoff value needs
to be shifted left by PAGE_SHIFT to obtain loff_t, not right.

This issue was identified through code inspection.

Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
Fixes: 066e053fe208 ("fsnotify: add pre-content hooks on mmap()")
Cc: stable@vger.kernel.org
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: Amir Goldstein <amir73il@gmail.com>
Cc: Jan Kara <jack@suse.cz>
---
 mm/util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/util.c b/mm/util.c
index f814e6a59ab1..52a667157264 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -573,7 +573,7 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 
 	ret = security_mmap_file(file, prot, flag);
 	if (!ret)
-		ret = fsnotify_mmap_perm(file, prot, pgoff >> PAGE_SHIFT, len);
+		ret = fsnotify_mmap_perm(file, prot, pgoff << PAGE_SHIFT, len);
 	if (!ret) {
 		if (mmap_write_lock_killable(mm))
 			return -EINTR;
-- 
2.50.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/mmap: Fix fsnotify_mmap_perm() call in vm_mmap_pgoff()
  2025-10-03 15:58 [PATCH] mm/mmap: Fix fsnotify_mmap_perm() call in vm_mmap_pgoff() Kiryl Shutsemau
@ 2025-10-03 16:25 ` Dev Jain
  2025-10-03 16:56 ` Kiryl Shutsemau
  1 sibling, 0 replies; 4+ messages in thread
From: Dev Jain @ 2025-10-03 16:25 UTC (permalink / raw)
  To: Kiryl Shutsemau, Andrew Morton, David Hildenbrand,
	Lorenzo Stoakes, Liam R. Howlett
  Cc: Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	linux-mm, linux-kernel, Kiryl Shutsemau, stable, Josef Bacik,
	Amir Goldstein, Jan Kara


On 03/10/25 9:28 pm, Kiryl Shutsemau wrote:
> From: Kiryl Shutsemau <kas@kernel.org>
>
> vm_mmap_pgoff() includes a fsnotify call that allows for pre-content
> hooks on mmap().
>
> The fsnotify_mmap_perm() function takes, among other arguments, an
> offset in the file in the form of loff_t. However, vm_mmap_pgoff() has
> file offset in the form of pgoff. This offset needs to be converted
> before being passed to fsnotify_mmap_perm().
>
> The conversion from pgoff to loff_t is incorrect. The pgoff value needs
> to be shifted left by PAGE_SHIFT to obtain loff_t, not right.
>
> This issue was identified through code inspection.
>
> Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
> Fixes: 066e053fe208 ("fsnotify: add pre-content hooks on mmap()")
> Cc: stable@vger.kernel.org
> Cc: Josef Bacik <josef@toxicpanda.com>
> Cc: Amir Goldstein <amir73il@gmail.com>
> Cc: Jan Kara <jack@suse.cz>
> ---
>   

Reviewed-by: Dev Jain <dev.jain@arm.com>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/mmap: Fix fsnotify_mmap_perm() call in vm_mmap_pgoff()
  2025-10-03 15:58 [PATCH] mm/mmap: Fix fsnotify_mmap_perm() call in vm_mmap_pgoff() Kiryl Shutsemau
  2025-10-03 16:25 ` Dev Jain
@ 2025-10-03 16:56 ` Kiryl Shutsemau
  2025-10-03 17:07   ` Dev Jain
  1 sibling, 1 reply; 4+ messages in thread
From: Kiryl Shutsemau @ 2025-10-03 16:56 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Ryan Roberts
  Cc: Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	linux-mm, linux-kernel, stable, Josef Bacik, Amir Goldstein,
	Jan Kara

On Fri, Oct 03, 2025 at 04:58:04PM +0100, Kiryl Shutsemau wrote:
> From: Kiryl Shutsemau <kas@kernel.org>
> 
> vm_mmap_pgoff() includes a fsnotify call that allows for pre-content
> hooks on mmap().
> 
> The fsnotify_mmap_perm() function takes, among other arguments, an
> offset in the file in the form of loff_t. However, vm_mmap_pgoff() has
> file offset in the form of pgoff. This offset needs to be converted
> before being passed to fsnotify_mmap_perm().
> 
> The conversion from pgoff to loff_t is incorrect. The pgoff value needs
> to be shifted left by PAGE_SHIFT to obtain loff_t, not right.
> 
> This issue was identified through code inspection.
> 
> Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
> Fixes: 066e053fe208 ("fsnotify: add pre-content hooks on mmap()")
> Cc: stable@vger.kernel.org
> Cc: Josef Bacik <josef@toxicpanda.com>
> Cc: Amir Goldstein <amir73il@gmail.com>
> Cc: Jan Kara <jack@suse.cz>
> ---
>  mm/util.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/util.c b/mm/util.c
> index f814e6a59ab1..52a667157264 100644
> --- a/mm/util.c
> +++ b/mm/util.c
> @@ -573,7 +573,7 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
>  
>  	ret = security_mmap_file(file, prot, flag);
>  	if (!ret)
> -		ret = fsnotify_mmap_perm(file, prot, pgoff >> PAGE_SHIFT, len);
> +		ret = fsnotify_mmap_perm(file, prot, pgoff << PAGE_SHIFT, len);

It misses the case to (loff_t) and it broken for 32-bit machines.

Luckily, Ryan submitted another fix for the same bug at the almost the
same time. And he was more careful around types:

https://lore.kernel.org/all/20251003155238.2147410-1-ryan.roberts@arm.com

-- 
  Kiryl Shutsemau / Kirill A. Shutemov


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/mmap: Fix fsnotify_mmap_perm() call in vm_mmap_pgoff()
  2025-10-03 16:56 ` Kiryl Shutsemau
@ 2025-10-03 17:07   ` Dev Jain
  0 siblings, 0 replies; 4+ messages in thread
From: Dev Jain @ 2025-10-03 17:07 UTC (permalink / raw)
  To: Kiryl Shutsemau, Andrew Morton, David Hildenbrand,
	Lorenzo Stoakes, Liam R. Howlett, Ryan Roberts
  Cc: Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	linux-mm, linux-kernel, stable, Josef Bacik, Amir Goldstein,
	Jan Kara


On 03/10/25 10:26 pm, Kiryl Shutsemau wrote:
> On Fri, Oct 03, 2025 at 04:58:04PM +0100, Kiryl Shutsemau wrote:
>> From: Kiryl Shutsemau <kas@kernel.org>
>>
>> vm_mmap_pgoff() includes a fsnotify call that allows for pre-content
>> hooks on mmap().
>>
>> The fsnotify_mmap_perm() function takes, among other arguments, an
>> offset in the file in the form of loff_t. However, vm_mmap_pgoff() has
>> file offset in the form of pgoff. This offset needs to be converted
>> before being passed to fsnotify_mmap_perm().
>>
>> The conversion from pgoff to loff_t is incorrect. The pgoff value needs
>> to be shifted left by PAGE_SHIFT to obtain loff_t, not right.
>>
>> This issue was identified through code inspection.
>>
>> Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
>> Fixes: 066e053fe208 ("fsnotify: add pre-content hooks on mmap()")
>> Cc: stable@vger.kernel.org
>> Cc: Josef Bacik <josef@toxicpanda.com>
>> Cc: Amir Goldstein <amir73il@gmail.com>
>> Cc: Jan Kara <jack@suse.cz>
>> ---
>>   mm/util.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/util.c b/mm/util.c
>> index f814e6a59ab1..52a667157264 100644
>> --- a/mm/util.c
>> +++ b/mm/util.c
>> @@ -573,7 +573,7 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
>>   
>>   	ret = security_mmap_file(file, prot, flag);
>>   	if (!ret)
>> -		ret = fsnotify_mmap_perm(file, prot, pgoff >> PAGE_SHIFT, len);
>> +		ret = fsnotify_mmap_perm(file, prot, pgoff << PAGE_SHIFT, len);
> It misses the case to (loff_t) and it broken for 32-bit machines.
>
> Luckily, Ryan submitted another fix for the same bug at the almost the
> same time. And he was more careful around types:
>
> https://lore.kernel.org/all/20251003155238.2147410-1-ryan.roberts@arm.com

Oops! I need to be more careful...

>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-10-03 17:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-03 15:58 [PATCH] mm/mmap: Fix fsnotify_mmap_perm() call in vm_mmap_pgoff() Kiryl Shutsemau
2025-10-03 16:25 ` Dev Jain
2025-10-03 16:56 ` Kiryl Shutsemau
2025-10-03 17:07   ` Dev Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox