From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 896893858C52 for ; Tue, 17 Oct 2023 14:11:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 896893858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 896893858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697551916; cv=none; b=gJYdLfI1BSiUiLmwCs+3UaRzEmc1c/2DrPVZoO27XtXuNwQIwdsrhGhCHsbhoj9Uxlq+wR2VvOj8Fk5Z5n0ys83OJMHDqv4q9BvqUAfYwgGJWeCt9JfZeIJ52vAd4XFvi1PNW+djPqzCRvOGGGlxziwjSq820pk1Lpe4dtQ3/Z0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697551916; c=relaxed/simple; bh=5y8pSxq3B8VnecPn0BCe6f2sb1MSSmRAZ0QsKJ4IZtY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=QldXaxrwAmyj+ufiW2hBjp5rBuYZhWsCh6sXGlwCqLKzkmBbl8pArKDkS2eHHWm8NhuZO1hKumQKi5ncQXQY8FvIt5ihiaSffbUvVoW7p6K+00mZKRGzpeORt8JKeom3V76bJLctvWOnq6QKKw8BTn24krxAImCocJowjdYXPxA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6bd73395bceso1979802b3a.0 for ; Tue, 17 Oct 2023 07:11:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697551911; x=1698156711; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=rAWqPlhBhBylPMfzP1nNZgDINoo/gYtcyAYpgqEx4Zw=; b=zams9Uh6h1/Vtzevnosff7CinGujHUaubPjon3orA/ukRSPVeuy2erQ0/DJTQCF7L/ 1he7sHDMUu6K42qOoPQ6P39Wc6y21xnIB3ublPAF0Q9eETar8a9fQGh2msY48Xx8K+K0 oV5F+UXyTq17Rbfh8+zHd9+iLIq/30V0Y/ZnkZJvfCK4uEgyw/Z+kcM+jfEHlxuLW6tb erdnc3cFD4pxnA/hyYB50VGTM4Ott5IFdlv1nlE1PwqSyoiZUoBH+MxtQiSXa2vYNdzm kXBdFOBKS9s1giGHGWWTPcrk4DBEOzU1/ahqL3KnYc4YpL+9mUESEY/g3tVKfr93Cxlh 25jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697551911; x=1698156711; h=content-transfer-encoding:in-reply-to:organization:from:references :cc: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=rAWqPlhBhBylPMfzP1nNZgDINoo/gYtcyAYpgqEx4Zw=; b=Ml5T3ppF85VMU6g3r73a0Ek9vINYAs9jhpLVwLG9XvAvtPEHloR38QL9Ih0q22MTAk xjJSVfQEWBrelO5KuqYM2RTbLoHBXug9XBfOyrUqvBuq22wvFalQsgtR5wM7f6dnuNI8 19GFBJpoiUFAQpAq2tZ/5I7pHSN/wqmJWQm8e3vu9EayMnJ6WxLkHd4uwkBDnf11zenN uCGRFllqHRyCXv9tkar36Z01N2jgxm1SYmbPs5xOT9M9T2yfvWeVLAUq9y3Qt0Zg6xK2 r5NKwHMcnhBdXSbhCkbYPqK+dLBBU41JpJZkOj08RWcSwJcY6jdZfiBP6aU9W4A1s/Ba 2X1A== X-Gm-Message-State: AOJu0Yz4BagxXTznAlaV9diaNa7PpgrZ0+/p/1HIf8edKmkRVD1rfuLm +SBiFaq8EMM6Q4NfsnI17H09qw== X-Google-Smtp-Source: AGHT+IFGwk6sayZwR/UJY02dVTNhVt7LaDCTBjHkHB4UQcYIGizCCOSjCuXb4O06oGjt4pMy06BsSg== X-Received: by 2002:a05:6a00:1812:b0:68f:ce6a:8685 with SMTP id y18-20020a056a00181200b0068fce6a8685mr2824317pfa.14.1697551911403; Tue, 17 Oct 2023 07:11:51 -0700 (PDT) Received: from [192.168.15.31] (201-92-183-120.dsl.telesp.net.br. [201.92.183.120]) by smtp.gmail.com with ESMTPSA id i13-20020a65484d000000b0058c1383fa8bsm1293865pgs.0.2023.10.17.07.11.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Oct 2023 07:11:50 -0700 (PDT) Message-ID: Date: Tue, 17 Oct 2023 11:10:32 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: RFC: system-wide default tunables Content-Language: en-US To: DJ Delorie Cc: libc-alpha@sourceware.org References: 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=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no 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 06/10/23 17:25, DJ Delorie wrote: > Adhemerval Zanella Netto writes: >> The hwcap-related are still used for library selection, the original >> intention of the ld.so.cache. What I am afraid is ld.so.cache start to >> being an umbrella for different and unrelated settings. > > The alternative is to add an /etc/tunables.cache which would correspond > to /etc/tunables.conf and/or /etc/tunables.conf.d/* > > On most systems (no files) that would add one unsuccessful stat() call. We can use 'access' to check for file existent first and then read the whole file, as we do for /etc/ld.so.preload. It should slight faster than stat. > >> It is not improper action that I worried, but security and performance >> implications. For instance, the malloc tunables change performance depending >> of the workload; a system-wide tunable might not the best option for all >> programs. > > Yup. That would be a bad choice, but not an *invalid* choice. The more > likely use of these tunables would be to alter the hwcaps logic to > better match the hardware, or to enforce a "common minimum" hardware > level for migratable programs. Or something else I can't imagine just > yet ;-) > >> But I am assuming that system-wide has preference >> over user-defined, which does not seems the case for your proposal. > > Since these are tunables and not, say, security settings, it seemed to > make sense that a system-wide setting would be "new default" relative to > the environment variable. An environment variable can be set for a > specific program; a system-wide setting cannot. > >> I think what is not clear is if the idea is to mimic the 'security_level' >> of tunable (which I intend to remove), in a way that we might have tunable >> that might overridden and/or disabled by the process (through the envvar). > > I thought of that - being able to have flags for tunables that control > those overrides et al - but decided against it. These are tunables, not > security settings, and are more "advisory" than "mandatory", and I > couldn't think of a legitimate reason to stop a program from having a > program-specific tuning. But we already have opt-in security features with glibc.cpu.x86_ibt, glibc.cpu.x86_shstk, and glibc.mem.tagging. At least the x86 ones, the default is set by an ELF property (assuming --enable-cet), but memory tagging is complete opt-in. That's why I think we either need to add some security context on system-wide tunables; where the tunable can not be override by user; or move the opt-in security tunable to a different mechanism. > >>>>> * Values in ld.so.cache will be parsed but not range checked; that's >>>>> dependent on what the glibc app expects. >>>> >>>> Importing the range information on tunable definition is straightforward, >>> >>> Unless it differs between applications. Or if the cache were generated >>> with one version of glibc and the application runs with a different >>> version. >> >> But in this case, and invalid/unknown value should be ignored if the program >> is using a different glibc version. > > The case I was referring to would be if the *range* changed between > versions. Same tunable name, different min/max. > > I don't think it would matter much to test the wrong range, but the app > still needs to range check at runtime anyway. Yes, I wasn't say otherwise. The range check should always be done at runtime as well. > >> Setting an invalid/unknown tunable still make little sense to me, it >> means that it will always be ignored by some target if you are running >> different glibc with different tunable setting support. And I don't >> see why we should not make it explicit for the administrator. >> >> Maybe the best way is to make the range/key check as default and add an >> option to force to set invalid values. > > I'm OK with warnings. > > On a system with multiple installed versions of glibc (no, don't ask me > how ;) there might not be one common set of checks that works. > >>> That enum might change from version to version. We're already seeing >>> enum-related issues with RHEL upgrades. >> >> Yes, Carlos has brought the awk sorting problem. I think this is fixable >> (maybe porting the tunables generation to python, run the sysdeps search >> in a predictable way, set enum value based on tunable ordering) and we can >> add test to check if tunable enum changes over releases. >> >> I still think this is simpler than data structure your are proposing, and >> with less performance issues. But I don't have a strong preference. > > If we store the enums, and *also* store the tunable name, we could use > the enum for lookup but also strcmp to validate that it's the correct > one. Sounds reasonable. > >>>>> * I'm not going to try to add some "syntax" to specify if a tunable is >>>>> overridable or not; this is a simple default-only change. >>>> >>>> How should we handle the envvar GLIBC_TUNABLEs in the presence of a system-wide >>>> tunable? >>> >>> The variable overrides the cache. >> >> Right. Do we allow security opt-in option as well? I am asking because >> in this case, it is expected that the system-wide should not be overridden. > > If a tunable needs to be ignored for security reasons, I would assume > the system-wide default would be left alone but the environment variable > would be ignored. I do not expect a case where a system-wide tunable > should become "sticky" and block the environment variable in a > non-security context. Yes, I would expect that once the administrator sets a opt-in security features; it should not be able to be disable by user tunables. > > This assumes that a correct tunable setting is required for > secure/proper operation; if this is not the case, the program is at > fault ;-) because it's not just "tuning" at that point. > >>> Er, isn't that the environment variable? >>> >> >> It is a easier way to configure per-process tunable, it avoid messing with FS >> that either are mounted RO or do not allow adding wrappers to setup GLIBC_TUNABLES. >> >> Also, my idea is to just remove the tunable setting for setuid/setguid; so >> per-process is a way to setup specific rules for security sensitive processes >> (assuming that we will support non-overriden security tunables). > > So /etc/tunables.conf would have something like this? > > [/bin/bash] > glibc.malloc.max_arenas=1 > > This is the type of complexity I wanted to avoid. > > We could, in theory, add an ELF section for embedding tunables into an > executable image, but that's outside my scope. > This was only an idea, but I take this might be added only if we do have a requirement for that. >> The alternative is to add an /etc/tunables.cache which would correspond >> to etc/tunables.conf and/or /etc/tunables.conf.d* > > This adds the question: if we have a separate cache file, do we need a > separate program to generate it? > I think it would make sense, since ldconfig is really described as 'configure dynamic linker run-time bindings'.