Return-Path: jm@dogma.slashnull.org Delivery-Date: Fri, 26 Jan 2001 19:38:05 +0000 Return-Path: Delivered-To: jm@netnoteinc.com Received: from dogma.slashnull.org (dogma.slashnull.org [212.17.35.15]) by mail.netnoteinc.com (Postfix) with ESMTP id 36CD511408D for ; Fri, 26 Jan 2001 19:34:23 +0000 (Eire) Received: (from jm@localhost) by dogma.slashnull.org (8.9.3/8.9.3) id TAA15365 for jm@netnoteinc.com; Fri, 26 Jan 2001 19:34:22 GMT Received: from lists.securityfocus.com (lists.securityfocus.com [207.126.127.68]) by dogma.slashnull.org (8.9.3/8.9.3) with ESMTP id TAA15360 for ; Fri, 26 Jan 2001 19:34:16 GMT Received: from lists.securityfocus.com (lists.securityfocus.com [207.126.127.68]) by lists.securityfocus.com (Postfix) with ESMTP id D46C524F013; Fri, 26 Jan 2001 10:19:59 -0800 (PST) Received: from LISTS.SECURITYFOCUS.COM by LISTS.SECURITYFOCUS.COM (LISTSERV-TCP/IP release 1.8d) with spool id 24079263 for SECPROG@LISTS.SECURITYFOCUS.COM; Fri, 26 Jan 2001 10:19:52 -0800 Approved-By: of@SECURITYFOCUS.COM Delivered-To: secprog@lists.securityfocus.com Received: from securityfocus.com (mail.securityfocus.com [207.126.127.78]) by lists.securityfocus.com (Postfix) with SMTP id 826E724C7F3 for ; Thu, 25 Jan 2001 17:21:49 -0800 (PST) Received: (qmail 25833 invoked by alias); 26 Jan 2001 01:21:53 -0000 Delivered-To: SECPROG@SECURITYFOCUS.COM Received: (qmail 25804 invoked from network); 26 Jan 2001 01:21:48 -0000 Received: from ma-northadams2-99.nad.adelphia.net (HELO sarah.home.blockdev.net) (24.51.232.99) by mail.securityfocus.com with SMTP; 26 Jan 2001 01:21:48 -0000 Received: from mary (Micah.internal.home.blockdev.net [10.0.0.100]) by sarah.home.blockdev.net (8.11.1/8.11.1) with SMTP id f0Q1OXq17769 for ; Thu, 25 Jan 2001 20:24:33 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2910.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Importance: Normal Message-ID: <000e01c08736$b9b674a0$6400000a@internal.home.blockdev.net> Date: Thu, 25 Jan 2001 20:24:22 -0500 Reply-To: Matt Block Sender: Secure Programming Mailing List From: Matt Block Subject: Re: Does anyone see a problem with this code? To: SECPROG@SECURITYFOCUS.COM In-Reply-To: <3A6A440E.7030808@paulbaker.net> Paul, If I understand your specification, all that is important (security-wise) for this system is that it not be used to clobber anything else on the system. You don't particularly care if the file gets mangled (so doing more than fstat is a waste of energy,) or very large (or you wouldn't use /tmp) or ... Your code appears to guarantee that other files won't get clobbered in two ways. One, by checking for symlinks. Two, by running with the priveleges of whomever called the program. Let me suggest a third way that might make improve things even a bit more... make it suid user and world executable. Then make sure that this file is the only thing on the system that owns. This has a side benefit of making the file only writeable, meaning this program will be the only thing that writes to it (so flock() and append will actually have meaning). -- Matt Brainbench Linux MVP -----Original Message----- From: Secure Programming Mailing List [mailto:SECPROG@SECURITYFOCUS.COM]On Behalf Of Paul J. Baker Sent: Saturday, January 20, 2001 9:06 PM To: SECPROG@SECURITYFOCUS.COM Subject: Does anyone see a problem with this code? I need to keep a world read/writeable file so multiple processes can stat this file to see if one of the others have made any updates to a database. This file will be stored in /tmp and since its world writable this could present some security risks if not taken care of properly. Does anyone see any problems with this code? Thanks, Paul Baker =================================== my $_dbstatfh; # file handle of the stat file my $dbstatsrc = '/tmp/dbstat'; # location of the file sub _dbstat { my $self = shift; my $ts = shift; # big avoiding security holes through race conditions stuff # first check if the file is already open (safe) unless($_dbstatfh) { # file is not open (unsafe), check if it exists if ( -e $dbstatsrc ) { # file exists. open it but do not hurt it $_dbstatfh = IO::File->new($dbstatsrc, O_RDWR) or confess "dbstat file could not be opened: $!"; } else { # the file does not exist. lets create the file by these specifications ## only create file if it does not already exist ## must be world rw-able my $tmp_umask = umask 0000; $_dbstatfh = IO::File->new($dbstatsrc, O_RDWR|O_EXCL|O_CREAT) or confess "dbstat file race condition detected: $!"; umask $tmp_umask; } # file is opened (unsafe), check that it is not a symlink -l $_dbstatfh and confess "dbstat file is a symlink!! system integrity has been comprimised!!"; # if we got this far, file is safe } if (defined $ts) { # setting new timestamp ## lock for write flock($_dbstatfh, Fcntl::LOCK_EX); ## seek to end of file for append seek($_dbstatfh, 0, 2); ## write timestamp print $_dbstatfh "$ts\n"; ## unlock flock($_dbstatfh, Fcntl::LOCK_UN); } # return current timestamp return (stat($_dbstatfh))[9]; }