From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 071E23858D32 for ; Mon, 26 Sep 2022 11:58:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 071E23858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ot1-x32d.google.com with SMTP id w22-20020a056830061600b006546deda3f9so4268495oti.4 for ; Mon, 26 Sep 2022 04:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:content-language :references:to:subject:from:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=YX4H4XtqwPdys4Fa2obMKouG+3t1ITfpgouSy2X45FM=; b=ZIP3iNVMAsjhUJ6+CvRebOnU+wzi5OgGU+ThUro3J8sCGvnuI1x+R37UBn5O1Vokfm YS4SEYUr+aRFvnG8Yb8ywzHKZUXLKUKujTW6d/YBhZprVShvDjZZXh6N4zeNBhSsfBkO 48Uscl9JYgQmpib49d/bgu3hTyCMqz63PC/wBgv0zg78jbTsok9mDypQeIsRjhthKMgV XiEej7BAZu/da3IvniNZqifW9yotLOlcQLazKzzzhIOjskBx1BukqaResfIzXmD6zKBs NlFlU+lTZ6pVsStcSx+J6hdmy8hUjHnFcr5fyjtpzXoV9OUEWNXTRzg4LTFKPdsjUBMq X9GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:content-language :references:to:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=YX4H4XtqwPdys4Fa2obMKouG+3t1ITfpgouSy2X45FM=; b=Y7yWGjB6xpFlEkMkXFlNzZI6ZZhdLGJvyq/JH6wtUfYF9BRiu5Rx65ENInbrggxC3O g1mMguOUCUzluX2Nq3uCFT8DxAL+63prfqHeMb3TPh10E2oUEDdpXtTR7oWk/02lmSV6 7fmb89DSO03TDZyjv08eXD/xZgDb7ZOW1Q4Zw0HyFRMjyy0UDqQ2xwnFT3mNhtkx5i2p jxNUWDl9sHgdjeamXGjyP/ejslez3Oi/F/stE7VwRhXAPXbvveUqZ0oa/Gb++NhceBQ3 WnGV4R6jTzduUzcQ8IDFhgSSrBuMf2t0k37c/rsJgeZGG2R8ukGGhb8L/ILBuPKwGEBG PAsA== X-Gm-Message-State: ACrzQf12nUyA4nJUK6YfTmsNp+YQs7pZItIs3yC7T6qVOpb2hAxiVHkw EWeUL1w4GOwst8NYWkDZV6dPT9Qt/wMljgR9 X-Google-Smtp-Source: AMsMyM7aF+3GKZ/Uz1Lz3QFrM8xCacmOp+A8EXylY/MAiy8A2ZNCddcIGx1UHZh1BtVHecnQSz+OWw== X-Received: by 2002:a9d:7e8c:0:b0:655:ca0f:a3ab with SMTP id m12-20020a9d7e8c000000b00655ca0fa3abmr9981058otp.47.1664193481920; Mon, 26 Sep 2022 04:58:01 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c2:3736:b07a:d8a3:b936:2ca2? ([2804:1b3:a7c2:3736:b07a:d8a3:b936:2ca2]) by smtp.gmail.com with ESMTPSA id p1-20020a9d4541000000b00618fa37308csm7570873oti.35.2022.09.26.04.58.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Sep 2022 04:58:01 -0700 (PDT) Message-ID: <86291bcc-22cb-5d6b-9056-3bea450e6dec@linaro.org> Date: Mon, 26 Sep 2022 08:57:59 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 From: Adhemerval Zanella Netto Subject: Re: What are the option for overriding system calls GNU libc calls? To: Adhemerval Zanella via Libc-help References: Content-Language: en-US Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 22/09/22 09:31, Godmar Back via Libc-help wrote: > Hi, > > I have a question. Say I wanted to override the `write()` system call in an > application so that when I compile and link it, my version of `write()` is > called by both the application program as well as by GNU libc, for > instance, from puts or printf. To what extent is this supported? > > I'm aware of the following options: > - (a) link statically. In this case, if I provide a strong definition of > `write()`, the application will pick it up. GNU libc, otoh, uses > `__write()` Overriding `__write` with a strong definition works and gets > libc to call my __write. > > - (b) link dynamically and use `LD_PRELOAD`. In this case, I can get the > application to call my `write`, but libc will continue to call `__write`; I > believe; I haven't tried if I can provide a __write and have libc pick up > on it since (I thought) that libc resolves these symbols internally or from > a dynamic library on its link chain. Unfortunately this is done intentionally and although the usual double underscore is used on mot symbol, some also uses different internal nomenclature (for instance __libc_sigaction). For internal libc usage, we explicit avoid PLT usage so you will need to either use a dynamic runtime tool to rewrite the text segment (DynamicRIO, etc.), a probe tools (uprobes, systemtap, etc. which might not fit the model you are aiming since it might not run in the process namespace), or recompile glibc to remove the hidden_def definition on the symbol (so PLT are generated for internal calls and LD_PRELOAD can override it). > > In any event, my question is: is there a sanctioned or semi-sanctioned way > to override system calls for both the static and dynamic linking process? > > - Godmar