All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@ftp.linux.org.uk>
To: linux-kernel@vger.kernel.org
Cc: selinux@tycho.nsa.gov,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-security-module@vger.kernel.org
Subject: [RFC] security_getprocattr() API idiocy
Date: Tue, 13 Feb 2007 13:47:30 +0000	[thread overview]
Message-ID: <20070213134730.GA28151@ftp.linux.org.uk> (raw)
In-Reply-To: <20070213134555.GG4095@ftp.linux.org.uk>

[apologies for resend, bogus address on the original mail]

	security_getprocattr() takes a buffer + length, copies data
to it and return the actual length.  If buffer is NULL, it just returns
the right length, a-la snprintf().  Observations:
	* at least selinux ends up actually allocating the buffer of the
right size, filling it, then copying its contents to buffer and freeing
what had been allocating.
	* all users allocate buffer, then call security_getprocattr() to
fill just allocated one.
	* one place does even worse - it calls security_getprocattr() passing
it NULL and uses obtained length to allocate buffer and call
security_getprocattr() _again_.

It's bloody bogus.  In all cases we would be just as happy if it returned
the buffer it'd allocated itself.  In the best case we end up with two
allocations; in the worst it's _three_, not to mention recalculating the
contents and size.  We end up doing
	* calculate size
	* allocate buffer of that size with GFP_ATOMIC
	* fill it
	* free it
	* allocate buffer of that size with GFP_KERNEL
	* caluclate the same size
	* allocate buffer of that size with GFP_ATOMIC
	* fill it with the same string
	* copy it to buffer we's allocated with GFP_KERNEL
	* free the buffer we'd allocated with GFP_ATOMIC
I'm sorry, but could we please not mix the kernel with Vogon poetry contest?

AFAICS, the sane solution is to make security_getprocattr() return the
allocated buffer instead.  All callers would be only happy with that.
Alternatively, we can introduce a new LSM hook (security_getprocattr_sane())
and leave the original as-is.

So, do we want to keep the original variant and add a saner one in parallel
to it or should we just switch to saner API?

       reply	other threads:[~2007-02-13 13:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20070213134555.GG4095@ftp.linux.org.uk>
2007-02-13 13:47 ` Al Viro [this message]
2007-02-13 13:52 ` [RFC] security_getprocattr() API idiocy Stephen Smalley
2007-02-13 13:52   ` Stephen Smalley
2007-02-13 16:38 ` Casey Schaufler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070213134730.GA28151@ftp.linux.org.uk \
    --to=viro@ftp.linux.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=selinux@tycho.nsa.gov \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.