← Back to team overview

kernel-packages team mailing list archive

[Bug 1483440] Re: odd behavior with /proc/net/route reading via sh 'read'

 

commit 25b97c016b26039982daaa2c11d83979f93b71ab
Author: Andy Whitcroft <apw@xxxxxxxxxxxxx>
Date:   Thu Aug 13 20:49:01 2015 +0100

    ipv4: off-by-one in continuation handling in /proc/net/route
    
    When generating /proc/net/route we emit a header followed by a line for
    each route.  When a short read is performed we will restart this process
    based on the open file descriptor.  When calculating the start point we
    fail to take into account that the 0th entry is the header.  This leads
    us to skip the first entry when doing a continuation read.
    
    This can be easily seen with the comparison below:
    
      while read l; do echo "$l"; done </proc/net/route >A
      cat /proc/net/route >B
      diff -bu A B | grep '^[+-]'
    
    On my example machine I have approximatly 10KB of route output.  There we
    see the very first non-title element is lost in the while read case,
    and an entry around the 8K mark in the cat case:
    
      +wlan0 00000000 02021EAC 0003 0 0 400 00000000 0 0 0
      -tun1  00C0AC0A 00000000 0001 0 0 950 00C0FFFF 0 0 0
    
    Fix up the off-by-one when reaquiring position on continuation.
    
    Fixes: 8be33e955cb9 ("fib_trie: Fib walk rcu should take a tnode and key instead of a trie and a leaf")
    BugLink: http://bugs.launchpad.net/bugs/1483440
    Acked-by: Alexander Duyck <alexander.h.duyck@xxxxxxxxxx>
    Signed-off-by: Andy Whitcroft <apw@xxxxxxxxxxxxx>
    Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>

-- 
You received this bug notification because you are a member of Kernel
Packages, which is subscribed to linux in Ubuntu.
https://bugs.launchpad.net/bugs/1483440

Title:
  odd behavior with /proc/net/route reading via sh 'read'

Status in linux package in Ubuntu:
  In Progress

Bug description:
  I saw some strange behavior when one of my scripts started failing to
  get the data it was looking for out of /proc/net/route

  $ uname -r
  $ dpkg -S /boot/vmlinux-$(uname -r)
  linux-image-4.1.0-3-generic: /boot/vmlinuz-4.1.0-3-generic

  
  $ id -u
  1000
  $ cp /proc/net/route /tmp/route
  $ diff /proc/net/route /tmp/route
  $ md5sum /proc/net/route /tmp/route
  4b3663ec7554cf91764106ea9dcc2ada  /proc/net/route
  4b3663ec7554cf91764106ea9dcc2ada  /tmp/route

  ## just cat the file
  $ cat /proc/net/route
  Iface Destination Gateway  Flags RefCnt   Use   Metric   Mask     MTU   Window   IRTT
  eth0  00000000 01A8F50A 0003  0  0  0  00000000 00 0
  eth0  00A8F50A 00000000 0001  0  0  0  00F8FFFF 00 0
  virbr0   007AA8C0 00000000 0001  0  0  0  00FFFFFF 00 0

  ## try to read it with sh while loop
  $ sh -c 'while read line; do echo line: $line; done' < /proc/net/route
  line: Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
  line: eth0 00A8F50A 00000000 0001 0 0 0 00F8FFFF 0 0 0
  line: virbr0 007AA8C0 00000000 0001 0 0 0 00FFFFFF 0 0 0

  ## odd, where did the first line go?
  ##
  ## maybe its still there if we cat
  $ cat /proc/net/route | sh -c 'while read line; do echo line: $line; done'
  line: Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
  line: eth0 00000000 01A8F50A 0003 0 0 0 00000000 0 0 0
  line: eth0 00A8F50A 00000000 0001 0 0 0 00F8FFFF 0 0 0
  line: virbr0 007AA8C0 00000000 0001 0 0 0 00FFFFFF 0 0 0

  ## Yep, still there.
  ## as expected, the copied file shows sane behavior
  $ sh -c 'while read line; do echo line: $line; done' < /tmp/route
  line: Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
  line: eth0 00000000 01A8F50A 0003 0 0 0 00000000 0 0 0
  line: eth0 00A8F50A 00000000 0001 0 0 0 00F8FFFF 0 0 0
  line: virbr0 007AA8C0 00000000 0001 0 0 0 00FFFFFF 0 0 0

  ProblemType: Bug
  DistroRelease: Ubuntu 15.10
  Package: linux-image-4.1.0-3-generic 4.1.0-3.3
  ProcVersionSignature: User Name 4.1.0-3.3-generic 4.1.3
  Uname: Linux 4.1.0-3-generic x86_64
  AlsaDevices:
   total 0
   crw-rw---- 1 root audio 116,  1 Aug 10 23:52 seq
   crw-rw---- 1 root audio 116, 33 Aug 10 23:52 timer
  AplayDevices: Error: [Errno 2] No such file or directory: 'aplay'
  ApportVersion: 2.18-0ubuntu6
  Architecture: amd64
  ArecordDevices: Error: [Errno 2] No such file or directory: 'arecord'
  AudioDevicesInUse: Error: command ['fuser', '-v', '/dev/snd/seq', '/dev/snd/timer'] failed with exit code 1:
  Date: Mon Aug 10 23:55:09 2015
  IwConfig: Error: [Errno 2] No such file or directory: 'iwconfig'
  MachineType: HP ProLiant DL360 Gen9
  PciMultimedia:

  ProcEnviron:
   TERM=xterm-256color
   PATH=(custom, no user)
   XDG_RUNTIME_DIR=<set>
   LANG=en_US.UTF-8
   SHELL=/bin/bash
  ProcFB: 0 EFI VGA
  ProcKernelCmdLine: BOOT_IMAGE=/boot/vmlinuz-4.1.0-3-generic root=UUID=ebea97f1-7014-4fac-bc87-c8ff465c566f ro --- console=ttyS1,115200
  RelatedPackageVersions:
   linux-restricted-modules-4.1.0-3-generic N/A
   linux-backports-modules-4.1.0-3-generic  N/A
   linux-firmware                           1.146
  RfKill: Error: [Errno 2] No such file or directory: 'rfkill'
  SourcePackage: linux
  UdevLog: Error: [Errno 2] No such file or directory: '/var/log/udev'
  UpgradeStatus: No upgrade log present (probably fresh install)
  dmi.bios.date: 03/05/2015
  dmi.bios.vendor: HP
  dmi.bios.version: P89
  dmi.chassis.type: 23
  dmi.chassis.vendor: HP
  dmi.modalias: dmi:bvnHP:bvrP89:bd03/05/2015:svnHP:pnProLiantDL360Gen9:pvr:cvnHP:ct23:cvr:
  dmi.product.name: ProLiant DL360 Gen9
  dmi.sys.vendor: HP

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1483440/+subscriptions


References