.\" -*- coding: UTF-8 -*- .\" Copyright (C) 2006, Janak Desai .\" and Copyright (C) 2006, 2012 Michael Kerrisk .\" .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE) .\" Licensed under the GPL .\" %%%LICENSE_END .\" .\" Patch Justification: .\" unshare system call is needed to implement, using PAM, .\" per-security_context and/or per-user namespace to provide .\" polyinstantiated directories. Using unshare and bind mounts, a .\" PAM module can create private namespace with appropriate .\" directories(based on user's security context) bind mounted on .\" public directories such as /tmp, thus providing an instance of .\" /tmp that is based on user's security context. Without the .\" unshare system call, namespace separation can only be achieved .\" by clone, which would require porting and maintaining all commands .\" such as login, and su, that establish a user session. .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH UNSHARE 2 "11 avril 2020" Linux "Manuel du programmeur Linux" .SH NOM unshare \- Désassocier certaines parties du contexte d'exécution .SH SYNOPSIS .nf \fB#define _GNU_SOURCE\fP \fB#include \fP .PP \fBint unshare(int \fP\fIflags\fP\fB);\fP .fi .SH DESCRIPTION \fBunshare\fP() allows a process (or thread) to disassociate parts of its execution context that are currently being shared with other processes (or threads). Part of the execution context, such as the mount namespace, is shared implicitly when a new process is created using \fBfork\fP(2) or \fBvfork\fP(2), while other parts, such as virtual memory, may be shared by explicit request when creating a process or thread using \fBclone\fP(2). .PP L'intérêt principal de \fBunshare\fP() est de permettre à un processus de contrôler son contexte d'exécution partagé sans avoir à créer un nouveau processus. .PP L'argument \fIflags\fP est un masque qui indique quelles parties du contexte d'exécution doivent être désassociées. Cet argument est construit comme un OU binaire entre les constantes suivantes\ : .TP \fBCLONE_FILES\fP A l'effet inverse de l'attribut \fBCLONE_FILES\fP de \fBclone\fP(2). Supprime le partage de la table des descripteurs de fichier, afin que le processus appelant ne partage plus ses descripteurs de fichier avec d'autres processus. .TP \fBCLONE_FS\fP Annuler l'effet de l'attribut \fBCLONE_FS\fP de \fBclone\fP(2). Supprime le partage des attributs de système de fichiers, afin que le processus appelant ne partage plus son répertoire racine (\fBchroot\fP(2)), son répertoire courant (\fBchdir\fP(2)) et sa valeur d'umask (\fBumask\fP(2)) avec d'autres processus. .TP \fBCLONE_NEWCGROUP\fP (depuis Linux 4.6) This flag has the same effect as the \fBclone\fP(2) \fBCLONE_NEWCGROUP\fP flag. Unshare the cgroup namespace. Use of \fBCLONE_NEWCGROUP\fP requires the \fBCAP_SYS_ADMIN\fP capability. .TP \fBCLONE_NEWIPC\fP (depuis Linux 2.6.19) This flag has the same effect as the \fBclone\fP(2) \fBCLONE_NEWIPC\fP flag. Unshare the IPC namespace, so that the calling process has a private copy of the IPC namespace which is not shared with any other process. Specifying this flag automatically implies \fBCLONE_SYSVSEM\fP as well. Use of \fBCLONE_NEWIPC\fP requires the \fBCAP_SYS_ADMIN\fP capability. .TP \fBCLONE_NEWNET\fP (depuis Linux 2.6.24) Cet attribut a le même effet que l'attribut \fBCLONE_NEWNET\fP de \fBclone\fP(2). Supprime le partage de l'espace de noms de réseau, afin que le processus appelant soit déplacé dans un nouvel espace de noms de réseau qui n'est pas partagé avec d'autres processus. \fBCLONE_NEWNET\fP nécessite la capacité \fBCAP_SYS_ADMIN\fP. .TP \fBCLONE_NEWNS\fP .\" These flag name are inconsistent: .\" CLONE_NEWNS does the same thing in clone(), but CLONE_VM, .\" CLONE_FS, and CLONE_FILES reverse the action of the clone() .\" flags of the same name. This flag has the same effect as the \fBclone\fP(2) \fBCLONE_NEWNS\fP flag. Unshare the mount namespace, so that the calling process has a private copy of its namespace which is not shared with any other process. Specifying this flag automatically implies \fBCLONE_FS\fP as well. Use of \fBCLONE_NEWNS\fP requires the \fBCAP_SYS_ADMIN\fP capability. For further information, see \fBmount_namespaces\fP(7). .TP \fBCLONE_NEWPID\fP (depuis Linux 3.8) Cet attribut a le même effet que l'attribut \fBCLONE_NEWNS\fP de \fBclone\fP(2). Supprime le partage l'espace de noms PID, afin que le processus génère un nouvel espace de noms PID qui ne soit pas partagé avec d'autres processus antérieurs et qui sera celui de ses fils. Le processus appelant \fIne change pas\fP d'espace de noms. Le premier fils créé par le processus appelant aura l'identifiant 1 et sera \fBinit\fP(1) dans le nouvel espace de noms. \fBCLONE_NEWPID\fP implique automatiquement \fBCLONE_THREAD\fP. L'utilisation de \fBCLONE_NEWPID\fP nécessite de disposer de la capacité \fBCAP_SYS_ADMIN\fP. Pour plus d'informations, consultez \fBCAP_SYS_ADMIN\fP. .TP \fBCLONE_NEWTIME\fP (since Linux 5.6) Unshare the time namespace, so that the calling process has a new time namespace for its children which is not shared with any previously existing process. The calling process is \fInot\fP moved into the new namespace. Use of \fBCLONE_NEWTIME\fP requires the \fBCAP_SYS_ADMIN\fP capability. For further information, see \fBtime_namespaces\fP(7). .TP \fBCLONE_NEWUSER\fP (depuis Linux 3.8) Cet attribut a le même effet que l'attribut \fBCLONE_NEWUSER\fP de \fBclone\fP(2). Supprime le partage de l'espace de noms de réseau, afin que le processus appelant soit déplacé dans un nouvel espace de noms utilisateur qui n'est pas partagé avec d'autres processus. Comme pour les fils créés par \fBclone\fP(2) avec l'attribut \fBCLONE_NEWUSER\fP, l'appelant obtient un ensemble de capacité dans le nouvel espace de noms. .IP .\" commit e66eded8309ebf679d3d3c1f5820d1f2ca332c71 .\" https://lwn.net/Articles/543273/ \fBCLONE_NEWUSER\fP nécessite que le processus appelant ne soit pas multi\-threadé\ ; si \fBCLONE_NEWUSER\fP est spécifié, \fBCLONE_THREAD\fP l'est automatiquement. À partir de Linux 3.9, \fBCLONE_NEWUSER\fP implique également automatiquement \fBCLONE_FS\fP. \fBCLONE_NEWUSER\fP nécessite que les identifiants utilisateur et groupe du processus appelant correspondent aux identifiants utilisateur et groupe dans l'espace de noms utilisateur du processus appelant au moment de l'appel. .IP Pour obtenir plus d'informations sur les espaces de noms utilisateur, consultez \fBuser_namespaces\fP(7). .TP \fBCLONE_NEWUTS\fP (depuis Linux 2.6.19) Cet attribut a le même effet que l'attribut \fBCLONE_NEWUTS\fP de \fBclone\fP(2). Départager l'espace de noms IPC UTS, afin que le processus appelant ait une copie privée de l'espace de noms UTS qui ne soit pas partagée avec d'autres processus. L'utilisation de \fBCLONE_NEWUTS\fP nécessite la capacité \fBCAP_SYS_ADMIN\fP. .TP \fBCLONE_SYSVSEM\fP (depuis Linux 2.6.26) .\" commit 9edff4ab1f8d82675277a04e359d0ed8bf14a7b7 .\" CLONE_NEWNS If CLONE_SIGHAND is set and signals are also being shared .\" (i.e., current->signal->count > 1), force CLONE_THREAD. Cet attribut inverse l'effet de l'attribut \fBCLONE_SYSVSEM\fP de \fBclone\fP(2). Supprime le partage des valeurs d'ajustement des sémaphores System\ V (\fIsemadj\fP), afin que le processus appelant ait une nouvelle liste \fIsemadj\fP vide qui ne soit partagée avec aucun autre processus. S'il s'agit du dernier processus ayant une référence à la liste (\fIsemadj\fP) du processus courant, alors les ajustements de cette liste sont appliqués au sémaphore correspondant, tel que décrit dans \fBsemop\fP(2). .PP .\" As at 3.9, the following forced implications also apply, .\" although the relevant flags are not yet implemented. .\" If CLONE_THREAD is set force CLONE_VM. .\" If CLONE_VM is set, force CLONE_SIGHAND. .\" .\" See kernel/fork.c::check_unshare_flags() De plus, \fBCLONE_THREAD\fP, \fBCLONE_SIGHAND\fP et \fBCLONE_VM\fP peuvent être invoqués dans \fIflags\fP si l'appelant est mono\-threadé (c'est\-à\-dire s'il ne partage pas son espace d'adressage avec un autre processus ou un autre thread). Dans ce cas, ces attributs sont sans effet. Notez également que spécifier \fBCLONE_THREAD\fP implique automatiquement \fBCLONE_VM\fP, et que spécifier \fBCLONE_VM\fP implique automatiquement \fBCLONE_SIGHAND\fP. Si le processus est multi\-threadé, alors ces attributs restent sans effet. .PP Si \fIflags\fP est nul, \fBunshare\fP() n'a aucun effet\ : le contexte d'exécution du processus appelant n'est pas modifié. .SH "VALEUR RENVOYÉE" S'il réussit l'appel renvoie zéro, sinon il renvoie \-1 et remplit \fIerrno\fP avec le code d'erreur. .SH ERREURS .TP \fBEINVAL\fP Un attribut invalide est indiqué dans \fIflags\fP. .TP \fBEINVAL\fP \fBCLONE_THREAD\fP, \fBCLONE_SIGHAND\fP ou \fBCLONE_VM\fP figurait dans \fIflags\fP, et l'appelant était multi\-threadé. .TP \fBEINVAL\fP \fBCLONE_NEWIPC\fP a été spécifié dans \fIflags\fP, mais le noyau n'a pas été configuré avec les options \fBCONFIG_SYSVIPC\fP et \fBCONFIG_IPC_NS\fP. .TP \fBEINVAL\fP \fBCLONE_NEWNET\fP a été spécifié dans \fIflags\fP, mais le noyau n'a pas été configuré avec l'option \fBCONFIG_NET_NS\fP. .TP \fBEINVAL\fP \fBCLONE_NEWPID\fP a été spécifié dans \fIflags\fP, mais le noyau n'a pas été configuré avec l'option \fBCONFIG_PID_NS\fP. .TP \fBEINVAL\fP \fBCLONE_NEWUSER\fP was specified in \fIflags\fP, but the kernel was not configured with the \fBCONFIG_USER_NS\fP option. .TP \fBEINVAL\fP \fBCLONE_NEWUTS\fP was specified in \fIflags\fP, but the kernel was not configured with the \fBCONFIG_UTS_NS\fP option. .TP \fBEINVAL\fP \fBCLONE_NEWPID\fP was specified in \fIflags\fP, but the process has previously called \fBunshare\fP() with the \fBCLONE_NEWPID\fP flag. .TP \fBENOMEM\fP Impossible d'allouer suffisamment de mémoire pour copier les parties du contexte de l'appelant qui doivent être rendues privées. .TP \fBENOSPC\fP (depuis Linux 3.7) .\" commit f2302505775fd13ba93f034206f1e2a587017929 \fBCLONE_NEWPID\fP was specified in flags, but the limit on the nesting depth of PID namespaces would have been exceeded; see \fBpid_namespaces\fP(7). .TP \fBENOSPC\fP (depuis Linux 4.9\ ; auparavant \fBEUSERS\fP) \fBCLONE_NEWUSER\fP a été spécifié dans \fIflags\fP, et l'appel provoquerait un dépassement de la limite du nombre maximum d'espace de noms utilisateur imbriqués. Consultez \fBuser_namespaces\fP(7). .IP De Linux 3.11 à Linux 4.8, l'erreur indiquée dans ce cas était \fBEUSERS\fP. .TP \fBENOSPC\fP (depuis Linux 4.9) One of the values in \fIflags\fP specified the creation of a new user namespace, but doing so would have caused the limit defined by the corresponding file in \fI/proc/sys/user\fP to be exceeded. For further details, see \fBnamespaces\fP(7). .TP \fBEPERM\fP Le processus appelant n'avait pas les privilèges appropriés pour effectuer cette opération. .TP \fBEPERM\fP \fBCLONE_NEWUSER\fP a été spécifié dans \fIflags\fP, mais l'identifiant utilisateur effectif ou l'identifiant groupe effectif de l'appelant n'a pas de correspondance dans l'espace de noms père (consultez \fBuser_namespaces\fP(7)). .TP \fBEPERM\fP (depuis Linux 3.9) .\" commit 3151527ee007b73a0ebd296010f1c0454a919c7d .\" FIXME What is the rationale for this restriction? \fBCLONE_NEWUSER\fP was specified in \fIflags\fP and the caller is in a chroot environment (i.e., the caller's root directory does not match the root directory of the mount namespace in which it resides). .TP \fBEUSERS\fP (from Linux 3.11 to Linux 4.8) \fBCLONE_NEWUSER\fP was specified in \fIflags\fP, and the limit on the number of nested user namespaces would be exceeded. See the discussion of the \fBENOSPC\fP error above. .SH VERSIONS L'appel système \fBunshare\fP() est apparu dans Linux 2.6.16. .SH CONFORMITÉ L'appel système \fBunshare\fP() est spécifique à Linux. .SH NOTES .\" FIXME all of the following needs to be reviewed for the current kernel .\" However, we can do unshare(CLONE_SIGHAND) if CLONE_SIGHAND .\" was not specified when doing clone(); i.e., unsharing .\" signal handlers is permitted if we are not actually .\" sharing signal handlers. mtk .\" However, we can do unshare(CLONE_VM) if CLONE_VM .\" was not specified when doing clone(); i.e., unsharing .\" virtual memory is permitted if we are not actually .\" sharing virtual memory. mtk .\" .\"9) Future Work .\"-------------- .\"The current implementation of unshare does not allow unsharing of .\"signals and signal handlers. Signals are complex to begin with and .\"to unshare signals and/or signal handlers of a currently running .\"process is even more complex. If in the future there is a specific .\"need to allow unsharing of signals and/or signal handlers, it can .\"be incrementally added to unshare without affecting legacy .\"applications using unshare. .\" Tous les attributs de processus qui peuvent être partagés lorsqu'un processus est créé avec \fBclone\fP(2) ne peuvent pas être rendus privés avec \fBunshare\fP(). En particulier, dans le noyau 3.8, \fBunshare\fP() n'implémente pas de drapeaux inversant les effets de \fBCLONE_SIGHAND\fP, \fBCLONE_THREAD\fP ou \fBCLONE_VM\fP. Cette fonctionnalité pourra être ajoutée plus tard si nécessaire. .SH EXEMPLES Le programme ci\-dessous est une implémentation simple de la commande \fBunshare\fP(1), qui supprime le partage d'un ou plusieurs espaces de noms et exécute la commande fournie en argument. Voici un exemple d'utilisation du programme qui exécute un shell dans un nouvel espace de noms de montage, puis vérifie que le shell initial et le nouveau shell sont bien dans les espaces de noms séparés\ : .PP .in +4n .EX $ \fBreadlink /proc/$$/ns/mnt\fP mnt:[4026531840] $ \fBsudo ./unshare \-m /bin/bash\fP # \fBreadlink /proc/$$/ns/mnt\fP mnt:[4026532325] .EE .in .PP Les deux chaînes renvoyées par \fBreadlink\fP(1) sont différentes, ce qui montre que les deux shells se trouvent dans des espaces de noms de montage différents. .SS "Source du programme" \& .EX /* unshare.c Une implémentation simple de la commande unshare(1): supprime le partage des espaces de noms et exécute une commande. */ #define _GNU_SOURCE #include #include #include #include /* Une fonction simple de gestion des erreurs\ : affiche un message d'erreur basé sur la valeur \(aqerrno\(aq et termine le processus appelant */ #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e } while (0) static void usage(char *pname) { fprintf(stderr, "Usage: %s [options] program [arg...]\en", pname); fprintf(stderr, "Options can be:\en"); fprintf(stderr, " \-C unshare cgroup namespace\en"); fprintf(stderr, " \-i unshare IPC namespace\en"); fprintf(stderr, " \-m unshare mount namespace\en"); fprintf(stderr, " \-n unshare network namespace\en"); fprintf(stderr, " \-p unshare PID namespace\en"); fprintf(stderr, " \-t unshare time namespace\en"); fprintf(stderr, " \-u unshare UTS namespace\en"); fprintf(stderr, " \-U unshare user namespace\en"); exit(EXIT_FAILURE); } int main(int argc, char *argv[]) { int flags, opt; flags = 0; while ((opt = getopt(argc, argv, "CimnptuU")) != \-1) { switch (opt) { case \(aqC\(aq: flags |= CLONE_NEWCGROUP; break; case \(aqi\(aq: flags |= CLONE_NEWIPC; break; case \(aqm\(aq: flags |= CLONE_NEWNS; break; case \(aqn\(aq: flags |= CLONE_NEWNET; break; case \(aqp\(aq: flags |= CLONE_NEWPID; break; case \(aqt\(aq: flags |= CLONE_NEWTIME; break; case \(aqu\(aq: flags |= CLONE_NEWUTS; break; case \(aqU\(aq: flags |= CLONE_NEWUSER; break; default: usage(argv[0]); } } if (optind >= argc) usage(argv[0]); if (unshare(flags) == \-1) errExit("unshare"); execvp(argv[optind], &argv[optind]); errExit("execvp"); } .EE .SH "VOIR AUSSI" \fBunshare\fP(1), \fBclone\fP(2), \fBfork\fP(2), \fBkcmp\fP(2), \fBsetns\fP(2), \fBvfork\fP(2), \fBnamespaces\fP(7) .PP .\" commit f504d47be5e8fa7ecf2bf660b18b42e6960c0eb2 \fIDocumentation/userspace\-api/unshare.rst\fP in the Linux kernel source tree (or \fIDocumentation/unshare.txt\fP before Linux 4.12) .SH COLOPHON Cette page fait partie de la publication\ 5.10 du projet \fIman\-pages\fP Linux. Une description du projet et des instructions pour signaler des anomalies et la dernière version de cette page peuvent être trouvées à l'adresse \%https://www.kernel.org/doc/man\-pages/. .SH TRADUCTION La traduction française de cette page de manuel a été créée par Christophe Blaess , Stéphan Rafin , Thierry Vignaud , François Micaux, Alain Portal , Jean-Philippe Guérard , Jean-Luc Coulon (f5ibh) , Julien Cristau , Thomas Huriaux , Nicolas François , Florentin Duneau , Simon Paillard , Denis Barbier , David Prévot , Cédric Boutillier et Frédéric Hantrais . Cette traduction est une documentation libre ; veuillez vous reporter à la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License version 3 .UE concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE. Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à .MT debian-l10n-french@lists.debian.org .ME .