Skip to contentSkip to conversation

FS crash

DISCUSSION Magosányi Árpád 4 participants 13 messages Jan 13, 2004 – Feb 4, 2004 2 messages not in the archive SELinux security module

lore
Share & tools
lore
#0 lore raw

Hi!

This is a sparc64 system with kernel 2.6.1-rc2, fs type is ext3. Distrib is Debian/sid
After doing a make relabel:
silo could not find /etc/silo.conf
could boot by adding the kernel image path by hand made an e2fsck (now I know it was not a good idea):
see the output below.
I have version 1.4-1 of the selinux utilities.

I guess it is either a kernel problem or a tool incompatibility. What is the problem?
How it can be cured?
The important data (tla archives of all config files changed/added is in an lvm logical volume). What would you do to get the data out?

root@(none)-TCB:/# e2fsck -f /dev/sda1
e2fsck 1.35-WIP (21-Aug-2003)
Pass 1: Checking inodes, blocks, and sizes
Extended attribute block 246069 has reference count 1020, should be
1018.  Fix<y>? yes

Pass 2: Checking directory structure
Entry 'awk' in /etc/{arch}/++pristine-trees/unlocked/tcb-etc/tcb-etc--active/tcb-etc--active--0.1/root@szoketto--2004-sys

Entry 'awk.1.gz' in /etc/{arch}/++pristine-trees/unlocked/tcb-etc/tcb-etc--active/tcb-etc--active--0.1/root@szoketto--20s

Entry 'builtins.7.gz' in /etc/{arch}/++pristine-trees/unlocked/tcb-etc/tcb-etc--active/tcb-etc--active--0.1/root@szoketts

Entry 'dhcp-options.5.gz' in /etc/{arch}/++pristine-trees/unlocked/tcb-etc/tcb-etc--active/tcb-etc--active--0.1/root@szos

Entry 'infobrowser' in /etc/{arch}/++pristine-trees/unlocked/tcb-etc/tcb-etc--active/tcb-etc--active--0.1/root@szoketto-s

Symlink /etc/{arch}/++pristine-trees/unlocked/tcb-etc/tcb-etc--active/tcb-etc--active--0.1/root@szoketto--2004-system/tc. Clear<y>? yes

Illegal block number passed to ext2fs_unmark_block_bitmap #1920169263 for in-use block map
Illegal block number passed to ext2fs_unmark_block_bitmap #1920169263 for block bitmap for /dev/sda1
Segmentation fault

Signature · 7 lines
GNU GPL: csak tiszta forrásból


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw
Quoted 3 lines · Magosányi Árpád

Pass 1: Checking inodes, blocks, and sizes
Extended attribute block 246069 has reference count 1020, should be 1018. Fix<y>? yes

I've seen this many times on i386 machines. So far no problems have occurred, so I conclude that it's moderately harmless.

The other errors seem more serious, and a SEGV is a very serious problem. Are you in a position to build a e2fsck with debugging code and get a stack trace?

Signature · 12 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page




--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw

Hi,

Quoted 7 lines · Russell Coker
Quoted 3 lines · Magosányi Árpád

Pass 1: Checking inodes, blocks, and sizes
Extended attribute block 246069 has reference count 1020, should be 1018. Fix<y>? yes

I've seen this many times on i386 machines. So far no problems have occurred, so I conclude that it's moderately harmless.

Found it --- there's a bug in the xattr code. And yes, apart from the disk space leak, it's harmless --- *except* on symlinks.

When you have an EA block that is shared between multiple inodes; AND you then change an attribute in that on one inode, AND the new attribute value is the same as the old, then xattr computes the new EA block, finds it still in the cache, bumps the reference count on it (and the i_blocks field on the inode, incidentally), and leaves it incremented because we haven't changed EA block so there's no need to drop the refcount on the old block.

So *every* time you have more than one inode sharing an EA block and you perform an identical write to an EA, you get a leak on both i_blocks and the EA refcount.

This is a big problem for symlinks, which rely on correct i_blocks accounting to determine the difference between fast and slow symlinks. With the leak, you end up thinking that a fast symlink (ie. one small enough to be stored in the inode direct blocks) is slow, so you dereference the ascii contents of the symlink as if they were a disk block address. That typically results in EIO all over the place.

The fix is really simple: just test for (old_bh != new_bh) before incrementing the refcounts. The patch below is for ext3, but ext2 needs the same fix.

Cheers,
Stephen

fs/ext3/xattr.c renamed from fs/ext3/xattr.c.~1~ +10 -8
@@ -763,15 +763,17 @@
 				(unsigned long) new_bh->b_blocknr);
 
 			error = -EDQUOT;
-			if (DQUOT_ALLOC_BLOCK(inode, 1)) {
-				unlock_buffer(new_bh);
-				journal_release_buffer(handle, new_bh, credits);
-				goto cleanup;
+			if (new_bh != old_bh) {
+				if (DQUOT_ALLOC_BLOCK(inode, 1)) {
+					unlock_buffer(new_bh);
+					journal_release_buffer(handle, new_bh, credits);
+					goto cleanup;
+				}
+				HDR(new_bh)->h_refcount = cpu_to_le32(
+					le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
+				ea_bdebug(new_bh, "refcount now=%d",
+					  le32_to_cpu(HDR(new_bh)->h_refcount));
 			}
-			HDR(new_bh)->h_refcount = cpu_to_le32(
-				le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
-			ea_bdebug(new_bh, "refcount now=%d",
-				le32_to_cpu(HDR(new_bh)->h_refcount));
 			unlock_buffer(new_bh);
 		} else if (old_bh && header == HDR(old_bh)) {
 			/* Keep this block. No need to lock the block as we
#3 lore raw
Quoted 3 lines · Stephen C. Tweedie

The fix is really simple: just test for (old_bh != new_bh) before incrementing the refcounts. The patch below is for ext3, but ext2 needs the same fix.

When I added the handler for selinux rfs I saw the same sort of thing. Would I presume that the xattr patches from Suse would require a similar mod?

Signature · 12 lines
------------------------------------------------------
   Dale Amon     [email protected]    +44-7802-188325
       International linux systems consultancy
     Hardware & software system design, security
    and networking, systems programming and Admin
	      "Have Laptop, Will Travel"
------------------------------------------------------

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#5 lore raw
In reply to a message not in the archive

Hi,

Quoted 2 lines · Andreas Gruenbacher

Yes. A diff for 2.4 is attached. This is not exploitable by ordinary users unless selinux is used,

The leak part of it is exploitable. It just requires you to go direct to the syscalls.

The normal attribute-setting programs --- setfattr, setfacl and also SELinux's chcon and setfiles --- check the value of the attr first and don't bother trying to set it if it already has the right contents. I found the problem here mainly because SELinux-aware rpm did not have that same optimisation.

But any user going direct to syscalls to set acls or attrs manually on a file will be able to exploit the same effect.

Cheers,
Stephen

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#10 lore raw
In reply to a message not in the archive

Hi,

Quoted 3 lines · Andreas Gruenbacher

thanks for hunting this bug and for the precise analysis. The identical bug is in ext2 as well. I will send the attached patch to LKML & Andrew after verifying. Is it correct?

Looks it to me, but I'll test it.

--Stephen

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#8 lore raw
In reply to Dale Amon

Hi,

Quoted 8 lines · Dale Amon
Quoted 3 lines · Stephen C. Tweedie

The fix is really simple: just test for (old_bh != new_bh) before incrementing the refcounts. The patch below is for ext3, but ext2 needs the same fix.

When I added the handler for selinux rfs I saw the same sort of thing. Would I presume that the xattr patches from Suse would require a similar mod?

Well, I was running 2.6 so xattr was built-in, not patched, so I haven't tested the 2.4 patches; but I would imagine all 2.4 xattr patches will have the same problem.

Cheers,
Stephen

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#6 lore raw
In reply to a message not in the archive
Quoted 6 lines · Andreas Gruenbacher
Quoted 5 lines · Dale Amon
Quoted 3 lines · Stephen C. Tweedie

The fix is really simple: just test for (old_bh != new_bh) before incrementing the refcounts. The patch below is for ext3, but ext2 needs the same fix.

Quoted 7 lines
Quoted 3 lines

When I added the handler for selinux rfs I saw the same sort of thing. Would I presume that the xattr patches from Suse would require a similar mod?

Yes. A diff for 2.4 is attached. This is not exploitable by ordinary users unless selinux is used, but as Stephen said, with selinux it will result in EIO or worse.

Actually I was working with Jeff's patches for 2.6.0:

ftp://ftp.suse.com/pub/people/jeffm/reiserfs/aclea/

I haven't tried anything since test4 because when I saw the errors after adding my handler patch I thought I'd tweaked a bug inside the fs that put the project well beyond the time (for learning curve) that I had available.

Does Jeff have any updates in the works? I see his latest is 2.6.0-test11.

Signature · 12 lines
------------------------------------------------------
   Dale Amon     [email protected]    +44-7802-188325
       International linux systems consultancy
     Hardware & software system design, security
    and networking, systems programming and Admin
	      "Have Laptop, Will Travel"
------------------------------------------------------

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#7 lore raw

Hi,

Quoted 3 lines · Dale Amon

Actually I was working with Jeff's patches for 2.6.0:

ftp://ftp.suse.com/pub/people/jeffm/reiserfs/aclea/

Reiserfs's xattr stuff works with a very different on-disk encoding, and the bug here is in the on-disk management routines, not the higher-level xattr code. So I'd expect those reiserfs patches are free from the bug.

--Stephen

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#11 lore raw
In reply to a message not in the archive

Hi,

Quoted 3 lines · Andreas Gruenbacher

thanks for hunting this bug and for the precise analysis. The identical bug is in ext2 as well. I will send the attached patch to LKML & Andrew after verifying. Is it correct?

Looks OK to me, and at least the ext3 bit survives my initial stress testing using the load that was previously reproducing the bugs.

--Stephen

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#12 lore raw
In reply to Stephen C. Tweedie

Hi!

Related to this same fs crash Theodore Y. Ts'o have found some endiannes problems in e2fslibs code. But I cannot get silo to use any symlinks, despite that I have recompiled it with the patched e2fslibs.

Can it be due to this xattr bug?

Thank you all for your marvellous help.

A levelezőm azt hiszi, hogy Stephen C. Tweedie a következőeket írta:

Quoted 25 lines

Found it --- there's a bug in the xattr code. And yes, apart from the disk space leak, it's harmless --- *except* on symlinks.

When you have an EA block that is shared between multiple inodes; AND you then change an attribute in that on one inode, AND the new attribute value is the same as the old, then xattr computes the new EA block, finds it still in the cache, bumps the reference count on it (and the i_blocks field on the inode, incidentally), and leaves it incremented because we haven't changed EA block so there's no need to drop the refcount on the old block.

So *every* time you have more than one inode sharing an EA block and you perform an identical write to an EA, you get a leak on both i_blocks and the EA refcount.

This is a big problem for symlinks, which rely on correct i_blocks accounting to determine the difference between fast and slow symlinks. With the leak, you end up thinking that a fast symlink (ie. one small enough to be stored in the inode direct blocks) is slow, so you dereference the ascii contents of the symlink as if they were a disk block address. That typically results in EIO all over the place.

The fix is really simple: just test for (old_bh != new_bh) before incrementing the refcounts. The patch below is for ext3, but ext2 needs the same fix.

Signature · 7 lines
GNU GPL: csak tiszta forrásból


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#13 lore raw

Hi,

Quoted 6 lines · Magosányi Árpád

Related to this same fs crash Theodore Y. Ts'o have found some endiannes problems in e2fslibs code. But I cannot get silo to use any symlinks, despite that I have recompiled it with the patched e2fslibs.

Can it be due to this xattr bug?

Any code that is aware of fast vs. slow symlinks will not work if the i_blocks gets out of sync, so it's possible that that's a problem. But fsck (with Ted's endian fixes) should correct the i_blocks counter. If you still have silo problems reading after that, then there must be something else going on.

Cheers,
Stephen

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#14 lore raw

A levelezőm azt hiszi, hogy Stephen C. Tweedie a következőeket írta:

Quoted 5 lines

Any code that is aware of fast vs. slow symlinks will not work if the i_blocks gets out of sync, so it's possible that that's a problem. But fsck (with Ted's endian fixes) should correct the i_blocks counter. If you still have silo problems reading after that, then there must be something else going on.

Well. How to look into the problem? I wanted to insert some debugging code into the secondary loader, but it is too complicated to my simple mind. I also could not figure out how to run a debugger on it.

Signature · 7 lines
GNU GPL: csak tiszta forrásból


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.