From patchwork Thu Nov 23 12:06:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 119514 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp720575qgn; Thu, 23 Nov 2017 04:06:52 -0800 (PST) X-Google-Smtp-Source: AGs4zMa5G7CTaRJovAF092DXzXt6Un0YgV6umHm25kvJFbiogGYbzDfguILk0a+Zi62CYuzzRs0U X-Received: by 10.84.133.1 with SMTP id 1mr24773068plf.203.1511438812007; Thu, 23 Nov 2017 04:06:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511438812; cv=none; d=google.com; s=arc-20160816; b=C0PDS6t9mNZFNxQJ+5Moq4QOLtXVN1RMf2iC0nnps8KDl2JmVku2vAd2/TnYdTzwH2 3B+aj5OXWEtX99eGWO6vrTupdoghoqcyGlMQx76+Zml/KH0HlbG9Q9c9q+YV2h0w//o9 K2PbVGYazXKWHE7/356R6MxwgdhRzYmpoS438SicFVAXFyruEGMVg1oIhu5yL+tnzM2J XU/Ae0QKeub3+YzNncoaz+PYJiYyE8l4sZ8UGcCtuvSgoZ+mkqrnc+gHTZC/KL4Nsf+9 xZFoVpML8KmL+v7bUyaigtEBNTdc5Xe3Gnv3dA95VRC526yDmh5BaKKKQ6CBgh94ogqO S1Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:delivered-to:sender:list-help :list-post:list-archive:list-subscribe:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=pDyRF5ksrfm90JaOkEBWisUcK+DT/VSJXBlDDnan7qI=; b=pLnx59J1xvsB6Y/BlfkyH+RI2v7CWx9/VFjKHTnv45lGdF9/OC0UwRSenbO0HcidNj WCodjgSix3E5wFGkNCnpkNIeSF+Z5bdeDl3QZ//+f+CpdEO36HzKHHeF9yv2O4SmkA3F aRU3RAMcQ0RKCbJw323SxaLHtuyEpear7JduW+887pj1g6+mPqZtLjodhKo8BcJV1v8o SBF7wzWfmRTcmBaSD4QTMXtAcnk+9VzX6ieL29BZzGNNllOCb+UzvDhyYrb2HDBtmYi8 YRkZBy+Uwf6+Ug4+52KaRTF3XsujrW+giI68LBqrra/vJrIcx4bEEhT1wLayzvXkXTpE Dleg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=lZEDSzre; spf=pass (google.com: domain of libc-alpha-return-87456-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-87456-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id e91si6935949plb.351.2017.11.23.04.06.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Nov 2017 04:06:51 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-87456-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 header.s=default header.b=lZEDSzre; spf=pass (google.com: domain of libc-alpha-return-87456-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-87456-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=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=kHo85H2X1mZ+N0gA+F0EkSNaqxMyunO0RDZPEvWzB0d+Dax6aHxnP 2d3HKnTJ1QcRLV8U7z3QvK+KP4UqxUdiPQHbqjdSbykuWdelpChyP5LdEAQVJwrk Peo92lDktLZxDUa3wNgfcDgl6Lqafe8pPWoBHHg3UnNQDrP1SHWuHI= 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=mYB9JoiCZvlqEy0xJJLHl97OhkY=; b=lZEDSzreKtLmD4khfaD5N19OL+5Y JewQ7xak5m+TzbE9iEFeS9KtJzO8NnwXLk4gT2ZqJ6c/ndkVKyAy5/Mk4iAxOs6K 4aJKOeM9opWNO6Nl5EleR68lBAkgo6mRVZyctXM7Ei+dA8gUOETpsm9LdhlIcyVs Cp6JaCrdRGVXwqg= Received: (qmail 15259 invoked by alias); 23 Nov 2017 12:06:42 -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 15248 invoked by uid 89); 23 Nov 2017 12:06:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=fortunately, mallocc, malloc.c, 5606 X-HELO: mail-qk0-f195.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=pDyRF5ksrfm90JaOkEBWisUcK+DT/VSJXBlDDnan7qI=; b=OCUNRzxsQ0DKVf6J/PY1BDVnk6T0vppBJCP876zpsgW8uqd5w7o0f1ZpYqJnY9GVx3 s/fkd1yWjspfhzJSBB4PtCE9snILlemZaSGBgwJ6OnVyRTFtgKxoWETeQprVj77SBwhU 5tRg2ZFm3MVKWSRlSVQmq6lpLu8xlPJRRTotsU1q4Ou3qZGehMH+V+bPBbtEy0guQvkG eAzr4kSZWbSBlFOut3AopaSiXMvBkKTpJbGkmHdIiLaBi32QSYORF9fMBelET7f5ieJ0 l6NNocL8T7d9cR7GBeo7o7zqi/bDauW609+ulKoAvOJkFKEwNnRtP9kPAivPHd/URcNb WzJg== X-Gm-Message-State: AJaThX41lfHXh5Ogisk6lA2L8Yd9YKnOti8B3S5V0zpTuHBCaOY35QlO r6PWX0H7tQpE/8gQbex5yHwuV5amoyM= X-Received: by 10.55.4.148 with SMTP id 142mr39366114qke.121.1511438793724; Thu, 23 Nov 2017 04:06:33 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] posix: Call internal free on fallback p{read, write}v on Linux (BZ#22457) Date: Thu, 23 Nov 2017 10:06:26 -0200 Message-Id: <1511438786-32436-1-git-send-email-adhemerval.zanella@linaro.org> As described in BZ#22457 an interpose malloc can free an invalid pointer for fallback preadv implementation. Fortunately this is just and issue on microblaze-linux-gnu running kernels older than 3.15. This patch fixes it by calling internal free (__libc_free). Another possible option would be replace posix_memalign/free with a mmap/unmap, however this is pessimization since it will two more syscalls necessary for each preadv/pwritev call. Checked on microblaze-linux-gnu check with run-built-tests=no and by using the sysdeps/posix implementation on x86_64-linux-gnu (just for sanity test where it shown no regression). [BZ #22457] * malloc/malloc.c (__libc_malloc, __libc_free, __libc_realloc, __libc_memalign, __libc_mallopt): Move declaration and libc_hidden_proto to ... * include/malloc.h: ... here. * sysdeps/posix/preadv_common.c (PREADV): Use __libc_free instead of free. * sysdeps/posix/pwritev_common.c (PWRITEV): Likewise. --- ChangeLog | 11 +++++++++++ include/malloc.h | 15 +++++++++++++++ malloc/malloc.c | 10 ---------- sysdeps/posix/preadv_common.c | 2 +- sysdeps/posix/pwritev_common.c | 2 +- 5 files changed, 28 insertions(+), 12 deletions(-) -- 2.7.4 diff --git a/include/malloc.h b/include/malloc.h index d4cd9a5..4b99dbc 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -14,5 +14,20 @@ extern __typeof (__malloc_check_init) __malloc_check_init attribute_hidden; struct malloc_state; typedef struct malloc_state *mstate; +extern void * __libc_malloc (size_t) attribute_hidden; +libc_hidden_proto (__libc_malloc) + +extern void __libc_free (void*) attribute_hidden; +libc_hidden_proto (__libc_free) + +extern void * __libc_realloc (void *, size_t) attribute_hidden; +libc_hidden_proto (__libc_realloc) + +extern void * __libc_memalign (size_t, size_t) attribute_hidden; +libc_hidden_proto (__libc_memalign) + +extern int __libc_mallopt (int, int) attribute_hidden; +libc_hidden_proto (__libc_mallopt) + # endif /* !_ISOMAC */ #endif diff --git a/malloc/malloc.c b/malloc/malloc.c index 2999ac4..5746193 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -500,8 +500,6 @@ void *(*__morecore)(ptrdiff_t) = __default_morecore; differs across systems, but is in all cases less than the maximum representable value of a size_t. */ -void* __libc_malloc(size_t); -libc_hidden_proto (__libc_malloc) /* free(void* p) @@ -514,8 +512,6 @@ libc_hidden_proto (__libc_malloc) when possible, automatically trigger operations that give back unused memory to the system, thus reducing program footprint. */ -void __libc_free(void*); -libc_hidden_proto (__libc_free) /* calloc(size_t n_elements, size_t element_size); @@ -551,8 +547,6 @@ void* __libc_calloc(size_t, size_t); The old unix realloc convention of allowing the last-free'd chunk to be used as an argument to realloc is not supported. */ -void* __libc_realloc(void*, size_t); -libc_hidden_proto (__libc_realloc) /* memalign(size_t alignment, size_t n); @@ -566,8 +560,6 @@ libc_hidden_proto (__libc_realloc) Overreliance on memalign is a sure way to fragment space. */ -void* __libc_memalign(size_t, size_t); -libc_hidden_proto (__libc_memalign) /* valloc(size_t n); @@ -599,8 +591,6 @@ void* __libc_valloc(size_t); M_MMAP_THRESHOLD -3 128*1024 any (or 0 if no MMAP support) M_MMAP_MAX -4 65536 any (0 disables use of mmap) */ -int __libc_mallopt(int, int); -libc_hidden_proto (__libc_mallopt) /* diff --git a/sysdeps/posix/preadv_common.c b/sysdeps/posix/preadv_common.c index 37efdc0..c650435 100644 --- a/sysdeps/posix/preadv_common.c +++ b/sysdeps/posix/preadv_common.c @@ -78,6 +78,6 @@ PREADV (int fd, const struct iovec *vector, int count, OFF_T offset) } end: - free (buffer); + __libc_free (buffer); return bytes_read; } diff --git a/sysdeps/posix/pwritev_common.c b/sysdeps/posix/pwritev_common.c index 0383065..6c364f8 100644 --- a/sysdeps/posix/pwritev_common.c +++ b/sysdeps/posix/pwritev_common.c @@ -66,7 +66,7 @@ PWRITEV (int fd, const struct iovec *vector, int count, OFF_T offset) ssize_t ret = PWRITE (fd, buffer, bytes, offset); - free (buffer); + __libc_free (buffer); return ret; }