[Pkg-samba-maint] Bug#914198: cifs-utils: after mkostemp() and unlink() cannot fstat() the file descriptor

Geoff Streeter geoff at streeter.gr
Tue Nov 20 13:45:26 GMT 2018


Package: cifs-utils
Version: 2:6.8-1
Severity: normal

Dear Maintainer,

*** Reporter, please consider answering these questions, where appropriate ***

   * What led up to the situation?
   * What exactly did you do (or not do) that was effective (or
     ineffective)?
   * What was the outcome of this action?
   * What outcome did you expect instead?

*** End of the template - remove these template lines ***
With current directory being a mount of an NTFS file system from a Windows 7
box.
I can use mkostemp() to create a file and obtain an fd
I can the fstat() the fd
I can unlink() the filename at which point /proc/<pid>/fd has an entry that
gives the file name and "(deleted)"
I can no longer fstat() the fd which I still have.



-- System Information:
Debian Release: buster/sid
  APT prefers bionic-updates
  APT policy: (500, 'bionic-updates'), (500, 'bionic-security'), (500, 'bionic'), (100, 'bionic-backports')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.15.0-38-generic (SMP w/8 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), LANGUAGE=en_GB:en (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages cifs-utils depends on:
ii  libc6         2.27-3ubuntu1
ii  libcap-ng0    0.7.7-3.1
ii  libkeyutils1  1.5.9-9.2ubuntu2
ii  libkrb5-3     1.16-2build1
ii  libpam0g      1.1.8-3.6ubuntu2
ii  libtalloc2    2.1.10-2ubuntu1
ii  libwbclient0  2:4.7.6+dfsg~ubuntu-0ubuntu2.2
ii  samba-common  2:4.7.6+dfsg~ubuntu-0ubuntu2.2

cifs-utils recommends no packages.

Versions of packages cifs-utils suggests:
ii  keyutils   1.5.9-9.2ubuntu2
pn  smbclient  <none>
pn  winbind    <none>

-- no debconf information
-------------- next part --------------
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

// Note: Run this in a current directory which resides on an NTFS file system
// on a box running Windows 7.
// My mount command returns:
// //10.0.38.34/e on /mnt type cifs (rw,relatime,vers=default,cache=strict,username=geoff,domain=,uid=6108,forceuid,gid=6116,forcegid,addr=10.0.38.34,file_mode=0755,dir_mode=0755,soft,nounix,mapposix,rsize=1048576,wsize=1048576,echo_interval=60,actimeo=1,user=geoff)
	
int statit(int fd, char *fail)
	{
	struct stat statbuf;
	int res;

	switch(res = fstat(fd, &statbuf))
		{
	case 0:
		break;
	case -1:
		perror(fail);
		res = 2;
		break;
	default:
		fprintf(stderr, "strange result from fstat()\n");
		res = 3;
		break;
		}
	return res;
	}

int main(void)
	{
	static char base[] = "APL.TEMPXXXXXX";
	size_t len = strlen(base);
	char name[len];
	int fd;
	int res;

	strcpy(name, base);
	switch(fd = mkostemp(name, O_CLOEXEC))
		{
	case -1:
		return 1;
		}
	0 == (res = statit(fd, "first try "))
&&	0 == unlink(name)
&&	0 == (res = statit(fd, "second try "))
;
	return res;
	}


More information about the Pkg-samba-maint mailing list