Bug 7169 - cannot use accton on a append-only file
Summary: cannot use accton on a append-only file
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 2.2.6-STABLE
Hardware: Any Any
: Normal Affects Only Me
Assignee: Johan Karlsson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 1998-07-05 08:50 UTC by jonny
Modified: 2002-07-24 19:34 UTC (History)
0 users

See Also:


Attachments
acc.diff (1.75 KB, patch)
2002-07-10 19:00 UTC, Johan Karlsson
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jonny 1998-07-05 08:50:00 UTC
	I want to raise the security of my system, making heavy use of
	securelevel and file flags.  All log files should be append-only,
	ie, flagged sappend.  This worked for most files, but not for
	accounting files (accton).  acct(2) is returning EPERM for an
	append-only file as argument.

Fix: 

I don't have enough knowledge to fix, but the bug seems to
	be in the kern_acct.c file.  I've sent a message about this
	to -hackers list, and received this answer.

...
Message-Id: <199807041545.RAA13938@semyam.dinoco.de>
cc: Joao Carlos Mendes Luis <jonny@jonny.eng.br>, seggers@semyam.dinoco.de
To: hackers@FreeBSD.ORG
Subject: Re: accton on a append-only file ? 
Date: Sat, 04 Jul 1998 17:45:36 +0200
From: Stefan Eggers <seggers@semyam.dinoco.de>

> I've created the /var/account/acct file with sappend,sunlink flags,
> but accton return EPERM.  If I run accton before setting those flags,

>   This seems to be a bug, but I still have much to learn from VFS

To me, too.  It is because kern_acct.c in 2.2-stable opens the file
for writing, not for appending.  There is the problem:

        /*
         * If accounting is to be started to a file, open that file for
         * writing and make sure it's a 'normal'.
         */
        if (uap->path != NULL) {
                NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, p);
                error = vn_open(&nd, FWRITE, 0);
                if (error)
                        return (error);


Unless there is already a PR for this (check the PR database on the
FreeBSD web pages) I'd suggest sending in a new one.

> before searching for the culprit myself.  Does it deserve a send-pr,
> even without patches ?

I think it's as easy as adding FAPPEND to the mode.  The only problem
is making sure that it has no unexpected side effects.  If you like
quote this email in the PR to point at a possible way to fix it.

Stefan.
-- 
Stefan Eggers                 Lu4 yao2 zhi1 ma3 li4,
Max-Slevogt-Str. 1            ri4 jiu3 jian4 ren2 xin1.
51109 Koeln
Federal Republic of Germany

...

	Taking a quick look at ufs_vnops.c, it really seems that
	a FWRITE|O_APPEND in the vnopen() call will fix, but again
	I'm not aware of possible problems.  I've tested it at home,
	and it worked, but it would be much better if it was revised
	by a real FS hacker.
How-To-Repeat: 
	$ chflags sappend /var/account/acct
	$ accton /var/account/acct
Comment 1 Poul-Henning Kamp freebsd_committer freebsd_triage 1998-07-07 10:52:57 UTC
State Changed
From-To: open->suspended

awaiting fix & committer 
Comment 2 Johan Karlsson freebsd_committer freebsd_triage 2002-06-30 20:31:04 UTC
Responsible Changed
From-To: freebsd-bugs->johan

I will have a look at this.
Comment 3 Johan Karlsson freebsd_committer freebsd_triage 2002-07-05 20:00:15 UTC
State Changed
From-To: suspended->analyzed

This is still a problem in stable and current. 
I'm currently working on fixing this.
Comment 4 Johan Karlsson freebsd_committer freebsd_triage 2002-07-10 18:34:05 UTC
State Changed
From-To: analyzed->patched

I have committed a fix to current and will 
MFC in two weeks, unless some problem shows up.
Comment 5 Johan Karlsson freebsd_committer freebsd_triage 2002-07-10 19:00:35 UTC
FYI

the equivalent patch for 4-Stable is attached here.
It should work on any 4.x version.

/Johan K
-- 
Johan Karlsson		mailto:johan@FreeBSD.org
Comment 6 Johan Karlsson freebsd_committer freebsd_triage 2002-07-24 19:34:09 UTC
State Changed
From-To: patched->closed

Fix committed to -stable.