Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.2/patches/807096/?format=api
{ "id": 807096, "url": "http://patchwork.ozlabs.org/api/1.2/patches/807096/?format=api", "web_url": "http://patchwork.ozlabs.org/project/glibc/patch/20170829134515.9345-2-christian.brauner@ubuntu.com/", "project": { "id": 41, "url": "http://patchwork.ozlabs.org/api/1.2/projects/41/?format=api", "name": "GNU C Library", "link_name": "glibc", "list_id": "libc-alpha.sourceware.org", "list_email": "libc-alpha@sourceware.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20170829134515.9345-2-christian.brauner@ubuntu.com>", "list_archive_url": null, "date": "2017-08-29T13:45:15", "name": "[2/2,v4] openpty: use TIOCGPTPEER to open slave side fd", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "bd6bf3bf8e35e7479c40ab4c6a1ab776a70aca5b", "submitter": { "id": 72235, "url": "http://patchwork.ozlabs.org/api/1.2/people/72235/?format=api", "name": "Christian Brauner", "email": "christian.brauner@ubuntu.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/glibc/patch/20170829134515.9345-2-christian.brauner@ubuntu.com/mbox/", "series": [ { "id": 373, "url": "http://patchwork.ozlabs.org/api/1.2/series/373/?format=api", "web_url": "http://patchwork.ozlabs.org/project/glibc/list/?series=373", "date": "2017-08-29T13:45:14", "name": "[1/2,v4] openpty: close slave pty fd on error", "version": 4, "mbox": "http://patchwork.ozlabs.org/series/373/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/807096/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/807096/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<libc-alpha-return-83817-incoming=patchwork.ozlabs.org@sourceware.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": [ "patchwork-incoming@bilbo.ozlabs.org", "mailing list libc-alpha@sourceware.org" ], "Authentication-Results": [ "ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-83817-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)", "ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"hoTWcoLA\"; dkim-atps=neutral", "sourceware.org; auth=none" ], "Received": [ "from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xhVKg50dQz9t33\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 29 Aug 2017 23:46:31 +1000 (AEST)", "(qmail 130625 invoked by alias); 29 Aug 2017 13:46:01 -0000", "(qmail 125279 invoked by uid 89); 29 Aug 2017 13:45:42 -0000" ], "DomainKey-Signature": "a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:from:to:cc:subject:date:message-id:in-reply-to\n\t:references; q=dns; s=default; b=vZIuxGxzPvG0GK1sZblkg6WeQHjGsDy\n\ts/j6guefzVwSEC5TAVmwfRbW225f08LCmd5S6oPd9Wi0iH6Lx0zar5COmgWiLJFU\n\tyB1O18Haies/VoE7Vsq1nAlq+Iqi/CYoWhkuXahPn4e8tFicgQR9Rwaiq+sERMYE\n\tbcxtDholobIc=", "DKIM-Signature": "v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:from:to:cc:subject:date:message-id:in-reply-to\n\t:references; s=default; bh=+z4VZ+ViCaecGZoeVFfj+DCw3Ko=; b=hoTWc\n\toLAEwmL+uemcvX00lXjSq9K2WP4xrJOGjBH9UDSY1O9gPEn0cE2TjyCqqQTV+R3m\n\taxmERla4Na9ekNvD+VpB2CNo05ouEOEq5VoCChFz3PnF3YLEGzwQtEKfSlA8gm6K\n\tYYV3/phRS9ZaMBT+6xU4hHyNOsNMJQGmGhm5qg=", "Mailing-List": "contact libc-alpha-help@sourceware.org; run by ezmlm", "Precedence": "bulk", "List-Id": "<libc-alpha.sourceware.org>", "List-Unsubscribe": "<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>", "List-Subscribe": "<mailto:libc-alpha-subscribe@sourceware.org>", "List-Archive": "<http://sourceware.org/ml/libc-alpha/>", "List-Post": "<mailto:libc-alpha@sourceware.org>", "List-Help": "<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>", "Sender": "libc-alpha-owner@sourceware.org", "X-Virus-Found": "No", "X-Spam-SWARE-Status": "No, score=-26.6 required=5.0 tests=BAYES_00, GIT_PATCH_0,\n\tGIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3,\n\tKAM_LAZY_DOMAIN_SECURITY,\n\tRCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=", "X-HELO": "mx1.mailbox.org", "From": "Christian Brauner <christian.brauner@ubuntu.com>", "To": "libc-alpha@sourceware.org, stgraber@stgraber.org, serge@hallyn.com,\n\tfweimer@redhat.com, joseph@codesourcery.com", "Cc": "Christian Brauner <christian.brauner@ubuntu.com>", "Subject": "[PATCH 2/2 v4] openpty: use TIOCGPTPEER to open slave side fd", "Date": "Tue, 29 Aug 2017 15:45:15 +0200", "Message-Id": "<20170829134515.9345-2-christian.brauner@ubuntu.com>", "In-Reply-To": "<20170829134515.9345-1-christian.brauner@ubuntu.com>", "References": "<a05d5603-c074-966d-f75e-cb268d0dc249@redhat.com>\n\t<20170829134515.9345-1-christian.brauner@ubuntu.com>" }, "content": "Newer kernels expose the ioctl TIOCGPTPEER [1] call to userspace which allows to\nsafely allocate a file descriptor for a pty slave based solely on the master\nfile descriptor. This allows us to avoid path-based operations and makes this\nfunction a lot safer in the face of devpts mounts in different mount namespaces.\n\n[1]: https://patchwork.kernel.org/patch/9760743/\n\nSigned-off-by: Christian Brauner <christian.brauner@ubuntu.com>\n---\nChangelog 2017-08-28:\n* Instead of #ifdefing the TIOCGPTPEER ioctl flag we now try the ioctl() first\n and if it fails we fallback to path-based allocation of the slave fd. This\n allows us retain backward compatibility with kernels that do not support this\n ioctl call.\n* A note on the following codepath\n\n if (name != NULL)\n {\n if (*buf == '\\0')\n if (pts_name (master, &buf, sizeof (_buf)))\n goto fail;\n\n strcpy (name, buf);\n }\n\n \"buf\" is guaranteed to be allocated in this case. If the pts_name() call above\n failed we would have never reached this code path. If it has been called\n succesfully it will either have handed us a valid buffer or \"buf\" will still\n point to the static char array \"_buf\" which is initialized to 0.\nChangelog 2017-08-28:\n* Preserve #ifdef for TIOCGPTPEER since it needs to work on non-Linux distros\n too.\n* Only intialize first byte of \"_buf\".\nChangelog 2017-08-29:\n* Adapt to unified error handling as suggested by Florian.\n---\n ChangeLog | 5 +++++\n login/openpty.c | 30 ++++++++++++++++++++++++------\n 2 files changed, 29 insertions(+), 6 deletions(-)", "diff": "diff --git a/ChangeLog b/ChangeLog\nindex bc5fb8e27f..30829e4c16 100644\n--- a/ChangeLog\n+++ b/ChangeLog\n@@ -1,3 +1,8 @@\n+2017-08-26 Christian Brauner <christian.brauner@ubuntu.com>\n+\n+\t* login/openpty.c (openpty): If defined, use the TIOCGPTPEER ioctl call\n+\tto allocate the slave pty file descriptor.\n+\n 2017-08-26 Christian Brauner <christian.brauner@ubuntu.com>\n \n \t* login/openpty.c (openpty): Close slave pty file descriptor on error.\ndiff --git a/login/openpty.c b/login/openpty.c\nindex a7b1ab5dde..766aa958ff 100644\n--- a/login/openpty.c\n+++ b/login/openpty.c\n@@ -94,6 +94,8 @@ openpty (int *amaster, int *aslave, char *name,\n char *buf = _buf;\n int master, ret = -1, slave = -1;\n \n+ *buf = '\\0';\n+\n master = getpt ();\n if (master == -1)\n return -1;\n@@ -104,12 +106,22 @@ openpty (int *amaster, int *aslave, char *name,\n if (unlockpt (master))\n goto on_error;\n \n- if (pts_name (master, &buf, sizeof (_buf)))\n- goto on_error;\n-\n- slave = open (buf, O_RDWR | O_NOCTTY);\n+#ifdef TIOCGPTPEER\n+ /* Try to allocate slave fd solely based on master fd first. */\n+ slave = ioctl (master, TIOCGPTPEER, O_RDWR | O_NOCTTY);\n+#endif\n if (slave == -1)\n- goto on_error;\n+ {\n+ /* Fallback to path-based slave fd allocation in case kernel doesn't\n+ * support TIOCGPTPEER.\n+ */\n+ if (pts_name (master, &buf, sizeof (_buf)))\n+ goto on_error;\n+\n+ slave = open (buf, O_RDWR | O_NOCTTY);\n+ if (slave == -1)\n+ goto on_error;\n+ }\n \n /* XXX Should we ignore errors here? */\n if (termp)\n@@ -122,7 +134,13 @@ openpty (int *amaster, int *aslave, char *name,\n *amaster = master;\n *aslave = slave;\n if (name != NULL)\n- strcpy (name, buf);\n+ {\n+ if (*buf == '\\0')\n+ if (pts_name (master, &buf, sizeof (_buf)))\n+ goto on_error;\n+\n+ strcpy (name, buf);\n+ }\n \n ret = 0;\n \n", "prefixes": [ "2/2", "v4" ] }