Bug 180438 - [smbfs] [patch] mount_smbfs fails on arm because of wrong endianess assumption in libsmb
Summary: [smbfs] [patch] mount_smbfs fails on arm because of wrong endianess assumptio...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.0-CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: Ian Lepore
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-10 16:40 UTC by rz-rpi03
Modified: 2016-01-19 23:37 UTC (History)
2 users (show)

See Also:


Attachments
file.diff (2.41 KB, patch)
2013-07-10 16:40 UTC, rz-rpi03
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description rz-rpi03 2013-07-10 16:40:00 UTC
When trying to mount an smb-share on arm with mount_smbfs I got the error message
"a bug somewhere in the nb_name* code".

Analysing the cause showed that nb_name_encode() in contrib/smbfs/lib/smb/nb_name.c
make assumptions about the layout of data (endianess) by writing at a u_char *
with casts to ushort * which are not true at (my) arm.

As a result the length information in the first byte of the encoded name gets
overwritten with a encoded nibble of the first character of the name.
This let nb_encname_len() calculate a different value as nb_name_len() and
nb_sockaddr() print out the error message above.

Fix: The attached patch fixes nb_name_encode().

With the patch applied I have successfully mounted a smb share using the arm
system. I also verified the patch using a i386 system to be shure not to
introduce a bug into the other architectures.

Patch attached with submission follows:
How-To-Repeat: Crosscompile libiconv libmchain smbfs modules for a arm CPU (RaspberryPi here).
Do not forget to compile mount_smbfs als well. The attached patch contains the
needed statements for arm as well. Then call
mount_smbfs -I mybox. //USER@MYBOX/home /mnt
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2013-07-10 21:43:40 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-fs

Over to maintainer(s).
Comment 3 commit-hook freebsd_committer freebsd_triage 2015-12-21 17:17:45 UTC
A commit references this bug:

Author: ian
Date: Mon Dec 21 17:17:00 UTC 2015
New revision: 292552
URL: https://svnweb.freebsd.org/changeset/base/292552

Log:
  Avoid unaligned memory accesses when encoding netbios names in libsmb.

  The current code for encoding a netbios name converts each byte to a 16-bit
  value and stores the result by casting a char* to u_short*, resulting in
  alignment faults on strict-alignment platforms.

  This change reimplements the encoding routine using only byte accesses to
  memory. There is no particular reason to work with 16-bit values just
  because the encoding process creates two bytes of output for every byte of
  input. Working a byte at at time also avoids endian problems for big-endian
  platforms.

  PR:		180438
  PR:		189415
  Differential Revision:	https://reviews.freebsd.org/D4622

Changes:
  head/contrib/smbfs/lib/smb/nb_name.c
Comment 4 commit-hook freebsd_committer freebsd_triage 2015-12-21 17:41:50 UTC
A commit references this bug:

Author: ian
Date: Mon Dec 21 17:41:09 UTC 2015
New revision: 292553
URL: https://svnweb.freebsd.org/changeset/base/292553

Log:
  Make the building of libsmb and mount_smbfs unconditional, now that r292552
  has eliminated alignment and endian problems that were making it fail on
  some platforms.

  PR:        180438
  PR:        189415

Changes:
  head/lib/Makefile
  head/usr.sbin/Makefile
  head/usr.sbin/Makefile.amd64
  head/usr.sbin/Makefile.arm
  head/usr.sbin/Makefile.i386
  head/usr.sbin/Makefile.powerpc
  head/usr.sbin/Makefile.sparc64
Comment 5 rz-rpi03 2015-12-22 08:01:46 UTC
Now this bug is fixed, so I am closing it. Thank you.
Comment 6 commit-hook freebsd_committer freebsd_triage 2016-01-19 23:37:31 UTC
A commit references this bug:

Author: ian
Date: Tue Jan 19 23:36:50 UTC 2016
New revision: 294364
URL: https://svnweb.freebsd.org/changeset/base/294364

Log:
  MFC r292337, r292552, r292553:

    Build mount_smbfs for arm.  Also sort the subdirs.

    Avoid unaligned memory accesses when encoding netbios names in libsmb.

    The current code for encoding a netbios name converts each byte to a 16-bit
    value and stores the result by casting a char* to u_short*, resulting in
    alignment faults on strict-alignment platforms.

    This change reimplements the encoding routine using only byte accesses to
    memory. There is no particular reason to work with 16-bit values just
    because the encoding process creates two bytes of output for every byte of
    input. Working a byte at at time also avoids endian problems for big-endian
    platforms.

    Make the building of libsmb and mount_smbfs unconditional, now that r292552
    has eliminated alignment and endian problems that were making it fail on
    some platforms.

  PR:           180438
  PR:           189415
  Relnotes:	Yes

Changes:
_U  stable/10/
  stable/10/contrib/smbfs/lib/smb/nb_name.c
  stable/10/lib/Makefile
  stable/10/usr.sbin/Makefile
  stable/10/usr.sbin/Makefile.amd64
  stable/10/usr.sbin/Makefile.arm
  stable/10/usr.sbin/Makefile.i386
  stable/10/usr.sbin/Makefile.ia64
  stable/10/usr.sbin/Makefile.powerpc
  stable/10/usr.sbin/Makefile.sparc64