public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/highmem: VM_BUG_ON() if offset + len > PAGE_SIZE
@ 2022-04-26 19:30 Fabio M. De Francesco
  2022-04-26 19:34 ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Fabio M. De Francesco @ 2022-04-26 19:30 UTC (permalink / raw)
  To: Andrew Morton, Ira Weiny, Catalin Marinas,
	Matthew Wilcox (Oracle), Peter Collingbourne, linux-kernel
  Cc: Fabio M. De Francesco

Add VM_BUG_ON() bounds checking to make sure that, if "offset + len>
PAGE_SIZE", memset() does not corrupt data in adjacent pages.

Cc: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
 include/linux/highmem.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 6b2d59e025c5..d54dbaae9a5e 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -380,6 +380,8 @@ static inline void memcpy_to_page(struct page *page, size_t offset,
 static inline void memzero_page(struct page *page, size_t offset, size_t len)
 {
 	char *addr = kmap_local_page(page);
+
+	VM_BUG_ON(offset + len > PAGE_SIZE);
 	memset(addr + offset, 0, len);
 	flush_dcache_page(page);
 	kunmap_local(addr);
-- 
2.34.1


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

* Re: [PATCH] mm/highmem: VM_BUG_ON() if offset + len > PAGE_SIZE
  2022-04-26 19:30 [PATCH] mm/highmem: VM_BUG_ON() if offset + len > PAGE_SIZE Fabio M. De Francesco
@ 2022-04-26 19:34 ` Andrew Morton
  2022-04-26 20:19   ` Fabio M. De Francesco
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2022-04-26 19:34 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Ira Weiny, Catalin Marinas, Matthew Wilcox (Oracle),
	Peter Collingbourne, linux-kernel

On Tue, 26 Apr 2022 21:30:20 +0200 "Fabio M. De Francesco" <fmdefrancesco@gmail.com> wrote:

> Add VM_BUG_ON() bounds checking to make sure that, if "offset + len>
> PAGE_SIZE", memset() does not corrupt data in adjacent pages.
> 

hm, why?  To match all the other functions in there?

I suppose that's logical.  Or we could just delete all the other
VM_BUG_ON()s.  Have any of them proven to be at all useful?

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

* Re: [PATCH] mm/highmem: VM_BUG_ON() if offset + len > PAGE_SIZE
  2022-04-26 19:34 ` Andrew Morton
@ 2022-04-26 20:19   ` Fabio M. De Francesco
  2022-04-26 20:48     ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Fabio M. De Francesco @ 2022-04-26 20:19 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Ira Weiny, Catalin Marinas, Matthew Wilcox (Oracle),
	Peter Collingbourne, linux-kernel

On martedì 26 aprile 2022 21:34:12 CEST Andrew Morton wrote:
> On Tue, 26 Apr 2022 21:30:20 +0200 "Fabio M. De Francesco" 
<fmdefrancesco@gmail.com> wrote:
> 
> > Add VM_BUG_ON() bounds checking to make sure that, if "offset + len>
> > PAGE_SIZE", memset() does not corrupt data in adjacent pages.
> > 
> 
> hm, why?  To match all the other functions in there?
> 
> I suppose that's logical.  Or we could just delete all the other
> VM_BUG_ON()s.  Have any of them proven to be at all useful?
> 
I am not so sure about it being so useful. I just noted that memzero_page() 
is the only function of that family that is implemented with no 
VM_BUG_ON(). I have no actual proofs of usefulness :( 

This is why yesterday I sent an "RFC Patch" (please see  
https://lore.kernel.org/lkml/20220424104806.25396-1-fmdefrancesco@gmail.com/

Soon after sending it I thought that VM_WARN_ON_ONCE() could have been 
better suited, but Ira Weiny wrote to use VM_BUG_ON() for consistency.

Now I could either delete all other VM_BUG_ON() or replace them with 
VM_WARN_ON_ONCE() (or some other macro). 

Ah, a third solution might be to leave highmem.h as it is now :)

What do you prefer?

Thanks,

Fabio



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

* Re: [PATCH] mm/highmem: VM_BUG_ON() if offset + len > PAGE_SIZE
  2022-04-26 20:19   ` Fabio M. De Francesco
@ 2022-04-26 20:48     ` Andrew Morton
  2022-04-26 21:10       ` Fabio M. De Francesco
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2022-04-26 20:48 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Ira Weiny, Catalin Marinas, Matthew Wilcox (Oracle),
	Peter Collingbourne, linux-kernel

On Tue, 26 Apr 2022 22:19:57 +0200 "Fabio M. De Francesco" <fmdefrancesco@gmail.com> wrote:

> On martedì 26 aprile 2022 21:34:12 CEST Andrew Morton wrote:
> > On Tue, 26 Apr 2022 21:30:20 +0200 "Fabio M. De Francesco" 
> <fmdefrancesco@gmail.com> wrote:
> > 
> > > Add VM_BUG_ON() bounds checking to make sure that, if "offset + len>
> > > PAGE_SIZE", memset() does not corrupt data in adjacent pages.
> > > 
> > 
> > hm, why?  To match all the other functions in there?
> > 
> > I suppose that's logical.  Or we could just delete all the other
> > VM_BUG_ON()s.  Have any of them proven to be at all useful?
> > 
> I am not so sure about it being so useful. I just noted that memzero_page() 
> is the only function of that family that is implemented with no 
> VM_BUG_ON(). I have no actual proofs of usefulness :( 
> 
> This is why yesterday I sent an "RFC Patch" (please see  
> https://lore.kernel.org/lkml/20220424104806.25396-1-fmdefrancesco@gmail.com/
> 
> Soon after sending it I thought that VM_WARN_ON_ONCE() could have been 
> better suited, but Ira Weiny wrote to use VM_BUG_ON() for consistency.
> 
> Now I could either delete all other VM_BUG_ON() or replace them with 
> VM_WARN_ON_ONCE() (or some other macro). 
> 
> Ah, a third solution might be to leave highmem.h as it is now :)
> 
> What do you prefer?

Merge this patch as-is, I guess.  Going through and removing unuseful
VM_BUG_ON()s is a separable activity.

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

* Re: [PATCH] mm/highmem: VM_BUG_ON() if offset + len > PAGE_SIZE
  2022-04-26 20:48     ` Andrew Morton
@ 2022-04-26 21:10       ` Fabio M. De Francesco
  0 siblings, 0 replies; 5+ messages in thread
From: Fabio M. De Francesco @ 2022-04-26 21:10 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Ira Weiny, Catalin Marinas, Matthew Wilcox (Oracle),
	Peter Collingbourne, linux-kernel

On martedì 26 aprile 2022 22:48:11 CEST Andrew Morton wrote:
> On Tue, 26 Apr 2022 22:19:57 +0200 "Fabio M. De Francesco" 
<fmdefrancesco@gmail.com> wrote:
> 
> > On martedì 26 aprile 2022 21:34:12 CEST Andrew Morton wrote:
> > > On Tue, 26 Apr 2022 21:30:20 +0200 "Fabio M. De Francesco" 
> > <fmdefrancesco@gmail.com> wrote:
> > > 
> > > > Add VM_BUG_ON() bounds checking to make sure that, if "offset + 
len>
> > > > PAGE_SIZE", memset() does not corrupt data in adjacent pages.
> > > > 
> > > 
> > > hm, why?  To match all the other functions in there?
> > > 
> > > I suppose that's logical.  Or we could just delete all the other
> > > VM_BUG_ON()s.  Have any of them proven to be at all useful?
> > > 
> > I am not so sure about it being so useful. I just noted that 
memzero_page() 
> > is the only function of that family that is implemented with no 
> > VM_BUG_ON(). I have no actual proofs of usefulness :( 
> > 
> > This is why yesterday I sent an "RFC Patch" (please see  
> > https://lore.kernel.org/lkml/20220424104806.25396-1-fmdefrancesco@gmail.com/
> > 
> > Soon after sending it I thought that VM_WARN_ON_ONCE() could have been 
> > better suited, but Ira Weiny wrote to use VM_BUG_ON() for consistency.
> > 
> > Now I could either delete all other VM_BUG_ON() or replace them with 
> > VM_WARN_ON_ONCE() (or some other macro). 
> > 
> > Ah, a third solution might be to leave highmem.h as it is now :)
> > 
> > What do you prefer?
> 
> Merge this patch as-is, I guess.  Going through and removing unuseful
> VM_BUG_ON()s is a separable activity.
> 
Thanks!

While at this, I've just noted that you sent a confirmation which lists all 
the patches of mine that are currently in your tree.

I see that you took v1 of "Extend and reorganize Highmem's documentation". 
I suppose that you missed the v2 of that series at
https://lore.kernel.org/lkml/20220425162400.11334-1-fmdefrancesco@gmail.com/ 

Can you please check it?

Thanks,

Fabio




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

end of thread, other threads:[~2022-04-26 21:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-26 19:30 [PATCH] mm/highmem: VM_BUG_ON() if offset + len > PAGE_SIZE Fabio M. De Francesco
2022-04-26 19:34 ` Andrew Morton
2022-04-26 20:19   ` Fabio M. De Francesco
2022-04-26 20:48     ` Andrew Morton
2022-04-26 21:10       ` Fabio M. De Francesco

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