LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-14-2008, 02:18 AM   #1
aus9
LQ 5k Club
 
Registered: Oct 2003
Location: Western Australia
Distribution: Icewm
Posts: 5,842

Rep: Reputation: Disabled
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
 
Old 04-15-2008, 12:12 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
For testing a chroot do 'stat -c %i /' or see http://www.linuxquestions.org/questi...64#post2315664 ?
 
Old 04-15-2008, 08:13 PM   #3
aus9
LQ 5k Club
 
Registered: Oct 2003
Location: Western Australia
Distribution: Icewm
Posts: 5,842

Original Poster
Rep: Reputation: Disabled
host stat for inode is 128 (not 2) is that bad?


2) stat for unpacked iso is different = 100663429
 
Old 04-15-2008, 08:25 PM   #4
aus9
LQ 5k Club
 
Registered: Oct 2003
Location: Western Australia
Distribution: Icewm
Posts: 5,842

Original Poster
Rep: Reputation: Disabled
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);
}
 
Old 04-15-2008, 09:12 PM   #5
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Try *argv[] in place of **argv
 
Old 04-15-2008, 09:48 PM   #6
aus9
LQ 5k Club
 
Registered: Oct 2003
Location: Western Australia
Distribution: Icewm
Posts: 5,842

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-16-2008, 07:00 AM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Compiles cleanly here.


Quote:
Originally Posted by aus9 View Post
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 View Post
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?
 
Old 04-16-2008, 07:19 AM   #8
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
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

Last edited by billymayday; 04-16-2008 at 07:21 AM.
 
Old 04-16-2008, 07:54 AM   #9
aus9
LQ 5k Club
 
Registered: Oct 2003
Location: Western Australia
Distribution: Icewm
Posts: 5,842

Original Poster
Rep: Reputation: Disabled
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
 
Old 04-17-2008, 12:01 AM   #10
aus9
LQ 5k Club
 
Registered: Oct 2003
Location: Western Australia
Distribution: Icewm
Posts: 5,842

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-17-2008, 07:01 AM   #11
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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.
 
Old 04-17-2008, 10:04 AM   #12
aus9
LQ 5k Club
 
Registered: Oct 2003
Location: Western Australia
Distribution: Icewm
Posts: 5,842

Original Poster
Rep: Reputation: Disabled
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
 
Old 04-17-2008, 11:33 AM   #13
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by aus9 View Post
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.
 
Old 04-17-2008, 07:42 PM   #14
aus9
LQ 5k Club
 
Registered: Oct 2003
Location: Western Australia
Distribution: Icewm
Posts: 5,842

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-05-2009, 06:10 AM   #15
aus9
LQ 5k Club
 
Registered: Oct 2003
Location: Western Australia
Distribution: Icewm
Posts: 5,842

Original Poster
Rep: Reputation: Disabled
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SMTP servers leaking info crimsontide Linux - Security 2 04-09-2007 01:54 PM
firefox 2.0.0.2 is leaking a lot of memory... Necronomicom Linux - Software 2 03-13-2007 12:24 AM
Leaking PF_NETLINK sockets paulbutcher Linux - Kernel 2 11-23-2006 03:37 AM
kernel leaking? caused by bittornado? restless Linux - Kernel 2 08-12-2006 03:16 PM
memory leaking in Qt program ih1008 Programming 0 10-08-2004 07:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration