From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: ** X-Spam-Status: No, score=2.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FCDEC433DB for ; Fri, 8 Jan 2021 15:10:16 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0FA38238EC for ; Fri, 8 Jan 2021 15:10:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0FA38238EC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94) (envelope-from ) id 1kxtOb-0005K7-2O; Fri, 08 Jan 2021 10:09:45 -0500 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94) (envelope-from ) id 1kxtOY-0005Jq-RH for kernelnewbies@kernelnewbies.org; Fri, 08 Jan 2021 10:09:42 -0500 Received: by mail-ej1-x62c.google.com with SMTP id qw4so14839142ejb.12 for ; Fri, 08 Jan 2021 07:09:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5zAqDCZABaf1krcRiwa0+YJw8q9aqRDGJ1OB+eIQtjA=; b=kyb6+xy0uWZcv1UFcZbucE1skKSb/NeFhV8xQ4NIFBzY4xi97GT78EgrFYR7WL6HVs feKUKrpXeXQ9smFUjzfzolP8kjrNLopfHAF8bu7QIZyZGW6U0Yp9DRUK656teA4EbApn e2k++MkiQJm+84A6SLI/iumOtcMTmebTQwXypeMipcJ6HM12RDQ35QBzPqBx1WcgnLdv fhvIbI1gVE5KBTLe0xJHPtoLu0KC71ApVX8+4zq14MVcGb/Mlk2jr5ssHNZAJCF2VJfW Entq4bv5zF6Ac9mWaFtWdYrDploNES/6Av3vZFGPxqh4RgYwl3j9pqKm2IkarhgTpsK/ R4nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5zAqDCZABaf1krcRiwa0+YJw8q9aqRDGJ1OB+eIQtjA=; b=kFlj3i8BLlWBHnu64xUuyZyNN5PqjeBXaQe+QjjR46zJF8h9kMTO5SfsmAJlk81Iho hq/XQUf0uTpdv/6LaZcCpgWc8WIa8hc9vZuDuR4nRHEIWpX8GvmI2GD3jlNd5YU2SXCw EFJUZxd2NTaaTOMXefrbJmfwLFqxW+OjQ/Ztbd2OzoYVRsUTG9p8XSg6nk476+jQB+be g+q6Wd0sLzOLiNv/fbBjywf/lbLqnWD8z4EpVqGnR0i6vha7tBY5oo0j6+xVg/XD4FO4 SzjbARaGFht9u5wFyVILNVX9NE/5WRNeSUIGcrOWMD6hNjFNrEBi2a+Mo7SvPfsis47n qffw== X-Gm-Message-State: AOAM5310/EXFFsC+qT4MwHB3+P0Rhq623hxQrhvGevxR/ZPIp++11sqd RzpLD5ZTioI9eN+HQ8HUpVRBKesdJJldbhcdx78= X-Google-Smtp-Source: ABdhPJzz6LPp5Ly2tAt5x/O40VKikHyQJyGV7vdAbXnPgS8T89KW1cD615D6/hVIrQn9jL+WpT/zlf0cH+v2VCO6CjM= X-Received: by 2002:a17:906:2f83:: with SMTP id w3mr3074780eji.292.1610118579845; Fri, 08 Jan 2021 07:09:39 -0800 (PST) MIME-Version: 1.0 References: <87y2jmwi58.fsf@gmail.com> In-Reply-To: From: Nicky Chorley Date: Fri, 8 Jan 2021 15:09:28 +0000 Message-ID: Subject: Re: Setting group/other write flags not honoured in open To: Marcelo Diop-Gonzalez Cc: kernelnewbies@kernelnewbies.org X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============3490638288300089134==" Errors-To: kernelnewbies-bounces@kernelnewbies.org --===============3490638288300089134== Content-Type: multipart/alternative; boundary="000000000000ff7e6005b864f126" --000000000000ff7e6005b864f126 Content-Type: text/plain; charset="UTF-8" I realised I never got back to this. Thanks Marcelo for that - I'll look into it. Best, Nicky On Sat, 31 Oct 2020 at 16:36, Marcelo Diop-Gonzalez wrote: > Hey, I think this is because the process's umask is changing the mode. In > fs/namei.c in the function lookup_open() there's this bit: > > .... > if (!IS_POSIXACL(dir->d_inode)) > mode &= ~current_umask(); > .... > > the open(2) and umask(2) manpages will explain how to deal with it > > -Marcelo > > > > On Sat, Oct 31, 2020 at 11:06 AM Nicky Chorley > wrote: > >> Hi folks, >> >> I hope it's OK to ask this question here. I'm reading The Linux >> Programming Interface and am beginning to get to grips with the file >> oriented system calls. >> >> I have a program that calls open to create a file, specifying the mode >> flags for owner, group, other read and write. The file is created >> sucessfully, but when I look at its permissions, I only see the read >> perms set for group and others: >> >> > ./create_file foo >> > ls -l foo >> -rw-r--r-- 1 nick users 0 Oct 31 14:52 foo >> >> Why would that be? The entirety of my program is >> >> #include >> #include >> >> int main(int argc, char *argv[]) { >> int open_flags = O_CREAT | O_WRONLY | O_TRUNC; >> mode_t file_perms = >> S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; >> >> int output_fd = open(argv[1], open_flags, file_perms); >> >> close(output_fd); >> } >> >> I also ran the program with strace and the perms in the openat call are >> as I would expect: >> >> openat(AT_FDCWD, "foo", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 >> >> I don't understand why the group and other write flags aren't being >> set. Could someone help shed some light on this please? >> >> I'm not sure what factors influence this, but I'm running openSUSE Leap >> 15.2, with kernel 5.3.18-lp152.47-default, gcc 7.5.0 and glibc 2.26. >> >> Thanks, >> >> Nicky >> >> _______________________________________________ >> Kernelnewbies mailing list >> Kernelnewbies@kernelnewbies.org >> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies >> > --000000000000ff7e6005b864f126 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I realised I never got back to this. Thanks Marcelo f= or that - I'll look into it.

Best,
<= br>
Nicky

On Sat, 31 Oct 2020 at 16:36, Marcelo Diop-Go= nzalez <marcelo827@gmail.com= > wrote:
Hey, I think this is because the process's umask is changi= ng the mode. In fs/namei.c in the function lookup_open() there's this b= it:

....
if (!IS_POSIXACL(dir->d_inode))=
=C2=A0 mode &=3D ~current_umask();
....

the open(2) and umask(2) manpages will explain how to deal with it<= /div>

-Marcelo



On Sat, Oct 31, 2= 020 at 11:06 AM Nicky Chorley <ndchorley@gmail.com> wrote:
Hi folks,

I hope it's OK to ask this question here. I'm reading The Linux
Programming Interface and am beginning to get to grips with the file
oriented system calls.

I have a program that calls open to create a file, specifying the mode
flags for owner, group, other read and write. The file is created
sucessfully, but when I look at its permissions, I only see the read
perms set for group and others:

> ./create_file foo
> ls -l foo
-rw-r--r-- 1 nick users 0 Oct 31 14:52 foo

Why would that be? The entirety of my program is

#include <fcntl.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
=C2=A0 int open_flags =3D O_CREAT | O_WRONLY | O_TRUNC;
=C2=A0 mode_t file_perms =3D
=C2=A0 =C2=A0 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
=C2=A0 int output_fd =3D open(argv[1], open_flags, file_perms);

=C2=A0 close(output_fd);
}

I also ran the program with strace and the perms in the openat call are
as I would expect:

openat(AT_FDCWD, "foo", O_WRONLY|O_CREAT|O_TRUNC, 0666) =3D 3

I don't understand why the group and other write flags aren't being=
set. Could someone help shed some light on this please?

I'm not sure what factors influence this, but I'm running openSUSE = Leap
15.2, with kernel 5.3.18-lp152.47-default, gcc 7.5.0 and glibc 2.26.

Thanks,

Nicky

_______________________________________________
Kernelnewbies mailing list
Kernel= newbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailma= n/listinfo/kernelnewbies
--000000000000ff7e6005b864f126-- --===============3490638288300089134== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============3490638288300089134==--