From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:44872) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghaBq-0008Rx-NE for guix-patches@gnu.org; Thu, 10 Jan 2019 08:16:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghaBm-0006mm-Lb for guix-patches@gnu.org; Thu, 10 Jan 2019 08:16:06 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:53765) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghaBm-0006mU-Hf for guix-patches@gnu.org; Thu, 10 Jan 2019 08:16:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ghaBm-0002vI-9i for guix-patches@gnu.org; Thu, 10 Jan 2019 08:16:02 -0500 Subject: [bug#33893] [PATCH v5 2/4] gnu: Add docker-engine. Resent-Message-ID: Date: Thu, 10 Jan 2019 14:15:42 +0100 From: Danny Milosavljevic Message-ID: <20190110141542.715a0274@scratchpost.org> In-Reply-To: <87k1jcew0m.fsf@gnu.org> References: <20181230121754.775-1-dannym@scratchpost.org> <20181230233903.23426-1-dannym@scratchpost.org> <20181230233903.23426-3-dannym@scratchpost.org> <87pnt9y1v0.fsf@gnu.org> <20190107194455.69823f82@scratchpost.org> <87va2z1qxl.fsf@gnu.org> <20190110032210.1242af1f@scratchpost.org> <87k1jcew0m.fsf@gnu.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; boundary="Sig_/_O0BSOIACqNHFGDwpAytbg9"; protocol="application/pgp-signature" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 33893-done@debbugs.gnu.org --Sig_/_O0BSOIACqNHFGDwpAytbg9 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Ludo, On Thu, 10 Jan 2019 09:50:49 +0100 Ludovic Court=C3=A8s wrote: > Howdy! >=20 > Danny Milosavljevic skribis: >=20 > > On Tue, 08 Jan 2019 09:42:14 +0100 > > Ludovic Court=C3=A8s wrote: > > =20 > >> > Go has peculiar ideas of how the directory layout is supposed to be = set up. > >> > I could probably figure it out - but if someone with more Go knowled= ge could > >> > step forward it would be much faster. =20 > >>=20 > >> I see Leo is Cc=E2=80=99d so we=E2=80=99ll see. :-) =20 > > > > Nevermind, I've fixed it and learned something in the process: > > > > Linux doesn't actually know the current working directory as a string. > > It only knows the inode, so if you call getcwd, what libc actually does= is > > it opendirs "..", then finds the entry with the same inode number as > > the current directory, and then returns the name of that entry. =20 According to the POSIX standard ;) > Are you sure? In the Linux port of glibc I see this: >=20 > --8<---------------cut here---------------start------------->8--- > char * > __getcwd (char *buf, size_t size) > { > char *path; > char *result; >=20 > // [=E2=80=A6] >=20 > retval =3D INLINE_SYSCALL (getcwd, 2, path, alloc_size); > --8<---------------cut here---------------end--------------->8--- >=20 > And indeed, there=E2=80=99s a =E2=80=98getcwd=E2=80=99 syscall: >=20 > --8<---------------cut here---------------start------------->8--- > $ strace -e getcwd guile -c '(getcwd)' > getcwd("/home/ludo", 100) =3D 11 > +++ exited with 0 +++ > --8<---------------cut here---------------end--------------->8--- Huh. I guess it boils down to whether the Linux "process" structure has the cwd in it as a string or as an inode. In Linux sources: static inline void get_fs_pwd(struct fs_struct *fs, struct path *pwd) { spin_lock(&fs->lock); *pwd =3D fs->pwd; path_get(pwd); spin_unlock(&fs->lock); } static void get_fs_root_and_pwd_rcu(struct fs_struct *fs, struct path *root, struct path *pwd) { unsigned seq; do { seq =3D read_seqcount_begin(&fs->seq); *root =3D fs->root; *pwd =3D fs->pwd; } while (read_seqcount_retry(&fs->seq, seq)); } struct path { struct vfsmount *mnt; struct dentry *dentry; } __randomize_layout; SYSCALL_DEFINE2(getcwd, char __user *, buf, unsigned long, size) { int error; struct path pwd, root; char *page =3D __getname(); if (!page) return -ENOMEM; rcu_read_lock(); get_fs_root_and_pwd_rcu(current->fs, &root, &pwd); error =3D -ENOENT; if (!d_unlinked(pwd.dentry)) { unsigned long len; char *cwd =3D page + PATH_MAX; int buflen =3D PATH_MAX; prepend(&cwd, &buflen, "\0", 1); error =3D prepend_path(&pwd, &root, &cwd, &buflen); rcu_read_unlock(); if (error < 0) goto out; /* Unreachable from current root */ if (error > 0) { error =3D prepend_unreachable(&cwd, &buflen); if (error) goto out; } error =3D -ERANGE; len =3D PATH_MAX + page - cwd; if (len <=3D size) { error =3D len; if (copy_to_user(buf, cwd, len)) error =3D -EFAULT; } } else { rcu_read_unlock(); } out: __putname(page); return error; } /* * Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values. * It can block. */ void set_fs_pwd(struct fs_struct *fs, const struct path *path) { struct path old_pwd; path_get(path); spin_lock(&fs->lock); write_seqcount_begin(&fs->seq); old_pwd =3D fs->pwd; fs->pwd =3D *path; <----------------- !!!! write_seqcount_end(&fs->seq); spin_unlock(&fs->lock); if (old_pwd.dentry) path_put(&old_pwd); } int ksys_chdir(const char __user *filename) { struct path path; int error; unsigned int lookup_flags =3D LOOKUP_FOLLOW | LOOKUP_DIRECTORY; retry: error =3D user_path_at(AT_FDCWD, filename, lookup_flags, &path); if (error) goto out; error =3D inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHD= IR); if (error) goto dput_and_out; set_fs_pwd(current->fs, &path); <----------------- !!! dput_and_out: path_put(&path); if (retry_estale(error, lookup_flags)) { lookup_flags |=3D LOOKUP_REVAL; goto retry; } out: return error; } SYSCALL_DEFINE1(chdir, const char __user *, filename) { return ksys_chdir(filename); } SYSCALL_DEFINE1(fchdir, unsigned int, fd) { struct fd f =3D fdget_raw(fd); int error; error =3D -EBADF; if (!f.file) goto out; error =3D -ENOTDIR; if (!d_can_lookup(f.file->f_path.dentry)) goto out_putf; error =3D inode_permission(file_inode(f.file), MAY_EXEC | MAY_CHDIR= ); if (!error) set_fs_pwd(current->fs, &f.file->f_path); out_putf: fdput(f); out: return error; } Interesting! > Thanks for taking the time to address this! No problem :) --Sig_/_O0BSOIACqNHFGDwpAytbg9 Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlw3RX4ACgkQ5xo1VCww uqW/Ngf8DrCj8kxRvkwVUpBmjoO+ywau0iykiwWhAHuQEcxyD/Rg1QYaw662in/p r0GCzjKCtxaaFrK7JmDbuwm2/5d7yaI8ABqj95Os+y+IrN47rysSuTa3LmdcbzCt YJKMoOD87vKEh3yLTvIfHOiQekTWUY+Fgac9W6ZRGCoKwN+Lz9TGPkcmNIGPrYA5 gOFX46Flka0SjPK7REbfguViR2ZLO6i8vyK/w2s4Pll+WShn15iWVzaHOr1PWDo6 o7yrMnqebXnFXdYGGghULHlvz54fRnetEN+pJZUfmenjV3VYyPS/cxpZnXfUNPKE 28B0D94VvFS4ZHjP6Pu0hD0avAHygw== =SUVE -----END PGP SIGNATURE----- --Sig_/_O0BSOIACqNHFGDwpAytbg9--