From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 43C6D1F66F for ; Mon, 9 Nov 2020 20:40:05 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0EDAF3857C56; Mon, 9 Nov 2020 20:40:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0EDAF3857C56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1604954404; bh=WylnDZJUHzJ8AIVu9aUBKqD3KxS2qRqTbYqnFfE1XY4=; h=To:References:Subject:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=MPkGCFe7oBohotE0i2vPEuNXeR8NG1kFyNEVbRNCLjyo7I9GcetqtZ78xMEHjsCVE z5Gw8jkvb0o7swtJB+5KAD04Xk9PGL38H+subZ7MiXGXTjDr94pfycr0Q+iMW94s4i TgLkKOwenloxYo1GuzXwGgGBmDAsmVGv+sJxdZeU= Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by sourceware.org (Postfix) with ESMTPS id 54E963857C46 for ; Mon, 9 Nov 2020 20:40:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 54E963857C46 Received: by mail-qk1-x72b.google.com with SMTP id 11so9303179qkd.5 for ; Mon, 09 Nov 2020 12:40:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:references:from:autocrypt:subject:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=WylnDZJUHzJ8AIVu9aUBKqD3KxS2qRqTbYqnFfE1XY4=; b=K4Lwan2hrTRONAiJ/tp/+GGBCFwcoJ9IwIWDCUA0kqthClBkC7SgsFA/TJ5xEiKsZo cOVvEgvqCvF98lN06Er/05a8FBudBSZLeApw+ntRv4wbOBxu5xXWr3LWYpUpqZ0d1ilT xoYeZCj6eHs/aolN0NnXZ9rDNKDpb/KtqNwqkOOuXzvDzTF1SMZx0ssTVbi5zmioWe3A 3+JZiVIHe3/FFGDgwhvUGP3KOpMF3J0rUny4Oe+PdVE1Ef5yIUDPAxuJEpxAnvQDlNvn 96bToYD5CaD3DfeZYiOH9IJ3R00hN+1ouJTpga7J6G4B349jxOcjoz3uBy70bRkZxLee Nhsg== X-Gm-Message-State: AOAM532A+3lMbTdNXRn3bcDh1iMuZDRpl4Q0pptRgS4r/sxnZNR2E155 zndM6xc+uY5FA6RUedmjRULZodE7ZFf1FA== X-Google-Smtp-Source: ABdhPJzkIAJZI/XWwREdcptKo9c5lZ49NpXlzlR5CZN84OZzHH4lj49eX4OhYK9Odyb2A+ofU8/j6w== X-Received: by 2002:a37:d244:: with SMTP id f65mr15184508qkj.124.1604954400753; Mon, 09 Nov 2020 12:40:00 -0800 (PST) Received: from [192.168.1.4] ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id 21sm6534060qkv.78.2020.11.09.12.39.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Nov 2020 12:40:00 -0800 (PST) To: libc-alpha@sourceware.org, =?UTF-8?Q?Alexandra_H=c3=a1jkov=c3=a1?= References: <20200428122019.26826-1-ahajkova@redhat.com> Autocrypt: addr=adhemerval.zanella@linaro.org; prefer-encrypt=mutual; keydata= mQINBFcVGkoBEADiQU2x/cBBmAVf5C2d1xgz6zCnlCefbqaflUBw4hB/bEME40QsrVzWZ5Nq 8kxkEczZzAOKkkvv4pRVLlLn/zDtFXhlcvQRJ3yFMGqzBjofucOrmdYkOGo0uCaoJKPT186L NWp53SACXguFJpnw4ODI64ziInzXQs/rUJqrFoVIlrPDmNv/LUv1OVPKz20ETjgfpg8MNwG6 iMizMefCl+RbtXbIEZ3TE/IaDT/jcOirjv96lBKrc/pAL0h/O71Kwbbp43fimW80GhjiaN2y WGByepnkAVP7FyNarhdDpJhoDmUk9yfwNuIuESaCQtfd3vgKKuo6grcKZ8bHy7IXX1XJj2X/ BgRVhVgMHAnDPFIkXtP+SiarkUaLjGzCz7XkUn4XAGDskBNfbizFqYUQCaL2FdbW3DeZqNIa nSzKAZK7Dm9+0VVSRZXP89w71Y7JUV56xL/PlOE+YKKFdEw+gQjQi0e+DZILAtFjJLoCrkEX w4LluMhYX/X8XP6/C3xW0yOZhvHYyn72sV4yJ1uyc/qz3OY32CRy+bwPzAMAkhdwcORA3JPb kPTlimhQqVgvca8m+MQ/JFZ6D+K7QPyvEv7bQ7M+IzFmTkOCwCJ3xqOD6GjX3aphk8Sr0dq3 4Awlf5xFDAG8dn8Uuutb7naGBd/fEv6t8dfkNyzj6yvc4jpVxwARAQABtElBZGhlbWVydmFs IFphbmVsbGEgTmV0dG8gKExpbmFybyBWUE4gS2V5KSA8YWRoZW1lcnZhbC56YW5lbGxhQGxp bmFyby5vcmc+iQI3BBMBCAAhBQJXFRpKAhsDBQsJCAcDBRUKCQgLBRYCAwEAAh4BAheAAAoJ EKqx7BSnlIjv0e8P/1YOYoNkvJ+AJcNUaM5a2SA9oAKjSJ/M/EN4Id5Ow41ZJS4lUA0apSXW NjQg3VeVc2RiHab2LIB4Mx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6gREidHLLqEb/otuwt1aoMPg97iUgDV5mlNef77lWE8vxmlY0FBWIXuZ yv0XYxf1WF6dRizwFFbxvUZzIJp3spAao7jLsQj1DbD2s5+S1BW09A0mI/1DjB6EhNN+4bDB SJCOv/ReK3tFJXuj/HbyDrOdoMt8aIFbe7YFLEExHpSk+HgN05Lg5TyTro8oW7TSMTk+8a5M kzaH4UGXTTBDP/g5cfL3RFPl79ubXwARAQABiQIfBBgBCAAJBQJXFRpKAhsMAAoJEKqx7BSn lIjvI/8P/jg0jl4Tbvg3B5kT6PxJOXHYu9OoyaHLcay6Cd+ZrOd1VQQCbOcgLFbf4Yr+rE9l mYsY67AUgq2QKmVVbn9pjvGsEaz8UmfDnz5epUhDxC6yRRvY4hreMXZhPZ1pbMa6A0a/WOSt AgFj5V6Z4dXGTM/lNManr0HjXxbUYv2WfbNt3/07Db9T+GZkpUotC6iknsTA4rJi6u2ls0W9 1UIvW4o01vb4nZRCj4rni0g6eWoQCGoVDk/xFfy7ZliR5B+3Z3EWRJcQskip/QAHjbLa3pml xAZ484fVxgeESOoaeC9TiBIp0NfH8akWOI0HpBCiBD5xaCTvR7ujUWMvhsX2n881r/hNlR9g fcE6q00qHSPAEgGr1bnFv74/1vbKtjeXLCcRKk3Ulw0bY1OoDxWQr86T2fZGJ/HIZuVVBf3+ gaYJF92GXFynHnea14nFFuFgOni0Mi1zDxYH/8yGGBXvo14KWd8JOW0NJPaCDFJkdS5hu0VY 7vJwKcyHJGxsCLU+Et0mryX8qZwqibJIzu7kUJQdQDljbRPDFd/xmGUFCQiQAncSilYOcxNU EMVCXPAQTteqkvA+gNqSaK1NM9tY0eQ4iJpo+aoX8HAcn4sZzt2pfUB9vQMTBJ2d4+m/qO6+ cFTAceXmIoFsN8+gFN3i8Is3u12u8xGudcBPvpoy4OoG Subject: Re: [PATCH] Linux: Add execveat system call wrapper Message-ID: <8e4bcdfa-0ecd-b076-a2a7-2cac9cb419b2@linaro.org> Date: Mon, 9 Nov 2020 17:39:57 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200428122019.26826-1-ahajkova@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Adhemerval Zanella via Libc-alpha Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" On 28/04/2020 09:20, Alexandra Hájková via Libc-alpha wrote: > From: Alexandra Hájková > diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h > index c315cc5cb8..55225b5447 100644 > --- a/sysdeps/unix/sysv/linux/bits/unistd_ext.h > +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h > @@ -17,7 +17,7 @@ > . */ > > #ifndef _UNISTD_H > -# error "Never include directly; use instead." > +#error "Never include directly; use instead." > #endif > Spurious change. > #ifdef __USE_GNU > @@ -33,4 +33,9 @@ > not detached and has not been joined. */ > extern __pid_t gettid (void) __THROW; > > +/* Execute program relative to a directory file descriptor. */ > + extern int execveat (int __fd, const char *__path, char *const __argv[], > + char *const __envp[], int __flags) > + __THROW __nonnull ((2, 3)); > + Indentation seems off here (extra space before extern). > #endif > diff --git a/sysdeps/unix/sysv/linux/execveat.c b/sysdeps/unix/sysv/linux/execveat.c > new file mode 100644 > index 0000000000..7ebf397091 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/execveat.c > @@ -0,0 +1,67 @@ > +/* Copyright (C) 1994-2020 Free Software Foundation, Inc. I think it should be solely 2020. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > + > + > +/* Execute the file FD refers to, overlaying the running program image. > + ARGV and ENVP are passed to the new program, as for `execve'. */ > +int > +execveat (int dirfd, const char *path, char *const argv[], char *const envp[], > + int flags) > +{ > + /* Avoid implicit array coercion in syscall macros. */ > + INLINE_SYSCALL_CALL (execveat, dirfd, path, &argv[0], &envp[0], flags);> +#ifndef __ASSUME_EXECVEAT > + if (errno != ENOSYS) > + return -1; > + > + int fd = openat (dirfd, path, flags | O_CLOEXEC); This will turn execevat in a cancellation entrypoint. > + if (fd < 0) > + return -1; > + > + struct fd_to_filename fdfilename; > + const char *gfilename > + = path != NULL ? path : __fd_to_filename (fd, &fdfilename); > + > + /* We do not need the return value. */ > + __execve (gfilename, argv, envp); > + > + int save = errno; > + > + /* We come here only if the 'execve' call fails. Determine whether > + /proc is mounted. If not we return ENOSYS. */ > + struct stat st; > + if (stat ("/proc/self/fd", &st) != 0 && errno == ENOENT) > + save = ENOSYS; Not sure if it would make a difference here, but I think it would be better to use the LFS interface here. > diff --git a/sysdeps/unix/sysv/linux/tst-execveat.c b/sysdeps/unix/sysv/linux/tst-execveat.c > new file mode 100644 > index 0000000000..06c4e9fc4b > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/tst-execveat.c > @@ -0,0 +1,68 @@ > +/* Copyright (C) 2017-2020 Free Software Foundation, Inc. Same as before, I think the Copyright year should be only 2020. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +static int > +do_test (void) > +{ > + char *argv[] = { (char *) "-c", (char *) "exit 3", NULL }; > + char *envp[] = { (char *) "FOO=BAR", NULL }; Maybe add a check if the environment variable is what you expect (to check if envp passing is ok)? > + DIR *dirp; > + int fd; > + pid_t pid; > + int status; > + > + dirp = opendir ("/bin"); > + if (!dirp) > + FAIL_EXIT1 ("failed to open /bin"); > + fd = dirfd (dirp); > + > + errno = 0; > + pid = xfork (); > + if (pid == 0) > + { > + execveat (fd, "sh", argv, envp, 0); > + > + if (errno) Don't use implicit checks. > + { > + closedir (dirp); > + FAIL_EXIT1 ("execveat failed, errno %d", errno); > + } > + } > + xwaitpid (pid, &status, 0); > + > + if (WIFEXITED (status)) > + TEST_COMPARE (WEXITSTATUS (status), 3); > + else > + { > + closedir (dirp); > + FAIL_EXIT1 ("execveat failed"); > + } > + > + closedir (dirp); > + return 0; > +} > + > +#include Besides the points raised by Joseph, the rest looks ok. I didn't check if it updates all the abilist files.