From owner-dev-commits-src-branches@freebsd.org Tue Jan 26 14:47:23 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 770CA4F1BB7; Tue, 26 Jan 2021 14:47:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DQ8hq2gyPz4THb; Tue, 26 Jan 2021 14:47:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4DE613286; Tue, 26 Jan 2021 14:47:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10QElNRR077994; Tue, 26 Jan 2021 14:47:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10QElN3M077993; Tue, 26 Jan 2021 14:47:23 GMT (envelope-from git) Date: Tue, 26 Jan 2021 14:47:23 GMT Message-Id: <202101261447.10QElN3M077993@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: d7e23b5cdd84 - stable/12 - elfctl: allow features to be specified by value MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: d7e23b5cdd8465bd50f88b1e38cb695a361a26f5 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jan 2021 14:47:23 -0000 The branch stable/12 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=d7e23b5cdd8465bd50f88b1e38cb695a361a26f5 commit d7e23b5cdd8465bd50f88b1e38cb695a361a26f5 Author: Ed Maste AuthorDate: 2021-01-22 17:22:35 +0000 Commit: Ed Maste CommitDate: 2021-01-26 14:46:00 +0000 elfctl: allow features to be specified by value This will allow elfctl on older releases to set bits that are not yet known there, so that the binary will have the correct settings applied if run on a later FreeBSD version. PR: 252629 (related) Suggested by: kib Reviewed by: gbe (manpage, earlier), kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D28284 (cherry picked from commit 86f33b5fcf6087bf4439881011b920ff99e6e300) elfctl: fix typo from last-minute refactoring Reported by: jkim (cherry picked from commit f302fd1aa6730facd53a3f761e0a57302731b03e) elfctl: Fix type errors. Target value for val has uint32_t type, not uint, adjust used constant. Change val type to unsigned so that left and right sides of comparision operator do not expose different signed types of same range [*]. Switch to unsigned long long and strtoll(3) so that 0x80000000 is accepted by conversion function [**]. Reported by: kargl [*] Noted by: emaste [**] Reviewed by: emaste Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D28301 (cherry picked from commit 9940ac808de7b7d4ed0408c3e739f667dca06d3b) --- usr.bin/elfctl/elfctl.1 | 15 +++++++++++++-- usr.bin/elfctl/elfctl.c | 26 +++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/usr.bin/elfctl/elfctl.1 b/usr.bin/elfctl/elfctl.1 index f93b558fdf0d..23e2dabea49c 100644 --- a/usr.bin/elfctl/elfctl.1 +++ b/usr.bin/elfctl/elfctl.1 @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 12, 2021 +.Dd January 22, 2021 .Dt ELFCTL 1 .Os .Sh NAME @@ -64,7 +64,8 @@ to turn on the features, to turn off the features, .Dq Li = to only turn on the given features. -A comma separated list of feature names follows the operation. +A comma separated list of feature names or numeric values follows the +operation. .El .Pp If @@ -86,6 +87,16 @@ command: elfctl file elfctl -e +aslr file .Ed +.Pp +Features may be specified as numerical values: +.Bd -literal -offset -indent +elfctl -e =0x0001,0x0004 file +.Ed +.Pp +Features may also be specified as a single combined value: +.Bd -literal -offset -indent +elfctl -e =0x5 file +.Ed .Sh HISTORY .Nm first appeared in diff --git a/usr.bin/elfctl/elfctl.c b/usr.bin/elfctl/elfctl.c index efc993302c60..15b35a5fec4b 100644 --- a/usr.bin/elfctl/elfctl.c +++ b/usr.bin/elfctl/elfctl.c @@ -33,12 +33,15 @@ #include #include +#include #include +#include #include #include #include #include #include +#include #include #include #include @@ -246,9 +249,26 @@ convert_to_feature_val(char *feature_str, uint32_t *feature_val) } } if (i == len) { - warnx("%s is not a valid feature", feature); - if (!iflag) - return (false); + if (isdigit(feature[0])) { + char *eptr; + unsigned long long val; + + errno = 0; + val = strtoll(feature, &eptr, 0); + if (eptr == feature || *eptr != '\0') + errno = EINVAL; + else if (val > UINT32_MAX) + errno = ERANGE; + if (errno != 0) { + warn("%s invalid", feature); + return (false); + } + input |= val; + } else { + warnx("%s is not a valid feature", feature); + if (!iflag) + return (false); + } } }