From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id F0728385783F for ; Tue, 16 May 2023 13:05:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F0728385783F 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-oi1-x22f.google.com with SMTP id 5614622812f47-38ea3f8e413so7056435b6e.2 for ; Tue, 16 May 2023 06:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684242352; x=1686834352; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=6EJrI7KZgKhLbZIekh/U7F/sagHfLP/qOYHo9ysRvp0=; b=AEnOfKgH7noS3JX/p8LU+laKIDps6UFjfOKHXAPBPSA9WV40q2c8ds4OTikb/lXri6 CMP4niPvaYBfLiF/pSwy+4ILHnDBB8ttk5704eNRSBgLhSsmPKunn4q8/DUow757qQ87 h7+hwkhlR5Xef5vgcQfag2LLw/BGVgH0gx8FFevTz6vlmhSY0pLZHivTOV5FyrcUYAaH mBoEq8TtU6Ov5HubiJnLqqj9XpXt78723i7vhnKrbwOAecubt1rHca5FV4u9/j62CjS5 /qj7dJ8Ih6qWNj9Mdz3G1dbnT+LD0ZflwAK+n+qQJdw3/BxIiI138w3uS2gs3fg+4qCl S5+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684242352; x=1686834352; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6EJrI7KZgKhLbZIekh/U7F/sagHfLP/qOYHo9ysRvp0=; b=T5a+OaQ4tfTEjLcqiYv/AZCXoSKnpUxnH27HstuciwLNoVQMnx0ooBT8SHUXDLebqk 0j0sxR0tXkMjArkDICtn9QvTenRqTkqv0HfEfGEvjgGyDlHgF9VCYWnh1xOGQgNEOaZH 7BdV9aQaueCY0ohG60xuUnmzwyptRskQRtcoBo0xergp+Y9cBeCDnkpwgkWnczE/a/q8 7DW7cKwZ1BbzGnVhQwIqV9N8BdVWhfwf3sEDduAT/FgLjXDmtGj0UUWkImPZ+4gFMHAW czWuW3q9WZMwdFxaNDPYe+jgpz2qVJipjda7EqxHmhWIeuaEJHA9XgoyxwcBybCHA0Nd k30A== X-Gm-Message-State: AC+VfDwXHJlyPTZseUEFYwoBt/f3F24tSkhYabebtTSR6hBJe9VVvq6W ERzN6gp1UcNnjNb2SMCjpkhg9mXG6kLjR/N6EYk2mw== X-Google-Smtp-Source: ACHHUZ7SzRbND+RNInmvSQvaGicAnk6rKFPHDSz2KnhppWA/VGmc+JA4F1+FtEtGdyhoS1qU1r4MMw== X-Received: by 2002:aca:100d:0:b0:394:3447:a84 with SMTP id 13-20020aca100d000000b0039434470a84mr9266715oiq.10.1684242351754; Tue, 16 May 2023 06:05:51 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c0:c914:28b3:cbf9:a103:6f88? ([2804:1b3:a7c0:c914:28b3:cbf9:a103:6f88]) by smtp.gmail.com with ESMTPSA id s185-20020acadbc2000000b0038eb56f5b87sm8780250oig.47.2023.05.16.06.05.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 May 2023 06:05:50 -0700 (PDT) Message-ID: <06d12b3f-a172-bca5-8e1d-5bf04d0becd4@linaro.org> Date: Tue, 16 May 2023 10:05:48 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v3 3/3] linux: Add pidfd_getpid Content-Language: en-US To: libc-alpha@sourceware.org References: <20230516114612.159103-1-adhemerval.zanella@linaro.org> <20230516114612.159103-4-adhemerval.zanella@linaro.org> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.6 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,T_SCC_BODY_TEXT_LINE 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 16/05/23 09:55, Zack Weinberg via Libc-alpha wrote: > On Tue, May 16, 2023, at 8:38 AM, Luca Boccassi via Libc-alpha wrote: >> On Tue, 16 May 2023 at 13:26, Adhemerval Zanella Netto >> wrote: >>>>> + unsigned long n = strtoul (l, &endp, 10); >>>>> + if (l == endp || (n > INT_MAX && n != ULONG_MAX)) >>>>> + return 0; >>>> >>>> How can this tell the difference between '-1' and garbage input? It >>>> seems to me this will confuse mangled input here with ESRCH, given the >>>> pid in fdinfo is initialized to -1, no? >>> >>> Because -1 will be parsed as ULONG_MAX. For instance, with the inputs: >>> >>> Input: | Function result | parse_fdinfo_t >>> -------------------|-----------------|----------------------- >>> "Pid: 0" | 1 | {1, 0} >>> "Pid: 1" | 1 | {1, 1} >>> "Pid: 2147483647" | 1 | {1, 2147483647} >>> "Pid: 2147483648" | 0 | {0, -1} >>> "Pid: -1" | 1 | {1, -1} >>> "Pid: -3" | 0 | {0, -1} >>> "Pid: -24x" | 0 | {0, -1} >>> >>> So only if the PID if positive less than INT_MAX or -1 the function >>> will set that the PID as found. >> >> This seems excessively convoluted and fragile to me, relying on >> overflows and so on. I cannot stress this enough, in order to use this >> from systemd et al I need to be absolutely certain that garbage input >> is not treated the same as ESCHR. Why not just use strtoll or so, to >> get an exact result out of it? > > Also, all of the strto* functions are sensitive to the locale. It shouldn't be too hard to make this function async-signal-safe and I think we really ought to. Indeed the locale sensitivity is far from ideal, I will change to a async-signal-safe one. > > (Actually, why isn't this operation exposed as an ioctl on the pidfd? I thought the kernel people had come around to accepting that parsing text files in /proc is fragile, inconvenient, and slow.) My guess is the usercases for this interface has not yet clashed with the interfaces that require direct pid access.