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-ASN: AS3215 2.6.0.0/16 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, RCVD_IN_DNSWL_MED,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 528A21F5AE for ; Mon, 3 May 2021 19:21:04 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 69F933950414; Mon, 3 May 2021 19:21:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69F933950414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1620069662; bh=hvDZ7lAF6wlDtYIP9qV0EJe9cIOJeEI8Wp1Znd2A6Qk=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=AEZO51eVuZqm/UqPy/nTdIZEzCAskfkx/ud0UdFKcC2ufjA4ad8UQ5edKzrdNzzsW KudjItwTSE0H7AOak4BY8kRRS40g3sJjrdJqw2Z8ZyKp/5SclykvM8aYcXn3N1wtgb dGAEMAZpnrqjjs7c6haZC/qZHWHbM5OtGqVZkltI= Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by sourceware.org (Postfix) with ESMTPS id 024C3393D033 for ; Mon, 3 May 2021 19:20:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 024C3393D033 Received: by mail-qt1-x829.google.com with SMTP id p6so2853707qtk.13 for ; Mon, 03 May 2021 12:20:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=hvDZ7lAF6wlDtYIP9qV0EJe9cIOJeEI8Wp1Znd2A6Qk=; b=gLuJhvtCPAlVGmHSkB9JMhu/IPGMzzD/J3CCiI4qxX0zac/SOK4zg68nMiVr59tfSr b9340BIlgcHhgToHPziujuscU8ZguRXOTq9ljPI/pSObyP72TR1A/FuHYQLP3dWO6mfY YDPcMNZtfEJHSn68QSd75GC6qEDBVsDJFOeFO0UktnOhFQ+cONhaN/77E++DmUJ5zz5t um5Q5/oIBof5s0G3KCO31X5mheHSzOY03JI8eE3KpsiV7Ti5Ioxu+wehTze77ru8PnW4 MhZamG9W2AlS3sWCVC6D3FkVsC8tRm+5jy4M0qG28AFXn8BJXp6/CEbB5sPP8UM8tz9s RfOQ== X-Gm-Message-State: AOAM531Fv4I0aaNfGDUvxVWbMXa49+LmDtOkLQsWwbRJ8ckboCJH7dij bvxtKX16QAqLJfL0K+rzb35yXA== X-Google-Smtp-Source: ABdhPJwR0GT3UflinRvoq6D4sy+4Xe2yAz6ivNhfuWIYHr39gstqzX0iu5JHlbnIQYISlv3Od8BlRg== X-Received: by 2002:a05:622a:1493:: with SMTP id t19mr5172565qtx.147.1620069658049; Mon, 03 May 2021 12:20:58 -0700 (PDT) Received: from [192.168.1.4] ([177.194.41.149]) by smtp.gmail.com with ESMTPSA id q7sm1378493qki.17.2021.05.03.12.20.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 03 May 2021 12:20:57 -0700 (PDT) Subject: Re: [PATCH] Linux: Add execveat system call wrapper To: libc-alpha@sourceware.org, =?UTF-8?Q?Alexandra_H=c3=a1jkov=c3=a1?= References: <20200428122019.26826-1-ahajkova@redhat.com> <20210421181159.3579223-1-ahajkova@redhat.com> Message-ID: <8fedbeac-5ff8-67bf-201f-3d59b106fbab@linaro.org> Date: Mon, 3 May 2021 16:20:54 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210421181159.3579223-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 21/04/2021 15:11, Alexandra Hájková via Libc-alpha wrote: > From: Alexandra Hájková > > Also add the test for the new wrapper. Patch looks ok in general, but there are minor issues. Since it is being back and forth for some time, I took the liberty to fix them and I will push it upstream. > > diff --git a/NEWS b/NEWS > index aa0f10a891..0765db4543 100644 > --- a/NEWS > +++ b/NEWS > @@ -18,6 +18,11 @@ Major new features: > a dump of information related to IFUNC resolver operation and > glibc-hwcaps subdirectory selection. > > +* The function execveat has been added and it operates similar to execve. > + The syscall is already used to implement fexecve without requiring /proc to > + be mounted. Similar to fexecve, if the syscall is not supported ENOSYS is > + returned. > + With the fallback removal, execveat does not act similar to fexecve. I changed the NEWS entry to: * On Linux, the function execveat has been added. It operates similar to execve and it is is already used to implement fexecve without requiring /proc to be mounted. However, different than fexecve, if the syscall is not supported by the kernel an error is returned instead of trying a fallback. > +int > +call_execveat (int fd, const char *pathname, int flags, int expected_fail, > + int num) > +{ > + char *envp[] = { (char *) "FOO=3", NULL }; > + char *argv[] = { (char *) "sh", (char *) "-c", (char *) "exit $FOO", NULL }; > + pid_t pid; > + int status; > + > + if (test_verbose > 0) > + printf ("call line number: %d\n", num); > + > + pid = xfork (); > + if (pid == 0) > + { > + TEST_COMPARE (execveat (fd, pathname, argv, envp, flags), -1); > + if (errno == ENOSYS) > + FAIL_UNSUPPORTED ("execveat is unimplemented"); This will print 'execveat is unimplemented', since the WEXITSTATUS below will already handle it. Instead I replace it with: exit (EXIT_UNSUPPORTED); > +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 ((flags & ~(AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW)) != 0) > + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); > + > + if (errno != ENOSYS) > + return -1; > + else > + return ENOSYS; > +#endif > + > + return -1; > +} Since there is no fallback anymore, there is no need to check for flag support neither handle the errno value. It can be simple as: int execveat (int dirfd, const char *path, char *const argv[], char *const envp[], int flags) { /* Avoid implicit array coercion in syscall macros. */ return INLINE_SYSCALL_CALL (execveat, dirfd, path, &argv[0], &envp[0], flags); }