From patchwork Thu May 26 14:37:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 68682 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp439416qge; Thu, 26 May 2016 07:37:58 -0700 (PDT) X-Received: by 10.66.231.35 with SMTP id td3mr14575739pac.56.1464273477901; Thu, 26 May 2016 07:37:57 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 6si7039207pfe.172.2016.05.26.07.37.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 May 2016 07:37:57 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-69895-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-69895-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-69895-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=R+zel0I72qlmZ/Uj3Qi+XjfeNAsytY//rY4ySDOo25rcajfGMDxIC JRX6Ih9PfNW6LpvStuPci590kUcNW+WRKiMb9Eb+zPrpHq25dbcVHDT+8TG5IdCw h9wRscoCZrzvHQH9rz91KN7mvQpAEg7LM4ypvyM6M+yIqrrOT8GWzg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=eHTGt60H4E+6WdgD36PGdA6AfGY=; b=QRmey+/M32NTi0U8FkQx7/ltqavB IdogF7XErrZn34bahem+zk0pk2I4yA1TyB1Lutrx64FpCK82Wn70oasyNAafaMrs F1UR1MYlplpUPQG0fY1PmRi4oqg4Zp+q9vJ2kUS1hwDO1zo4zrl4jQWwi9BqMMi0 XeVjdEzkg0FL+vM= Received: (qmail 127805 invoked by alias); 26 May 2016 14:37:49 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 127796 invoked by uid 89); 26 May 2016 14:37:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=adjustments, 2048, usar, shlib-compat.h X-HELO: mail-yw0-f171.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=BWcrfCP9qSXQpRFKY5NUeW8jkjhWQ+PyfkFp7IXq9Kg=; b=ZarzMt2VgPVBZcXFe+e57zDeVr0qL8adsiemzvPFEbN/xUU7KHY1BQGmMn9FUKRsvv 8sxoJSzNdMp0xBJcrJhjUPjF73kwg0x508e3tykjV0K0jXooMTBR0yw3+OiSPl5hQJ8z +IRLxoMhgFucMComSzW6iT9J6WV1+q5/g1k2cYAUcvQGixdDY/DdLJ/wdHmxW2qSCkh/ HExG8qSlSI/aCfbC/56o8US5mx4hJkdRp/gSy9q85RGj9FAJ3UCz84/MjObFa2qMn4N6 XbIB0myrKHVHSX8CkslM5B1DWD+KL/uVYozPSYPfwPTmQrQYDBdEtikMwRoFARsJMHPA OXDg== X-Gm-Message-State: ALyK8tIwbsEBBGeOIFSk7LemtDX0aOJq5rkPn7F8odgC7uyB2Ul5FhmmjoBg24yVtoAxvvPS X-Received: by 10.129.75.87 with SMTP id y84mr6542354ywa.91.1464273456647; Thu, 26 May 2016 07:37:36 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] network: Fix cmsghdr padding in sendmsg (BZ#16919) Date: Thu, 26 May 2016 11:37:30 -0300 Message-Id: <1464273450-31507-1-git-send-email-adhemerval.zanella@linaro.org> This patch fixes the remaining issue in sendmsg POSIX compliance by adjusting the cmsghdr padding accordingly for 64-bits ABIs. Since function contract does not allow to modify it in place, a temporary buffer instead. Although the value used is arbitrary (current 2048 bytes), it is expected to cover mostly common usar cases for this facility (passing file descriptors and permission between processes). I did not send this change on previous patches because I would like some feedback about buffer size used in copy operations. Tested on x86_64 and i686. * sysdeps/unix/sysv/linux/sendmsg.c (__libc_sendmsg): Fix cmsghdr padding for 64-bits. --- ChangeLog | 3 +++ sysdeps/unix/sysv/linux/sendmsg.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) -- 2.7.4 diff --git a/ChangeLog b/ChangeLog index ecedf6f..317d228 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,9 @@ 2016-05-25 Adhemerval Zanella + * sysdeps/unix/sysv/linux/sendmsg.c (__libc_sendmsg): Fix cmsghdr + padding for 64-bits. + * sysdeps/unix/sysv/linux/Makefile [$(subdir) = socket] (sysdep_routines): Add oldrecvmmsg and oldsendmmsg. diff --git a/sysdeps/unix/sysv/linux/sendmsg.c b/sysdeps/unix/sysv/linux/sendmsg.c index a5ef238..4a5420a 100644 --- a/sysdeps/unix/sysv/linux/sendmsg.c +++ b/sysdeps/unix/sysv/linux/sendmsg.c @@ -19,6 +19,7 @@ #include #include #include +#include ssize_t __libc_sendmsg (int fd, const struct msghdr *msg, int flags) @@ -28,13 +29,35 @@ __libc_sendmsg (int fd, const struct msghdr *msg, int flags) both size_t. So for 64-bit it requires some adjustments by copying to temporary header and zeroing the pad fields. */ #if __WORDSIZE == 64 +# define CMSGHDR_CONTROLLEN_MAX 2048 struct msghdr hdr; + struct cmsghdr auxcbuf[CMSGHDR_CONTROLLEN_MAX/sizeof(struct cmsghdr)+1]; if (msg != NULL) { hdr = *msg; hdr.__glibc_reserved1 = 0; hdr.__glibc_reserved2 = 0; msg = &hdr; + + if (hdr.msg_controllen > 0) + { + /* Since function contract does not allow modify the msg_controllen + in place it requires to copy on a temporary buffer to make the + adjustment required by POSIX. Current limit is quite arbitrary + and it is expected to cover the mostly common user cases for + this (passing file descriptors and permission between processes + over unix sockets). */ + if (hdr.msg_controllen > CMSGHDR_CONTROLLEN_MAX) + { + __set_errno (ENOMEM); + return -1; + } + memcpy (auxcbuf, hdr.msg_control, hdr.msg_controllen); + hdr.msg_control = auxcbuf; + for (struct cmsghdr *c = CMSG_FIRSTHDR (&hdr); c != NULL; + c = CMSG_NXTHDR(&hdr, c)) + c->__glibc_reserved1 = 0; + } } #endif