LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   leaking chroot (https://www.linuxquestions.org/questions/linux-general-1/leaking-chroot-635185/)

aus9 04-14-2008 02:18 AM

leaking chroot
 
hi

I am a newbie with chroot.

I have previously successfully added a package to a live cd....RecoveryIsPossible (RIP)

2) this time I tried to use chroot with it and I have partial success

snip-------------------------------------------------
[gordy@gs ~]$ cd /a/g/isos/rip3/boot/1/
[gordy@gs 1]$ su
Password:
[root@gs 1]# chroot /a/g/isos/rip3/boot/1/ bash -i
bash-3.2# hostname
gs.net
bash-3.2# pwd
/
bash-3.2#
----------------------------------------------------

The structure /a/g/isos/ is of course non-FHS but has the same permissions as my home.

I have tried this with and without the bash -i command same result.

3) It looks like a chroot...until you notice that hostname.

I suspect that this is the reason why I am getting some errors in trying to compile a kernel under chroot and or when I tried to install newt....it gave me errors consistent with finding my host locale and not the locale of the unpacked iso.

4) any clues?

thanks for reading

unSpawn 04-15-2008 12:12 PM

For testing a chroot do 'stat -c %i /' or see http://www.linuxquestions.org/questi...64#post2315664 ?

aus9 04-15-2008 08:13 PM

host stat for inode is 128 (not 2) is that bad?


2) stat for unpacked iso is different = 100663429

aus9 04-15-2008 08:25 PM

I made your code in the link executable and tried to run it
my errors were

./chrootcode: line 6: syntax error near unexpected token `('
./chrootcode: line 6: `int main(int argc, char **argv) {'


here is the original code....LQ may have space truncation but I played with spaces between brackets and don't know what I am doing of course.

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(int argc, char **argv) {
struct stat x;

if (stat("/", &x)) {
printf("Unable to stat /");
exit(EXIT_FAILURE);
}

if (x.st_ino==2) {
printf("NOT chrooted\n");
} else {
printf("chrooted OK\n");
}
exit(EXIT_SUCCESS);
}

billymayday 04-15-2008 09:12 PM

Try *argv[] in place of **argv

aus9 04-15-2008 09:48 PM

Billy

thanks for helping as well...I used copy and paste and here is a similar error

bash-3.2# ./chrootcode
./chrootcode: line 6: syntax error near unexpected token `('
./chrootcode: line 6: `int main (int argc, char *argv[]){'

2) And does anyone know if stat of / must produce inode of 2 or is return of 128 ok?

3) Trying to be smart...I wondered if chroot on host was rooted so I swapped in the unpacked iso edition of chroot but I still get my hostname from host showing up.

unSpawn 04-16-2008 07:00 AM

Compiles cleanly here.


Quote:

Originally Posted by aus9 (Post 3122578)
And does anyone know if stat of / must produce inode of 2 or is return of 128 ok?

Yes. Must. If it's not 2 then that indicates a chroot, AFAIK.


Quote:

Originally Posted by aus9 (Post 3122578)
I wondered if chroot on host was rooted so I swapped in the unpacked iso edition of chroot but I still get my hostname from host showing up.

So what's inside your chroot wrt /etc? Did you just copy any configs over?

billymayday 04-16-2008 07:19 AM

The code's in C aus.

put it in a file (say chroot_test.c)
then compile it (gcc chroot_test.c -o chroot_test)
then run it (./chroot_test)

Both your original and my forms work btw

aus9 04-16-2008 07:54 AM

1) ok am just testing mandriva 2008.1 stat of / gives 2 inode...thats a relief.

thanks for the heads up on 2...my mdv 2008.0= the host =the real thing must have a weird glitch. Looks like I will be migrating faster than expected.

2) sorry for misleading you guys by running it as a executable file....shows I have more to learn.

3) but a repeat of normal chroot commands on 2008.1 and running hostname still gives my real host hostname...false tho it is....
gs.net

3) using gcc stuff....first attempt got a newline error so added a blank line to the c file and my host without chrooting....as expected...gives not chrooted. (So code works)

I am unable to complete the test inside the unpack at this stage as I just found out....it has not compiler.

I attempted to just copy the new c file that I called code into the unpack but get this error after chrooting into the unpack

bash-3.2# ./code
Floating point exception


but me thinks I need a gcc in there first.

4) I will have to sign off at this stage until I get my new distro up to the point where I am happy with it.

so thanks for all patience you guys have shown.

I will only post back when I sort myself out.

cheerio

aus9 04-17-2008 12:01 AM

as OP I am hijacking chroot to look at inode issues for Mandriva in case that is an issue. 2008.0 had non-2 inode for /

you can apparently run ls -i

http://www.faqs.org/docs/linux_intro/sect_03_01.html
http://www.cyberciti.biz/tips/unders...em-inodes.html
has some info on inodes but not why / must be 2

2) I have on 2008.1
[root@gs /]# ls -i
884737 etc/ 11 lost+found/ 1 proc/
524289 tmp/ 1302529 bin/ 1187841 home/
1384449 media/ 1204225 root/ 1843201 usr/
1712129 boot/ 679937 initrd/ 172033 mnt/
131073 sbin/ 376833 var/ 131 dev/
49153 lib/ 1662977 opt/ 1 sys/

where proc and sys both have inode of 1.

I am aware that both are virtual.

3) can anyone point to a link on explanation of inode numbers please.

unSpawn 04-17-2008 07:01 AM

AFAIK "/" is points to the Virtual FileSystem, maybe searching for Filesystem or VFS HOWTO/texts or a copy of "Understanding the Linux Kernel" might help.

aus9 04-17-2008 10:04 AM

thanks for that.

yet to find the exact table but
http://www.diskdatarecovery.net/linux-file-system

is a intro that we have an inode table.

2) mention of inode 2 only
http://72.14.253.104/linux?q=cache:k...lnk&cd=9&gl=au

3) beyond my comprehension but may be the key
http://www.sabi.co.uk/Notes/linuxFS.html

I had slightly better results with google inode table.

thanks again

unSpawn 04-17-2008 11:33 AM

Quote:

Originally Posted by aus9 (Post 3124207)
http://www.sabi.co.uk/Notes/linuxFS.html

Nice list of links there. I was thinking more of http://tldp.org/LDP/tlk/fs/filesystem.html or http://www.atnf.csiro.au/~rgooch/linux/vfs.txt. BTW I think you *really* want to find yourself a copy of the ULK3 to get a more complete picture (if that's what you want). Comes in handy anyway.

aus9 04-17-2008 07:42 PM

signing off for now thanks
 
I am not prepared to buy the book sorry. I was hoping for a online instruction why / had to be inode 2

your second link shows
A single inode can be pointed to by multiple dentries...explains why I had proc and sysfs with same inode. (I hope)

I was hoping to find a reference that said something like
/ inode 2 ..../root inode x etc.

2) I have not solved the probable leaking chroot as indicated by the output of hostname

3) I will only post back when others indicate (maybe on Mdv) they too have an issue with leaking chroot or I discover a new way of fixing it.

After discovering I needed to install a slack gcc and dependencies to test the chroot code....I gave up because my initial reason for doing it...on another post appears to have lapsed with that poster. He wanted to build a new kernel with RIP.

but thanks to you, my knowledge is expanding.

aus9 04-05-2009 06:10 AM

hi

I am reviving old thread because my brain hurts

ok my understanding is that....quote"
inode number
This is the number of the inode and is unique within this file system. The combination of device and inode number is unique within the Virtual File System,"

so ignoring virtual files...real files and folders should not have the same inode?

but I am wrong.

today on sidux....

Code:

env stat /
  File: `/'
  Size: 4096            Blocks: 8          IO Block: 4096  directory
Device: 801h/2049d      Inode: 2          Links: 22
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)  Gid: (    0/    root)
Access: 2009-04-05 07:22:11.000000000 +0800
Modify: 2009-04-05 13:34:53.000000000 +0800
Change: 2009-04-05 13:34:53.000000000 +0800
gordy@siduxbox:~$ env stat /mnt/
  File: `/mnt/'
  Size: 4096            Blocks: 8          IO Block: 4096  directory
Device: 801h/2049d      Inode: 376833      Links: 3
Access: (0755/drwxr-xr-x)  Uid: ( 1000/  gordy)  Gid: ( 1000/  gordy)
Access: 2009-04-05 07:17:56.000000000 +0800
Modify: 2009-04-05 07:44:55.000000000 +0800
Change: 2009-04-05 18:20:44.000000000 +0800
gordy@siduxbox:~$ env stat /mnt/a
  File: `/mnt/a'
  Size: 4096            Blocks: 8          IO Block: 4096  directory
Device: 802h/2050d      Inode: 2          Links: 7
Access: (0755/drwxr-xr-x)  Uid: ( 1000/  gordy)  Gid: ( 1000/  gordy)
Access: 2009-04-06 00:47:46.000000000 +0800
Modify: 2009-04-05 18:24:33.000000000 +0800
Change: 2009-04-05 18:24:33.000000000 +0800

So inode of 2 is supposed to be for /...no problem
but / mounts to /dev/sda1

I have a new partition called /dev/sda2 and its mount point is
/mnt/a

it could of course be called /data or anything

....on IRC at sidux...an attempt was made by worthy ppl to try and explain it....and I almost understood it....as....
for each distro installed...each mount point has the same inode internal to each and different from a different distro....but I still can not resolve the initial quote...that inodes point to files and so I should have a different indode at /mnt/a

Anyone care to offer an explanation?

So do I have a corrupt filesystem or not?

thanks for reading and I hope you enjoy me squiriming with lack of understanding heh heh


All times are GMT -5. The time now is 02:53 PM.