selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v2 7/7] virtio_balloon: Stop calling page_address() in free_pages()
       [not found]     ` <aK9Ogjn71JoOM3w3@fedora>
@ 2025-08-28 14:53       ` Matthew Wilcox
  2025-08-30 11:48         ` Michael S. Tsirkin
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2025-08-28 14:53 UTC (permalink / raw)
  To: Vishal Moola (Oracle)
  Cc: David Hildenbrand, linux-mm, linux-kernel, Andrew Morton,
	Michael S. Tsirkin, Paul Moore, Stephen Smalley, Ondrej Mosnacek,
	selinux

On Wed, Aug 27, 2025 at 11:29:22AM -0700, Vishal Moola (Oracle) wrote:
> I imagine theres more of these lingering in the kernel, but theres so
> many callers and I only looked for the ones that were calling
> page_address() inline :(.

There's only 841 callers of free_page() and free_pages()!

It's a bit of a disease we have, to be honest,  Almost all of
them should be using kmalloc() instead.  To pick on one at random,
sel_read_bool() in security/selinux/selinuxfs.c is the implementation
of read() for some file in selinux.  All it's trying to do is output two
numbers, so it allocates an entire page of memory, prints two numbers
to it (while being VERY CAREFUL not to overflow the buffer!) and copies
the buffer to userspace.

It should just use kmalloc.  Oh, and it should avoid leaking the buffer
if security_get_bool_value() returns an error.


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

* Re: [PATCH v2 7/7] virtio_balloon: Stop calling page_address() in free_pages()
  2025-08-28 14:53       ` [PATCH v2 7/7] virtio_balloon: Stop calling page_address() in free_pages() Matthew Wilcox
@ 2025-08-30 11:48         ` Michael S. Tsirkin
  2025-09-02 13:19           ` Stephen Smalley
  0 siblings, 1 reply; 3+ messages in thread
From: Michael S. Tsirkin @ 2025-08-30 11:48 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Vishal Moola (Oracle), David Hildenbrand, linux-mm, linux-kernel,
	Andrew Morton, Paul Moore, Stephen Smalley, Ondrej Mosnacek,
	selinux

On Thu, Aug 28, 2025 at 03:53:56PM +0100, Matthew Wilcox wrote:
> On Wed, Aug 27, 2025 at 11:29:22AM -0700, Vishal Moola (Oracle) wrote:
> > I imagine theres more of these lingering in the kernel, but theres so
> > many callers and I only looked for the ones that were calling
> > page_address() inline :(.
> 
> There's only 841 callers of free_page() and free_pages()!
> 
> It's a bit of a disease we have, to be honest,  Almost all of
> them should be using kmalloc() instead.  To pick on one at random,
> sel_read_bool() in security/selinux/selinuxfs.c is the implementation
> of read() for some file in selinux.  All it's trying to do is output two
> numbers, so it allocates an entire page of memory, prints two numbers
> to it (while being VERY CAREFUL not to overflow the buffer!) and copies
> the buffer to userspace.
> 
> It should just use kmalloc.

Why even kmalloc? Why not have a small array on stack?

>  Oh, and it should avoid leaking the buffer
> if security_get_bool_value() returns an error.


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

* Re: [PATCH v2 7/7] virtio_balloon: Stop calling page_address() in free_pages()
  2025-08-30 11:48         ` Michael S. Tsirkin
@ 2025-09-02 13:19           ` Stephen Smalley
  0 siblings, 0 replies; 3+ messages in thread
From: Stephen Smalley @ 2025-09-02 13:19 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Matthew Wilcox, Vishal Moola (Oracle), David Hildenbrand,
	linux-mm, linux-kernel, Andrew Morton, Paul Moore,
	Ondrej Mosnacek, selinux

On Sat, Aug 30, 2025 at 7:48 AM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Thu, Aug 28, 2025 at 03:53:56PM +0100, Matthew Wilcox wrote:
> > On Wed, Aug 27, 2025 at 11:29:22AM -0700, Vishal Moola (Oracle) wrote:
> > > I imagine theres more of these lingering in the kernel, but theres so
> > > many callers and I only looked for the ones that were calling
> > > page_address() inline :(.
> >
> > There's only 841 callers of free_page() and free_pages()!
> >
> > It's a bit of a disease we have, to be honest,  Almost all of
> > them should be using kmalloc() instead.  To pick on one at random,
> > sel_read_bool() in security/selinux/selinuxfs.c is the implementation
> > of read() for some file in selinux.  All it's trying to do is output two
> > numbers, so it allocates an entire page of memory, prints two numbers
> > to it (while being VERY CAREFUL not to overflow the buffer!) and copies
> > the buffer to userspace.
> >
> > It should just use kmalloc.
>
> Why even kmalloc? Why not have a small array on stack?

Patch posted at
https://lore.kernel.org/selinux/20250902131107.13509-2-stephen.smalley.work@gmail.com/T/#u

>
> >  Oh, and it should avoid leaking the buffer
> > if security_get_bool_value() returns an error.

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

end of thread, other threads:[~2025-09-02 13:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250826205617.1032945-1-vishal.moola@gmail.com>
     [not found] ` <20250826205617.1032945-8-vishal.moola@gmail.com>
     [not found]   ` <5ee2b684-94d9-40be-b01c-b0538ced33bc@redhat.com>
     [not found]     ` <aK9Ogjn71JoOM3w3@fedora>
2025-08-28 14:53       ` [PATCH v2 7/7] virtio_balloon: Stop calling page_address() in free_pages() Matthew Wilcox
2025-08-30 11:48         ` Michael S. Tsirkin
2025-09-02 13:19           ` Stephen Smalley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).