Invariant Properties

  • rss
  • Home

Making /tmp Safe

Bear Giles | April 6, 2011

Another quick security tip. Many attacks depend on being able to copy a file or script onto the system and executing it. The only places the average user is guaranteed to be able to write a file is their home directory and /tmp.

No user, with the possible exception of developers, needs exec or suid permissions in their home directory. The /home partition should always be mounted ‘noexec,nosuid,nodev’ unless there’s a compelling reason to allow local execution. Such as, alas, the MyEclipse IDE which installs in the user’s home directory by default.

The /home partition should never have suid permission.

The /tmp partition is a little more complicated. You generally don’t want to execute anything out of your /tmp partition… but the standard Debian/Ubuntu installers will occasionally need to do this. The problem is you never know which packages will require this and it’s easy to forget to change mount options, twice, every time you install or upgrade a package.

There’s a simple solution. Create a file called /etc/apt/apt.conf.d/local-tmp-noexec with the following content:
DPkg
{
Pre-Invoke { "mount -o remount,exec /tmp" };
Post-Invoke { "mount -o remount,noexec,nosuid,nodev /tmp" };
};

This will automatically remount the /tmp partition with exec permission before installing packages, then remove that permission once the package is installed. I also remove the ‘nosuid’ and ‘nodev’ permissions just in case they were somehow enabled.

Finally it’s usually a good idea to mount /tmp on a tmpfs device instead of a physical location. This may not be possible if you have applications that consume massive amounts of /tmp space but as a general rule you’ll get a huge performance gain with minimal problems. At most you’ll want to add some extra memory and/or use a larger than standard swap partition.

Categories
linux, security
Comments rss
Comments rss
Trackback
Trackback

« Quick Security Finds Wrapping Package Management With Immutability »

Leave a Reply

Click here to cancel reply.

You must be logged in to post a comment.

Archives

  • May 2020 (1)
  • March 2019 (1)
  • August 2018 (1)
  • May 2018 (1)
  • February 2018 (1)
  • November 2017 (4)
  • January 2017 (3)
  • June 2016 (1)
  • May 2016 (1)
  • April 2016 (2)
  • March 2016 (1)
  • February 2016 (3)
  • January 2016 (6)
  • December 2015 (2)
  • November 2015 (3)
  • October 2015 (2)
  • August 2015 (4)
  • July 2015 (2)
  • June 2015 (2)
  • January 2015 (1)
  • December 2014 (6)
  • October 2014 (1)
  • September 2014 (2)
  • August 2014 (1)
  • July 2014 (1)
  • June 2014 (2)
  • May 2014 (2)
  • April 2014 (1)
  • March 2014 (1)
  • February 2014 (3)
  • January 2014 (6)
  • December 2013 (13)
  • November 2013 (6)
  • October 2013 (3)
  • September 2013 (2)
  • August 2013 (5)
  • June 2013 (1)
  • May 2013 (2)
  • March 2013 (1)
  • November 2012 (1)
  • October 2012 (3)
  • September 2012 (2)
  • May 2012 (6)
  • January 2012 (2)
  • December 2011 (12)
  • July 2011 (1)
  • June 2011 (2)
  • May 2011 (5)
  • April 2011 (6)
  • March 2011 (4)
  • February 2011 (3)
  • October 2010 (6)
  • September 2010 (8)

Recent Posts

  • 8-bit Breadboard Computer: Good Encapsulation!
  • Where are all the posts?
  • Better Ad Blocking Through Pi-Hole and Local Caching
  • The difference between APIs and SPIs
  • Hadoop: User Impersonation with Kerberos Authentication

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Pages

  • About Me
  • Notebook: Common XML Tasks
  • Notebook: Database/Webapp Security
  • Notebook: Development Tips

Syndication

Java Code Geeks

Know Your Rights

Support Bloggers' Rights
Demand Your dotRIGHTS

Security

  • Dark Reading
  • Krebs On Security Krebs On Security
  • Naked Security Naked Security
  • Schneier on Security Schneier on Security
  • TaoSecurity TaoSecurity

Politics

  • ACLU ACLU
  • EFF EFF

News

  • Ars technica Ars technica
  • Kevin Drum at Mother Jones Kevin Drum at Mother Jones
  • Raw Story Raw Story
  • Tech Dirt Tech Dirt
  • Vice Vice

Spam Blocked

53,793 spam blocked by Akismet
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox