[SRU] nmbd shuts down when network disconnected

Bug #180493 reported by Troy C
50
Affects Status Importance Assigned to Milestone
samba
Fix Released
Medium
samba (Debian)
Fix Released
Unknown
samba (Ubuntu)
Fix Released
Medium
Unassigned
Hardy
Fix Released
Undecided
Unassigned
Intrepid
Fix Released
Medium
Unassigned

Bug Description

Binary package hint: samba

There's probably a good reason for this behavior, but it sure is annoying!

Steps to reproduce:
1. Start samba services, ensure nmbd is running. with `ps faux | grep nmbd`
2. `tail -f /var/log/samba/log.nmbd &` <-- observe
3. disable networking in nm-applet.
4. the log will eventually say, "reload_interfaces: No subnets to listen to. Shutting down.."

Expected results:
nmbd runs until told otherwise

Here are a few brief discussions(?) elsewhere about this issue:
http://<email address hidden>/msg41675.html (contains a patch, but was supposed to be for version 3.0.5pre2)
http://lists.apple.com/archives/macos-x-server/2006/Mar/msg01363.html
http://lists.samba.org/archive/samba-technical/2002-June/022340.html

Here's a quick 'n dirty potential fix (the samba code just looked way too nice not to try :) but it may have undesirable side effects. I'm not an expert by any means!

--- samba-3.0.26a/source/nmbd/nmbd.c 2007-02-28 21:54:45.000000000 -0700
+++ samba-3.0.26afixed/source/nmbd/nmbd.c 2008-01-04 15:38:24.000000000 -0700
@@ -566,8 +566,7 @@

                /* check for new network interfaces */

- if(reload_interfaces(t))
- return;
+ while(reload_interfaces(t));

                /* free up temp memory */
                        lp_TALLOC_FREE();

Related branches

CVE References

Revision history for this message
Soren Hansen (soren) wrote :

The idea is good, the patch not so much :) Busy-waiting for a network to show up is less than optimal. Adding a sleep(5) or something to the loop would make me happy. Could you (or someone else) whip up a new patch with that change in it?

Revision history for this message
Troy C (troxor) wrote :

Sorry for the delay, real life got in the way ;)

Revision history for this message
Troy C (troxor) wrote :

this patch is for gutsy (samba-3.0.26a), the previous for dapper (3.0.22)

Changed in samba:
status: Unknown → Confirmed
Revision history for this message
Mathias Gug (mathiaz) wrote :

Using an ifup.d hook to start nmbd if it's not already running (and does nothing if nmbd is already running) would be a better solution. An ifdown.d hook is not necessary as nmbd exits by itself when an interface disappears.

Changed in samba:
importance: Undecided → Medium
status: New → Triaged
Revision history for this message
phirestalker (firestalker1-deactivatedaccount) wrote : Re: [Bug 180493] Re: nmbd shuts down when network disconnected

I think that would be better for resources as well good idea :)

On Mon, 2008-03-03 at 23:13 +0000, Mathias Gug wrote:
> Using an ifup.d hook to start nmbd if it's not already running (and does
> nothing if nmbd is already running) would be a better solution. An
> ifdown.d hook is not necessary as nmbd exits by itself when an interface
> disappears.
>
> ** Changed in: samba (Ubuntu)
> Importance: Undecided => Medium
> Status: New => Triaged
>

Revision history for this message
CheShA (8-launchpad-net-chesha-com) wrote : Re: nmbd shuts down when network disconnected

an effective workaround is to have a small script at /etc/network/if-up.d/start-samba.sh that simply contains the lines:

#!/bin/bash
/etc/init.d/samba restart

Changed in samba:
status: Confirmed → Fix Released
Changed in samba:
status: Unknown → Confirmed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package samba - 3.0.28a-0ubuntu1

---------------
samba (3.0.28a-0ubuntu1) hardy; urgency=low

  [Chuck Short]
  * New upstream release. This fixes the following Ubuntu bugs.
    - Prevent nmbd from shutting down when no network interfaces can be
      located. (LP: #180493)
    - Fixes I/O errors on access to SMB shares of OS/2. (LP: #112839)
  * Dropped patches:
    - make-distclean.patch
    - linux-cifs-user-perms.patch
    - cifs-umount-same-user.patch
    - get_global_sam_sid-non-root.patch
    - chgpasswd.patch
    - cups.patch
    - samba-syslog.patch
  * debian/mksambapasswd.awk
    - Don't add user with UID less than 1000 to smbpasswd. (LP: #199412)
  * debian/samba.if-up
    - ifup hook to reload samba once the interfaces comes up. (LP: #180493)
  * Updated control version.

  [Nicolas Valcárcel]
  * debian/patches/fix-documentation.patch
    - Fixed some escape typos in smb.conf(5) manpage. (LP: #182571)

  [Shawn Smith]
  * debian/samba.init
    - Samba init script does not conform to the LSP specification; it needs a
      status section (LP: #39157)

 -- Chuck Short <email address hidden> Tue, 11 Mar 2008 14:21:29 -0400

Changed in samba:
status: Triaged → Fix Released
Steve Langasek (vorlon)
Changed in samba:
status: Fix Released → Confirmed
Revision history for this message
Steve Langasek (vorlon) wrote :

This patch does not achieve its stated purpose, for two reasons:

- the file is missing from debian/samba.files, so never gets installed to
  the package.
- the /etc/init.d/samba reload target only reloads smbd, it does nothing
  to nmbd - certainly nothing that would start nmbd in the case that it was
  not running!

Reopening the bug.

Changed in samba:
status: Confirmed → Fix Released
Revision history for this message
Steve Langasek (vorlon) wrote :

Testing with samba 3.0.28a, here is the output in /var/log/samba/log.nmbd if I start samba before the network is up:

  [2008/03/16 04:35:51, 0] nmbd/nmbd.c:main(711)
    Netbios nameserver version 3.0.28a started.
    Copyright Andrew Tridgell and the Samba Team 1992-2008
  [2008/03/16 04:35:51, 0] nmbd/nmbd_subnetdb.c:create_subnets(190)
    create_subnets: No local interfaces !
  [2008/03/16 04:35:51, 0] nmbd/nmbd_subnetdb.c:create_subnets(191)
    create_subnets: Waiting for an interface to appear ...
  [2008/03/16 04:42:11, 0] nmbd/nmbd_become_lmb.c:become_local_master_stage2(396)
    *****

    Samba name server DARIO is now a local master browser for workgroup WORKGROUP
  on subnet 192.168.13.50

    *****

However, if I specify an 'interfaces' line in /etc/samba/smb.conf, the behavior is this:

  [2008/03/16 14:23:41, 0] nmbd/nmbd.c:main(711)
    Netbios nameserver version 3.0.28a started.
    Copyright Andrew Tridgell and the Samba Team 1992-2008
  [2008/03/16 14:23:41, 0] nmbd/nmbd_subnetdb.c:create_subnets(245)
    create_subnets: unable to create any subnet from given interfaces. nmbd is terminating
  [2008/03/16 14:23:41, 0] nmbd/nmbd.c:main(785)
    ERROR: Failed when creating subnet lists. Exiting.

So the upstream changes do not resolve this issue for all use cases, and it looks like a if-up.d script is still needed.

Furthermore, if I bring nmbd up with an 'interfaces' line, then drop the network interface and kill nmbd with -HUP (emulating the circumstances when logrotate runs while the network is down), nmbd goes into an infinite loop thousands of times a second, reporting:

  [2008/03/16 14:29:08, 0] nmbd/nmbd.c:reload_interfaces(239)
    reload_interfaces: No subnets to listen to. Waiting..

and the process doesn't notice when the network comes back, and isn't killable with /etc/init.d/samba stop.

This same procedure without an explicit 'interfaces' line in smb.conf appears to give the desired results, aside from the lack of indication in the logfile that it's finished waiting.

So the if-up.d script is probably expendible if the 'interfaces' case is fixed upstream, which is somewhat necessary anyway.

Changed in samba:
status: Confirmed → Fix Released
status: Fix Released → Confirmed
Revision history for this message
Chuck Short (zulcss) wrote :

How long does it take to get this message?

Changed in samba:
status: Fix Released → Confirmed
Revision history for this message
Chuck Short (zulcss) wrote :

Hi,

Can you try the version in my ppa: http://launchpad.net/~zulcss/+archive ?

Thanks
chuck

Revision history for this message
Troy C (troxor) wrote :

Using the PPA version above, starting samba without an explicit 'interfaces' line Instead,

[2008/06/16 21:30:04, 0] nmbd/nmbd.c:main(721)
  Netbios nameserver version 3.0.28a started.
  Copyright Andrew Tridgell and the Samba Team 1992-2008
[2008/06/16 21:30:04, 0] nmbd/nmbd_subnetdb.c:create_subnets(190)
  create_subnets: No local interfaces !
[2008/06/16 21:30:04, 0] nmbd/nmbd_subnetdb.c:create_subnets(191)
  create_subnets: Waiting for an interface to appear ...
---brought interface up here---
[2008/06/16 21:36:35, 0] nmbd/nmbd_become_lmb.c:become_local_master_stage2(396)
  *****

  Samba name server RAVANA is now a local master browser for workgroup MICRIPOFFT on subnet 10.1.0.12

  *****

Specifying an unconfigured interface on the 'interfaces = ' line, nmbd just polls every 5 seconds.
Changing 'interfaces = ' to a configured (but downed) interface, then bringing it up yields nice output, though a little delayed :)

[2008/06/16 21:40:54, 0] nmbd/nmbd.c:main(721)
  Netbios nameserver version 3.0.28a started.
  Copyright Andrew Tridgell and the Samba Team 1992-2008
[2008/06/16 21:40:54, 0] lib/interface.c:load_interfaces(229)
  WARNING: no network interfaces found
[2008/06/16 21:40:54, 0] nmbd/nmbd_subnetdb.c:create_subnets(190)
  create_subnets: No local interfaces !
[2008/06/16 21:40:54, 0] nmbd/nmbd_subnetdb.c:create_subnets(191)
  create_subnets: Waiting for an interface to appear ...
[2008/06/16 21:40:59, 0] lib/interface.c:load_interfaces(229)
  WARNING: no network interfaces found
...snip....
[2008/06/16 21:41:24, 0] lib/interface.c:load_interfaces(229)
  WARNING: no network interfaces found
---brought up interface here---
[2008/06/16 21:47:14, 0] nmbd/nmbd_become_lmb.c:become_local_master_stage2(396)
  *****

  Samba name server RAVANA is now a local master browser for workgroup MICRIPOFFT on subnet 10.1.0.12

  *****

In all cases, nmbd never shut down!

Revision history for this message
Chuck Short (zulcss) wrote :

So that is fixed for you?

Revision history for this message
Troy C (troxor) wrote :

Yes; in my case, nmbd no longer shuts down when the network is disconnected. The only way I could get it to shut down was to specify "bind interfaces only = true" and "interfaces = lo". Using "bind interfaces only = true" and "interfaces = ath0", where ath0 is connected to the network but disabled through NetworkManager, nmbd waits until ath0 comes up and starts functioning normally. Thanks for all your efforts. :)

Revision history for this message
Chuck Short (zulcss) wrote :

IMPACT: When suspending a laptop or disabling a network interface nmbd shuts down because there is no interfaces available. This is not the desired case. This bug has been fixed upstream in

http://git.samba.org/?p=samba.git;a=blobdiff;f=source/nmbd/nmbd.c;h=9797a7adb673b0774672ca586b1f6b625c4faf5c;hp=00d252940afc33bcf34e9d98dca13c89b15b0408;hb=4b03f4eb2da7a523967ace3d13e79406ade07d47hpb=085887eed71ed1ffdb30100d83763e671ea10eee

which I have back ported the fix for (attached).

TEST CASE:

As per above:

1. Start samba services, ensure nmbd is running. with `ps faux | grep nmbd`
2. `tail -f /var/log/samba/log.nmbd &` <-- observe
3. disable networking in nm-applet.
4. the log will eventually say, "reload_interfaces: No subnets to listen to. Shutting down.."

If you have any questions please let me know.

Thanks
chuck

Changed in samba:
status: Confirmed → Fix Released
Revision history for this message
Chuck Short (zulcss) wrote :
Revision history for this message
Steve Langasek (vorlon) wrote :

Chuck,

Sorry, this SRU upload has been pre-empted by an upload for bug #209520. It would not have been accepted before 8.04.1 anyway, 8.04.1 is closed for any not-already-identified targets.

I did notice a couple of problems with the upload, before bumping it from the queue:

diff -u samba-3.0.28a/debian/patches/series samba-3.0.28a/debian/patches/series
--- samba-3.0.28a/debian/patches/series
+++ samba-3.0.28a/debian/patches/series
@@ -21 +21 @@
-security-CVE-2008-1105.patch
+fix-wireless-not-found.patch

You seem to have disabled the security patch from the previous upload, here! Please restore this patch in your next upload.

And your changelog references two bugs: this one, and bug #172541. Do you think these are the same bug? If so, the bugs ought to be merged in LP and listed once in the changelog. If not, I wonder why both bugs are fixed by a single patch?

Changed in samba:
status: Confirmed → Fix Released
Revision history for this message
Chuck Short (zulcss) wrote :

Steve,

I have updated and uploaded to proposed. Just to let you know.

Thanks
chuck

Revision history for this message
Martin Pitt (pitti) wrote :

Accepted into -proposed, please test and give feedback here. Please see https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Thank you in advance!

Changed in samba:
status: New → Fix Committed
Revision history for this message
Chuck Short (zulcss) wrote :

Troy C:

Can you enable hardy-proposed and test this out?

Thanks
chuck

Revision history for this message
Troy C (troxor) wrote :

The machine that originally experienced this bug has since been upgraded to Intrepid.

However, upon testing both the stable and -proposed samba packages on different machines with both wired and wireless interfaces, nmbd didn't shut down. Instead, all 4 times the logs showed the message "No subnets to listen to. Waiting.." before eventually announcing "... master browser for workgroup ...".

Tested: samba_3.0.28a-1ubuntu4.4 from hardy stable and samba_3.0.28a-1ubuntu4.5 from hardy-proposed. These were on fresh samba installations (no prior smb.conf edits)

Testing Process:
1. install samba normally.
2. Disconnect network, monitor log until "Waiting.." message occurs.
3. Reconnect network, monitor log until "master browser" message occurs.
4. Enable hardy-proposed, update samba, samba-common.
5. repeat step 2 and 3

Everything seems OK, Thanks!

Revision history for this message
Martin Pitt (pitti) wrote :

Copied to hardy-updates.

Changed in samba:
status: Fix Committed → Fix Released
Changed in samba (Ubuntu Intrepid):
status: Fix Released → Fix Committed
Revision history for this message
Steve Langasek (vorlon) wrote :

Please do not change bug statuses without explanation.

Changed in samba (Ubuntu Intrepid):
status: Fix Committed → Fix Released
Changed in samba:
importance: Unknown → Medium
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.