Had a similar question for Ubuntu 22.04.2 LTS and exfat flash drives, which also mounts with fmask=0022,dmask=0022 by default which results in all files being marked as executable by default.
Automounting of external flash drives are handled by UDisks daemon - this is noticeable by uhelper=udisks2 meta-option listed in mount output:
$ mount | grep /dev/sde1
/dev/sde1 on /media/user/Sandisk128 type exfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,iocharset=utf8,errors=remount-ro,uhelper=udisks2)
UDisks can be configured to pass specific mount options for different filesystem types/different devices. Configuration example can be found in /etc/udisks2/mount_options.conf.example, and based on it I created:
$ cat /etc/udisks2/mount_options.conf
[defaults]
exfat_defaults=uid=$UID,gid=$GID,iocharset=utf8,errors=remount-ro,fmask=0133,dmask=0022
exfat_allow=uid=$UID,gid=$GID,dmask,errors,fmask,iocharset,namecase,umask
Essentially adding fmask=0133,dmask=0022 to exfat_defaults (others *_defaults/*_allow should be used for other filesystem types, e.g. vfat_defaults/vfat_allow for vfat, see /etc/udisks2/mount_options.conf.example for examples).
Now restarting the UDisks with sudo systemctl restart udisks and re-pluggin the flash drive I see in logs:
Apr 13 11:26:55 host udisksd[9586]: Using overridden mount options: uid=$UID,gid=$GID,iocharset=utf8,errors=remount-ro,fmask=0133,dmask=0022
And applied settings in the mount output:
$ findmnt /media/user/Sandisk128
TARGET SOURCE FSTYPE OPTIONS
/media/user/Sandisk128 /dev/sde1 exfat rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0133,dmask=0022,iocharset=utf8,errors=remount-ro
Answering the question where those defaults are coming from is a bit more interesting.
Mounting exfat disk without any options we can trace that no options are passed to the kernel:
# strace -e mount -f mount -t exfat /dev/sde1 /mnt/point/
mount("/dev/sde1", "/mnt/point", "exfat", 0, NULL) = 0
+++ exited with 0 +++
but fmask=0022,dmask=0022 are still present in the options list:
$ findmnt /mnt/point
TARGET SOURCE FSTYPE OPTIONS
/mnt/point /dev/sde1 exfat rw,relatime,fmask=0022,dmask=0022,iocharset=utf8,errors=remount-ro
Looking through the kernel sources we can see that fmask=...,dmask=... are appended in exfat_show_options() based on opts->fs_fmask, opts->fs_dmask values:
static int exfat_show_options(struct seq_file *m, struct dentry *root)
{
...
seq_printf(m, ",fmask=%04o,dmask=%04o", opts->fs_fmask, opts->fs_dmask);
fs_fmask, fs_dmask are set in exfat_parse_param() if the relevant mount option is provided (not our case), and otherwise initialized from the current task umask in exfat_init_fs_context():
static int exfat_init_fs_context(struct fs_context *fc)
{
...
sbi->options.fs_fmask = current->fs->umask;
sbi->options.fs_dmask = current->fs->umask;
We can confirm that Udisks is running with the umask of 0022:
$ grep '^Umask:' "/proc/$(pgrep udisksd)/status"
Umask: 0022
And manually confirm that changing umask of the process will change the used fmask/dmask, e.g. with umask 0133:
# umask 0133
# umask -S
u=rw,g=r,o=r
# strace -e mount -f mount -t exfat /dev/sde1 /mnt/point/
mount("/dev/sde1", "/mnt/point", "exfat", 0, NULL) = 0
+++ exited with 0 +++
# findmnt /mnt/point
TARGET SOURCE FSTYPE OPTIONS
/mnt/point /dev/sde1 exfat rw,relatime,fmask=0133,dmask=0133,iocharset=utf8,errors=remount-ro
# ls -l /mnt/point/README.txt
-rw-r--r-- 1 root root 72 Apr 12 11:40 /mnt/point/README.txt
# mkdir /mnt/point/directory
# ls -ld /mnt/point/directory/
drw-r--r-- 2 root root 131072 Apr 13 11:19 /mnt/point/directory/
# umount /mnt/point
I.e. default fmask/dmask values for exfat filesystem are coming from the process umask (the same for vfat filesystems).
Since typically we want to have different fmask/dmask (to make directories executable, and regular field non-executable), the preferred method to customize fmask/dmask is to explicitly add those options in the UDisks daemon configuration as suggested above.