Bug 204417 - [autofs] automountd truncates labels > 23 characters long
Summary: [autofs] automountd truncates labels > 23 characters long
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Edward Tomasz Napierala
URL:
Keywords: needs-qa
Depends on:
Blocks:
 
Reported: 2015-11-10 04:08 UTC by Jan Beich
Modified: 2017-01-21 12:01 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer freebsd_triage 2015-11-10 04:08:05 UTC
$ uname -a
FreeBSD bar 11.0-CURRENT FreeBSD 11.0-CURRENT #0 r290495M: Sat Nov  7 14:57:28 UTC 2015     foo@bar:/usr/obj/usr/src/sys/NONGENERIC  amd64

1. Download http://releases.ubuntu.com/14.04.3/ubuntu-14.04.3-desktop-amd64.iso
2. Either flash it on a USB drive or emulate with something like DriveDroid
3. Uncomment -media in /etc/auto_master
4. automount; automountd; or use service(8)

$ ls /media
ls: Ubuntu 14.04.3 LTS amd6: No such file or directory
da0s2

$ /etc/autofs/special_media
da0s2
Ubuntu 14.04.3 LTS amd64

$ /etc/autofs/special_media | vis -w
da0s2\012Ubuntu\04014.04.3\040LTS\040amd64\012

$ /etc/autofs/special_media 'Ubuntu 14.04.3 LTS amd6'
$ /etc/autofs/special_media 'Ubuntu 14.04.3 LTS amd64'
-fstype=cd9660,nosuid   :/dev/da0

$ automountd -d
automountd: waiting for request from the kernel
automountd: not forking due to -d flag; will exit after servicing a single request
automountd: got request 14: from map -media, path /media/, prefix "/media", key "Ubuntu 14.04.3 LTS amd6", options "nosuid"
automountd: parsing map "-media"
automountd: executing "/etc/autofs/special_media Ubuntu 14.04.3 LTS amd6" as pid 5493
automountd: "/etc/autofs/special_media Ubuntu 14.04.3 LTS amd6", pid 5493, terminated gracefully
automountd: map may contain wildcard entries
automountd: found node defined at [kernel request]:0; not a mountpoint
automountd: creating subtree at /media
automountd: nothing to mount; exiting
automountd: completing request 14 with error 0

Can you reproduce? If not I'll try to debug my environment more.
Comment 1 Jan Beich freebsd_committer freebsd_triage 2015-11-10 04:21:09 UTC
Err, (2) step can also be done with

  mdconfig -f /path/to/ubuntu-14.04.3-desktop-amd64.iso
Comment 2 Jan Beich freebsd_committer freebsd_triage 2015-11-10 04:44:52 UTC
Better, (1) and (2) can be replaced with

  $ makefs -o label=$(jot -c - a z | rs -g) foo.img /rescue
  $ mdconfig -f foo.img

which still leads to an error

  $ ls /media
  ls: abcdefghijklmnopqrstuvw: No such file or directory

Kernel issue?
Comment 3 Edward Tomasz Napierala freebsd_committer freebsd_triage 2015-11-10 09:21:58 UTC
Kind of - you'll see it if you grep for AUTOFS_NAMELEN in sys/fs/autofs/.  Right now the code uses dirents of fixed size, which simplifies it a lot.  I'll see what I can do.
Comment 4 Mike Hibler 2016-02-11 15:59:00 UTC
This 24 character limitation has been biting us as well.

I completely understand the desire to use a fixed length for simplification, but why 24? Is that a "least common denominator" value for some known underlying filesystem type? It seems like MAXNAMLEN (255) would be a better choice.
Comment 5 Edward Tomasz Napierala freebsd_committer freebsd_triage 2016-02-16 17:32:48 UTC
There's an experimental patch at https://reviews.freebsd.org/D5266.  Testing is welcome :-)
Comment 6 Mike Hibler 2016-02-19 19:00:14 UTC
Thanks! I will give it a try next week.
Comment 7 Jan Beich freebsd_committer freebsd_triage 2016-02-28 17:27:27 UTC
(In reply to Edward Tomasz Napierala from comment #5)
> https://reviews.freebsd.org/D5266

It does help, tested comment 0 and comment 2. However, FFS, ISO9660, NTFS don't allow labels > 32 characters long, FAT32, EXT4, XFS even less.

With NFS hostname (FQDN) is treated as volume label. autofs: <= 251 works fine, 252-255 aborts with ENOENT, >= 256 label disappears from browsing. mount_nfs: > 80 aborts with ENAMETOOLONG.

With FUSE my quick test choked on / (slash) truncating the label.

  # Android 5.1, TWRP 3.0, MTP-enabled
  $ simple-mtpfs -l
  1: Google Inc (for LG Electronics/Samsung)Nexus 4/5/7/10 (MTP+ADB)

  $ ls -1 /mtp
  Google Inc (for LG Electronics

  $ ls -1 /mtp/"Google Inc (for LG Electronics"
  Internal Storage
  Micro SDCard
Comment 8 Mike Hibler 2016-03-02 16:49:16 UTC
(In reply to Mike Hibler from comment #6)
You fix works fine for me. But we are doing pretty straight-forward NFS mounts. Obviously Jan's use and testing are much more extensive and I will defer to Jan ging forward.
Comment 9 Mike Hibler 2016-03-06 17:46:41 UTC
(In reply to Mike Hibler from comment #8)
I take that back! It doesn't quite work right. The getcwd() function was getting massively confused, always thinking it was at the mountpoint no matter how far descended from the mountpoint you were.

This was due to returning a rounded-up name length in autofs_readdir_one:

        namlen = roundup2(strlen(name) + 1, 4);
        ...
        dirent.d_namlen = namlen;

Use of the rounded value is fine for computing reclen and doing the strlcpy(), but the true name length needs to be returned in d_namlen:

        dirent.d_namlen = strlen(name);

Now it seems to be working fine.
Comment 10 commit-hook freebsd_committer freebsd_triage 2016-03-13 14:17:59 UTC
A commit references this bug:

Author: trasz
Date: Sun Mar 13 14:17:23 UTC 2016
New revision: 296798
URL: https://svnweb.freebsd.org/changeset/base/296798

Log:
  Remove name length limitation from autofs(5). The linear search with
  strlens is somewhat suboptimal, but it's a temporary measure that will
  be replaced with red-black trees later on.

  PR:		204417
  Reviewed by:	kib@
  MFC after:	1 month
  Sponsored by:	The FreeBSD Foundation
  Differential Revision:	https://reviews.freebsd.org/D5266

Changes:
  head/sys/fs/autofs/autofs.h
  head/sys/fs/autofs/autofs_vnops.c
Comment 11 Edward Tomasz Napierala freebsd_committer freebsd_triage 2016-03-14 17:47:04 UTC
Ok, stuff should work correctly now; testing is welcome.  Regarding the slashes - there's nothing that autofs can do in this case, the dynamic map should be updated to replace pluses and slashes with eg '-'.  I've just committed a fix to special_media that does that.
Comment 12 Edward Tomasz Napierala freebsd_committer freebsd_triage 2017-01-21 12:01:10 UTC
I don't plan to MFC this back to 10-STABLE.