From: "David Schwartz" <davids@webmaster.com>
To: <torvalds@linux-foundation.org>
Cc: "Johannes Weiner" <hannes@saeurebad.de>,
"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
<clameter@sgi.com>, <penberg@cs.helsinki.fi>
Subject: RE: Why is the kfree() argument const?
Date: Fri, 18 Jan 2008 12:55:09 -0800 [thread overview]
Message-ID: <MDEHLPKNGKAHNMBLJOLKGEPKJJAC.davids@webmaster.com> (raw)
In-Reply-To: <alpine.LFD.1.00.0801180754050.2957@woody.linux-foundation.org>
> On Thu, 17 Jan 2008, David Schwartz wrote:
> > Nonsense. The 'kfree' function *destroys* the object pointer to by the
> > pointer. How can you describe that as not doing anything to the object?
>
> Here's an idea. Think it through.
>
> Why don't we need write permissions to a file to unlink it?
You cannot unlink a file. Given a file, if you were to attempt to unlink it,
what directory would you remove it from?
Unlinking a file is an operation on the directory the file is in, not on the
directory itself. We do need write permissions to the directory.
If you had only a const pointer to the data in the file, you should
definitely not be able to use that pointer to find a directory the file is
in and remove it without clearly indicating you know *exactly* what you're
doing. Given just that 'const' pointer, you're not supposed to be modifying
the data and certainly using that pointer to modify anything logically above
it.
> Here's a hint: because unlinking doesn't *write* to it. In fact, it
> doesn't read from it either. It doesn't do any access at all to that
> object, it just *removes* it.
Right. It's an operation on the directory the file is in that might have
consequences for the file.
> Is the file gone after you unlink it? Yes (modulo refcounting for
> aliasing
> "pointers" aka filenames, but that's the same for any memory manager -
> malloc/free just doesn't have any, so you could think of it as a
> non-hardlinking filesystem).
The file is gone if and only if the directory was the only thing that needed
the file to exist. A file that is only on one directory "belongs to" that
directory. So write permission to the directory is all that is needed.
What you are arguing is essentially that you should be able to remove a file
from any directory it is in just because you have write access to the file's
data.
> So you're the one who are speaking nonsense. Making something "not exist"
> is not at all the same thing as accessing it for a write (or a read). It
> is a metadata operation that doesn't conceptually change the data in any
> way, shape or form - it just makes it go away.
Making something "not exist" is a modification operation on that thing.
> And btw, exactly as with kfree(), a unlink() may well do something like
> "disk scrubbing" for security purposes, or cancel pending writes to the
> backing store. But even though it may write (or, by undoing a pending
> write, effectively "change the state") to the disk sectors that used to
> contain the file data, ONLY AN IDIOT would call it "writing to the file".
> Because "the file" is gone. Writing to the place where the file
> used to be
> is a different thing.
I agree with you about that part. I can't understand why you keep thinking
this is where our disagreement lies when I've stated at least three times
that I agree about this. The issue has nothing to do with whether or not
'kfree' modifies the particular bytes pointed to. It has to do with whether
or not 'kfree' is the kind of operation one would normally want to allow on
a 'const' object.
> So give it up. You're wrong. Freeing a memory area is not "writing to it"
> or accessing it in *any* manner, it's an operation on another level
> entirely.
Nevertheless, it's a modification operation on an object that's not supposed
to be modified.
By the way, I did think of one argument that supports your position: Suppose
you have a reference counted object. You have a 'release reference and free
if zero' function. Should it be 'const'? If not, how can a 'lookup and
reference for read' function return a const pointer to the object?
However, on balance, I think a 'release reference and free if zero' function
that operates on a const pointer is sufficiently unusual that a cast to show
you know what you're doing is not a bad thing. In this case, you know it's
safe to destroy the object through a const pointer because you *know* nobody
gave you the 'const' pointer trusting you not to destroy the object. A cast
to show you have that special knowledge is, IMO, reasonable.
DS
next prev parent reply other threads:[~2008-01-18 20:55 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <MDEHLPKNGKAHNMBLJOLKIEGIJJAC.davids@webmaster.com>
2008-01-17 21:25 ` Linus Torvalds
2008-01-17 22:28 ` David Schwartz
2008-01-17 23:10 ` Linus Torvalds
2008-01-18 0:56 ` David Schwartz
2008-01-18 1:15 ` Linus Torvalds
2008-01-18 5:02 ` David Schwartz
2008-01-18 15:38 ` Chris Friesen
2008-01-18 16:10 ` Linus Torvalds
2008-01-18 20:55 ` David Schwartz [this message]
2008-01-18 17:37 ` Olivier Galibert
2008-01-18 18:06 ` DM
2008-01-18 7:51 ` Giacomo Catenazzi
2008-01-18 8:20 ` Giacomo Catenazzi
2008-01-18 13:53 ` Andy Lutomirski
2008-01-18 17:24 ` Olivier Galibert
2008-01-18 22:29 ` J.A. Magallón
2008-01-18 23:44 ` Krzysztof Halasa
2008-01-18 13:54 ` Andy Lutomirski
2008-01-18 19:14 ` Vadim Lobanov
2008-01-18 19:31 ` Zan Lynx
2008-01-18 19:55 ` Vadim Lobanov
2008-01-18 8:30 ` Vadim Lobanov
2008-01-18 9:48 ` Jakob Oestergaard
2008-01-18 11:47 ` Giacomo A. Catenazzi
2008-01-18 14:39 ` Jakob Oestergaard
2008-01-18 19:06 ` Vadim Lobanov
2008-01-18 13:31 ` Björn Steinbrink
2008-01-18 14:53 ` Jakob Oestergaard
[not found] <fa.cHMztHfqJXv7vw5O0nQ8SdTrma0@ifi.uio.no>
[not found] ` <fa.V9M+5l8C/um5KEiBtZOjbJDQmu4@ifi.uio.no>
2013-01-12 19:18 ` antoine.trux
2013-01-13 8:10 ` Chen Gang F T
2013-01-13 17:41 ` Guenter Roeck
2013-01-14 1:45 ` Chen Gang F T
2013-01-13 20:54 ` Cong Ding
2013-01-14 1:18 ` Chen Gang F T
2008-01-18 19:10 ecolbus
-- strict thread matches above, loose matches on Subject: below --
2008-01-18 16:45 ecolbus
2008-01-18 18:20 ` Olivier Galibert
2008-01-18 12:45 ecolbus
2008-01-18 15:20 ` Giacomo A. Catenazzi
2008-01-16 16:32 Johannes Weiner
2008-01-16 16:48 ` Christoph Lameter
2008-01-16 17:34 ` Bernd Petrovitsch
2008-01-16 17:45 ` Pekka J Enberg
2008-01-16 18:39 ` Linus Torvalds
2008-01-16 22:19 ` Johannes Weiner
2008-01-16 22:20 ` Christoph Lameter
2008-01-16 22:37 ` Johannes Weiner
2008-01-16 23:13 ` Johannes Weiner
2008-01-16 23:18 ` Linus Torvalds
2008-01-16 23:16 ` Linus Torvalds
2008-01-16 22:33 ` Steven Rostedt
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=MDEHLPKNGKAHNMBLJOLKGEPKJJAC.davids@webmaster.com \
--to=davids@webmaster.com \
--cc=clameter@sgi.com \
--cc=hannes@saeurebad.de \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@cs.helsinki.fi \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®