Is it possible to change the process on the master or slave side of a pseudoterminal pair?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















Given a pair of pseudoterminal master and slave, and two processes communicating via them,



  • is it possible to change the process on the master side to another process?

  • is it possible to change the process on the slave side to another process?

My questions comes from 炸鱼薯条德里克's comment at Can ssh client connect to an existing shell running on a remote machine?




How is the SSH server "connect" to a shell session? It holds the master pty fd and ensure shell use the corresponding slave pty fd as its stdin/stdout/stderr. Does any SSH server provide the functionality of stealing out the corresponding master pty fd of a already running shell session? I don't think so.




Thanks.










share|improve this question






















  • A process holding fd to them, not the process of them. Two processes are possible to hold fds to the same open file description, and so the same pty. I think it's possible, for example, if these processes holding these fds allow you to communicate with them through UNIX domain socket and pass you that fd, then you can get these fd. Or simply ptrace() to the process and steal these fd out. But I have no experience of ptrace() at all.

    – 炸鱼薯条德里克
    Mar 1 at 13:48











  • Yes and yes. Of course, it's hacky (you should use a debugger) and you need the right permissions; for the case of ssh, the master side is held by a process running as root. In a script I wrote for one of your question, I was calling ptsname() on the master side of a pty to get the name of its slave side; instead of calling ptsname(), you can call read() or write().

    – mosvy
    Mar 1 at 13:49












  • It's just normally distro setup the kernel that disallow you to steal other process's fd, and most program wouldn't provide such functionality of giving out fd by UDS.

    – 炸鱼薯条德里克
    Mar 1 at 13:51











  • @炸鱼薯条德里克 It's not a "distro thing", it's a permission thing. You have to either have CAP_SYS_PTRACE or be the same user in order to attach to another process and "steal" its fds via SCM_RIGHTS (or simply run ops on them in the context of that process).

    – mosvy
    Mar 1 at 13:55






  • 1





    @炸鱼薯条德里克 I never had to turn any switch in order to be able to send fds via SCM_RIGHTS ancillary messages; and if you attach to a process with ptrace(), you can run any command in the context of that process, including sending fds via a UNIX socket.

    – mosvy
    Mar 1 at 14:02















0















Given a pair of pseudoterminal master and slave, and two processes communicating via them,



  • is it possible to change the process on the master side to another process?

  • is it possible to change the process on the slave side to another process?

My questions comes from 炸鱼薯条德里克's comment at Can ssh client connect to an existing shell running on a remote machine?




How is the SSH server "connect" to a shell session? It holds the master pty fd and ensure shell use the corresponding slave pty fd as its stdin/stdout/stderr. Does any SSH server provide the functionality of stealing out the corresponding master pty fd of a already running shell session? I don't think so.




Thanks.










share|improve this question






















  • A process holding fd to them, not the process of them. Two processes are possible to hold fds to the same open file description, and so the same pty. I think it's possible, for example, if these processes holding these fds allow you to communicate with them through UNIX domain socket and pass you that fd, then you can get these fd. Or simply ptrace() to the process and steal these fd out. But I have no experience of ptrace() at all.

    – 炸鱼薯条德里克
    Mar 1 at 13:48











  • Yes and yes. Of course, it's hacky (you should use a debugger) and you need the right permissions; for the case of ssh, the master side is held by a process running as root. In a script I wrote for one of your question, I was calling ptsname() on the master side of a pty to get the name of its slave side; instead of calling ptsname(), you can call read() or write().

    – mosvy
    Mar 1 at 13:49












  • It's just normally distro setup the kernel that disallow you to steal other process's fd, and most program wouldn't provide such functionality of giving out fd by UDS.

    – 炸鱼薯条德里克
    Mar 1 at 13:51











  • @炸鱼薯条德里克 It's not a "distro thing", it's a permission thing. You have to either have CAP_SYS_PTRACE or be the same user in order to attach to another process and "steal" its fds via SCM_RIGHTS (or simply run ops on them in the context of that process).

    – mosvy
    Mar 1 at 13:55






  • 1





    @炸鱼薯条德里克 I never had to turn any switch in order to be able to send fds via SCM_RIGHTS ancillary messages; and if you attach to a process with ptrace(), you can run any command in the context of that process, including sending fds via a UNIX socket.

    – mosvy
    Mar 1 at 14:02













0












0








0








Given a pair of pseudoterminal master and slave, and two processes communicating via them,



  • is it possible to change the process on the master side to another process?

  • is it possible to change the process on the slave side to another process?

My questions comes from 炸鱼薯条德里克's comment at Can ssh client connect to an existing shell running on a remote machine?




How is the SSH server "connect" to a shell session? It holds the master pty fd and ensure shell use the corresponding slave pty fd as its stdin/stdout/stderr. Does any SSH server provide the functionality of stealing out the corresponding master pty fd of a already running shell session? I don't think so.




Thanks.










share|improve this question














Given a pair of pseudoterminal master and slave, and two processes communicating via them,



  • is it possible to change the process on the master side to another process?

  • is it possible to change the process on the slave side to another process?

My questions comes from 炸鱼薯条德里克's comment at Can ssh client connect to an existing shell running on a remote machine?




How is the SSH server "connect" to a shell session? It holds the master pty fd and ensure shell use the corresponding slave pty fd as its stdin/stdout/stderr. Does any SSH server provide the functionality of stealing out the corresponding master pty fd of a already running shell session? I don't think so.




Thanks.







pseudoterminal






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 1 at 13:29









TimTim

28.3k78269490




28.3k78269490












  • A process holding fd to them, not the process of them. Two processes are possible to hold fds to the same open file description, and so the same pty. I think it's possible, for example, if these processes holding these fds allow you to communicate with them through UNIX domain socket and pass you that fd, then you can get these fd. Or simply ptrace() to the process and steal these fd out. But I have no experience of ptrace() at all.

    – 炸鱼薯条德里克
    Mar 1 at 13:48











  • Yes and yes. Of course, it's hacky (you should use a debugger) and you need the right permissions; for the case of ssh, the master side is held by a process running as root. In a script I wrote for one of your question, I was calling ptsname() on the master side of a pty to get the name of its slave side; instead of calling ptsname(), you can call read() or write().

    – mosvy
    Mar 1 at 13:49












  • It's just normally distro setup the kernel that disallow you to steal other process's fd, and most program wouldn't provide such functionality of giving out fd by UDS.

    – 炸鱼薯条德里克
    Mar 1 at 13:51











  • @炸鱼薯条德里克 It's not a "distro thing", it's a permission thing. You have to either have CAP_SYS_PTRACE or be the same user in order to attach to another process and "steal" its fds via SCM_RIGHTS (or simply run ops on them in the context of that process).

    – mosvy
    Mar 1 at 13:55






  • 1





    @炸鱼薯条德里克 I never had to turn any switch in order to be able to send fds via SCM_RIGHTS ancillary messages; and if you attach to a process with ptrace(), you can run any command in the context of that process, including sending fds via a UNIX socket.

    – mosvy
    Mar 1 at 14:02

















  • A process holding fd to them, not the process of them. Two processes are possible to hold fds to the same open file description, and so the same pty. I think it's possible, for example, if these processes holding these fds allow you to communicate with them through UNIX domain socket and pass you that fd, then you can get these fd. Or simply ptrace() to the process and steal these fd out. But I have no experience of ptrace() at all.

    – 炸鱼薯条德里克
    Mar 1 at 13:48











  • Yes and yes. Of course, it's hacky (you should use a debugger) and you need the right permissions; for the case of ssh, the master side is held by a process running as root. In a script I wrote for one of your question, I was calling ptsname() on the master side of a pty to get the name of its slave side; instead of calling ptsname(), you can call read() or write().

    – mosvy
    Mar 1 at 13:49












  • It's just normally distro setup the kernel that disallow you to steal other process's fd, and most program wouldn't provide such functionality of giving out fd by UDS.

    – 炸鱼薯条德里克
    Mar 1 at 13:51











  • @炸鱼薯条德里克 It's not a "distro thing", it's a permission thing. You have to either have CAP_SYS_PTRACE or be the same user in order to attach to another process and "steal" its fds via SCM_RIGHTS (or simply run ops on them in the context of that process).

    – mosvy
    Mar 1 at 13:55






  • 1





    @炸鱼薯条德里克 I never had to turn any switch in order to be able to send fds via SCM_RIGHTS ancillary messages; and if you attach to a process with ptrace(), you can run any command in the context of that process, including sending fds via a UNIX socket.

    – mosvy
    Mar 1 at 14:02
















A process holding fd to them, not the process of them. Two processes are possible to hold fds to the same open file description, and so the same pty. I think it's possible, for example, if these processes holding these fds allow you to communicate with them through UNIX domain socket and pass you that fd, then you can get these fd. Or simply ptrace() to the process and steal these fd out. But I have no experience of ptrace() at all.

– 炸鱼薯条德里克
Mar 1 at 13:48





A process holding fd to them, not the process of them. Two processes are possible to hold fds to the same open file description, and so the same pty. I think it's possible, for example, if these processes holding these fds allow you to communicate with them through UNIX domain socket and pass you that fd, then you can get these fd. Or simply ptrace() to the process and steal these fd out. But I have no experience of ptrace() at all.

– 炸鱼薯条德里克
Mar 1 at 13:48













Yes and yes. Of course, it's hacky (you should use a debugger) and you need the right permissions; for the case of ssh, the master side is held by a process running as root. In a script I wrote for one of your question, I was calling ptsname() on the master side of a pty to get the name of its slave side; instead of calling ptsname(), you can call read() or write().

– mosvy
Mar 1 at 13:49






Yes and yes. Of course, it's hacky (you should use a debugger) and you need the right permissions; for the case of ssh, the master side is held by a process running as root. In a script I wrote for one of your question, I was calling ptsname() on the master side of a pty to get the name of its slave side; instead of calling ptsname(), you can call read() or write().

– mosvy
Mar 1 at 13:49














It's just normally distro setup the kernel that disallow you to steal other process's fd, and most program wouldn't provide such functionality of giving out fd by UDS.

– 炸鱼薯条德里克
Mar 1 at 13:51





It's just normally distro setup the kernel that disallow you to steal other process's fd, and most program wouldn't provide such functionality of giving out fd by UDS.

– 炸鱼薯条德里克
Mar 1 at 13:51













@炸鱼薯条德里克 It's not a "distro thing", it's a permission thing. You have to either have CAP_SYS_PTRACE or be the same user in order to attach to another process and "steal" its fds via SCM_RIGHTS (or simply run ops on them in the context of that process).

– mosvy
Mar 1 at 13:55





@炸鱼薯条德里克 It's not a "distro thing", it's a permission thing. You have to either have CAP_SYS_PTRACE or be the same user in order to attach to another process and "steal" its fds via SCM_RIGHTS (or simply run ops on them in the context of that process).

– mosvy
Mar 1 at 13:55




1




1





@炸鱼薯条德里克 I never had to turn any switch in order to be able to send fds via SCM_RIGHTS ancillary messages; and if you attach to a process with ptrace(), you can run any command in the context of that process, including sending fds via a UNIX socket.

– mosvy
Mar 1 at 14:02





@炸鱼薯条德里克 I never had to turn any switch in order to be able to send fds via SCM_RIGHTS ancillary messages; and if you attach to a process with ptrace(), you can run any command in the context of that process, including sending fds via a UNIX socket.

– mosvy
Mar 1 at 14:02










0






active

oldest

votes












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f503785%2fis-it-possible-to-change-the-process-on-the-master-or-slave-side-of-a-pseudoterm%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f503785%2fis-it-possible-to-change-the-process-on-the-master-or-slave-side-of-a-pseudoterm%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?