Help - Search - Members - Calendar
Full Version: HOW-TO: Mount /tmp with noexec
The Planet Forums > System Administration > HOWTOs
Pages: 1, 2, 3
SwirlDot
By default, RS servers come with everything lumped in / and a small amount partitioned for /boot and some for swap. With this current setup, you have no room for making more partitions unless you have a second hard-drive.

Recently, I found out it would be worthwhile to give /tmp it's own partition and mount it using noexec- This would protect your system from MANY local and remote exploits of rootkits being run from your /tmp folder.

First off, I want to thank everyone for their help from this thread:

http://forum.rackshack.net/showthread.php?...&threadid=27470

I am simply compiling their advice into a how-to...

What we are doing it creating a file that we will use to mount at /tmp.

CODE
cd /dev


Create 100MB file for our /tmp partition. If you need more space, make count size larger.

CODE
dd if=/dev/zero of=tmpMnt bs=1024 count=100000


Make an extended filesystem for our tmpMnt file

CODE
mke2fs /dev/tmpMnt




Backup your /tmp dir- I had mysql.sock file that I needed to recreate the symbolic link for. Other programs may use it to store cache files or whatever.

CODE
cd /

CODE
cp -R /tmp /tmp_backup


Mount the new /tmp filesystem with noexec

CODE
mount -o loop,noexec,nosuid,rw /dev/tmpMnt /tmp

CODE
chmod 0777 /tmp


Copy everything back to new /tmp and remove backup

CODE
cp -R /tmp_backup/* /tmp/

CODE
rm -rf /tmp_backup


Now we need to add this to fstab so it mounts automatically on reboots.

CODE
pico -w /etc/fstab


You should see something like this:

CODE
/dev/hda3               /                       ext3    defaults,usrquota        1 1

/dev/hda1               /boot                   ext3    defaults        1 2

none                    /dev/pts                devpts  gid=5,mode=620  0 0

none                    /proc                   proc    defaults        0 0

none                    /dev/shm                tmpfs   defaults        0 0

/dev/hda2               swap                    swap    defaults        0 0


At the bottom add

CODE
/dev/tmpMnt             /tmp                    ext2    loop,noexec,nosuid,rw  0 0


(Each space is a tab)

Ctrl + X and Y

Your done- /tmp is now mounted as noexec. You can sleep a little bit safer tonight. I created a hello world c++ and compiled it then moved it to /tmp. Upon trying to run it (even chmod +x'ed), it gives the following error:

CODE
bash: ./a.out: Permission denied


Yay! /tmp no longer has execute permissions :-D

Regards,

Steve
underzen
Ok. I'm gonna give this a shot on my cpanel server. Thanks for the howto.

http://forum.rackshack.net/showthre...&threadid=27470 this thread was great!!!!!!!!!!
ramprage
Very usefull howto, thank you very much!

One question though -

At the bottom add


dev/tmpMnt /tmp ext2 loop,noexec,rw 0 0


What does the loop feature do?
Should we add these as well?

nosuid,noatime,nodev
SwirlDot
Updated Main Tutorial
ramprage
QUOTE
Originally posted by SwirlDot

Your /etc/fstab should look like this after modifications:

CODE
/dev/hda3               /                       ext3    defaults,usrquota        1 1

/dev/hda1               /boot                   ext3    defaults        1 2

none                    /dev/pts                devpts  gid=5,mode=620  0 0

none                    /proc                   proc    defaults        0 0

none                    /dev/shm                tmpfs   defaults        0 0

/dev/hda2               swap                    swap    defaults        0 0

/dev/tmpMnt             /tmp                    ext2   loop,defaults,rw,nosuid,nodev,noexec  0 0
 


Steve - Why do you have defaults listed in your /tmp partition?
SwirlDot
Updated Main Tutorial
mickalo
QUOTE
Originally posted by SwirlDot
Hehe, it's kind of pointless I guess to have it- I'll remove it.


Was just wondering if a reboot is needed after applying these changes or does it take affect rigth away ??

Thx's
martinjr76
i got the below error though

mke2fs 1.27 (8-Mar-2002)
/dev/tmpMnt is not a block special device.

how do i solve this?
phiberoptikk
i got a "continue anyway" after that message, saying yes just worked fine...no problems so far.
martinjr76
ahh yes.. didnt notice the continue option icon_razz.gif
SwirlDot
QUOTE
Originally posted by mickalo
Was just wondering if a reboot is needed after applying these changes or does it take affect rigth away ??

Thx's


With the mount command, it should happen right away. Adding it to fstab just tells the server to remount it on reboots.

To test it did happen, type:

CODE
df -h


You should see on the last line the /dev/tmpMnt partition. If you do, then your changes have taken effect (as they should have) without a reboot.
mickalo
QUOTE
Originally posted by SwirlDot
With the mount command, it should happen right away. Adding it to fstab just tells the server to remount it on reboots.

To test it did happen, type:

CODE
df -h


You should see on the last line the /dev/tmpMnt partition. If you do, then your changes have taken effect (as they should have) without a reboot.


thx's

worked fine icon_smile.gif
mickalo
Is there a way to reverse this.. apparently it causes problems with Cpanel

this is the error we get when logging into the Cpanel control panel now when displaying current disc quota usage:
CODE
Disk usage  quota:

Device (/dev/tmpMnt) filesystem is mounted on isn't block or

character device nor it's loopback or bind mount. Skipping.

quota: Quota file not found or has wrong format. 0.00 Megabytes


this is what out fstab file looked like prior to the changes:
CODE
/dev/sda3       /       ext3    defaults,usrquota 1 1

/dev/sda1       /boot   ext3    defaults 1 2

none    /dev/pts devpts gid=5,mode=620 0 0

none    /proc   proc    defaults 0 0

none    /dev/shm tmpfs  defaults 0 0

/dev/sda2       swap    swap    defaults 0 0

/dev/fd0   /mnt/floppy auto noauto,owner,kudzu 0 0

/dev/cdrom              /mnt/cdrom              iso9660 noauto,owner,kudzu,ro 0 0

any help appreciated.

thx's
mickalo
QUOTE
Originally posted by SwirlDot
With the mount command, it should happen right away. Adding it to fstab just tells the server to remount it on reboots.

To test it did happen, type:

CODE
df -h


You should see on the last line the /dev/tmpMnt partition. If you do, then your changes have taken effect (as they should have) without a reboot.


is there any way to remove or reverse this apparently it causes problems with servers with Cpanels and disc quotas.

Need help asap icon_wink.gif

thx's
Err0r
Just so you dont get a false sense of security...

You can just do sh even if its in /tmp... noexec just stops the execute flag being set on the programs
mickalo
QUOTE
Originally posted by Err0r
Just so you dont get a false sense of security...  

You can just do [b]sh
even if its in /tmp... noexec just stops the execute flag being set on the programs [/B]


is there away to restore the fstab back to it's original settings as it was prior to the changes??
SwirlDot
QUOTE
Originally posted by mickalo
Is there a way to reverse this.. apparently it causes problems with Cpanel

this is the error we get when logging into the Cpanel control panel now when displaying current disc quota usage:
CODE
Disk usage  quota:

Device (/dev/tmpMnt) filesystem is mounted on isn't block or

character device nor it's loopback or bind mount. Skipping.

quota: Quota file not found or has wrong format. 0.00 Megabytes


this is what out fstab file looked like prior to the changes:
CODE
/dev/sda3       /       ext3    defaults,usrquota 1 1

/dev/sda1       /boot   ext3    defaults 1 2

none    /dev/pts devpts gid=5,mode=620 0 0

none    /proc   proc    defaults 0 0

none    /dev/shm tmpfs  defaults 0 0

/dev/sda2       swap    swap    defaults 0 0

/dev/fd0   /mnt/floppy auto noauto,owner,kudzu 0 0

/dev/cdrom              /mnt/cdrom              iso9660 noauto,owner,kudzu,ro 0 0

any help appreciated.

thx's


Hi- I have cPanel also but no problems. It looks like you have a Dell dual xeon I believe? Anyways, you can just remove the line from /etc/fstab and do a umount /dev/tmpMnt

Steve
mickalo
QUOTE

Hi- I have cPanel also but no problems. It looks like you have a Dell dual xeon I believe? Anyways, you can just remove the line from /etc/fstab and do a umount /dev/tmpMnt


Steve,

Yes, we are on a Dell dual xeon.

Do I first remove the line in the fstab file, then do the command: umount /dev/tmpMnt or does it matter ??

thx's
mickalo
I get this message when attempting to do umount /dev/tmpMnt

umount: /tmp: device is busy
SwirlDot
There is probably another way- But the easiet would just be to do a reboot. You may have to remake your /tmp folder and chmod it 777. You may also have to create a mysql.sock symlink to /var/lib/mysql/mysql.sock with ln -s /var/lib/mysql/mysql.sock mysql.sock in /tmp
mickalo
QUOTE
Originally posted by SwirlDot
There is probably another way- But the easiet would just be to do a reboot. You may have to remake your /tmp folder and chmod it 777. You may also have to create a mysql.sock symlink to /var/lib/mysql/mysql.sock with ln -s /var/lib/mysql/mysql.sock mysql.sock in /tmp


So I would edit the fstab file, removing the new line, reboot, then recreate the /tmp folder or remove the /tmp folder before rebooting, then recreate the /tmp folder ??

thx's
SwirlDot
QUOTE
Originally posted by mickalo
So I would edit the fstab file, removing the new line, reboot, then recreate the /tmp folder or remove the /tmp folder before rebooting, then recreate the /tmp folder ??

thx's


Edit fstab
Remove new line
Reboot with shutdown -r now
When you come back you should have no /tmp
Mkdir /tmp
chmod 0777 /tmp
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
mickalo
QUOTE
Originally posted by SwirlDot
Edit fstab
Remove new line
Reboot with shutdown -r now
When you come back you should have no /tmp
Mkdir /tmp
chmod 0777 /tmp
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock


Thanks Steve, all is back to normal again. Everything appears to be back to normal.

Thank you for your help, much appreciated. icon_wink.gif

Mickalo
SwirlDot
QUOTE
Originally posted by mickalo
Thanks Steve, all is back to normal again. Everything appears to be back to normal.

Thank you for your help, much appreciated. icon_wink.gif

Mickalo


No problem- I'm unsure what caused the problem for you, worked wonderful on my cPanel system.
mickalo
Not sure either, but I guess I'll leave it as it is for now... it's diplaying all the quotas properly now in the Cpanels... plus I couldn't change Disc Quotas in the WHM. I had to manuall edit the /etc/quota.conf then run the /scripts/fixquotas in order to make changes in an account disc quota, but now it's all working fine.

Thx's
ramprage
Guys I've found the "nodev" option to give me errors in WHM when creating accounts

- here are the errors I encounter:

edquota: Device (/dev/tmpMnt) filesystem is mounted on isn't block or character device nor it's loopback or bind mount. Skipping.
No filesystems with quota detected.

Once I removed the "nodev" option from the /tmp partition in /etc/fstab the error went away, so it may be wise to remove it from your fstab if you have it there.

I'm also getting this message after account creation:

"No filesystems with quota detected."

Any suggestions?

Just ran /scripts/fixquotas I'll let you know if that fixed anything icon_smile.gif

Update: /scripts/fixquotas did fix my problem, thanks!
SwirlDot
QUOTE
Originally posted by ramprage
Guys I've found the "nodev" option to give me errors in WHM when creating accounts

- here are the errors I encounter:

edquota: Device (/dev/tmpMnt) filesystem is mounted on isn't block or character device nor it's loopback or bind mount. Skipping.
No filesystems with quota detected.

Once I removed the "nodev" option from the /tmp partition in /etc/fstab the error went away, so it may be wise to remove it from your fstab if you have it there.

I'm also getting this message after account creation:

"No filesystems with quota detected."

Any suggestions?

Just ran /scripts/fixquotas I'll let you know if that fixed anything icon_smile.gif

Update: /scripts/fixquotas did fix my problem, thanks!


Again - Did not happen in my case. Odd, what version of cPanel you running? Do you have dual hd's? Are they scsi?
mickalo
QUOTE
Originally posted by SwirlDot
Again - Did not happen in my case. Odd, what version of cPanel you running? Do you have dual hd's? Are they scsi?


we just setup on a Dell Dual Xeon RAID5 w/(3) 73GBHD's. We are running Cpanel 6.4 at the moment, haven't upgraded yet do to all the problems with Exim and the Apache upgrades.
mickalo
QUOTE
Originally posted by ramprage
Guys I've found the "nodev" option to give me errors in WHM when creating accounts

- here are the errors I encounter:

edquota: Device (/dev/tmpMnt) filesystem is mounted on isn't block or character device nor it's loopback or bind mount. Skipping.
No filesystems with quota detected.

Once I removed the "nodev" option from the /tmp partition in /etc/fstab the error went away, so it may be wise to remove it from your fstab if you have it there.

I'm also getting this message after account creation:

"No filesystems with quota detected."

Any suggestions?

Just ran /scripts/fixquotas I'll let you know if that fixed anything icon_smile.gif

Update: /scripts/fixquotas did fix my problem, thanks!


what kind of machine are you on ?? RH version ??

Can you briefly outline the steps you did to set this up ?

Thx's
ramprage
P4 machine with single 80 gig hard drive.

WHM 7.2.0 cPanel 7.2.1-E46
RedHat 7.3 - WHM X v2.1

Simply followed SwirlDot's tutorial on the first page:
But did this for /etc/fstab

/dev/tmpMnt /tmp ext2 loop,nosuid,noexec,rw 0 0

Then rebooted my machine

Then ran /scripts/fixquotas

Seems to be working fine now icon_wink.gif
mickalo
QUOTE
Originally posted by ramprage
P4 machine with single 80 gig hard drive.

WHM 7.2.0 cPanel 7.2.1-E46  
RedHat 7.3 - WHM X v2.1

Simply followed SwirlDot's tutorial on the first page:
But did this for /etc/fstab

/dev/tmpMnt     /tmp    ext2    loop,nosuid,noexec,rw 0 0

Then rebooted my machine

Then ran /scripts/fixquotas

Seems to be working fine now icon_wink.gif


great thanks icon_smile.gif I'll give it another shot. Now that I know how to remove it if necessary.

One question, from SwrilDot instructions he says to type:
CODE
mount -o  loop,noexec,rw  /dev/tmpMnt  /tmp

can this be replaced with this instead, adding the nosuid in the command line:
CODE
mount -o  loop,nosuid,noexec,rw  /dev/tmpMnt  /tmp
without causing any problems ??

thx's
SwirlDot
Yes.
mickalo
QUOTE
Originally posted by SwirlDot
Yes.


thx's icon_wink.gif
Miso
how can I double check to make sure this set up correctly...
nature
QUOTE
Originally posted by mickalo
great thanks icon_smile.gif I'll give it another shot. Now that I know how to remove it if necessary.

mickalo, can you post a quick how-to for a dual xeon if you manage to get it working on yours? Thanks! icon_smile.gif
mickalo
QUOTE
Originally posted by nature
mickalo, can you post a quick how-to for a dual xeon if you manage to get it working on yours? Thanks! icon_smile.gif


I just followed the steps on the very first post in this thread by SwirlDot, except changed one line from this:
CODE
mount -o loop,noexec,rw  /dev/tmpMnt  /tmp

to this
CODE
mount -o  loop,noexec,nosuid,rw  /dev/tmpMnt  /tmp


eveything else is the same.
SwirlDot
QUOTE
Originally posted by Miso
how can I double check to make sure this set up correctly...


Type df -h

If you see a line with /dev/tmpMnt in it, it is working correctly.

You may also want to try and reboot and check df -h again to see if it mounts on reboot with fstab, as it should.

Regards,

Steve
nature
QUOTE
Originally posted by Err0r
Just so you dont get a false sense of security...  

You can just do [b]sh
even if its in /tmp... noexec just stops the execute flag being set on the programs [/B]

What then is the use of performing this /tmp mount procedure?
Wako
What does nodev do?
null
I followed the HOW-TO, everything went smoothly.

I created file a with the following code:

echo "HELLO WORLD!"

sh /tmp/a

will give me the output "HELLO WORLD!"

Why is that happening? I thought noexec should prevent this
SwirlDot
noexec prevents the execute mode from being set...

You can run things with..

sh ./hello.sh

But, you cannot run things with just ./hello.sh

I believe this also prevents any compiled code from being run (I tried with just ./a.out but I don't know if there is another way for the C++ program I compiled??)

-Steve
null
I just did a small test

Created file hello.c

CODE
#include <stdio.h>



int main (void)

{

       printf("Hello, World!");

       return 1;

}


Compiled the c program

cc hello.c -o hello

Tried to execure ./hello but

bash: ./hello: Permission denied

So indeed compiled programs will not be executed. What about shell scripts? Should I just chmod sh to 700?

Thanks
elor
Installed and working great but....

chkrootkit shows /dev/tmpmnt as an alias. Does anyone know if this is a problem or is there something to make it be non-aliased?

Thanks
mikejrm
anyone did this on PLESK machine? thanks...
SwirlDot
Hi, it does not matter what control panel you are using.

This HOW-TO will work on any RedHat Linux system that RackShack offers as long as you have common utilities and root priveleges.
SwirlDot
Oops, meant to edit the "add-on" posts I made because I put it all together in the first post. Accidently clicked quote instead of edit. Sorry.
sfxx
Hello, I think /var/tmp and /dev/shm also has permission like "1777". We don't have to think about those directories?
I mean should we mount those directories with noexec?

Sorry if this is a dumb question.
Thanks
Wako
What does /dev/shm do? what is in it?
sfxx
QUOTE
Originally posted by Wako
What does /dev/shm do?  what is in it?


I'm not sure... It looks like nothing is in it, but it has something to do with kernel?
elor
/var/tmp - just make it a link to /tmp.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.