Your message dated Sat, 5 Mar 2011 10:04:42 -0800
with message-id <[email protected]>
and subject line 
has caused the Debian Bug report #398831,
regarding spamassassin: File locking not thread safe (uses $$ in filename)
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)


-- 
398831: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=398831
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: spamassassin
Version: 3.1.7-1
Severity: important
Tags: patch

In /usr/share/perl5/Mail/SpamAssassin/Locker/UnixNFSSafe.pm a lock
filename is constructed using the $$ variable. However, in a
multithreaded application, like mimedefang-multiplexor, $$ has the same
value in all threads, causing errors like the following:

Nov 15 20:46:50 comedy mimedefang-multiplexor[26981]: Slave 0 stderr:
print() on closed filehandle LTMP at
/usr/share/perl5/Mail/SpamAssassin/Locker/UnixNFSSafe.pm line 146.
stat() on closed filehandle LTMP at
/usr/share/perl5/Mail/SpamAssassin/Locker/UnixNFSSafe.pm line 148.
locker: safe_unlock: failed to create lock tmpfile
/var/spool/MIMEDefang/.spamassassin/auto-whitelist.lock.comedy.dante.de.26981
at
/usr/share/perl5/Mail/SpamAssassin/Locker/UnixNFSSafe.pm line 149.
Nov 15 20:47:18 comedy mimedefang-multiplexor[26981]: Slave 3 stderr:
locker: safe_lock: unlink of temp lock
/var/spool/MIMEDefang/.spamassassin/auto-whitelist.lock.comedy.dante.de.26981
failed: No such file or directory

Solution (from the perlvar man page): Use the getpid function from
Linux::Pid.

The patch implements this, as well as some additional error checking.



-- System Information:
Debian Release: 3.1
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.6.8-2-686-smp
Locale: LANG=en_US.ISO-8859-15, LC_CTYPE=en_US.ISO-8859-15 (charmap=ISO-8859-15)

Versions of packages spamassassin depends on:
ii  libarchive-tar-perl           1.23-1     Archive::Tar - manipulate tar file
ii  libdigest-sha1-perl           2.10-1     NIST SHA-1 message digest algorith
ii  libhtml-parser-perl           3.45-2     A collection of modules that parse
ii  libsocket6-perl               0.19-1     Perl extensions for IPv6
ii  libwww-perl                   5.803-4    WWW client/server library for Perl
ii  perl                          5.8.8-6.1  Larry Wall's Practical Extraction 

-- debconf information excluded
*** /usr/share/perl5/Mail/SpamAssassin/Locker/UnixNFSSafe.pm.~4~        
2006-09-29 15:06:39.000000000 +0200
--- /usr/share/perl5/Mail/SpamAssassin/Locker/UnixNFSSafe.pm    2006-11-15 
21:12:04.529752788 +0100
***************
*** 29,34 ****
--- 29,36 ----
  use Time::Local;
  use Fcntl qw(:DEFAULT :flock);
  
+ use Linux::Pid qw(getpid);
+ 
  use vars qw{
    @ISA
  };
***************
*** 67,73 ****
    my $lock_file = "$path.lock";
    my $hname = Mail::SpamAssassin::Util::fq_hostname();
    my $lock_tmp = Mail::SpamAssassin::Util::untaint_file_path
!                                       ($path.".lock.".$hname.".".$$);
  
    # keep this for unlocking
    $self->{lock_tmp} = $lock_tmp;
--- 69,75 ----
    my $lock_file = "$path.lock";
    my $hname = Mail::SpamAssassin::Util::fq_hostname();
    my $lock_tmp = Mail::SpamAssassin::Util::untaint_file_path
!                                       ($path.".lock.".$hname.".".getpid());
  
    # keep this for unlocking
    $self->{lock_tmp} = $lock_tmp;
***************
*** 92,98 ****
      }
      # link _may_ return false even if the link _is_ created
      @stat = lstat($lock_tmp);
!     if ($stat[3] > 1) {
        dbg("locker: safe_lock: link to $lock_file: stat ok");
        $is_locked = 1;
        last;
--- 94,100 ----
      }
      # link _may_ return false even if the link _is_ created
      @stat = lstat($lock_tmp);
!     if ($#stat >= 11 && $stat[3] > 1) {
        dbg("locker: safe_lock: link to $lock_file: stat ok");
        $is_locked = 1;
        last;
***************
*** 101,107 ****
      my $now = ($#stat < 11 ? undef : $stat[10]);
      @stat = lstat($lock_file);
      my $lock_age = ($#stat < 11 ? undef : $stat[10]);
!     if (defined($lock_age) && ($now - $lock_age) > LOCK_MAX_AGE) {
        # we got a stale lock, break it
        dbg("locker: safe_lock: breaking stale $lock_file: age=" .
          (defined $lock_age ? $lock_age : "undef") . " now=$now");
--- 103,109 ----
      my $now = ($#stat < 11 ? undef : $stat[10]);
      @stat = lstat($lock_file);
      my $lock_age = ($#stat < 11 ? undef : $stat[10]);
!     if (defined $now && defined($lock_age) && ($now - $lock_age) > 
LOCK_MAX_AGE) {
        # we got a stale lock, break it
        dbg("locker: safe_lock: breaking stale $lock_file: age=" .
          (defined $lock_age ? $lock_age : "undef") . " now=$now");
***************
*** 141,147 ****
    # directly because the server's clock may be out of sync with the client's.
  
    my @stat_ourtmp;
!   sysopen(LTMP, $lock_tmp, O_CREAT|O_WRONLY|O_EXCL, 0700);
    autoflush LTMP 1;
    print LTMP "\n";
  
--- 143,152 ----
    # directly because the server's clock may be out of sync with the client's.
  
    my @stat_ourtmp;
!   if (!sysopen(LTMP, $lock_tmp, O_CREAT|O_WRONLY|O_EXCL, 0700)) {
!       warn "sysopen on $lock_tmp returned $!";
!       return;
!   }
    autoflush LTMP 1;
    print LTMP "\n";
  

--- End Message ---
--- Begin Message ---
Closing this bug, per request.



--- End Message ---

Reply via email to