Operating System - HP-UX
1829009 Members
2227 Online
109986 Solutions
New Discussion

Re: How do I re-attach an i-node

 
SOLVED
Go to solution
Tim D Fulford
Honored Contributor

How do I re-attach an i-node

Hi

I've got a process where someone had done rm whilst the process was still attached. Unfortunately I'm not able to stop this process (it will constitute an outage) and the FS is [obviously] still full.

I know the i-node number (4122 fyi). I want to re-attach it to a dummy file[handle?] so I can echo /dev/null to it. How can I re-attch the i-node?

Tim
-
11 REPLIES 11
Patrick Wallek
Honored Contributor

Re: How do I re-attach an i-node

Have a look at this article from Sys Admin magazine.
http://www.samag.com/print/documentID=16685

I'm not sure this will work for you, but it's the closest thing I can think of for what you require.
A. Clay Stephenson
Acclaimed Contributor

Re: How do I re-attach an i-node

Hi Tim:

The tool you are looking for is called 'fsdb'. However, you really don't want to use this guy as it is extrememly dangerous. Man fsdb_vxfs (or fsdb_hfs) for details. I'm not going to give you the specifics because you really don't want to do this especially on a mounted, active filesystem. I rather doubt that trying to copy to /dev/null is going to help anyway because the file is probably opened in append mode and will continue to try to write at EOF.

If it ain't broke, I can fix that.
harry d brown jr
Honored Contributor

Re: How do I re-attach an i-node

The Coroners Toolkit (TCT) has an "unrm", but it's only good for HFS filesystems. But, I'm wondering if you could modify it, especially if you have the inode? Any thoughts anyone?

live free or die
harry
Live Free or Die
Tim D Fulford
Honored Contributor

Re: How do I re-attach an i-node

Patric:
Thanks for the pointer to the sysadm site. unfortunately the documentID=16685 does not seem to exist so it throws me to the home page & I can't seem to find the areticle you are talking about? Could you expand?

Clay:
fsdb, I did have a quick look at this but did not like the warning (words to the effect) "if you use this utility you can irrevacbly loose all the data on your filesystem" - None the less I'm still curious as to how I could re-attach the i-node even if I only ever use it on "test" systems. the man page is a little fuzzy on this.

It look like shut down the process!! Outage time. I'll assign points some time tomorrow

Cheers

Tim
-
Knut Eckstein
Advisor

Re: How do I re-attach an i-node

All,

Sorry for being extremly late on this thread :-) but I'm the guy who does the port of TCT to HP-UX...and I just stumbled across this discussion via google and would like to quickly add two general points from TCT's perspective:

unrm does not work on the relationship between inode and file name, so it can't be used to reassign another filename to the inode. What unrm does is it collects all data blocks from a filesystem which are marked as free and spits them onto stdout where you then have to sort out the mess using e.g. lazarus. So it's only for recovering file data.

Even if there was a tool that could easily assign a filename to a specific inode number, Unix in general and HP-UX would keep you from doing what Tim wanted to. When the last reference to an inode is removed by rm , the inode's refcount is normally set to zero, but the inode is not marked as free. So the tool would get back to you with an error message saying that that inode was still in use. HP-UX even goes one step further and keeps the refcount at 1, even though there are no references to the inode any more...

So the only way would have been the fsdb, but with unforseable consequences for the application process, who, for the "file removal philosophy" laid out can always safely assume that a file handle he has open remains available for him until he closes it or the process terminates. Evil software uses this property to hide sniffer log files etc. by "removing" them after program startup. So looking back the process shutdown was clearly the best path.

Harry, adding vxfs support is something I keep thinking about, but is is a very large endeavor, because disk layout and internal structures of vxfs are much more complex than HFS. HFS was easy, because from the disk layout it's idential to UFS/Berkeley FFS, which is well documented.
Public information about VxFS is very scarce, only recently I found a book which goes a bit beyond the standard whitepapers: UNIX Filesystems : Evolution, Design, and Implementation by Steve D. Pate. Any additional pointers to documentation would be greatly appreciated.

Best regards,

Knut
Tim D Fulford
Honored Contributor

Re: How do I re-attach an i-node

Many thanks Knut for the reply, super late (over 1 year!!!), but useful none the less. I never actualy got 'round to doing fsdb on anything, good job really!

Regards

Tim
-
Josh Caster_1
New Member

Re: How do I re-attach an i-node

Its seems as though its been another year and I would like to know if there has been any progress on this. Basically I have an opened file which was removed and would like to unrm it. Any hp-ux or 3rd party releases? Seems easy enough if the internals were known and I am particularly talking about vfs or onlinejfs.
Thanks
Josh
Tim D Fulford
Honored Contributor

Re: How do I re-attach an i-node

Hi

Hmm, me too.. I never actually tried (actually understood is more accurate) the above.. I was too scared..
-
Tim D Fulford
Honored Contributor

Re: How do I re-attach an i-node

Hi

I'd like to re-itterate my question, as I've realised there are at least two interpretations
o A file that is STILL ATTACHED to a RUNNING process was removed. Thus the DATA within the file is DEFINITELY still intact, but unaccessable. you can spot these types of situatiions with the tool lsof.
o Someone has done rm and there are NO programs attached to it the file & it's data is destroyed.

I'm only concerned with the first case. This is a common problem e.g. when someone does "rm /var/adm/syslog/syslog.log". What they should have/intended to do is something like "> /var.adm/syslog/syslog.log".. I effectively want to do this data removel AFTER the rm has been issued.
I think Knut Eckstein is talkin partially about this. but I'm still slightly confused .. as Knut mentions a scenario similar to this..
"Evil software uses this property to hide sniffer log files etc. by "removing" them after program startup"

This implies to me the Evil software is able to hide it's log files for latter extraction... Thus I conclude the Evil software must do one of two things
1 - re-attach the i-node to the intact data
2 - attach the data to another i-node for latter extraction.
3 - spool the data into another file (OK this does not help me, as the original data is hidden and this is what I want to delete)

Just to re-itterate, I'm not interested in getting back the data.. I actually want to destroy it!!! (though reserecting the data may be useful for others)

Regards

Tim
-
Knut Eckstein
Advisor
Solution

Re: How do I re-attach an i-node

Hello Tim, hello everybody

thanks for making a number of additional, good points. I will try and answer them while at the same time improve my previous explanations.

In summary, if you rm a file that is being held open by a running process, you only lose it's "reference by name", because the directory entry is being removed. The computer prefers to know files by inode number, so the OS is still fine and the process can still read from or write to the file. The icat tool from TCT/TSK is designed to read such a file by just specifying the inode number and the file system's device file, but of course only for supported file systems. In terms of "evil software", I have not checked myself so the following is a guess: The attacker may possess low-level tools to do either 1) or 2) of what Tim has listed, but most likely he does 3) e.g. after a signal was sent to the sniffer software it could copy the data into another file... Another interesting thing in this context is that on HP-UX you cannot rm the executable of a running process. In other UNIXes you can, thus attackers sometimes do this to "hide" their malware process from disk scans by file integrity checking software like tripwire.

Tim, if you now want to destroy the data, that is quite a different story. Even if you rm a file which no process has currently open, the data is often not destroyed, contrary to what you wrote in decribing you 2nd scenario. This of course depends on the file system, but what I've seen so far with FFS/UFS/HFS for Sun/HP/*BSD, ext2/3 and JFS for Linux, (and in some sense in FAT and NTFS too) is the following:

When a file gets rm'ed, first its filename is being removed from the directory where it resided in. For multiple reasons, already this step is often times not a true erasure, but the directory entry is just marked invisible. For this reason, the fls tool of TSK is able to list names of deleted files and sometimes even the inode numbers of those deleted files. HP-UX's HFS is the exception here, it zeroizes both the name string and the inode number. (in the past, a poor man's version of fls was to just run 'strings' on a directory, but nowadays, many UNIXes disallow this).

The second step in file deletion deals with the inode. There the refcount is set to zero and the inode is marked as free in the inode allocation table. Then the disk block pointers are examined and the disk blocks are marked as free *in the disk block allocation table*, i.e. the disk blocks themselves are not zeroized, so your data remains on disk and may very well "survive" for years to come, depending on the usage pattern of the disk. HP-UX's HFS, Solaris and *BSD UFS do then zeroize the disk block pointers, which makes it harder to "undelete" the file, because you don't know which "free" disk block belonged to which former file. But the data is still there and Linux even keeps the block pointers, so there "icat" can be used to easily undelete a rm'ed file, assuming that its disk blocks are not already in use by another file. For the other UNIXes TCT offers the lazarus tool, which tries to classify disk blocks which are "officially" free, and because UFS/FFS/FFS try to allocate files contiguously on disk, success rates at least for small file sizes are not too bad.

So for really "destroying' a file in UNIX you have to overwrite it with e.g. all zeros (or multiple overwrites with alternating bit pattern, depending on you level of paranoia :-) before actually deleting it. There are "secure deletion" utilities available which perform this task, although off my head I don't know a product name for HP-UX. Such a tool may either choose to ignore file system specifics and open the file in write mode, or it may query the system via an ioctl for the actual sectors in use by the file and directly deal with those. While the first approach is easy to implement, there is the risk that the file system decides to reallocate the file to another set of disk blocks when it "sees" the write requests intended to overwrite the existing file.

Tim, your problem with this is that these tools - as far as I know - only work with files that still exist (although it should not be too hard for the implementor of such a tool to accept an inode number instead of a file name...). So in your case you would again have to re-attach using fsdb.

Clay, on a second thought, do you really think re-attaching would be that "dangerous". I mean, barring typos while using fsdb technically I think all you would have to do is create another directory entry that points to the inode number in question. Regarding updating the refcount, in HP-UX's HFS that would not even be necessary, because that is still kept at 1 even though the file has been "officially" deleted (don't know about vxfs of course).

Josh, sorry but no HP-UX/vxfs specific news from my side. I'm also not aware of a commercial offering for HP-UX. About a year ago I saw an ad for an undelete tool for AIX' JFS and JFS2. I myself did an extension of TCT/TSK to JFS for Linux, mostly to learn/study journaling file systems. This was considerably easier than vxfs/onlinejfs because the file system has been "donated" to Linux by IBM and excellent documentation about the layout of data and meta-data is available. Thus the internals in that case were known and it was not too difficult to implement, as you were stating in your post. Probably a week of coding and two weeks of testing/verification. (My JFS for Linux modul for TSK is not yet published, I'm waiting for TSK 2.0 plus I have to tie up a few loose ends here and there...)

I know I've left out some details but regretfully I'm running out of time...

Best regards,

Knut

PS: We may ask the forum admin to award some extra points for what probably is the longest running thread ever (or at least the thread with the longest intermittent breaks :-)
Tim D Fulford
Honored Contributor

Re: How do I re-attach an i-node

Knut

May thanks for the reply. I've learnt quite a few things from it. I'm giving you 10 points not so much because you answered my question, but because you told me why the answer (what I wanted from it any way) is no-can-do...

Cheers

Tim
-