3.16.83-rc1 review
Subsystems (6)
cover 3.16.83-rc1 review
This is the start of the stable review cycle for the 3.16.83 release. There are 245 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Tue Apr 28 18:00:00 UTC 2020. Anything received after that time might be too late.
All the patches have also been committed to the linux-3.16.y-rc branch of
https://git.kernel.org/pub/scm/linux/kernel/git/bwh/linux-stable-rc.git . A shortlog and diffstat can be found below.
Ben.
-------------
Al Viro (2):
do_last(): fetch directory ->i_mode and ->i_uid before it's too late
[d0cb50185ae942b03c4327be322055d622dc79f6]
vfs: fix do_last() regression
[6404674acd596de41fd3ad5f267b4525494a891a]Alan Cox (1):
usb: dwc3: pci: Add PCI ID for Intel Braswell
[7d643664ea559b36188cae264047ce3c9bfec3a2]
Alan Stern (1):
HID: Fix slab-out-of-bounds read in hid_field_extract
[8ec321e96e056de84022c032ffea253431a83c3c]
Alberto Aguirre (2):
ALSA: usb-audio: add implicit fb quirk for Axe-Fx II
[17f08b0d9aafccdb10038ab6dbd9ddb6433c13e2]
ALSA: usb-audio: simplify set_sync_ep_implicit_fb_quirk
[103e9625647ad74d201e26fb74afcd8479142a37]
Alex Sverdlin (1):
ARM: 8950/1: ftrace/recordmcount: filter relocation types
[927d780ee371d7e121cea4fc7812f6ef2cea461c]
Amir Goldstein (1):
locks: print unsigned ino in /proc/locks
[98ca480a8f22fdbd768e3dad07024c8d4856576c]
Ard Biesheuvel (1):
x86/efistub: Disable paging at mixed mode entry
[4911ee401b7ceff8f38e0ac597cbf503d71e690c]
Arnd Bergmann (2):
btrfs: tree-checker: use %zu format string for size_t
[7cfad65297bfe0aa2996cd72d21c898aa84436d9]
scsi: fnic: fix invalid stack access
[42ec15ceaea74b5f7a621fc6686cbf69ca66c4cf]
Avinash Patil (1):
mwifiex: fix probable memory corruption while processing TDLS frame
[3c99832d74777c9ec5545a92450fac5d37b0d0e1]
Brian Norris (1):
mwifiex: fix unbalanced locking in mwifiex_process_country_ie()
[65b1aae0d9d5962faccc06bdb8e91a2a0b09451c]
Cengiz Can (1):
blktrace: fix dereference after null check
[153031a301bb07194e9c37466cfce8eacb977621]
Chao Yu (1):
quota: fix wrong condition in is_quota_modification()
[6565c182094f69e4ffdece337d395eb7ec760efc]
Chen-Yu Tsai (1):
net: stmmac: dwmac-sunxi: Allow all RGMII modes
[52cc73e5404c7ba0cbfc50cb4c265108c84b3d5a]
Christian Brauner (1):
taskstats: fix data-race
[0b8d616fb5a8ffa307b1d3af37f55c15dae14f28]
Christophe Leroy (1):
powerpc/irq: fix stack overflow verification
[099bc4812f09155da77eeb960a983470249c9ce1]
Cong Wang (2):
net_sched: fix datalen for ematch
[61678d28d4a45ef376f5d02a839cc37509ae9281]
netfilter: fix a use-after-free in mtype_destroy()
[c120959387efa51479056fd01dc90adfba7a590c]
Dan Carpenter (1):
scsi: iscsi: qla4xxx: fix double free in probe
[fee92f25777789d73e1936b91472e9c4644457c8]
David Hildenbrand (1):
virtio-balloon: fix managed page counts when migrating pages between zones
[63341ab03706e11a31e3dd8ccc0fbc9beaf723f0]
David Sterba (6):
btrfs: add more checks to btrfs_read_sys_array
[e3540eab29e1b2260bc4b9b3979a49a00e3e3af8]
btrfs: cleanup, rename a few variables in btrfs_read_sys_array
[1ffb22cf8c322bbfea6b35fe23d025841b49fede]
btrfs: handle invalid num_stripes in sys_array
[f5cdedd73fa71b74dcc42f2a11a5735d89ce7c4f]
btrfs: kill extent_buffer_page helper
[fb85fc9a675738ee2746b51c3aedde944b18ca02]
btrfs: new define for the inline extent data start
[7ec20afbcb7b257aec82ea5d66e6b0b7499abaca]
btrfs: tree-check: reduce stack consumption in check_dir_item
[e2683fc9d219430f5b78889b50cde7f40efeba7b]
Davidlohr Bueso (1):
blktrace: re-write setting q->blk_trace
[cdea01b2bf98affb7e9c44530108a4a28535eee8]Dedy Lansky (1):
cfg80211/mac80211: make ieee80211_send_layer2_update a public function
[30ca1aa536211f5ac3de0173513a7a99a98a97f3]Dmitry Torokhov (5):
HID: hid-input: clear unmapped usages
[4f3882177240a1f55e45a3d241d3121341bead78]
Input: add safety guards to input_set_keycode()
[cb222aed03d798fc074be55e59d9a112338ee784]
ptp: create "pins" together with the rest of attributes
[85a66e55019583da1e0f18706b7a8281c9f6de5b]
ptp: do not explicitly set drvdata in ptp_clock_register()
[882f312dc0751c973db26478f07f082c584d16aa]
ptp: use is_visible method to hide unused attributes
[af59e717d5ff9c8dbf9bcc581c0dfb3b2a9c9030]
Emiliano Ingrassia (1):
usb: core: urb: fix URB structure initialization function
[1cd17f7f0def31e3695501c4f86cd3faf8489840]
Eric Dumazet (9):
6pack,mkiss: fix possible deadlock
[5c9934b6767b16ba60be22ec3cbd4379ad64170d]
bonding: fix bond_neigh_init()
[9e99bfefdbce2e23ef37487a3bcb4adf90a791d1]
macvlan: do not assume mac_header is set in macvlan_broadcast()
[96cc4b69581db68efc9749ef32e9cf8e0160c509]
macvlan: use skb_reset_mac_header() in macvlan_queue_xmit()
[1712b2fff8c682d145c7889d2290696647d82dab]
neighbour: remove neigh_cleanup() method
[f394722fb0d0f701119368959d7cd0ecbc46363a]
netfilter: bridge: make sure to pull arp header in br_nf_forward_arp()
[5604285839aaedfb23ebe297799c6e558939334d]
pkt_sched: fq: do not accept silly TCA_FQ_QUANTUM
[d9e15a2733067c9328fb56d98fe8e574fa19ec31]
tcp: do not send empty skb from tcp_write_xmit()
[1f85e6267caca44b30c54711652b0726fadbb131]
vlan: vlan_changelink() should propagate errors
[eb8ef2a3c50092bb018077c047b8dba1ce0e78e3]
Erkka Talvitie (1):
USB: EHCI: Do not return -EPIPE when hub is disconnected
[64cc3f12d1c7dd054a215bc1ff9cc2abcfe35832]
Eryu Guan (1):
ext4: update c/mtime on truncate up
[911af577de4e444622d46500c1f9a37ab4335d3a]
Eugenio Pérez (1):
vhost: Check docket sk_family instead of call getname
[42d84c8490f9f0931786f1623191fcab397c3d64]
Fabian Henneke (1):
hidraw: Return EPOLLOUT from hidraw_poll
[378b80370aa1fe50f9c48a3ac8af3e416e73b89f]
Felipe Balbi (3):
usb: dwc3: pci: Add Support for Intel Elkhart Lake Devices
[dbb0569de852fb4576d6f62078d515f989a181ca]
usb: dwc3: pci: add support for Comet Lake PCH ID
[7ae622c978db6b2e28b4fced6ecd2a174492059d]
usb: dwc3: pci: add support for TigerLake Devices
[b3649dee5fbb0f6585010e6e9313dfcbb075b22b]
Filipe Manana (3):
Btrfs: fix emptiness check for dirtied extent buffers at check_leaf()
[f177d73949bf758542ca15a1c1945bd2e802cc65]
Btrfs: fix infinite loop during nocow writeback due to race
[de7999afedff02c6631feab3ea726a0e8f8c3d40]
Btrfs: fix removal logic of the tree mod log that leads to use-after-free issues
[6609fee8897ac475378388238456c84298bff802]
Finn Thain (4):
net/sonic: Add mutual exclusion for accessing shared state
[865ad2f2201dc18685ba2686f13217f8b3a9c52c]
net/sonic: Fix receive buffer handling
[9e311820f67e740f4fb8dcb82b4c4b5b05bdd1a5]
net/sonic: Quiesce SONIC before re-initializing descriptor memory
[3f4b7e6a2be982fd8820a2b54d46dd9c351db899]
net/sonic: Use MMIO accessors
[e3885f576196ddfc670b3d53e745de96ffcb49ab]
Florian Faber (1):
can: mscan: mscan_rx_poll(): fix rx path lockup when returning from polling to irq mode
[2d77bd61a2927be8f4e00d9478fe6996c47e8d45]
Florian Westphal (6):
netfilter: arp_tables: init netns pointer in xt_tgchk_param struct
[1b789577f655060d98d20ed0c6f9fbd469d6ba63]
netfilter: arp_tables: init netns pointer in xt_tgdtor_param struct
[212e7f56605ef9688d0846db60c6c6ec06544095]
netfilter: ctnetlink: netns exit must wait for callbacks
[18a110b022a5c02e7dc9f6109d0bd93e58ac6ebb]
netfilter: ebtables: compat: reject all padding in matches/watchers
[e608f631f0ba5f1fc5ee2e260a3a35d13107cbfe]
netfilter: ebtables: convert BUG_ONs to WARN_ONs
[fc6a5d0601c5ac1d02f283a46f60b87b2033e5ca]
netfilter: ipset: avoid null deref when IPSET_ATTR_LINENO is present
[22dad713b8a5ff488e07b821195270672f486eb2]
Geert Uytterhoeven (1):
gpio: Fix error message on out-of-range GPIO in lookup table
[d935bd50dd14a7714cbdba9a76435dbb56edb1ae]
Goldwyn Rodrigues (1):
dm flakey: check for null arg_name in parse_features()
[7690e25302dc7d0cd42b349e746fe44b44a94f2b]
Gu Jinxiang (1):
btrfs: validate type when reading a chunk
[315409b0098fb2651d86553f0436b70502b29bb2]
Hangbin Liu (1):
vxlan: fix tos value before xmit
[71130f29979c7c7956b040673e6b9d5643003176]
Hans de Goede (2):
pinctrl: baytrail: Really serialize all register accesses
[40ecab551232972a39cdd8b6f17ede54a3fdb296]
platform/x86: hp-wmi: Make buffer for HPWMI_FEATURE2_QUERY 128 bytes
[133b2acee3871ae6bf123b8fe34be14464aa3d2c]
Heikki Krogerus (8):
usb: dwc3: pci: add ID for one more Intel Broxton platform
[1ffb4d5cc78a3a99109ff0808ce6915de07a0588]
usb: dwc3: pci: add ID for the Intel Comet Lake -H variant
[3c3caae4cd6e122472efcf64759ff6392fb6bce2]
usb: dwc3: pci: add Intel Cannonlake PCI IDs
[682179592e48fa66056fbad1a86604be4992f885]
usb: dwc3: pci: add Intel Gemini Lake PCI ID
[8f8983a5683623b62b339d159573f95a1fce44f3]
usb: dwc3: pci: add Intel Kabylake PCI ID
[4491ed5042f0419b22a4b08331adb54af31e2caa]
usb: dwc3: pci: add support for Intel Broxton SOC
[b4c580a43d520b7812c0fd064fbab929ce2f1da0]
usb: dwc3: pci: add support for Intel IceLake
[00908693c481f7298adf8cf4d2ff3dfbea8c375f]
usb: dwc3: pci: add support for Intel Sunrise Point PCH
[84a2b61b6eb94036093531cdabc448dddfbae45a]
Hou Tao (1):
dm btree: increase rebalance threshold in __rebalance2()
[474e559567fa631dea8fb8407ab1b6090c903755]
James Bottomley (1):
scsi: enclosure: Fix stale device oops with hot replug
[529244bd1afc102ab164429d338d310d5d65e60d]
Jan Kara (7):
blktrace: Protect q->blk_trace with RCU
[c780e86dd48ef6467a1146cf7d0fe1e05a635039]
ext4: check for directory entries too close to block end
[109ba779d6cca2d519c5dd624a3276d03e21948e]
ext4: fix races between buffered IO and collapse / insert range
[32ebffd3bbb4162da5ff88f9a35dd32d0a28ea70]
ext4: fix races between page faults and hole punching
[ea3d7209ca01da209cda6f0dea8be9cc4b7a933b]
ext4: fix races of writeback with punch hole and zero range
[011278485ecc3cd2a3954b5d4c73101d919bf1fa]
ext4: move unlocked dio protection from ext4_alloc_file_blocks()
[17048e8a083fec7ad841d88ef0812707fbc7e39f]
kobject: Export kobject_get_unless_zero()
[c70c176ff8c3ff0ac6ef9a831cd591ea9a66bd1a]Jari Ruusu (1):
Fix built-in early-load Intel microcode alignment
[f5ae2ea6347a308cfe91f53b53682ce635497d0d]
Jeff Mahoney (2):
btrfs: cleanup, stop casting for extent_map->lookup everywhere
[95617d69326ce386c95e33db7aeb832b45ee9f8f]
btrfs: struct-funcs, constify readers
[1cbb1f454e5321e47fc1e6b233066c7ccc979d15]Jerónimo Borque (1):
USB: serial: simple: Add Motorola Solutions TETRA MTP3xxx and MTP85xx
[260e41ac4dd3e5acb90be624c03ba7f019615b75]
Jian-Hong Pan (1):
platform/x86: asus-wmi: Fix keyboard brightness cannot be set to 0
[176a7fca81c5090a7240664e3002c106d296bf31]
Jim Mattson (1):
kvm: x86: Host feature SSBD doesn't imply guest feature SPEC_CTRL_SSBD
[396d2e878f92ec108e4293f1c77ea3bc90b414ff]
Jiri Kosina (1):
HID: hidraw, uhid: Always report EPOLLOUT
[9e635c2851df6caee651e589fbf937b637973c91]
Jiri Slaby (4):
vt: selection, close sel_buffer race
[07e6124a1a46b4b5a9b3cacc0c306b50da87abf5]
vt: selection, handle pending signals in paste_selection
[687bff0cd08f790d540cfb7b2349f0d876cdddec]
vt: selection, push console lock down
[4b70dd57a15d2f4685ac6e38056bad93e81e982f]
vt: selection, push sel_lock up
[e8c75a30a23c6ba63f4ef6895cbf41fd42f21aa2]
Johan Hovold (29):
ALSA: usb-audio: fix sync-ep altsetting sanity check
[5d1b71226dc4d44b4b65766fa9d74492f9d4587b]
Input: aiptek - fix endpoint sanity check
[3111491fca4f01764e0c158c5e0f7ced808eef51]
Input: gtco - fix endpoint sanity check
[a8eeb74df5a6bdb214b2b581b14782c5f5a0cf83]
Input: keyspan-remote - fix control-message timeouts
[ba9a103f40fc4a3ec7558ec9b0b97d4f92034249]
Input: sur40 - fix interface sanity checks
[6b32391ed675827f8425a414abbc6fbd54ea54fe]
USB: adutux: fix interface sanity check
[3c11c4bed02b202e278c0f5c319ae435d7fb9815]
USB: atm: ueagle-atm: add missing endpoint check
[09068c1ad53fb077bdac288869dec2435420bdc4]
USB: core: add endpoint-blacklist quirk
[73f8bda9b5dc1c69df2bc55c0cbb24461a6391a9]
USB: core: fix check for duplicate endpoints
[3e4f8e21c4f27bcf30a48486b9dcc269512b79ff]
USB: idmouse: fix interface sanity checks
[59920635b89d74b9207ea803d5e91498d39e8b69]
USB: quirks: blacklist duplicate ep on Sound Devices USBPre2
[bdd1b147b8026df0e4260b387026b251d888ed01]
USB: serial: ch341: handle unbound port at reset_resume
[4d5ef53f75c22d28f490bcc5c771fcc610a9afa4]
USB: serial: io_edgeport: add missing active-port sanity check
[1568c58d11a7c851bd09341aeefd6a1c308ac40d]
USB: serial: io_edgeport: fix epic endpoint lookup
[7c5a2df3367a2c4984f1300261345817d95b71f8]
USB: serial: io_edgeport: handle unbound ports on URB completion
[e37d1aeda737a20b1846a91a3da3f8b0f00cf690]
USB: serial: keyspan: handle unbound ports
[3018dd3fa114b13261e9599ddb5656ef97a1fa17]
USB: serial: opticon: fix control-message timeouts
[5e28055f340275a8616eee88ef19186631b4d136]
USB: serial: quatech2: handle unbound ports
[9715a43eea77e42678a1002623f2d9a78f5b81a1]
USB: serial: suppress driver bind attributes
[fdb838efa31e1ed9a13ae6ad0b64e30fdbd00570]
can: gs_usb: gs_usb_probe(): use descriptors of current altsetting
[2f361cd9474ab2c4ab9ac8db20faf81e66c6279b]
media: ov519: add missing endpoint sanity checks
[998912346c0da53a6dbb71fab3a138586b596b30]
media: stv06xx: add missing descriptor sanity checks
[485b06aadb933190f4bc44e006076bc27a23f205]
media: xirlink_cit: add missing descriptor sanity checks
[a246b4d547708f33ff4d4b9a7a5dbac741dc89d8]
r8152: add missing endpoint sanity check
[86f3f4cd53707ceeec079b83205c8d3c756eca93]
staging: gigaset: add endpoint-type sanity check
[ed9ed5a89acba51b82bdff61144d4e4a4245ec8a]
staging: gigaset: fix general protection fault on probe
[53f35a39c3860baac1e5ca80bf052751cfb24a99]
staging: gigaset: fix illegal free on probe errors
[84f60ca7b326ed8c08582417493982fe2573a9ad]
staging: rtl8188eu: fix interface sanity check
[74ca34118a0e05793935d804ccffcedd6eb56596]
staging: rtl8712: fix interface sanity check
[c724f776f048538ecfdf53a52b7a522309f5c504]
Johannes Thumshirn (1):
btrfs: ensure that a DUP or RAID1 block group has exactly two stripes
[349ae63f40638a28c6fce52e8447c2d14b84cc0c]
Jose Abreu (2):
net: stmmac: 16KB buffer must be 16 byte aligned
[8605131747e7e1fd8f6c9f97a00287aae2b2c640]
net: stmmac: Enable 16KB buffer size
[b2f3a481c4cd62f78391b836b64c0a6e72b503d2]
Josef Bacik (9):
Btrfs: fix em leak in find_first_block_group
[187ee58c62c1d0d238d3dc4835869d33e1869906]
btrfs: abort transaction after failed inode updates in create_subvol
[c7e54b5102bf3614cadb9ca32d7be73bad6cecf0]
btrfs: check rw_devices, not num_devices for balance
[b35cf1f0bf1f2b0b193093338414b9bd63b29015]
btrfs: do not call synchronize_srcu() in inode_tree_del
[f72ff01df9cf5db25c76674cac16605992d15467]
btrfs: do not delete mismatched root refs
[423a716cd7be16fb08690760691befe3be97d3fc]
btrfs: do not leak reloc root if we fail to read the fs root
[ca1aa2818a53875cfdd175fb5e9a2984e997cce9]
btrfs: handle ENOENT in btrfs_uuid_tree_iterate
[714cd3e8cba6841220dce9063a7388a81de03825]
btrfs: skip log replay on orphaned roots
[9bc574de590510eff899c3ca8dbaf013566b5efe]
ext4: only call ext4_truncate when size <= isize
[3da40c7b089810ac9cf2bb1e59633f619f3a7312]
Jouni Malinen (1):
mac80211: Do not send Layer 2 Update frame before authorization
[3e493173b7841259a08c5c8e5cbe90adb349da7e]
Kaitao Cheng (1):
kernel/trace: Fix do not unregister tracepoints when register sched_migrate_task fail
[50f9ad607ea891a9308e67b81f774c71736d1098]
Keiya Nobuta (1):
usb: core: hub: Improved device recognition on remote wakeup
[9c06ac4c83df6d6fbdbf7488fbad822b4002ba19]
Kenneth Klette Jonassen (1):
pkt_sched: fq: avoid hang when quantum 0
[3725a269815ba6dbb415feddc47da5af7d1fac58]
Lars Möllendorf (1):
iio: buffer: align the size of scan bytes to size of the largest element
[883f616530692d81cb70f8a32d85c0d2afc05f69]
Leo Yan (1):
tty: serial: msm_serial: Fix lockup for sysrq and oops
[0e4f7f920a5c6bfe5e851e989f27b35a0cc7fb7e]
Linus Torvalds (1):
floppy: check FDC index for errors before assigning it
[2e90ca68b0d2f5548804f22f0dd61145516171e3]
Liu Bo (9):
Btrfs: add validadtion checks for chunk loading
[e06cd3dd7cea50e87663a88acdfdb7ac1c53a5ca]
Btrfs: check btree node's nritems
[053ab70f0604224c7893b43f9d9d5efa283580d6]
Btrfs: check inconsistence between chunk and block group
[6fb37b756acce6d6e045f79c3764206033f617b4]
Btrfs: detect corruption when non-root leaf has zero item
[1ba98d086fe3a14d6a31f2f66dbab70c45d00f63]
Btrfs: fix BUG_ON in btrfs_mark_buffer_dirty
[ef85b25e982b5bba1530b936e283ef129f02ab9d]
Btrfs: improve check_node to avoid reading corrupted nodes
[6b722c1747d533ac6d4df110dc8233db46918b65]
Btrfs: kill BUG_ON in run_delayed_tree_ref
[02794222c4132ac003e7281fb71f4ec1645ffc87]
Btrfs: memset to avoid stale content in btree leaf
[851cd173f06045816528176001cf82948282029c]
Btrfs: memset to avoid stale content in btree node block
[3eb548ee3a8042d95ad81be254e67a5222c24e03]
Logan Gunthorpe (1):
chardev: add helper function to register char devs with a struct device
[233ed09d7fdacf592ee91e6c97ce5f4364fbe7c0]
Lu Fengqi (1):
btrfs: Remove redundant btrfs_release_path from btrfs_unlink_subvol
[5b7d687ad5913a56b6a8788435d7a53990b4176d]
Lukas Czerner (1):
ext4: wait for existing dio workers in ext4_alloc_file_blocks()
[0d306dcf86e8f065dff42a4a934ae9d99af35ba5]
Luuk Paulussen (1):
hwmon: (adt7475) Make volt2reg return same reg as reg2volt input
[cf3ca1877574a306c0207cbf7fdf25419d9229df]
Mao Wenan (2):
af_packet: set defaule value for tmo
[b43d1f9f7067c6759b1051e8ecb84e82cef569fe]
net: sonic: return NETDEV_TX_OK if failed to map buffer
[6e1cdedcf0362fed3aedfe051d46bd7ee2a85fe1]
Marcel Holtmann (2):
HID: hidraw: Fix returning EPOLLOUT from hidraw_poll
[9f3b61dc1dd7b81e99e7ed23776bb64a35f39e1a]
HID: uhid: Fix returning EPOLLOUT from uhid_char_poll
[be54e7461ffdc5809b67d2aeefc1ddc9a91470c7]
Mathias Nyman (2):
xhci: handle some XHCI_TRUST_TX_LENGTH quirks cases as default behaviour.
[7ff11162808cc2ec66353fc012c58bb449c892c3]
xhci: make sure interrupts are restored to correct state
[bd82873f23c9a6ad834348f8b83f3b6a5bca2c65]
Mauro Carvalho Chehab (3):
[media] media-device: dynamically allocate struct media_devnode
[a087ce704b802becbb4b0f2a20f2cb3f6911802e]
[media] media-devnode: fix namespace mess
[163f1e93e995048b894c5fc86a6034d16beed740]
[media] media-devnode: just return 0 instead of using a var
[8b37c6455fc8f43e0e95db2847284e618db6a4f8]
Max Kellermann (2):
[media] drivers/media/media-devnode: clear private_data before put_device()
[bf244f665d76d20312c80524689b32a752888838]
[media] media-devnode: add missing mutex lock in error handler
[88336e174645948da269e1812f138f727cd2896b]
Michael Straube (1):
staging: rtl8188eu: Add device code for TP-Link TL-WN727N v5.21
[58dcc5bf4030cab548d5c98cd4cd3632a5444d5a]
Michał Mirosław (1):
mmc: sdhci: fix minimum clock rate for v3 controller
[2a187d03352086e300daa2044051db00044cd171]
Mika Westerberg (4):
pinctrl: baytrail: Clear interrupt triggering from pins that are in GPIO mode
[95f0972c7e4cbf3fc68160131c5ac2f033481d00]
pinctrl: baytrail: Relax GPIO request rules
[f8323b6bb2cc7d26941d4838dd4375952980a88a]
pinctrl: baytrail: Rework interrupt handling
[31e4329f99062a06dca5a493bb4495a63b2dc6ba]
pinctrl: baytrail: Serialize all register access
[39ce8150a079e3ae6ed9abf26d7918a558ef7c19]
Mike Snitzer (1):
dm flakey: fix reads to be issued if drop_writes configured
[299f6230bc6d0ccd5f95bb0fb865d80a9c7d5ccc]
Mikulas Patocka (1):
block: fix an integer overflow in logical block size
[ad6bf88a6c19a39fb3b0045d78ea880325dfcf15]
Moni Shoua (1):
IB/mlx4: Avoid executing gid task when device is being removed
[4bf9715f184969dc703bde7be94919995024a6a9]
Nicolai Stange (2):
libertas: don't exit from lbs_ibss_join_existing() with RCU read lock held
[c7bf1fb7ddca331780b9a733ae308737b39f1ad4]
libertas: make lbs_ibss_join_existing() return error code on rates overflow
[1754c4f60aaf1e17d886afefee97e94d7f27b4cb]
Nikos Tsironis (1):
dm thin metadata: Add support for a pre-commit callback
[ecda7c0280e6b3398459dc589b9a41c1adb45529]
Pablo Neira Ayuso (2):
netfilter: nf_tables: missing sanitization in data from userspace
[71df14b0ce094be46d105b5a3ededd83b8e779a0]
netfilter: nf_tables: validate NFT_DATA_VALUE after nft_data_init()
[0d2c96af797ba149e559c5875c0151384ab6dd14]
Paolo Bonzini (1):
KVM: nVMX: Don't emulate instructions in guest mode
[07721feee46b4b248402133228235318199b05ec]
Parav Pandit (1):
IB/mlx4: Follow mirror sequence of device add during device removal
[89f988d93c62384758b19323c886db917a80c371]
Paul Cercueil (1):
usb: musb: dma: Correct parameter passed to IRQ handler
[c80d0f4426c7fdc7efd6ae8d8b021dcfc89b4254]
Pavel Tatashin (1):
x86/pti/efi: broken conversion from efi to kernel page table
[not upstream; fixes a bug specific to KAISER]
Pengcheng Yang (1):
tcp: fix "old stuff" D-SACK causing SACK to be treated as D-SACK
[c9655008e7845bcfdaac10a1ed8554ec167aea88]
Pete Zaitcev (1):
usb: mon: Fix a deadlock in usbmon between mmap and read
[19e6317d24c25ee737c65d1ffb7483bdda4bb54a]
Peter Hurley (1):
tty: vt: Fix !TASK_RUNNING diagnostic warning from paste_selection()
[61e86cc90af49cecef9c54ccea1f572fbcb695ac]
Qize Wang (1):
mwifiex: Fix heap overflow in mmwifiex_process_tdls_action_frame()
[1e58252e334dc3f3756f424a157d1b7484464c40]
Qu Wenruo (14):
btrfs: Add checker for EXTENT_CSUM
[4b865cab96fe2a30ed512cf667b354bd291b3b0a]
btrfs: Add sanity check for EXTENT_DATA when reading out leaf
[40c3c40947324d9f40bf47830c92c59a9bbadf4a]
btrfs: Check if item pointer overlaps with the item itself
[7f43d4affb2a254d421ab20b0cf65ac2569909fb]
btrfs: Check that each block group has corresponding chunk at mount time
[514c7dca85a0bf40be984dab0b477403a6db901f]
btrfs: Enhance chunk validation check
[f04b772bfc17f502703794f4d100d12155c1a1a9]
btrfs: Move leaf and node validation checker to tree-checker.c
[557ea5dd003d371536f6b4e8f7c8209a2b6fd4e3]
btrfs: Refactor check_leaf function for later expansion
[c3267bbaa9cae09b62960eafe33ad19196803285]
btrfs: Verify that every chunk has corresponding block group at mount time
[7ef49515fa6727cb4b6f2f5b0ffbc5fc20a9f8c6]
btrfs: tree-checker: Add checker for dir item
[ad7b0368f33cffe67fecd302028915926e50ef7e]
btrfs: tree-checker: Check level for leaves and nodes
[f556faa46eb4e96d0d0772e74ecf66781e132f72]
btrfs: tree-checker: Detect invalid and empty essential trees
[ba480dd4db9f1798541eb2d1c423fc95feee8d36]
btrfs: tree-checker: Enhance btrfs_check_node output
[bba4f29896c986c4cec17bc0f19f2ce644fceae1]
btrfs: tree-checker: Fix false panic for sanity test
[69fc6cbbac542c349b3d350d10f6e394c253c81d]
btrfs: tree-checker: Verify block_group_item
[fce466eab7ac6baa9d2dcd88abcf945be3d4a089]
Radoslaw Tyl (1):
ixgbevf: Remove limit of 10 entries for unicast filter list
[aa604651d523b1493988d0bf6710339f3ee60272]
Rafael J. Wysocki (1):
ACPI: PM: Avoid attaching ACPI PM domain to certain devices
[b9ea0bae260f6aae546db224daa6ac1bd9d94b91]
Randy Dunlap (1):
mm: mempolicy: require at least one nodeid for MPOL_PREFERRED
[aa9f7d5172fac9bf1f09e678c35e287a40a7b7dd]
Richard Palethorpe (2):
can, slip: Protect tty->disc_data in write_wakeup and close with RCU
[0ace17d56824165c7f4c68785d6b58971db954dd]
slcan: Don't transmit uninitialized stack data in padding
[b9258a2cece4ec1f020715fe3554bc2e360f6264]Russell King (2):
gpiolib: fix up emulated open drain outputs
[256efaea1fdc4e38970489197409a26125ee0aaa]
mod_devicetable: fix PHY module format
[d2ed49cf6c13e379c5819aa5ac20e1f9674ebc89]
Sabrina Dubroca (1):
net: ipv6_stub: use ip6_dst_lookup_flow instead of ip6_dst_lookup
[6c8991f41546c3c472503dff1ea9daaddf9331c2]
Salvatore Mesoraca (1):
namei: allow restricted O_CREAT of FIFOs and regular files
[30aba6656f61ed44cba445a3c0d38b296fa9e8f5]
Shaokun Zhang (1):
btrfs: tree-checker: Fix misleading group system information
[761333f2f50ccc887aa9957ae829300262c0d15b]
Shengjiu Wang (1):
ASoC: wm8962: fix lambda value
[556672d75ff486e0b6786056da624131679e0576]
Shuah Khan (3):
[media] media: Fix media_open() to clear filp->private_data in error leg
[d40ec6fdb0b03b7be4c7923a3da0e46bf943740a]
[media] media: fix media devnode ioctl/syscall and unregister race
[6f0dd24a084a17f9984dd49dffbf7055bf123993]
[media] media: fix use-after-free in cdev_put() when app exits after driver unbind
[5b28dde51d0ccc54cee70756e1800d70bed7114a]Steven Rostedt (1):
tracing: Have stack tracer compile when MCOUNT_INSN_SIZE is not defined
[b8299d362d0837ae39e87e9019ebe6b736e0f035]
Sudip Mukherjee (2):
tty: always relink the port
[273f632912f1b24b642ba5b7eb5022e43a72f3b5]
tty: link tty and port before configuring it as console
[fb2b90014d782d80d7ebf663e50f96d8c507a73c]
Suren Baghdasaryan (1):
staging: android: ashmem: Disallow ashmem memory from being remapped
[6d67b0290b4b84c477e6a2fc6e005e174d3c7786]
Suwan Kim (1):
usbip: Fix error path of vhci_recv_ret_submit()
[aabb5b833872524eaf28f52187e5987984982264]
Sven Eckelmann (1):
batman-adv: Fix DAT candidate selection on little endian systems
[4cc4a1708903f404d2ca0dfde30e71e052c6cbc9]
Takashi Iwai (4):
ALSA: hda/ca0132 - Avoid endless loop
[cb04fc3b6b076f67d228a0b7d096c69ad486c09c]
ALSA: ice1724: Fix sleep-in-atomic in Infrasonic Quartet support code
[0aec96f5897ac16ad9945f531b4bef9a2edd2ebd]
ALSA: pcm: Avoid possible info leaks from PCM stream buffers
[add9d56d7b3781532208afbff5509d7382fb6efe]
ALSA: seq: Fix racy access for queue timer in proc read
[60adcfde92fa40fcb2dbf7cc52f9b096e0cd109a]
Tom Lendacky (1):
x86/microcode/AMD: Add support for fam17h microcode loading
[f4e9b7af0cd58dd039a0fb2cd67d57cea4889abf]
Vivek Goyal (1):
dm: do not override error code returned from dm_get_device()
[e80d1c805a3b2f0ad2081369be5dc5deedd5ee59]
Vladis Dronov (2):
ptp: fix the race between the release of ptp_clock and cdev
[a33121e5487b424339636b25c35d3a180eaa5f5e]
ptp: free ptp device pin descriptors properly
[75718584cb3c64e6269109d4d54f888ac5a5fd15]
Wang Shilong (1):
Btrfs: fix wrong max inline data size limit
[c01a5c074c0f6f85a3b02e39432b9e5576ab51de]
Wei Yongjun (1):
dm flakey: return -EINVAL on interval bounds error in flakey_ctr()
[bff7e067ee518f9ed7e1cbc63e4c9e01670d0b71]
Wen Huang (1):
libertas: Fix two buffer overflows at parsing bss descriptor
[e5e884b42639c74b5b57dc277909915c0aefc8bb]
Wen Yang (1):
ftrace: Avoid potential division by zero in function profiler
[e31f7939c1c27faa5d0e3f14519eaf7c89e8a69d]
Will Deacon (1):
chardev: Avoid potential use-after-free in 'chrdev_open()'
[68faa679b8be1a74e6663c21c3a9d25d32f1c079]
Xiang Chen (1):
scsi: sd: Clear sdkp->protection_type if disk is reformatted without PI
[465f4edaecc6c37f81349233e84d46246bcac11a]Xin Long (1):
sctp: free cmd->obj.chunk for the unprocessed SCTP_CMD_REPLY
[be7a7729207797476b6666f046d765bdf9630407]YueHaibing (1):
ptp: Fix pass zero to ERR_PTR() in ptp_clock_register
[aea0a897af9e44c258e8ab9296fad417f1bc063a]
Zhang Xiaoxu (1):
vgacon: Fix a UAF in vgacon_invert_region
[513dc792d6060d5ef572e43852683097a8420f56]
Documentation/sysctl/fs.txt | 36 ++++ Makefile | 4 +- arch/powerpc/kernel/irq.c | 4 +- arch/x86/boot/compressed/head_64.S | 5 + arch/x86/include/asm/kaiser.h | 10 + arch/x86/kernel/cpu/microcode/amd.c | 4 + arch/x86/kvm/cpuid.c | 3 +- arch/x86/kvm/vmx.c | 2 +- arch/x86/realmode/init.c | 4 +- arch/x86/realmode/rm/trampoline_64.S | 3 +- block/blk-settings.c | 2 +- drivers/acpi/device_pm.c | 12 +- drivers/block/floppy.c | 7 +- drivers/gpio/gpiolib.c | 13 +- drivers/hid/hid-core.c | 6 + drivers/hid/hid-input.c | 16 +- drivers/hid/hidraw.c | 7 +- drivers/hid/uhid.c | 5 +- drivers/hwmon/adt7475.c | 5 +- drivers/iio/industrialio-buffer.c | 6 +- drivers/infiniband/hw/mlx4/main.c | 16 +- drivers/input/input.c | 26 ++- drivers/input/misc/keyspan_remote.c | 9 +- drivers/input/tablet/aiptek.c | 6 +- drivers/input/tablet/gtco.c | 10 +- drivers/input/touchscreen/sur40.c | 2 +- drivers/isdn/gigaset/usb-gigaset.c | 23 ++- drivers/md/dm-crypt.c | 4 +- drivers/md/dm-delay.c | 16 +- drivers/md/dm-flakey.c | 40 ++-- drivers/md/dm-linear.c | 7 +- drivers/md/dm-raid1.c | 8 +- drivers/md/dm-snap-persistent.c | 2 +- drivers/md/dm-stripe.c | 8 +- drivers/md/dm-thin-metadata.c | 29 +++ drivers/md/dm-thin-metadata.h | 7 + drivers/md/persistent-data/dm-btree-remove.c | 8 +- drivers/md/raid0.c | 2 +- drivers/media/media-device.c | 43 +++-- drivers/media/media-devnode.c | 171 +++++++++-------- drivers/media/usb/gspca/ov519.c | 10 + drivers/media/usb/gspca/stv06xx/stv06xx.c | 19 +- drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c | 4 + drivers/media/usb/gspca/xirlink_cit.c | 18 +- drivers/media/usb/uvc/uvc_driver.c | 2 +- drivers/misc/enclosure.c | 3 +- drivers/mmc/host/sdhci.c | 10 +- drivers/net/bonding/bond_main.c | 40 ++-- drivers/net/can/mscan/mscan.c | 21 +-- drivers/net/can/slcan.c | 16 +- drivers/net/can/usb/gs_usb.c | 4 +- drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 5 - drivers/net/ethernet/natsemi/sonic.c | 113 +++++++++--- drivers/net/ethernet/natsemi/sonic.h | 25 ++- drivers/net/ethernet/stmicro/stmmac/common.h | 5 +- drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c | 2 +- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 +- drivers/net/hamradio/6pack.c | 4 +- drivers/net/hamradio/mkiss.c | 4 +- drivers/net/macvlan.c | 3 +- drivers/net/slip/slip.c | 12 +- drivers/net/usb/r8152.c | 3 + drivers/net/vxlan.c | 5 +- drivers/net/wireless/libertas/cfg.c | 18 +- drivers/net/wireless/mwifiex/sta_ioctl.c | 1 + drivers/net/wireless/mwifiex/tdls.c | 74 +++++++- drivers/pinctrl/pinctrl-baytrail.c | 212 +++++++++++++--------- drivers/platform/x86/asus-wmi.c | 8 +- drivers/platform/x86/hp-wmi.c | 2 +- drivers/ptp/ptp_clock.c | 42 ++--- drivers/ptp/ptp_private.h | 9 +- drivers/ptp/ptp_sysfs.c | 162 +++++++---------- drivers/scsi/fnic/vnic_dev.c | 20 +- drivers/scsi/qla4xxx/ql4_os.c | 1 - drivers/scsi/sd.c | 4 +- drivers/staging/android/ashmem.c | 28 +++ drivers/staging/rtl8188eu/os_dep/usb_intf.c | 3 +- drivers/staging/rtl8712/usb_intf.c | 2 +- drivers/staging/usbip/vhci_rx.c | 13 +- drivers/tty/serial/msm_serial.c | 13 +- drivers/tty/serial/serial_core.c | 1 + drivers/tty/vt/selection.c | 34 +++- drivers/tty/vt/vt.c | 2 - drivers/usb/atm/ueagle-atm.c | 18 +- drivers/usb/core/config.c | 77 +++++++- drivers/usb/core/hub.c | 1 + drivers/usb/core/quirks.c | 37 ++++ drivers/usb/core/urb.c | 1 + drivers/usb/core/usb.h | 3 + drivers/usb/dwc3/dwc3-pci.c | 30 +++ drivers/usb/host/ehci-q.c | 13 +- drivers/usb/host/xhci-hub.c | 8 +- drivers/usb/host/xhci-ring.c | 3 +- drivers/usb/misc/adutux.c | 2 +- drivers/usb/misc/idmouse.c | 2 +- drivers/usb/mon/mon_bin.c | 32 ++-- drivers/usb/musb/musbhsdma.c | 2 +- drivers/usb/serial/ch341.c | 6 +- drivers/usb/serial/io_edgeport.c | 26 +-- drivers/usb/serial/keyspan.c | 4 + drivers/usb/serial/opticon.c | 2 +- drivers/usb/serial/quatech2.c | 6 + drivers/usb/serial/usb-serial-simple.c | 2 + drivers/usb/serial/usb-serial.c | 3 + drivers/vhost/net.c | 13 +- drivers/video/console/vgacon.c | 3 + drivers/virtio/virtio_balloon.c | 10 + firmware/Makefile | 2 +- fs/btrfs/Makefile | 2 +- fs/btrfs/ctree.c | 19 +- fs/btrfs/ctree.h | 157 +++++++++------- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/disk-io.c | 80 ++------ fs/btrfs/extent-tree.c | 110 ++++++++++- fs/btrfs/extent_io.c | 98 +++++----- fs/btrfs/extent_io.h | 25 +-- fs/btrfs/extent_map.c | 2 +- fs/btrfs/extent_map.h | 10 +- fs/btrfs/inode.c | 8 +- fs/btrfs/ioctl.c | 10 +- fs/btrfs/relocation.c | 1 + fs/btrfs/root-tree.c | 10 +- fs/btrfs/scrub.c | 2 +- fs/btrfs/struct-funcs.c | 9 +- fs/btrfs/tree-log.c | 24 ++- fs/btrfs/uuid-tree.c | 2 + fs/btrfs/volumes.c | 206 +++++++++++++++++---- fs/btrfs/volumes.h | 2 + fs/char_dev.c | 88 ++++++++- fs/ext4/dir.c | 5 + fs/ext4/ext4.h | 13 ++ fs/ext4/extents.c | 89 +++++---- fs/ext4/file.c | 2 +- fs/ext4/inode.c | 117 +++++++++--- fs/ext4/super.c | 1 + fs/ext4/truncate.h | 2 + fs/locks.c | 2 +- fs/namei.c | 56 +++++- include/linux/blkdev.h | 10 +- include/linux/blktrace_api.h | 6 +- include/linux/cdev.h | 5 + include/linux/fs.h | 2 + include/linux/if_ether.h | 8 + include/linux/kobject.h | 2 + include/linux/mod_devicetable.h | 4 +- include/linux/netfilter_arp/arp_tables.h | 2 +- include/linux/posix-clock.h | 19 +- include/linux/quotaops.h | 2 +- include/linux/usb/quirks.h | 3 + include/media/media-device.h | 5 +- include/media/media-devnode.h | 32 +++- include/net/addrconf.h | 5 +- include/net/cfg80211.h | 11 ++ include/net/neighbour.h | 1 - kernel/sysctl.c | 18 ++ kernel/taskstats.c | 30 +-- kernel/time/posix-clock.c | 31 ++-- kernel/trace/blktrace.c | 129 ++++++++----- kernel/trace/ftrace.c | 6 +- kernel/trace/trace_sched_wakeup.c | 4 +- kernel/trace/trace_stack.c | 5 + lib/kobject.c | 5 +- mm/mempolicy.c | 6 +- net/8021q/vlan_netlink.c | 10 +- net/batman-adv/distributed-arp-table.c | 4 +- net/bridge/br_netfilter.c | 3 + net/bridge/netfilter/ebtables.c | 58 +++--- net/core/neighbour.c | 3 - net/ipv4/netfilter/arp_tables.c | 42 +++-- net/ipv4/netfilter/arptable_filter.c | 2 +- net/ipv4/tcp_input.c | 5 +- net/ipv4/tcp_output.c | 8 + net/ipv6/af_inet6.c | 2 +- net/mac80211/cfg.c | 55 +----- net/mac80211/sta_info.c | 4 + net/netfilter/ipset/ip_set_bitmap_gen.h | 2 +- net/netfilter/ipset/ip_set_core.c | 3 +- net/netfilter/nf_conntrack_netlink.c | 3 + net/netfilter/nft_bitwise.c | 19 +- net/netfilter/nft_cmp.c | 18 +- net/packet/af_packet.c | 3 +- net/sched/ematch.c | 2 +- net/sched/sch_fq.c | 10 +- net/sctp/sm_sideeffect.c | 28 ++- net/wireless/util.c | 45 +++++ scripts/recordmcount.c | 17 ++ sound/core/pcm_native.c | 4 + sound/core/seq/seq_timer.c | 14 +- sound/pci/hda/patch_ca0132.c | 5 +- sound/pci/ice1712/ice1724.c | 9 +- sound/soc/codecs/wm8962.c | 4 +- sound/usb/pcm.c | 44 +++-- 192 files changed, 2624 insertions(+), 1185 deletions(-)
Signature · 2 lines
Ben Hutchings Knowledge is power. France is bacon.
PATCH 1/245 mwifiex: fix unbalanced locking in mwifiex_process_country_ie()
3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Brian Norris <[email protected]>
commit 65b1aae0d9d5962faccc06bdb8e91a2a0b09451c upstream.
We called rcu_read_lock(), so we need to call rcu_read_unlock() before we return.
--- drivers/net/wireless/mwifiex/sta_ioctl.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/wireless/mwifiex/sta_ioctl.c +1 -0
@@ -226,6 +226,7 @@ static int mwifiex_process_country_ie(stif (country_ie_len > (IEEE80211_COUNTRY_STRING_LEN +MWIFIEX_MAX_TRIPLET_802_11D )) { +rcu_read_unlock ();wiphy_dbg (priv->wdev->wiphy,"11D: country_ie_len overflow!, deauth AP\n" );return -EINVAL ;
PATCH 2/245 libertas: Fix two buffer overflows at parsing bss descriptor
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Wen Huang <[email protected]>
commit e5e884b42639c74b5b57dc277909915c0aefc8bb upstream.
add_ie_rates() copys rates without checking the length in bss descriptor from remote AP.when victim connects to remote attacker, this may trigger buffer overflow. lbs_ibss_join_existing() copys rates without checking the length in bss descriptor from remote IBSS node.when victim connects to remote attacker, this may trigger buffer overflow.
Fix them by putting the length check before performing copy.
This fix addresses CVE-2019-14896 and CVE-2019-14897. This also fix build warning of mixed declarations and code.
--- drivers/net/wireless/libertas/cfg.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/wireless/libertas/cfg.c +13 -3
@@ -272,6 +272,10 @@ add_ie_rates(u8 *tlv, const u8 *ie, intint hw, ap, ap_max = ie[1 ];u8 hw_rate; +if (ap_max >MAX_RATES ) { +lbs_deb_assoc ("invalid rates\n" ); +return tlv; + }/* Advance past IE header */ ie +=2 ;
@@ -1785,6 +1789,9 @@ static int lbs_ibss_join_existing(structstruct cmd_ds_802_11_ad_hoc_join cmd;u8 preamble =RADIO_PREAMBLE_SHORT ;int ret =0 ; +int hw, i; +u8 rates_max; +u8 *rates;lbs_deb_enter (LBS_DEB_CFG80211 );
@@ -1845,9 +1852,12 @@ static int lbs_ibss_join_existing(structif (!rates_eid) {lbs_add_rates (cmd.bss.rates); }else { -int hw, i; -u8 rates_max = rates_eid[1 ]; -u8 *rates = cmd.bss.rates; + rates_max = rates_eid[1 ]; +if (rates_max >MAX_RATES ) { +lbs_deb_join ("invalid rates" ); + goto out; + } + rates = cmd.bss.rates;for (hw =0 ; hw <ARRAY_SIZE (lbs_rates); hw++) {u8 hw_rate = lbs_rates[hw].bitrate /5 ;for (i =0 ; i < rates_max; i++) {
PATCH 3/245 libertas: don't exit from lbs_ibss_join_existing() with RCU read lock held
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Stange <[email protected]>
commit c7bf1fb7ddca331780b9a733ae308737b39f1ad4 upstream.
Commit e5e884b42639 ("libertas: Fix two buffer overflows at parsing bss descriptor") introduced a bounds check on the number of supplied rates to lbs_ibss_join_existing().
Unfortunately, it introduced a return path from within a RCU read side critical section without a corresponding rcu_read_unlock(). Fix this.
--- drivers/net/wireless/libertas/cfg.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/wireless/libertas/cfg.c +1 -0
@@ -1855,6 +1855,7 @@ static int lbs_ibss_join_existing(struct rates_max = rates_eid[1 ];if (rates_max >MAX_RATES ) {lbs_deb_join ("invalid rates" ); +rcu_read_unlock (); goto out; } rates = cmd.bss.rates;
PATCH 4/245 libertas: make lbs_ibss_join_existing() return error code on rates overflow
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Stange <[email protected]>
commit 1754c4f60aaf1e17d886afefee97e94d7f27b4cb upstream.
Commit e5e884b42639 ("libertas: Fix two buffer overflows at parsing bss descriptor") introduced a bounds check on the number of supplied rates to lbs_ibss_join_existing() and made it to return on overflow.
However, the aforementioned commit doesn't set the return value accordingly and thus, lbs_ibss_join_existing() would return with zero even though it failed.
Make lbs_ibss_join_existing return -EINVAL in case the bounds check on the number of supplied rates fails.
--- drivers/net/wireless/libertas/cfg.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/wireless/libertas/cfg.c +1 -0
@@ -1856,6 +1856,7 @@ static int lbs_ibss_join_existing(structif (rates_max >MAX_RATES ) {lbs_deb_join ("invalid rates" );rcu_read_unlock (); + ret = -EINVAL ; goto out; } rates = cmd.bss.rates;
PATCH 5/245 mwifiex: fix probable memory corruption while processing TDLS frame
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Avinash Patil <[email protected]>
commit 3c99832d74777c9ec5545a92450fac5d37b0d0e1 upstream.
Size of RSN IE buffer in driver is 254 while maximum size of received buffer to be copied to RSN IE buffer can be 255. Add boundary check to copy maximum of 254 bytes into RSN IE buffer.
--- drivers/net/wireless/mwifiex/tdls.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/mwifiex/tdls.c +3 -1
@@ -877,7 +877,9 @@ void mwifiex_process_tdls_action_frame(sbreak ;case WLAN_EID_RSN :memcpy ((u8 *)&sta_ptr->tdls_cap.rsn_ie, pos, -sizeof (struct ieee_types_header ) + pos[1 ]); +sizeof (struct ieee_types_header ) + +min_t (u8, pos[1 ],IEEE_MAX_IE_SIZE - +sizeof (struct ieee_types_header )));break ;case WLAN_EID_QOS_CAPA : sta_ptr->tdls_cap.qos_info = pos[2 ];
PATCH 6/245 mwifiex: Fix heap overflow in mmwifiex_process_tdls_action_frame()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: qize wang <[email protected]>
commit 1e58252e334dc3f3756f424a157d1b7484464c40 upstream.
mwifiex_process_tdls_action_frame() without checking the incoming tdls infomation element's vality before use it, this may cause multi heap buffer overflows.
Fix them by putting vality check before use it.
IE is TLV struct, but ht_cap and ht_oper aren’t TLV struct. the origin marvell driver code is wrong:
memcpy(&sta_ptr->tdls_cap.ht_oper, pos,.... memcpy((u8 *)&sta_ptr->tdls_cap.ht_capb, pos,...
Fix the bug by changing pos(the address of IE) to pos+2 ( the address of IE value ).
--- drivers/net/wireless/mwifiex/tdls.c | 70 +++++++++++++++++++-- 1 file changed, 64 insertions(+), 6 deletions(-)
drivers/net/wireless/mwifiex/tdls.c +64 -6
@@ -847,59 +847,117 @@ void mwifiex_process_tdls_action_frame(sswitch (*pos) {case WLAN_EID_SUPP_RATES : +if (pos[1 ] >32 ) +return ; sta_ptr->tdls_cap.rates_len = pos[1 ];for (i =0 ; i < pos[1 ]; i++) sta_ptr->tdls_cap.rates[i] = pos[i +2 ];break ;case WLAN_EID_EXT_SUPP_RATES : +if (pos[1 ] >32 ) +return ; basic = sta_ptr->tdls_cap.rates_len; +if (pos[1 ] >32 - basic) +return ;for (i =0 ; i < pos[1 ]; i++) sta_ptr->tdls_cap.rates[basic + i] = pos[i +2 ]; sta_ptr->tdls_cap.rates_len += pos[1 ];break ;case WLAN_EID_HT_CAPABILITY : -memcpy ((u8 *)&sta_ptr->tdls_cap.ht_capb, pos, +if (pos > end -sizeof (struct ieee80211_ht_cap ) -2 ) +return ; +if (pos[1 ] !=sizeof (struct ieee80211_ht_cap )) +return ; +/* copy the ie's value into ht_capb*/ +memcpy ((u8 *)&sta_ptr->tdls_cap.ht_capb, pos +2 ,sizeof (struct ieee80211_ht_cap )); sta_ptr->is_11n_enabled =1 ;break ;case WLAN_EID_HT_OPERATION : -memcpy (&sta_ptr->tdls_cap.ht_oper, pos, +if (pos > end - +sizeof (struct ieee80211_ht_operation ) -2 ) +return ; +if (pos[1 ] !=sizeof (struct ieee80211_ht_operation )) +return ; +/* copy the ie's value into ht_oper*/ +memcpy (&sta_ptr->tdls_cap.ht_oper, pos +2 ,sizeof (struct ieee80211_ht_operation ));break ;case WLAN_EID_BSS_COEX_2040 : +if (pos > end -3 ) +return ; +if (pos[1 ] !=1 ) +return ; sta_ptr->tdls_cap.coex_2040 = pos[2 ];break ;case WLAN_EID_EXT_CAPABILITY : +if (pos > end -sizeof (struct ieee_types_header )) +return ; +if (pos[1 ] <sizeof (struct ieee_types_header )) +return ; +if (pos[1 ] >8 ) +return ;memcpy ((u8 *)&sta_ptr->tdls_cap.extcap, pos,sizeof (struct ieee_types_header ) +min_t (u8, pos[1 ],8 ));break ;case WLAN_EID_RSN : +if (pos > end -sizeof (struct ieee_types_header )) +return ; +if (pos[1 ] <sizeof (struct ieee_types_header )) +return ; +if (pos[1 ] >IEEE_MAX_IE_SIZE - +sizeof (struct ieee_types_header )) +return ;memcpy ((u8 *)&sta_ptr->tdls_cap.rsn_ie, pos,sizeof (struct ieee_types_header ) +min_t (u8, pos[1 ],IEEE_MAX_IE_SIZE -sizeof (struct ieee_types_header )));break ;case WLAN_EID_QOS_CAPA : +if (pos > end -3 ) +return ; +if (pos[1 ] !=1 ) +return ; sta_ptr->tdls_cap.qos_info = pos[2 ];break ;case WLAN_EID_VHT_OPERATION : -if (priv->adapter->is_hw_11ac_capable) -memcpy (&sta_ptr->tdls_cap.vhtoper, pos, +if (priv->adapter->is_hw_11ac_capable) { +if (pos > end - +sizeof (struct ieee80211_vht_operation ) -2 ) +return ; +if (pos[1 ] != +sizeof (struct ieee80211_vht_operation )) +return ; +/* copy the ie's value into vhtoper*/ +memcpy (&sta_ptr->tdls_cap.vhtoper, pos +2 ,sizeof (struct ieee80211_vht_operation )); + }break ;case WLAN_EID_VHT_CAPABILITY :if (priv->adapter->is_hw_11ac_capable) { -memcpy ((u8 *)&sta_ptr->tdls_cap.vhtcap, pos, +if (pos > end - +sizeof (struct ieee80211_vht_cap ) -2 ) +return ; +if (pos[1 ] !=sizeof (struct ieee80211_vht_cap )) +return ; +/* copy the ie's value into vhtcap*/ +memcpy ((u8 *)&sta_ptr->tdls_cap.vhtcap, pos +2 ,sizeof (struct ieee80211_vht_cap )); sta_ptr->is_11ac_enabled =1 ; }break ;case WLAN_EID_AID : -if (priv->adapter->is_hw_11ac_capable) +if (priv->adapter->is_hw_11ac_capable) { +if (pos > end -4 ) +return ; +if (pos[1 ] !=2 ) +return ; sta_ptr->tdls_cap.aid =le16_to_cpu (*(__le16 *)(pos +2 )); + } +break ;default :break ; }
PATCH 7/245 cfg80211/mac80211: make ieee80211_send_layer2_update a public function
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dedy Lansky <[email protected]>
commit 30ca1aa536211f5ac3de0173513a7a99a98a97f3 upstream.
Make ieee80211_send_layer2_update() a common function so other drivers can re-use it.
[bwh: Backported to 3.16 as dependency of commit 3e493173b784
"mac80211: Do not send Layer 2 Update frame before authorization":
- Retain type-casting of skb_put() return value
- Adjust context]
--- include/net/cfg80211.h | 11 ++++++++++ net/mac80211/cfg.c | 48 ++---------------------------------------- net/wireless/util.c | 45 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 46 deletions(-)
include/net/cfg80211.h +11 -0
@@ -3627,6 +3627,17 @@ const u8 *cfg80211_find_vendor_ie(unsign const u8 *ies, int len);/** +* cfg80211_send_layer2_update - send layer 2 update frame +* +* @dev: network device +* @addr: STA MAC address +* +* Wireless drivers can use this function to update forwarding tables in bridge +* devices upon STA association. +*/ +void cfg80211_send_layer2_update (struct net_device *dev,const u8 *addr); + +/** * DOC: Regulatory enforcement infrastructure * * TODO
net/mac80211/cfg.c +2 -46
66 lines not on this page · raw message
net/wireless/util.c +45 -0
48 lines not on this page · raw message
PATCH 8/245 mac80211: Do not send Layer 2 Update frame before authorization
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jouni Malinen <[email protected]>
commit 3e493173b7841259a08c5c8e5cbe90adb349da7e upstream.
The Layer 2 Update frame is used to update bridges when a station roams to another AP even if that STA does not transmit any frames after the reassociation. This behavior was described in IEEE Std 802.11F-2003 as something that would happen based on MLME-ASSOCIATE.indication, i.e., before completing 4-way handshake. However, this IEEE trial-use recommended practice document was published before RSN (IEEE Std 802.11i-2004) and as such, did not consider RSN use cases. Furthermore, IEEE Std 802.11F-2003 was withdrawn in 2006 and as such, has not been maintained amd should not be used anymore.
Sending out the Layer 2 Update frame immediately after association is fine for open networks (and also when using SAE, FT protocol, or FILS authentication when the station is actually authenticated by the time association completes). However, it is not appropriate for cases where RSN is used with PSK or EAP authentication since the station is actually fully authenticated only once the 4-way handshake completes after authentication and attackers might be able to use the unauthenticated triggering of Layer 2 Update frame transmission to disrupt bridge behavior.
Fix this by postponing transmission of the Layer 2 Update frame from station entry addition to the point when the station entry is marked authorized. Similarly, send out the VLAN binding update only if the STA entry has already been authorized.
--- net/mac80211/cfg.c | 11 +++-------- net/mac80211/sta_info.c | 4 ++++ 2 files changed, 7 insertions(+), 8 deletions(-)
net/mac80211/cfg.c +3 -8
@@ -1436,7 +1436,6 @@ static int ieee80211_add_station(structstruct sta_info *sta;struct ieee80211_sub_if_data *sdata;int err; -int layer2_update;if (params->vlan) { sdata =IEEE80211_DEV_TO_SUB_IF (params->vlan);
@@ -1481,18 +1480,12 @@ static int ieee80211_add_station(structif (!test_sta_flag (sta,WLAN_STA_TDLS_PEER ))rate_control_rate_init (sta); - layer2_update = sdata->vif.type ==NL80211_IFTYPE_AP_VLAN || - sdata->vif.type ==NL80211_IFTYPE_AP ; - err =sta_info_insert_rcu (sta);if (err) {rcu_read_unlock ();return err; } -if (layer2_update) -cfg80211_send_layer2_update (sta->sdata->dev, sta->sta.addr); -rcu_read_unlock ();return 0 ;
@@ -1596,7 +1589,9 @@ static int ieee80211_change_station(struatomic_inc (&sta->sdata->bss->num_mcast_sta); } -cfg80211_send_layer2_update (sta->sdata->dev, sta->sta.addr); +if (sta->sta_state ==IEEE80211_STA_AUTHORIZED ) +cfg80211_send_layer2_update (sta->sdata->dev, + sta->sta.addr); } err =sta_apply_parameters (local, sta, params);
net/mac80211/sta_info.c +4 -0
@@ -1666,6 +1666,10 @@ int sta_info_move_state(struct sta_infoatomic_inc (&sta->sdata->bss->num_mcast_sta);set_bit (WLAN_STA_AUTHORIZED , &sta->_flags); } +if (sta->sdata->vif.type ==NL80211_IFTYPE_AP_VLAN || + sta->sdata->vif.type ==NL80211_IFTYPE_AP ) +cfg80211_send_layer2_update (sta->sdata->dev, + sta->sta.addr);break ;default :break ;
PATCH 9/245 x86/microcode/AMD: Add support for fam17h microcode loading
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Tom Lendacky <[email protected]>
commit f4e9b7af0cd58dd039a0fb2cd67d57cea4889abf upstream.
The size for the Microcode Patch Block (MPB) for an AMD family 17h processor is 3200 bytes. Add a #define for fam17h so that it does not default to 2048 bytes and fail a microcode load/update.
--- arch/x86/kernel/cpu/microcode/amd.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/kernel/cpu/microcode/amd.c +4 -0
@@ -154,6 +154,7 @@ static unsigned int verify_patch_size(u8#define F14H_MPB_MAX_SIZE 1824#define F15H_MPB_MAX_SIZE 4096#define F16H_MPB_MAX_SIZE 3458 +#define F17H_MPB_MAX_SIZE 3200switch (family) {case 0x14 :
@@ -165,6 +166,9 @@ static unsigned int verify_patch_size(u8case 0x16 : max_size =F16H_MPB_MAX_SIZE ;break ; +case 0x17 : + max_size =F17H_MPB_MAX_SIZE ; +break ;default : max_size =F1XH_MPB_MAX_SIZE ;break ;
PATCH 10/245 ext4: wait for existing dio workers in ext4_alloc_file_blocks()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Czerner <[email protected]>
commit 0d306dcf86e8f065dff42a4a934ae9d99af35ba5 upstream.
Currently existing dio workers can jump in and potentially increase extent tree depth while we're allocating blocks in ext4_alloc_file_blocks(). This may cause us to underestimate the number of credits needed for the transaction because the extent tree depth can change after our estimation.
Fix this by waiting for all the existing dio workers in the same way as we do it in ext4_punch_hole. We've seen errors caused by this in xfstest generic/299, however it's really hard to reproduce.
--- fs/ext4/extents.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/ext4/extents.c +6 -0
@@ -4707,6 +4707,10 @@ static int ext4_alloc_file_blocks(structif (len <=EXT_UNWRITTEN_MAX_LEN ) flags |=EXT4_GET_BLOCKS_NO_NORMALIZE ; +/* Wait all existing dio workers, newcomers will block on i_mutex */ +ext4_inode_block_unlocked_dio (inode); +inode_dio_wait (inode); +/* * credits to insert 1 extent into extent tree */
@@ -4756,6 +4760,8 @@ retry: goto retry; } +ext4_inode_resume_unlocked_dio (inode); +return ret >0 ? ret2 : ret; }
PATCH 11/245 ext4: only call ext4_truncate when size <= isize
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
commit 3da40c7b089810ac9cf2bb1e59633f619f3a7312 upstream.
At LSF we decided that if we truncate up from isize we shouldn't trim fallocated blocks that were fallocated with KEEP_SIZE and are past the new i_size. This patch fixes ext4 to do this.
[ Completely reworked patch so that i_disksize would actually get set
when truncating up. Also reworked the code for handling truncate so that it's easier to handle. -- tytso ]
[bwh: Backported to 3.16 as dependency of commit ea3d7209ca01
"ext4: fix races between page faults and hole punching":
- Adjust context]
--- fs/ext4/inode.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-)
fs/ext4/inode.c +18 -20
@@ -4809,8 +4809,10 @@ int ext4_setattr(struct dentry *dentry,ext4_journal_stop (handle); } -if (attr->ia_valid &ATTR_SIZE && attr->ia_size != inode->i_size) { +if (attr->ia_valid &ATTR_SIZE ) {handle_t *handle; +loff_t oldsize = inode->i_size; +int shrink = (attr->ia_size <= inode->i_size);if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) {struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb);
@@ -4818,24 +4820,26 @@ int ext4_setattr(struct dentry *dentry,if (attr->ia_size > sbi->s_bitmap_maxbytes)return -EFBIG ; } +if (!S_ISREG (inode->i_mode)) +return -EINVAL ;if (IS_I_VERSION (inode) && attr->ia_size != inode->i_size)inode_inc_iversion (inode); -if (S_ISREG (inode->i_mode) && +if (ext4_should_order_data (inode) && (attr->ia_size < inode->i_size)) { -if (ext4_should_order_data (inode)) { - error =ext4_begin_ordered_truncate (inode, + error =ext4_begin_ordered_truncate (inode, attr->ia_size); -if (error) - goto err_out; - } +if (error) + goto err_out; + } +if (attr->ia_size != inode->i_size) { handle =ext4_journal_start (inode,EXT4_HT_INODE ,3 );if (IS_ERR (handle)) { error =PTR_ERR (handle); goto err_out; } -if (ext4_handle_valid (handle)) { +if (ext4_handle_valid (handle) && shrink) { error =ext4_orphan_add (handle, inode); orphan =1 ; }
@@ -4854,15 +4858,13 @@ int ext4_setattr(struct dentry *dentry,up_write (&EXT4_I (inode)->i_data_sem);ext4_journal_stop (handle);if (error) { -ext4_orphan_del (NULL , inode); +if (orphan) +ext4_orphan_del (NULL , inode); goto err_out; } - }else { -loff_t oldsize = inode->i_size; - -i_size_write (inode, attr->ia_size); -pagecache_isize_extended (inode, oldsize, inode->i_size); } +if (!shrink) +pagecache_isize_extended (inode, oldsize, inode->i_size);/* * Blocks are going to be removed from the inode. Wait
@@ -4882,13 +4884,9 @@ int ext4_setattr(struct dentry *dentry,* in data=journal mode to make pages freeable. */ truncate_pagecache (inode, inode->i_size); +if (shrink) +ext4_truncate (inode); } -/* -* We want to call ext4_truncate() even if attr->ia_size == -* inode->i_size for cases like truncation of fallocated space -*/ -if (attr->ia_valid &ATTR_SIZE ) -ext4_truncate (inode);if (!rc) {setattr_copy (inode, attr);
PATCH 12/245 ext4: update c/mtime on truncate up
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eryu Guan <[email protected]>
commit 911af577de4e444622d46500c1f9a37ab4335d3a upstream.
Commit 3da40c7b0898 ("ext4: only call ext4_truncate when size <= isize") introduced a bug that c/mtime is not updated on truncate up.
Fix the issue by setting c/mtime explicitly in the truncate up case.
Note that ftruncate(2) is not affected, so you won't see this bug using truncate(1) and xfs_io(1).
--- fs/ext4/inode.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ext4/inode.c +8 -0
@@ -4843,6 +4843,14 @@ int ext4_setattr(struct dentry *dentry, error =ext4_orphan_add (handle, inode); orphan =1 ; } +/* +* Update c/mtime on truncate up, ext4_truncate() will +* update c/mtime in shrink case below +*/ +if (!shrink) { + inode->i_mtime =ext4_current_time (inode); + inode->i_ctime = inode->i_mtime; + }down_write (&EXT4_I (inode)->i_data_sem);EXT4_I (inode)->i_disksize = attr->ia_size; rc =ext4_mark_inode_dirty (handle, inode);
PATCH 13/245 quota: fix wrong condition in is_quota_modification()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
commit 6565c182094f69e4ffdece337d395eb7ec760efc upstream.
Quoted from
commit 3da40c7b0898 ("ext4: only call ext4_truncate when size <= isize")
" At LSF we decided that if we truncate up from isize we shouldn't trim
fallocated blocks that were fallocated with KEEP_SIZE and are past the
new i_size. This patch fixes ext4 to do this. "
And generic/092 of fstest have covered this case for long time, however is_quota_modification() didn't adjust based on that rule, so that in below condition, we will lose to quota block change:
- fallocate blocks beyond EOF
- remount
- truncate(file_path, file_size)
Fix it.
--- include/linux/quotaops.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/quotaops.h +1 -1
@@ -21,7 +21,7 @@ static inline struct quota_info *sb_dqop/* i_mutex must being held */ static inline bool is_quota_modification (struct inode *inode,struct iattr *ia) { -return (ia->ia_valid &ATTR_SIZE && ia->ia_size != inode->i_size) || +return (ia->ia_valid &ATTR_SIZE ) || (ia->ia_valid &ATTR_UID && !uid_eq (ia->ia_uid, inode->i_uid)) || (ia->ia_valid &ATTR_GID && !gid_eq (ia->ia_gid, inode->i_gid)); }
PATCH 14/245 ext4: fix races between page faults and hole punching
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
commit ea3d7209ca01da209cda6f0dea8be9cc4b7a933b upstream.
Currently, page faults and hole punching are completely unsynchronized. This can result in page fault faulting in a page into a range that we are punching after truncate_pagecache_range() has been called and thus we can end up with a page mapped to disk blocks that will be shortly freed. Filesystem corruption will shortly follow. Note that the same race is avoided for truncate by checking page fault offset against i_size but there isn't similar mechanism available for punching holes.
Fix the problem by creating new rw semaphore i_mmap_sem in inode and grab it for writing over truncate, hole punching, and other functions removing blocks from extent tree and for read over page faults. We cannot easily use i_data_sem for this since that ranks below transaction start and we need something ranking above it so that it can be held over the whole truncate / hole punching operation. Also remove various workarounds we had in the code to reduce race window when page fault could have created pages with stale mapping information.
[bwh: Backported to 3.16:
- Drop changes in ext4_insert_range(), ext4_dax_*
- Adjust context]
---
fs/ext4/ext4.h +10 -0
@@ -937,6 +937,15 @@ struct ext4_inode_info {* by other means, so we have i_data_sem. */ struct rw_semaphore i_data_sem; +/* +* i_mmap_sem is for serializing page faults with truncate / punch hole +* operations. We have to make sure that new page cannot be faulted in +* a section of the inode that is being punched. We cannot easily use +* i_data_sem for this since we need protection for the whole punch +* operation and i_data_sem ranks below transaction start so we have +* to occasionally drop it. +*/ +struct rw_semaphore i_mmap_sem;struct inode vfs_inode;struct jbd2_inode *jinode;
@@ -2205,6 +2214,7 @@ extern int ext4_chunk_trans_blocks(strucextern int ext4_zero_partial_blocks (handle_t *handle,struct inode *inode,loff_t lstart,loff_t lend);extern int ext4_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf); +extern int ext4_filemap_fault (struct vm_area_struct *vma,struct vm_fault *vmf);extern qsize_t *ext4_get_reserved_space (struct inode *inode);extern void ext4_da_update_reserve_space (struct inode *inode,int used,int quota_claim);
fs/ext4/extents.c +20 -20
@@ -4778,7 +4778,6 @@ static long ext4_zero_range(struct fileint partial_begin, partial_end;loff_t start, end;ext4_lblk_t lblk; -struct address_space *mapping = inode->i_mapping;unsigned int blkbits = inode->i_blkbits;trace_ext4_zero_range (inode, offset, len, mode);
@@ -4794,17 +4793,6 @@ static long ext4_zero_range(struct file }/* -* Write out all dirty pages to avoid race conditions -* Then release them. -*/ -if (mapping->nrpages &&mapping_tagged (mapping,PAGECACHE_TAG_DIRTY )) { - ret =filemap_write_and_wait_range (mapping, offset, - offset + len -1 ); -if (ret) -return ret; - } - -/* * Round up offset. This is not fallocate, we neet to zero out * blocks, so convert interior block aligned part of the range to * unwritten and possibly manually zero out unaligned parts of the
@@ -4865,16 +4853,22 @@ static long ext4_zero_range(struct file flags |= (EXT4_GET_BLOCKS_CONVERT_UNWRITTEN |EXT4_EX_NOCACHE ); -/* Now release the pages and zero block aligned part of pages*/ -truncate_pagecache_range (inode, start, end -1 ); - inode->i_mtime = inode->i_ctime =ext4_current_time (inode); -/* Wait all existing dio workers, newcomers will block on i_mutex */ ext4_inode_block_unlocked_dio (inode);inode_dio_wait (inode); +/* +* Prevent page faults from reinstantiating pages we have +* released from page cache. +*/ +down_write (&EXT4_I (inode)->i_mmap_sem); +/* Now release the pages and zero block aligned part of pages */ +truncate_pagecache_range (inode, start, end -1 ); + inode->i_mtime = inode->i_ctime =ext4_current_time (inode); + ret =ext4_alloc_file_blocks (file, lblk, max_blocks, new_size, flags, mode); +up_write (&EXT4_I (inode)->i_mmap_sem);if (ret) goto out_dio; }
@@ -5490,17 +5484,22 @@ int ext4_collapse_range(struct inode *in goto out_mutex; } -truncate_pagecache (inode, ioffset); -/* Wait for existing dio to complete */ ext4_inode_block_unlocked_dio (inode);inode_dio_wait (inode); +/* +* Prevent page faults from reinstantiating pages we have released from +* page cache. +*/ +down_write (&EXT4_I (inode)->i_mmap_sem); +truncate_pagecache (inode, ioffset); + credits =ext4_writepage_trans_blocks (inode); handle =ext4_journal_start (inode,EXT4_HT_TRUNCATE , credits);if (IS_ERR (handle)) { ret =PTR_ERR (handle); - goto out_dio; + goto out_mmap; }down_write (&EXT4_I (inode)->i_data_sem);
@@ -5540,7 +5539,8 @@ int ext4_collapse_range(struct inode *in out_stop:ext4_journal_stop (handle); -out_dio: +out_mmap: +up_write (&EXT4_I (inode)->i_mmap_sem);ext4_inode_resume_unlocked_dio (inode); out_mutex:mutex_unlock (&inode->i_mutex);
fs/ext4/file.c +1 -1
@@ -199,7 +199,7 @@ errout: }static const struct vm_operations_struct ext4_file_vm_ops = { - .fault = filemap_fault, + .fault = ext4_filemap_fault, .map_pages = filemap_map_pages, .page_mkwrite = ext4_page_mkwrite, };
fs/ext4/inode.c +27 -9
@@ -3716,6 +3716,15 @@ int ext4_punch_hole(struct inode *inode, } +/* Wait all existing dio workers, newcomers will block on i_mutex */ +ext4_inode_block_unlocked_dio (inode); +inode_dio_wait (inode); + +/* +* Prevent page faults from reinstantiating pages we have released from +* page cache. +*/ +down_write (&EXT4_I (inode)->i_mmap_sem); first_block_offset =round_up (offset, sb->s_blocksize); last_block_offset =round_down ((offset + length), sb->s_blocksize) -1 ;
@@ -3724,10 +3733,6 @@ int ext4_punch_hole(struct inode *inode,truncate_pagecache_range (inode, first_block_offset, last_block_offset); -/* Wait all existing dio workers, newcomers will block on i_mutex */ -ext4_inode_block_unlocked_dio (inode); -inode_dio_wait (inode); -if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) credits =ext4_writepage_trans_blocks (inode);else
@@ -3773,11 +3778,6 @@ int ext4_punch_hole(struct inode *inode,if (IS_SYNC (inode))ext4_handle_sync (handle); -/* Now release the pages again to reduce race window */ -if (last_block_offset > first_block_offset) -truncate_pagecache_range (inode, first_block_offset, - last_block_offset); - inode->i_mtime = inode->i_ctime =ext4_current_time (inode);ext4_mark_inode_dirty (handle, inode);if (ret >=0 )
@@ -3785,6 +3785,7 @@ int ext4_punch_hole(struct inode *inode, out_stop:ext4_journal_stop (handle); out_dio: +up_write (&EXT4_I (inode)->i_mmap_sem);ext4_inode_resume_unlocked_dio (inode); out_mutex:mutex_unlock (&inode->i_mutex);
@@ -4879,6 +4880,7 @@ int ext4_setattr(struct dentry *dentry, }else ext4_wait_for_tail_page_commit (inode); } +down_write (&EXT4_I (inode)->i_mmap_sem);/* * Truncate pagecache after we've waited for commit * in data=journal mode to make pages freeable.
@@ -4886,6 +4888,7 @@ int ext4_setattr(struct dentry *dentry,truncate_pagecache (inode, inode->i_size);if (shrink)ext4_truncate (inode); +up_write (&EXT4_I (inode)->i_mmap_sem); }if (!rc) {
@@ -5338,6 +5341,8 @@ int ext4_page_mkwrite(struct vm_area_strsb_start_pagefault (inode->i_sb);file_update_time (vma->vm_file); +down_read (&EXT4_I (inode)->i_mmap_sem); + ret =ext4_convert_inline_data (inode);if (ret) goto out_ret;
@@ -5411,6 +5416,19 @@ retry_alloc: out_ret: ret =block_page_mkwrite_return (ret); out: +up_read (&EXT4_I (inode)->i_mmap_sem);sb_end_pagefault (inode->i_sb);return ret; } + +int ext4_filemap_fault (struct vm_area_struct *vma,struct vm_fault *vmf) +{ +struct inode *inode =file_inode (vma->vm_file); +int err; + +down_read (&EXT4_I (inode)->i_mmap_sem); + err =filemap_fault (vma, vmf); +up_read (&EXT4_I (inode)->i_mmap_sem); + +return err; +}
fs/ext4/super.c +1 -0
@@ -967,6 +967,7 @@ static void init_once(void *foo)INIT_LIST_HEAD (&ei->i_orphan);init_rwsem (&ei->xattr_sem);init_rwsem (&ei->i_data_sem); +init_rwsem (&ei->i_mmap_sem);inode_init_once (&ei->vfs_inode); }
fs/ext4/truncate.h +2 -0
@@ -10,8 +10,10 @@*/ static inline void ext4_truncate_failed_write (struct inode *inode) { +down_write (&EXT4_I (inode)->i_mmap_sem);truncate_inode_pages (inode->i_mapping, inode->i_size);ext4_truncate (inode); +up_write (&EXT4_I (inode)->i_mmap_sem); }/*
PATCH 15/245 ext4: move unlocked dio protection from ext4_alloc_file_blocks()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
commit 17048e8a083fec7ad841d88ef0812707fbc7e39f upstream.
Currently ext4_alloc_file_blocks() was handling protection against unlocked DIO. However we now need to sometimes call it under i_mmap_sem and sometimes not and DIO protection ranks above it (although strictly speaking this cannot currently create any deadlocks). Also ext4_zero_range() was actually getting & releasing unlocked DIO protection twice in some cases. Luckily it didn't introduce any real bug but it was a land mine waiting to be stepped on. So move DIO protection out from ext4_alloc_file_blocks() into the two callsites.
--- fs/ext4/extents.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
fs/ext4/extents.c +10 -11
@@ -4707,10 +4707,6 @@ static int ext4_alloc_file_blocks(structif (len <=EXT_UNWRITTEN_MAX_LEN ) flags |=EXT4_GET_BLOCKS_NO_NORMALIZE ; -/* Wait all existing dio workers, newcomers will block on i_mutex */ -ext4_inode_block_unlocked_dio (inode); -inode_dio_wait (inode); -/* * credits to insert 1 extent into extent tree */
@@ -4760,8 +4756,6 @@ retry: goto retry; } -ext4_inode_resume_unlocked_dio (inode); -return ret >0 ? ret2 : ret; }
@@ -4836,6 +4830,10 @@ static long ext4_zero_range(struct fileif (mode &FALLOC_FL_KEEP_SIZE ) flags |=EXT4_GET_BLOCKS_KEEP_SIZE ; +/* Wait all existing dio workers, newcomers will block on i_mutex */ +ext4_inode_block_unlocked_dio (inode); +inode_dio_wait (inode); +/* Preallocate the range including the unaligned edges */ if (partial_begin || partial_end) { ret = ext4_alloc_file_blocks(file,
@@ -4844,7 +4842,7 @@ static long ext4_zero_range(struct file round_down(offset, 1 << blkbits)) >> blkbits, new_size, flags, mode);if (ret) - goto out_mutex; + goto out_dio; }
@@ -4853,10 +4851,6 @@ static long ext4_zero_range(struct file flags |= (EXT4_GET_BLOCKS_CONVERT_UNWRITTEN |EXT4_EX_NOCACHE ); -/* Wait all existing dio workers, newcomers will block on i_mutex */ -ext4_inode_block_unlocked_dio (inode); -inode_dio_wait (inode); -/* * Prevent page faults from reinstantiating pages we have * released from page cache.
@@ -4985,8 +4979,13 @@ long ext4_fallocate(struct file *file, i goto out; } +/* Wait all existing dio workers, newcomers will block on i_mutex */ +ext4_inode_block_unlocked_dio (inode); +inode_dio_wait (inode); + ret =ext4_alloc_file_blocks (file, lblk, max_blocks, new_size, flags, mode); +ext4_inode_resume_unlocked_dio (inode);if (ret) goto out;
PATCH 16/245 ext4: fix races between buffered IO and collapse / insert range
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
commit 32ebffd3bbb4162da5ff88f9a35dd32d0a28ea70 upstream.
Current code implementing FALLOC_FL_COLLAPSE_RANGE and FALLOC_FL_INSERT_RANGE is prone to races with buffered writes and page faults. If buffered write or write via mmap manages to squeeze between filemap_write_and_wait_range() and truncate_pagecache() in the fallocate implementations, the written data is simply discarded by truncate_pagecache() although it should have been shifted.
Fix the problem by moving filemap_write_and_wait_range() call inside i_mutex and i_mmap_sem. That way we are protected against races with both buffered writes and page faults.
---
fs/ext4/extents.c +21 -14
@@ -5453,21 +5453,7 @@ int ext4_collapse_range(struct inode *inreturn ret; } -/* -* Need to round down offset to be aligned with page size boundary -* for page size > block size. -*/ - ioffset =round_down (offset,PAGE_SIZE ); - -/* Write out all dirty pages */ - ret =filemap_write_and_wait_range (inode->i_mapping, ioffset, -LLONG_MAX ); -if (ret) -return ret; - -/* Take mutex lock */ mutex_lock (&inode->i_mutex); -/* * There is no need to overlap collapse range with EOF, in which case * it is effectively a truncate operation
@@ -5492,6 +5478,27 @@ int ext4_collapse_range(struct inode *in* page cache. */ down_write (&EXT4_I (inode)->i_mmap_sem); +/* +* Need to round down offset to be aligned with page size boundary +* for page size > block size. +*/ + ioffset =round_down (offset,PAGE_SIZE ); +/* +* Write tail of the last page before removed range since it will get +* removed from the page cache below. +*/ + ret =filemap_write_and_wait_range (inode->i_mapping, ioffset, offset); +if (ret) + goto out_mmap; +/* +* Write data that will be shifted to preserve them when discarding +* page cache below. We are also protected from pages becoming dirty +* by i_mmap_sem. +*/ + ret =filemap_write_and_wait_range (inode->i_mapping, offset + len, +LLONG_MAX ); +if (ret) + goto out_mmap;truncate_pagecache (inode, ioffset); credits =ext4_writepage_trans_blocks (inode);
PATCH 17/245 ext4: fix races of writeback with punch hole and zero range
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
commit 011278485ecc3cd2a3954b5d4c73101d919bf1fa upstream.
When doing delayed allocation, update of on-disk inode size is postponed until IO submission time. However hole punch or zero range fallocate calls can end up discarding the tail page cache page and thus on-disk inode size would never be properly updated.
Make sure the on-disk inode size is updated before truncating page cache.
--- fs/ext4/ext4.h | 3 +++ fs/ext4/extents.c | 5 +++++ fs/ext4/inode.c | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-)
fs/ext4/ext4.h +3 -0
@@ -2560,6 +2560,9 @@ static inline int ext4_update_inode_sizereturn changed; } +int ext4_update_disksize_before_punch (struct inode *inode,loff_t offset, +loff_t len); +struct ext4_group_info {unsigned long bb_state;struct rb_root bb_free_root;
fs/ext4/extents.c +5 -0
@@ -4856,6 +4856,11 @@ static long ext4_zero_range(struct file* released from page cache. */ down_write (&EXT4_I (inode)->i_mmap_sem); + ret =ext4_update_disksize_before_punch (inode, offset, len); +if (ret) { +up_write (&EXT4_I (inode)->i_mmap_sem); + goto out_dio; + }/* Now release the pages and zero block aligned part of pages */ truncate_pagecache_range (inode, start, end -1 ); inode->i_mtime = inode->i_ctime =ext4_current_time (inode);
fs/ext4/inode.c +34 -1
@@ -3652,6 +3652,35 @@ int ext4_can_truncate(struct inode *inod }/* +* We have to make sure i_disksize gets properly updated before we truncate +* page cache due to hole punching or zero range. Otherwise i_disksize update +* can get lost as it may have been postponed to submission of writeback but +* that will never happen after we truncate page cache. +*/ +int ext4_update_disksize_before_punch (struct inode *inode,loff_t offset, +loff_t len) +{ +handle_t *handle; +loff_t size =i_size_read (inode); + +WARN_ON (!mutex_is_locked (&inode->i_mutex)); +if (offset > size || offset + len < size) +return 0 ; + +if (EXT4_I (inode)->i_disksize >= size) +return 0 ; + + handle =ext4_journal_start (inode,EXT4_HT_MISC ,1 ); +if (IS_ERR (handle)) +return PTR_ERR (handle); +ext4_update_i_disksize (inode, size); +ext4_mark_inode_dirty (handle, inode); +ext4_journal_stop (handle); + +return 0 ; +} + +/* * ext4_punch_hole: punches a hole in a file by releaseing the blocks * associated with the given offset and length *
@@ -3729,9 +3758,13 @@ int ext4_punch_hole(struct inode *inode, last_block_offset =round_down ((offset + length), sb->s_blocksize) -1 ;/* Now release the pages and zero block aligned part of pages*/ -if (last_block_offset > first_block_offset) +if (last_block_offset > first_block_offset) { + ret =ext4_update_disksize_before_punch (inode, offset, length); +if (ret) + goto out_dio;truncate_pagecache_range (inode, first_block_offset, last_block_offset); + }if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) credits =ext4_writepage_trans_blocks (inode);
PATCH 18/245 Btrfs: fix wrong max inline data size limit
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Wang Shilong <[email protected]>
commit c01a5c074c0f6f85a3b02e39432b9e5576ab51de upstream.
inline data is stored from offset of @disk_bytenr in struct btrfs_file_extent_item. So substracting total size of struct btrfs_file_extent_item is wrong, fix it.
--- fs/btrfs/ctree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/ctree.h +1 -1
@@ -394,7 +394,7 @@ struct btrfs_header {#define BTRFS_LEAF_DATA_SIZE (r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))#define BTRFS_MAX_INLINE_DATA_SIZE (r) (BTRFS_LEAF_DATA_SIZE(r) - \ sizeof(struct btrfs_item) - \ - sizeof(struct btrfs_file_extent_item)) + offsetof(struct btrfs_file_extent_item, disk_bytenr))#define BTRFS_MAX_XATTR_SIZE (r) (BTRFS_LEAF_DATA_SIZE(r) - \ sizeof(struct btrfs_item) -\ sizeof(struct btrfs_dir_item))
PATCH 19/245 btrfs: new define for the inline extent data start
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: David Sterba <[email protected]>
commit 7ec20afbcb7b257aec82ea5d66e6b0b7499abaca upstream.
Use a common definition for the inline data start so we don't have to open-code it and introduce bugs like "Btrfs: fix wrong max inline data size limit" fixed.
--- fs/btrfs/ctree.c | 3 +-- fs/btrfs/ctree.h | 16 ++++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-)
fs/btrfs/ctree.c +1 -2
@@ -4609,8 +4609,7 @@ void btrfs_truncate_item(struct btrfs_ro ptr =btrfs_item_ptr_offset (leaf, slot);memmove_extent_buffer (leaf, ptr, (unsigned long )fi, - offsetof(struct btrfs_file_extent_item , - disk_bytenr)); +BTRFS_FILE_EXTENT_INLINE_DATA_START ); } }
fs/btrfs/ctree.h +8 -8
@@ -392,9 +392,11 @@ struct btrfs_header { sizeof(struct btrfs_key_ptr))#define __BTRFS_LEAF_DATA_SIZE (bs) ((bs) - sizeof(struct btrfs_header))#define BTRFS_LEAF_DATA_SIZE (r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize)) +#define BTRFS_FILE_EXTENT_INLINE_DATA_START \ + (offsetof(struct btrfs_file_extent_item, disk_bytenr))#define BTRFS_MAX_INLINE_DATA_SIZE (r) (BTRFS_LEAF_DATA_SIZE(r) - \ sizeof(struct btrfs_item) - \ - offsetof(struct btrfs_file_extent_item, disk_bytenr)) + BTRFS_FILE_EXTENT_INLINE_DATA_START)#define BTRFS_MAX_XATTR_SIZE (r) (BTRFS_LEAF_DATA_SIZE(r) - \ sizeof(struct btrfs_item) -\ sizeof(struct btrfs_dir_item))
@@ -904,6 +906,8 @@ struct btrfs_file_extent_item {/* * disk space consumed by the extent, checksum blocks are included * in these numbers +* +* At this offset in the structure, the inline extent data start. */ __le64 disk_bytenr;__le64 disk_num_bytes;
@@ -3050,14 +3054,12 @@ BTRFS_SETGET_STACK_FUNCS(stack_file_extestatic inline unsigned long btrfs_file_extent_inline_start (struct btrfs_file_extent_item *e) { -unsigned long offset = (unsigned long )e; - offset += offsetof(struct btrfs_file_extent_item , disk_bytenr); -return offset; +return (unsigned long )e +BTRFS_FILE_EXTENT_INLINE_DATA_START ; }static inline u32 btrfs_file_extent_calc_inline_size (u32 datasize) { -return offsetof(struct btrfs_file_extent_item , disk_bytenr) + datasize; +return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize; } BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
@@ -3087,9 +3089,7 @@ BTRFS_SETGET_FUNCS(file_extent_other_encstatic inline u32 btrfs_file_extent_inline_item_len (struct extent_buffer *eb,struct btrfs_item *e) { -unsigned long offset; - offset = offsetof(struct btrfs_file_extent_item , disk_bytenr); -return btrfs_item_size (eb, e) - offset; +return btrfs_item_size (eb, e) -BTRFS_FILE_EXTENT_INLINE_DATA_START ; }/* this returns the number of file bytes represented by the inline item.
PATCH 20/245 btrfs: kill extent_buffer_page helper
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: David Sterba <[email protected]>
commit fb85fc9a675738ee2746b51c3aedde944b18ca02 upstream.
It used to be more complex but now it's just a simple array access.
--- fs/btrfs/extent_io.c | 55 +++++++++++++++++++++----------------------- fs/btrfs/extent_io.h | 6 ----- 2 files changed, 26 insertions(+), 35 deletions(-)
fs/btrfs/extent_io.c +26 -29
@@ -2082,7 +2082,7 @@ int repair_eb_io_failure(struct btrfs_roreturn -EROFS ;for (i =0 ; i < num_pages; i++) { -struct page *p =extent_buffer_page (eb, i); +struct page *p = eb->pages[i]; ret =repair_io_failure (root->fs_info, start,PAGE_CACHE_SIZE , start, p, mirror_num);if (ret)
@@ -3558,7 +3558,7 @@ lock_extent_buffer_for_io(struct extent_ num_pages =num_extent_pages (eb->start, eb->len);for (i =0 ; i < num_pages; i++) { -struct page *p =extent_buffer_page (eb, i); +struct page *p = eb->pages[i];if (!trylock_page (p)) {if (!flush) {
@@ -3629,7 +3629,7 @@ static noinline_for_stack int write_one_ bio_flags =EXTENT_BIO_TREE_LOG ;for (i =0 ; i < num_pages; i++) { -struct page *p =extent_buffer_page (eb, i); +struct page *p = eb->pages[i];clear_page_dirty_for_io (p);set_page_writeback (p);
@@ -3652,10 +3652,8 @@ static noinline_for_stack int write_one_ }if (unlikely (ret)) { -for (; i < num_pages; i++) { -struct page *p =extent_buffer_page (eb, i); -unlock_page (p); - } +for (; i < num_pages; i++) +unlock_page (eb->pages[i]); }return ret;
@@ -4459,7 +4457,7 @@ static void btrfs_release_extent_buffer_ do { index--; - page = extent_buffer_page(eb, index); + page = eb->pages[index]; if (page && mapped) { spin_lock(&page->mapping->private_lock); /*
@@ -4641,7 +4639,8 @@ static void mark_extent_buffer_accessed( num_pages =num_extent_pages (eb->start, eb->len);for (i =0 ; i < num_pages; i++) { -struct page *p =extent_buffer_page (eb, i); +struct page *p = eb->pages[i]; +if (p != accessed)mark_page_accessed (p); }
@@ -4810,7 +4809,7 @@ again:*/ SetPageChecked (eb->pages[0 ]);for (i =1 ; i < num_pages; i++) { - p =extent_buffer_page (eb, i); + p = eb->pages[i];ClearPageChecked (p);unlock_page (p); }
@@ -4921,7 +4920,7 @@ void clear_extent_buffer_dirty(struct ex num_pages =num_extent_pages (eb->start, eb->len);for (i =0 ; i < num_pages; i++) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];if (!PageDirty (page))continue ;
@@ -4957,7 +4956,7 @@ int set_extent_buffer_dirty(struct extenWARN_ON (!test_bit (EXTENT_BUFFER_TREE_REF , &eb->bflags));for (i =0 ; i < num_pages; i++) -set_page_dirty (extent_buffer_page (eb, i)); +set_page_dirty (eb->pages[i]);return was_dirty; }
@@ -4970,7 +4969,7 @@ int clear_extent_buffer_uptodate(structclear_bit (EXTENT_BUFFER_UPTODATE , &eb->bflags); num_pages =num_extent_pages (eb->start, eb->len);for (i =0 ; i < num_pages; i++) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];if (page)ClearPageUptodate (page); }
@@ -4986,7 +4985,7 @@ int set_extent_buffer_uptodate(struct exset_bit (EXTENT_BUFFER_UPTODATE , &eb->bflags); num_pages =num_extent_pages (eb->start, eb->len);for (i =0 ; i < num_pages; i++) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];SetPageUptodate (page); }return 0 ;
@@ -5026,7 +5025,7 @@ int read_extent_buffer_pages(struct exte num_pages =num_extent_pages (eb->start, eb->len);for (i = start_i; i < num_pages; i++) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];if (wait ==WAIT_NONE ) {if (!trylock_page (page)) goto unlock_exit;
@@ -5049,7 +5048,7 @@ int read_extent_buffer_pages(struct exte eb->read_mirror =0 ;atomic_set (&eb->io_pages, num_reads);for (i = start_i; i < num_pages; i++) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];if (!PageUptodate (page)) {ClearPageError (page); err = __extent_read_full_page(tree, page,
@@ -5074,7 +5073,7 @@ int read_extent_buffer_pages(struct extereturn ret;for (i = start_i; i < num_pages; i++) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];wait_on_page_locked (page);if (!PageUptodate (page)) ret = -EIO ;
@@ -5085,7 +5084,7 @@ int read_extent_buffer_pages(struct exte unlock_exit: i = start_i;while (locked_pages >0 ) { - page =extent_buffer_page (eb, i); + page = eb->pages[i]; i++;unlock_page (page); locked_pages--;
@@ -5111,7 +5110,7 @@ void read_extent_buffer(struct extent_bu offset = (start_offset + start) & (PAGE_CACHE_SIZE -1 );while (len >0 ) { - page =extent_buffer_page (eb, i); + page = eb->pages[i]; cur =min (len, (PAGE_CACHE_SIZE - offset)); kaddr =page_address (page);
@@ -5143,7 +5142,7 @@ int read_extent_buffer_to_user(struct ex offset = (start_offset + start) & (PAGE_CACHE_SIZE -1 );while (len >0 ) { - page =extent_buffer_page (eb, i); + page = eb->pages[i]; cur =min (len, (PAGE_CACHE_SIZE - offset)); kaddr =page_address (page);
@@ -5192,7 +5191,7 @@ int map_private_extent_buffer(struct extreturn -EINVAL ; } - p =extent_buffer_page (eb, i); + p = eb->pages[i]; kaddr =page_address (p); *map = kaddr + offset; *map_len =PAGE_CACHE_SIZE - offset;
@@ -5218,7 +5217,7 @@ int memcmp_extent_buffer(struct extent_b offset = (start_offset + start) & (PAGE_CACHE_SIZE -1 );while (len >0 ) { - page =extent_buffer_page (eb, i); + page = eb->pages[i]; cur =min (len, (PAGE_CACHE_SIZE - offset));
@@ -5252,7 +5251,7 @@ void write_extent_buffer(struct extent_b offset = (start_offset + start) & (PAGE_CACHE_SIZE -1 );while (len >0 ) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];WARN_ON (!PageUptodate (page)); cur =min (len,PAGE_CACHE_SIZE - offset);
@@ -5282,7 +5281,7 @@ void memset_extent_buffer(struct extent_ offset = (start_offset + start) & (PAGE_CACHE_SIZE -1 );while (len >0 ) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];WARN_ON (!PageUptodate (page)); cur =min (len,PAGE_CACHE_SIZE - offset);
@@ -5313,7 +5312,7 @@ void copy_extent_buffer(struct extent_bu (PAGE_CACHE_SIZE -1 );while (len >0 ) { - page =extent_buffer_page (dst, i); + page = dst->pages[i];WARN_ON (!PageUptodate (page)); cur =min (len, (unsigned long )(PAGE_CACHE_SIZE - offset));
@@ -5391,8 +5390,7 @@ void memcpy_extent_buffer(struct extent_ cur = min_t(unsigned long, cur, (unsigned long )(PAGE_CACHE_SIZE - dst_off_in_page)); -copy_pages (extent_buffer_page (dst, dst_i), -extent_buffer_page (dst, src_i), +copy_pages (dst->pages[dst_i], dst->pages[src_i], dst_off_in_page, src_off_in_page, cur); src_offset += cur;
@@ -5438,8 +5436,7 @@ void memmove_extent_buffer(struct extent cur = min_t(unsigned long, len, src_off_in_page + 1); cur =min (cur, dst_off_in_page +1 ); -copy_pages (extent_buffer_page (dst, dst_i), -extent_buffer_page (dst, src_i), +copy_pages (dst->pages[dst_i], dst->pages[src_i], dst_off_in_page - cur +1 , src_off_in_page - cur +1 , cur);
fs/btrfs/extent_io.h +0 -6
@@ -286,12 +286,6 @@ static inline unsigned long num_extent_p (start >>PAGE_CACHE_SHIFT ); } -static inline struct page *extent_buffer_page (struct extent_buffer *eb, -unsigned long i) -{ -return eb->pages[i]; -} -static inline void extent_buffer_get (struct extent_buffer *eb) {atomic_inc (&eb->refs);
PATCH 21/245 btrfs: cleanup, rename a few variables in btrfs_read_sys_array
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: David Sterba <[email protected]>
commit 1ffb22cf8c322bbfea6b35fe23d025841b49fede upstream.
There's a pointer to buffer, integer offset and offset passed as pointer, try to find matching names for them.
--- fs/btrfs/volumes.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
fs/btrfs/volumes.c +16 -15
@@ -6032,13 +6032,13 @@ int btrfs_read_sys_array(struct btrfs_rostruct extent_buffer *sb;struct btrfs_disk_key *disk_key;struct btrfs_chunk *chunk; -u8 *ptr; -unsigned long sb_ptr; +u8 *array_ptr; +unsigned long sb_array_offset;int ret =0 ;u32 num_stripes;u32 array_size;u32 len =0 ; -u32 cur; +u32 cur_offset;struct btrfs_key key; sb = btrfs_find_create_tree_block(root, BTRFS_SUPER_INFO_OFFSET,
@@ -6065,20 +6065,21 @@ int btrfs_read_sys_array(struct btrfs_rowrite_extent_buffer (sb, super_copy,0 ,BTRFS_SUPER_INFO_SIZE ); array_size =btrfs_super_sys_array_size (super_copy); - ptr = super_copy->sys_chunk_array; - sb_ptr = offsetof(struct btrfs_super_block , sys_chunk_array); - cur =0 ; + array_ptr = super_copy->sys_chunk_array; + sb_array_offset = offsetof(struct btrfs_super_block , sys_chunk_array); + cur_offset =0 ; -while (cur < array_size) { - disk_key = (struct btrfs_disk_key *)ptr; +while (cur_offset < array_size) { + disk_key = (struct btrfs_disk_key *)array_ptr;btrfs_disk_key_to_cpu (&key, disk_key); - len =sizeof (*disk_key); ptr += len; - sb_ptr += len; - cur += len; + len =sizeof (*disk_key); + array_ptr += len; + sb_array_offset += len; + cur_offset += len;if (key.type ==BTRFS_CHUNK_ITEM_KEY ) { - chunk = (struct btrfs_chunk *)sb_ptr; + chunk = (struct btrfs_chunk *)sb_array_offset; ret =read_one_chunk (root, &key, sb, chunk);if (ret)break ;
@@ -6088,9 +6089,9 @@ int btrfs_read_sys_array(struct btrfs_ro ret = -EIO ;break ; } - ptr += len; - sb_ptr += len; - cur += len; + array_ptr += len; + sb_array_offset += len; + cur_offset += len; }free_extent_buffer (sb);return ret;
PATCH 22/245 btrfs: add more checks to btrfs_read_sys_array
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: David Sterba <[email protected]>
commit e3540eab29e1b2260bc4b9b3979a49a00e3e3af8 upstream.
Verify that the sys_array has enough bytes to read the next item.
--- fs/btrfs/volumes.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
fs/btrfs/volumes.c +23 -3
@@ -6071,20 +6071,34 @@ int btrfs_read_sys_array(struct btrfs_rowhile (cur_offset < array_size) { disk_key = (struct btrfs_disk_key *)array_ptr; + len =sizeof (*disk_key); +if (cur_offset + len > array_size) + goto out_short_read; +btrfs_disk_key_to_cpu (&key, disk_key); - len =sizeof (*disk_key); array_ptr += len; sb_array_offset += len; cur_offset += len;if (key.type ==BTRFS_CHUNK_ITEM_KEY ) { chunk = (struct btrfs_chunk *)sb_array_offset; +/* +* At least one btrfs_chunk with one stripe must be +* present, exact stripe count check comes afterwards +*/ + len =btrfs_chunk_item_size (1 ); +if (cur_offset + len > array_size) + goto out_short_read; + + num_stripes =btrfs_chunk_num_stripes (sb, chunk); + len =btrfs_chunk_item_size (num_stripes); +if (cur_offset + len > array_size) + goto out_short_read; + ret =read_one_chunk (root, &key, sb, chunk);if (ret)break ; - num_stripes =btrfs_chunk_num_stripes (sb, chunk); - len =btrfs_chunk_item_size (num_stripes); }else { ret = -EIO ;break ;
@@ -6095,6 +6109,12 @@ int btrfs_read_sys_array(struct btrfs_ro }free_extent_buffer (sb);return ret; + +out_short_read: +printk (KERN_ERR "BTRFS: sys_array too short to read %u bytes at offset %u\n" , + len, cur_offset); +free_extent_buffer (sb); +return -EIO ; }int btrfs_read_chunk_tree (struct btrfs_root *root)
PATCH 23/245 btrfs: cleanup, stop casting for extent_map->lookup everywhere
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Mahoney <[email protected]>
commit 95617d69326ce386c95e33db7aeb832b45ee9f8f upstream.
Overloading extent_map->bdev to struct map_lookup * might have started out as a means to an end, but it's a pattern that's used all over the place now. Let's get rid of the casting and just add a union instead.
[bwh: Backported to 3.16: drop changes in
btrfs_start_trans_remove_block_group(),
btrfs_update_commit_device_bytes_used()]
---
fs/btrfs/dev-replace.c +1 -1
@@ -614,7 +614,7 @@ static void btrfs_dev_replace_update_dev em =lookup_extent_mapping (em_tree, start, (u64)-1 );if (!em)break ; - map = (struct map_lookup *)em->bdev; + map = em->map_lookup;for (i =0 ; i < map->num_stripes; i++)if (srcdev == map->stripes[i].dev) map->stripes[i].dev = tgtdev;
fs/btrfs/extent_map.c +1 -1
@@ -76,7 +76,7 @@ void free_extent_map(struct extent_map *WARN_ON (extent_map_in_tree (em));WARN_ON (!list_empty (&em->list));if (test_bit (EXTENT_FLAG_FS_MAPPING , &em->flags)) -kfree (em->bdev); +kfree (em->map_lookup);kmem_cache_free (extent_map_cache, em); } }
fs/btrfs/extent_map.h +9 -1
@@ -32,7 +32,15 @@ struct extent_map {u64 block_len;u64 generation;unsigned long flags; -struct block_device *bdev; +union { +struct block_device *bdev; + +/* +* used for chunk mappings +* flags & EXTENT_FLAG_FS_MAPPING must be set +*/ +struct map_lookup *map_lookup; + };atomic_t refs;unsigned int compress_type;struct list_head list;
fs/btrfs/scrub.c +1 -1
@@ -2637,7 +2637,7 @@ static noinline_for_stack int scrub_chunif (!em)return -EINVAL ; - map = (struct map_lookup *)em->bdev; + map = em->map_lookup;if (em->start != chunk_offset) goto out;
fs/btrfs/volumes.c +11 -11
@@ -1047,7 +1047,7 @@ static int contains_pending_extent(strucstruct map_lookup *map;int i; - map = (struct map_lookup *)em->bdev; + map = em->map_lookup;for (i =0 ; i < map->num_stripes; i++) {if (map->stripes[i].dev != device)continue ;
@@ -2533,7 +2533,7 @@ static int btrfs_relocate_chunk(struct bBUG_ON (!em || em->start > chunk_offset || em->start + em->len < chunk_offset); - map = (struct map_lookup *)em->bdev; + map = em->map_lookup;for (i =0 ; i < map->num_stripes; i++) { ret = btrfs_free_dev_extent(trans, map->stripes[i].dev,
@@ -4322,7 +4322,7 @@ static int __btrfs_alloc_chunk(struct bt goto error; }set_bit (EXTENT_FLAG_FS_MAPPING , &em->flags); - em->bdev = (struct block_device *)map; + em->map_lookup = map; em->start = start; em->len = num_bytes; em->block_start =0 ;
@@ -4405,7 +4405,7 @@ int btrfs_finish_chunk_alloc(struct btrfreturn -EINVAL ; } - map = (struct map_lookup *)em->bdev; + map = em->map_lookup; item_size =btrfs_chunk_item_size (map->num_stripes); stripe_size = em->orig_block_len;
@@ -4547,7 +4547,7 @@ int btrfs_chunk_readonly(struct btrfs_roreturn 0 ; } - map = (struct map_lookup *)em->bdev; + map = em->map_lookup;for (i =0 ; i < map->num_stripes; i++) {if (!map->stripes[i].dev->writeable) { readonly =1 ;
@@ -4613,7 +4613,7 @@ int btrfs_num_copies(struct btrfs_fs_infreturn 1 ; } - map = (struct map_lookup *)em->bdev; + map = em->map_lookup;if (map->type & (BTRFS_BLOCK_GROUP_DUP |BTRFS_BLOCK_GROUP_RAID1 )) ret = map->num_stripes;else if (map->type &BTRFS_BLOCK_GROUP_RAID10 )
@@ -4649,7 +4649,7 @@ unsigned long btrfs_full_stripe_len(struBUG_ON (!em);BUG_ON (em->start > logical || em->start + em->len < logical); - map = (struct map_lookup *)em->bdev; + map = em->map_lookup;if (map->type & (BTRFS_BLOCK_GROUP_RAID5 |BTRFS_BLOCK_GROUP_RAID6 )) { len = map->stripe_len *nr_data_stripes (map);
@@ -4672,7 +4672,7 @@ int btrfs_is_parity_mirror(struct btrfs_BUG_ON (!em);BUG_ON (em->start > logical || em->start + em->len < logical); - map = (struct map_lookup *)em->bdev; + map = em->map_lookup;if (map->type & (BTRFS_BLOCK_GROUP_RAID5 |BTRFS_BLOCK_GROUP_RAID6 )) ret =1 ;
@@ -4794,7 +4794,7 @@ static int __btrfs_map_block(struct btrfreturn -EINVAL ; } - map = (struct map_lookup *)em->bdev; + map = em->map_lookup; offset = logical - em->start; stripe_len = map->stripe_len;
@@ -5321,7 +5321,7 @@ int btrfs_rmap_block(struct btrfs_mappinfree_extent_map (em);return -EIO ; } - map = (struct map_lookup *)em->bdev; + map = em->map_lookup; length = em->len; rmap_len = map->stripe_len;
@@ -5846,7 +5846,7 @@ static int read_one_chunk(struct btrfs_r }set_bit (EXTENT_FLAG_FS_MAPPING , &em->flags); - em->bdev = (struct block_device *)map; + em->map_lookup = map; em->start = logical; em->len = length; em->orig_start =0 ;
PATCH 24/245 btrfs: handle invalid num_stripes in sys_array
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: David Sterba <[email protected]>
commit f5cdedd73fa71b74dcc42f2a11a5735d89ce7c4f upstream.
We can handle the special case of num_stripes == 0 directly inside btrfs_read_sys_array. The BUG_ON in btrfs_chunk_item_size is there to catch other unhandled cases where we fail to validate external data.
A crafted or corrupted image crashes at mount time:
BTRFS: device fsid 9006933e-2a9a-44f0-917f-514252aeec2c devid 1 transid 7 /dev/loop0 BTRFS info (device loop0): disk space caching is enabled
BUG: failure at fs/btrfs/ctree.h:337/btrfs_chunk_item_size()! Kernel panic - not syncing: BUG! CPU: 0 PID: 313 Comm: mount Not tainted 4.2.5-00657-ge047887-dirty #25 Stack: 637af890 60062489 602aeb2e 604192ba 60387961 00000011 637af8a0 6038a835 637af9c0 6038776b 634ef32b 00000000 Call Trace: [<6001c86d>] show_stack+0xfe/0x15b [<6038a835>] dump_stack+0x2a/0x2c [<6038776b>] panic+0x13e/0x2b3 [<6020f099>] btrfs_read_sys_array+0x25d/0x2ff [<601cfbbe>] open_ctree+0x192d/0x27af [<6019c2c1>] btrfs_mount+0x8f5/0xb9a [<600bc9a7>] mount_fs+0x11/0xf3 [<600d5167>] vfs_kern_mount+0x75/0x11a [<6019bcb0>] btrfs_mount+0x2e4/0xb9a [<600bc9a7>] mount_fs+0x11/0xf3 [<600d5167>] vfs_kern_mount+0x75/0x11a [<600d710b>] do_mount+0xa35/0xbc9 [<600d7557>] SyS_mount+0x95/0xc8 [<6001e884>] handle_syscall+0x6b/0x8e
--- fs/btrfs/volumes.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/btrfs/volumes.c +8 -0
@@ -6092,6 +6092,14 @@ int btrfs_read_sys_array(struct btrfs_ro goto out_short_read; num_stripes =btrfs_chunk_num_stripes (sb, chunk); +if (!num_stripes) { +printk (KERN_ERR +"BTRFS: invalid number of stripes %u in sys_array at offset %u\n" , + num_stripes, cur_offset); + ret = -EIO ; +break ; + } + len =btrfs_chunk_item_size (num_stripes);if (cur_offset + len > array_size) goto out_short_read;
PATCH 25/245 btrfs: Enhance chunk validation check
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit f04b772bfc17f502703794f4d100d12155c1a1a9 upstream.
Enhance chunk validation:
1) Num_stripes
We already have such check but it's only in super block sys chunk array.
Now check all on-disk chunks.
2) Chunk logical
It should be aligned to sector size.
This behavior should be *DOUBLE CHECKED* for 64K sector size like PPC64 or AArch64.
Maybe we can found some hidden bugs.
3) Chunk length
Same as chunk logical, should be aligned to sector size.
4) Stripe length
It should be power of 2.
5) Chunk type
Any bit out of TYPE_MAS | PROFILE_MASK is invalid.
With all these much restrict rules, several fuzzed image reported in mail list should no longer cause kernel panic.
--- fs/btrfs/volumes.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
fs/btrfs/volumes.c +32 -1
@@ -5814,6 +5814,7 @@ static int read_one_chunk(struct btrfs_rstruct extent_map *em;u64 logical;u64 length; +u64 stripe_len;u64 devid;u8 uuid[BTRFS_UUID_SIZE ];int num_stripes;
@@ -5822,6 +5823,37 @@ static int read_one_chunk(struct btrfs_r logical = key->offset; length =btrfs_chunk_length (leaf, chunk); + stripe_len =btrfs_chunk_stripe_len (leaf, chunk); + num_stripes =btrfs_chunk_num_stripes (leaf, chunk); +/* Validation check */ +if (!num_stripes) { +btrfs_err (root->fs_info,"invalid chunk num_stripes: %u" , + num_stripes); +return -EIO ; + } +if (!IS_ALIGNED (logical, root->sectorsize)) { +btrfs_err (root->fs_info, +"invalid chunk logical %llu" , logical); +return -EIO ; + } +if (!length || !IS_ALIGNED (length, root->sectorsize)) { +btrfs_err (root->fs_info, +"invalid chunk length %llu" , length); +return -EIO ; + } +if (!is_power_of_2 (stripe_len)) { +btrfs_err (root->fs_info,"invalid chunk stripe length: %llu" , + stripe_len); +return -EIO ; + } +if (~(BTRFS_BLOCK_GROUP_TYPE_MASK |BTRFS_BLOCK_GROUP_PROFILE_MASK ) & +btrfs_chunk_type (leaf, chunk)) { +btrfs_err (root->fs_info,"unrecognized chunk type: %llu" , + ~(BTRFS_BLOCK_GROUP_TYPE_MASK | +BTRFS_BLOCK_GROUP_PROFILE_MASK ) & +btrfs_chunk_type (leaf, chunk)); +return -EIO ; + }read_lock (&map_tree->map_tree.lock); em =lookup_extent_mapping (&map_tree->map_tree, logical,1 );
@@ -5838,7 +5870,6 @@ static int read_one_chunk(struct btrfs_r em =alloc_extent_map ();if (!em)return -ENOMEM ; - num_stripes =btrfs_chunk_num_stripes (leaf, chunk); map =kmalloc (map_lookup_size (num_stripes),GFP_NOFS );if (!map) {free_extent_map (em);
PATCH 26/245 Btrfs: add validadtion checks for chunk loading
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit e06cd3dd7cea50e87663a88acdfdb7ac1c53a5ca upstream.
To prevent fuzzed filesystem images from panic the whole system, we need various validation checks to refuse to mount such an image if btrfs finds any invalid value during loading chunks, including both sys_array and regular chunks.
Note that these checks may not be sufficient to cover all corner cases, feel free to add more checks.
--- fs/btrfs/volumes.c | 82 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 15 deletions(-)
fs/btrfs/volumes.c +67 -15
@@ -5805,27 +5805,23 @@ struct btrfs_device *btrfs_alloc_device(return dev; } -static int read_one_chunk (struct btrfs_root *root,struct btrfs_key *key, -struct extent_buffer *leaf, -struct btrfs_chunk *chunk) +/* Return -EIO if any error, otherwise return 0. */ +static int btrfs_check_chunk_valid (struct btrfs_root *root, +struct extent_buffer *leaf, +struct btrfs_chunk *chunk,u64 logical) { -struct btrfs_mapping_tree *map_tree = &root->fs_info->mapping_tree; -struct map_lookup *map; -struct extent_map *em; -u64 logical;u64 length;u64 stripe_len; -u64 devid; -u8 uuid[BTRFS_UUID_SIZE ]; -int num_stripes; -int ret; -int i; +u16 num_stripes; +u16 sub_stripes; +u64 type; - logical = key->offset; length =btrfs_chunk_length (leaf, chunk); stripe_len =btrfs_chunk_stripe_len (leaf, chunk); num_stripes =btrfs_chunk_num_stripes (leaf, chunk); -/* Validation check */ + sub_stripes =btrfs_chunk_sub_stripes (leaf, chunk); + type =btrfs_chunk_type (leaf, chunk); +if (!num_stripes) {btrfs_err (root->fs_info,"invalid chunk num_stripes: %u" , num_stripes);
@@ -5836,6 +5832,11 @@ static int read_one_chunk(struct btrfs_r "invalid chunk logical %llu", logical);return -EIO ; } +if (btrfs_chunk_sector_size (leaf, chunk) != root->sectorsize) { +btrfs_err (root->fs_info,"invalid chunk sectorsize %u" , +btrfs_chunk_sector_size (leaf, chunk)); +return -EIO ; + }if (!length || !IS_ALIGNED (length, root->sectorsize)) {btrfs_err (root->fs_info,"invalid chunk length %llu" , length);
@@ -5847,13 +5848,54 @@ static int read_one_chunk(struct btrfs_rreturn -EIO ; }if (~(BTRFS_BLOCK_GROUP_TYPE_MASK |BTRFS_BLOCK_GROUP_PROFILE_MASK ) & -btrfs_chunk_type (leaf, chunk)) { + type) {btrfs_err (root->fs_info,"unrecognized chunk type: %llu" , ~(BTRFS_BLOCK_GROUP_TYPE_MASK |BTRFS_BLOCK_GROUP_PROFILE_MASK ) &btrfs_chunk_type (leaf, chunk));return -EIO ; } +if ((type &BTRFS_BLOCK_GROUP_RAID10 && sub_stripes !=2 ) || + (type &BTRFS_BLOCK_GROUP_RAID1 && num_stripes <1 ) || + (type &BTRFS_BLOCK_GROUP_RAID5 && num_stripes <2 ) || + (type &BTRFS_BLOCK_GROUP_RAID6 && num_stripes <3 ) || + (type &BTRFS_BLOCK_GROUP_DUP && num_stripes >2 ) || + ((type &BTRFS_BLOCK_GROUP_PROFILE_MASK ) ==0 && + num_stripes !=1 )) { +btrfs_err (root->fs_info, +"invalid num_stripes:sub_stripes %u:%u for profile %llu" , + num_stripes, sub_stripes, + type &BTRFS_BLOCK_GROUP_PROFILE_MASK ); +return -EIO ; + } + +return 0 ; +} + +static int read_one_chunk (struct btrfs_root *root,struct btrfs_key *key, +struct extent_buffer *leaf, +struct btrfs_chunk *chunk) +{ +struct btrfs_mapping_tree *map_tree = &root->fs_info->mapping_tree; +struct map_lookup *map; +struct extent_map *em; +u64 logical; +u64 length; +u64 stripe_len; +u64 devid; +u8 uuid[BTRFS_UUID_SIZE ]; +int num_stripes; +int ret; +int i; + + logical = key->offset; + length =btrfs_chunk_length (leaf, chunk); + stripe_len =btrfs_chunk_stripe_len (leaf, chunk); + num_stripes =btrfs_chunk_num_stripes (leaf, chunk); + + ret =btrfs_check_chunk_valid (root, leaf, chunk, logical); +if (ret) +return ret;read_lock (&map_tree->map_tree.lock); em =lookup_extent_mapping (&map_tree->map_tree, logical,1 );
@@ -6070,6 +6112,7 @@ int btrfs_read_sys_array(struct btrfs_rou32 array_size;u32 len =0 ;u32 cur_offset; +u64 type;struct btrfs_key key; sb = btrfs_find_create_tree_block(root, BTRFS_SUPER_INFO_OFFSET,
@@ -6130,6 +6173,15 @@ int btrfs_read_sys_array(struct btrfs_ro ret = -EIO ;break ; } + + type =btrfs_chunk_type (sb, chunk); +if ((type &BTRFS_BLOCK_GROUP_SYSTEM ) ==0 ) { +btrfs_err (root->fs_info, +"invalid chunk type %llu in sys_array at offset %u" , + type, cur_offset); + ret = -EIO ; +break ; + } len =btrfs_chunk_item_size (num_stripes);if (cur_offset + len > array_size)
PATCH 27/245 Btrfs: check inconsistence between chunk and block group
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit 6fb37b756acce6d6e045f79c3764206033f617b4 upstream.
With btrfs-corrupt-block, one can drop one chunk item and mounting will end up with a panic in btrfs_full_stripe_len().
This doesn't not remove the BUG_ON, but instead checks it a bit earlier when we find the block group item.
--- fs/btrfs/extent-tree.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
fs/btrfs/extent-tree.c +16 -1
@@ -8571,7 +8571,22 @@ static int find_first_block_group(structif (found_key.objectid >= key->objectid && found_key.type ==BTRFS_BLOCK_GROUP_ITEM_KEY ) { - ret =0 ; +struct extent_map_tree *em_tree; +struct extent_map *em; + + em_tree = &root->fs_info->mapping_tree.map_tree; +read_lock (&em_tree->lock); + em =lookup_extent_mapping (em_tree, found_key.objectid, + found_key.offset); +read_unlock (&em_tree->lock); +if (!em) { +btrfs_err (root->fs_info, +"logical %llu len %llu found bg but no related chunk" , + found_key.objectid, found_key.offset); + ret = -ENOENT ; + }else { + ret =0 ; + } goto out; } path->slots[0 ]++;
PATCH 28/245 Btrfs: fix em leak in find_first_block_group
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
commit 187ee58c62c1d0d238d3dc4835869d33e1869906 upstream.
We need to call free_extent_map() on the em we look up.
--- fs/btrfs/extent-tree.c | 1 + 1 file changed, 1 insertion(+)
fs/btrfs/extent-tree.c +1 -0
@@ -8587,6 +8587,7 @@ static int find_first_block_group(struct }else { ret =0 ; } +free_extent_map (em); goto out; } path->slots[0 ]++;
PATCH 29/245 Btrfs: detect corruption when non-root leaf has zero item
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit 1ba98d086fe3a14d6a31f2f66dbab70c45d00f63 upstream.
Right now we treat leaf which has zero item as a valid one because we could have an empty tree, that is, a root that is also a leaf without any item, however, in the same case but when the leaf is not a root, we can end up with hitting the BUG_ON(1) in btrfs_extend_item() called by setup_inline_extent_backref().
This makes us check the situation as a corruption if leaf is not its own root.
--- fs/btrfs/disk-io.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
fs/btrfs/disk-io.c +22 -1
@@ -520,8 +520,29 @@ static noinline int check_leaf(struct btu32 nritems =btrfs_header_nritems (leaf);int slot; -if (nritems ==0 ) +if (nritems ==0 ) { +struct btrfs_root *check_root; + + key.objectid =btrfs_header_owner (leaf); + key.type =BTRFS_ROOT_ITEM_KEY ; + key.offset = (u64)-1 ; + + check_root =btrfs_get_fs_root (root->fs_info, &key, false); +/* +* The only reason we also check NULL here is that during +* open_ctree() some roots has not yet been set up. +*/ +if (!IS_ERR_OR_NULL (check_root)) { +/* if leaf is the root, then it's fine */ +if (leaf->start != +btrfs_root_bytenr (&check_root->root_item)) { +CORRUPT ("non-root leaf's nritems is 0" , + leaf, root,0 ); +return -EIO ; + } + }return 0 ; + }/* Check the 0 item */ if (btrfs_item_offset_nr(leaf, 0) + btrfs_item_size_nr(leaf, 0) !=
PATCH 30/245 Btrfs: check btree node's nritems
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit 053ab70f0604224c7893b43f9d9d5efa283580d6 upstream.
When btree node (level = 1) has nritems which equals to zero, we can end up with panic due to insert_ptr()'s
BUG_ON(slot > nritems);
where slot is 1 and nritems is 0, as copy_for_split() calls insert_ptr(.., path->slots[1] + 1, ...);
A invalid value results in the whole mess, this adds the check for btree's node nritems so that we stop reading block when when something is wrong.
--- fs/btrfs/disk-io.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
fs/btrfs/disk-io.c +16 -0
@@ -594,6 +594,19 @@ static noinline int check_leaf(struct btreturn 0 ; } +static int check_node (struct btrfs_root *root,struct extent_buffer *node) +{ +unsigned long nr =btrfs_header_nritems (node); + +if (nr ==0 || nr >BTRFS_NODEPTRS_PER_BLOCK (root)) { +btrfs_crit (root->fs_info, +"corrupt node: block %llu root %llu nritems %lu" , + node->start, root->objectid, nr); +return -EIO ; + } +return 0 ; +} +static int btree_readpage_end_io_hook (struct btrfs_io_bio *io_bio,u64 phy_offset,struct page *page,u64 start,u64 end,int mirror)
@@ -666,6 +679,9 @@ static int btree_readpage_end_io_hook(st ret = -EIO ; } +if (found_level >0 &&check_node (root, eb)) + ret = -EIO ; +if (!ret)set_extent_buffer_uptodate (eb); err:
PATCH 31/245 Btrfs: fix BUG_ON in btrfs_mark_buffer_dirty
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit ef85b25e982b5bba1530b936e283ef129f02ab9d upstream.
This can only happen with CONFIG_BTRFS_FS_CHECK_INTEGRITY=y.
Commit 1ba98d0 ("Btrfs: detect corruption when non-root leaf has zero item") assumes that a leaf is its root when leaf->bytenr == btrfs_root_bytenr(root), however, we should not use btrfs_root_bytenr(root) since it's mainly got updated during committing transaction. So the check can fail when doing COW on this leaf while it is a root.
This changes to use "if (leaf == btrfs_root_node(root))" instead, just like how we check whether leaf is a root in __btrfs_cow_block().
--- fs/btrfs/disk-io.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
fs/btrfs/disk-io.c +7 -3
@@ -533,13 +533,17 @@ static noinline int check_leaf(struct bt* open_ctree() some roots has not yet been set up. */ if (!IS_ERR_OR_NULL (check_root)) { +struct extent_buffer *eb; + + eb =btrfs_root_node (check_root);/* if leaf is the root, then it's fine */ -if (leaf->start != -btrfs_root_bytenr (&check_root->root_item)) { +if (leaf != eb) {CORRUPT ("non-root leaf's nritems is 0" , - leaf, root,0 ); + leaf, check_root,0 ); +free_extent_buffer (eb);return -EIO ; } +free_extent_buffer (eb); }return 0 ; }
PATCH 32/245 Btrfs: memset to avoid stale content in btree node block
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit 3eb548ee3a8042d95ad81be254e67a5222c24e03 upstream.
During updating btree, we could push items between sibling nodes/leaves, for leaves data sections starts reversely from the end of the block while for nodes we only have key pairs which are stored one by one from the start of the block.
So we could do try to push key pairs from one node to the next node right in the tree, and after that, we update the node's nritems to reflect the correct end while leaving the stale content in the node. One may intentionally corrupt the fs image and access the stale content by bumping the nritems and causes various crashes.
This takes the in-memory @nritems as the correct one and gets to memset the unused part of a btree node.
--- fs/btrfs/extent_io.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/btrfs/extent_io.c +11 -0
@@ -3628,6 +3628,17 @@ static noinline_for_stack int write_one_if (btrfs_header_owner (eb) ==BTRFS_TREE_LOG_OBJECTID ) bio_flags =EXTENT_BIO_TREE_LOG ; +/* set btree node beyond nritems with 0 to avoid stale content */ +if (btrfs_header_level (eb) >0 ) { +u32 nritems; +unsigned long end; + + nritems =btrfs_header_nritems (eb); + end =btrfs_node_key_ptr_offset (nritems); + +memset_extent_buffer (eb,0 , end, eb->len - end); + } +for (i =0 ; i < num_pages; i++) {struct page *p = eb->pages[i];
PATCH 33/245 Btrfs: improve check_node to avoid reading corrupted nodes
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit 6b722c1747d533ac6d4df110dc8233db46918b65 upstream.
We need to check items in a node to make sure that we're reading a valid one, otherwise we could get various crashes while processing delayed_refs.
--- fs/btrfs/disk-io.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-)
fs/btrfs/disk-io.c +28 -4
@@ -508,9 +508,10 @@ static int check_tree_block_fsid(struct }#define CORRUPT (reason, eb, root, slot) \ - btrfs_crit(root->fs_info, "corrupt leaf, %s: block=%llu," \ - "root=%llu, slot=%d", reason, \ - btrfs_header_bytenr(eb), root->objectid, slot) + btrfs_crit(root->fs_info, "corrupt %s, %s: block=%llu," \ + " root=%llu, slot=%d", \ + btrfs_header_level(eb) == 0 ? "leaf" : "node",\ + reason, btrfs_header_bytenr(eb), root->objectid, slot) static noinline int check_leaf(struct btrfs_root *root,struct extent_buffer *leaf)
@@ -601,6 +602,10 @@ static noinline int check_leaf(struct btstatic int check_node (struct btrfs_root *root,struct extent_buffer *node) {unsigned long nr =btrfs_header_nritems (node); +struct btrfs_key key, next_key; +int slot; +u64 bytenr; +int ret =0 ;if (nr ==0 || nr >BTRFS_NODEPTRS_PER_BLOCK (root)) { btrfs_crit(root->fs_info,
@@ -608,7 +613,26 @@ static int check_node(struct btrfs_root node->start, root->objectid, nr);return -EIO ; } -return 0 ; + +for (slot =0 ; slot < nr -1 ; slot++) { + bytenr =btrfs_node_blockptr (node, slot); +btrfs_node_key_to_cpu (node, &key, slot); +btrfs_node_key_to_cpu (node, &next_key, slot +1 ); + +if (!bytenr) { +CORRUPT ("invalid item slot" , node, root, slot); + ret = -EIO ; + goto out; + } + +if (btrfs_comp_cpu_keys (&key, &next_key) >=0 ) { +CORRUPT ("bad key order" , node, root, slot); + ret = -EIO ; + goto out; + } + } +out: +return ret; } static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,
PATCH 34/245 Btrfs: kill BUG_ON in run_delayed_tree_ref
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit 02794222c4132ac003e7281fb71f4ec1645ffc87 upstream.
In a corrupted btrfs image, we can come across this BUG_ON and get an unreponsive system, but if we return errors instead, its caller can handle everything gracefully by aborting the current transaction.
--- fs/btrfs/extent-tree.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/btrfs/extent-tree.c +7 -1
@@ -2258,7 +2258,13 @@ static int run_delayed_tree_ref(struct b ins.type =BTRFS_EXTENT_ITEM_KEY ; } -BUG_ON (node->ref_mod !=1 ); +if (node->ref_mod !=1 ) { +btrfs_err (root->fs_info, +"btree block(%llu) has %d references rather than 1: action %d ref_root %llu parent %llu" , + node->bytenr, node->ref_mod, node->action, ref_root, + parent); +return -EIO ; + }if (node->action ==BTRFS_ADD_DELAYED_REF && insert_reserved) {BUG_ON (!extent_op || !extent_op->update_flags); ret = alloc_reserved_tree_block(trans, root,
PATCH 35/245 Btrfs: memset to avoid stale content in btree leaf
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit 851cd173f06045816528176001cf82948282029c upstream.
This is an additional patch to
"Btrfs: memset to avoid stale content in btree node block".
This uses memset to initialize the unused space in a leaf to avoid potential stale content, which may be incurred by pushing items between sibling leaves.
--- fs/btrfs/ctree.c | 14 -------------- fs/btrfs/ctree.h | 15 +++++++++++++++ fs/btrfs/extent_io.c | 18 +++++++++++++----- 3 files changed, 28 insertions(+), 19 deletions(-)
fs/btrfs/ctree.c +0 -14
@@ -1721,20 +1721,6 @@ int btrfs_realloc_node(struct btrfs_tranreturn err; } -/* -* The leaf data grows from end-to-front in the node. -* this returns the address of the start of the last item, -* which is the stop of the leaf data stack -*/ -static inline unsigned int leaf_data_end (struct btrfs_root *root, -struct extent_buffer *leaf) -{ -u32 nr =btrfs_header_nritems (leaf); -if (nr ==0 ) -return BTRFS_LEAF_DATA_SIZE (root); -return btrfs_item_offset_nr (leaf, nr -1 ); -} -/* * search for key in the extent_buffer. The items start at offset p,
fs/btrfs/ctree.h +15 -0
@@ -3036,6 +3036,21 @@ static inline unsigned long btrfs_leaf_dreturn offsetof(struct btrfs_leaf , items); } +/* +* The leaf data grows from end-to-front in the node. +* this returns the address of the start of the last item, +* which is the stop of the leaf data stack +*/ +static inline unsigned int leaf_data_end (struct btrfs_root *root, +struct extent_buffer *leaf) +{ +u32 nr =btrfs_header_nritems (leaf); + +if (nr ==0 ) +return BTRFS_LEAF_DATA_SIZE (root); +return btrfs_item_offset_nr (leaf, nr -1 ); +} +/* struct btrfs_file_extent_item */ BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr,
fs/btrfs/extent_io.c +13 -5
@@ -3617,8 +3617,10 @@ static noinline_for_stack int write_one_struct block_device *bdev = fs_info->fs_devices->latest_bdev;struct extent_io_tree *tree = &BTRFS_I (fs_info->btree_inode)->io_tree;u64 offset = eb->start; +u32 nritems;unsigned long i, num_pages;unsigned long bio_flags =0 ; +unsigned long start, end;int rw = (epd->sync_io ?WRITE_SYNC :WRITE ) |REQ_META ;int ret =0 ;
@@ -3628,15 +3630,21 @@ static noinline_for_stack int write_one_if (btrfs_header_owner (eb) ==BTRFS_TREE_LOG_OBJECTID ) bio_flags =EXTENT_BIO_TREE_LOG ; -/* set btree node beyond nritems with 0 to avoid stale content */ +/* set btree blocks beyond nritems with 0 to avoid stale content. */ + nritems =btrfs_header_nritems (eb);if (btrfs_header_level (eb) >0 ) { -u32 nritems; -unsigned long end; - - nritems =btrfs_header_nritems (eb); end =btrfs_node_key_ptr_offset (nritems);memset_extent_buffer (eb,0 , end, eb->len - end); + }else { +/* +* leaf: +* header 0 1 2 .. N ... data_N .. data_2 data_1 data_0 +*/ + start =btrfs_item_nr_offset (nritems); + end =btrfs_leaf_data (eb) + +leaf_data_end (fs_info->tree_root, eb); +memset_extent_buffer (eb,0 , start, end - start); }for (i =0 ; i < num_pages; i++) {
PATCH 36/245 Btrfs: fix emptiness check for dirtied extent buffers at check_leaf()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
commit f177d73949bf758542ca15a1c1945bd2e802cc65 upstream.
We can not simply use the owner field from an extent buffer's header to get the id of the respective tree when the extent buffer is from a relocation tree. When we create the root for a relocation tree we leave (on purpose) the owner field with the same value as the subvolume's tree root (we do this at ctree.c:btrfs_copy_root()). So we must ignore extent buffers from relocation trees, which have the BTRFS_HEADER_FLAG_RELOC flag set, because otherwise we will always consider the extent buffer as not being the root of the tree (the root of original subvolume tree is always different from the root of the respective relocation tree).
This lead to assertion failures when running with the integrity checker enabled (CONFIG_BTRFS_FS_CHECK_INTEGRITY=y) such as the following:
[ 643.393409] BTRFS critical (device sdg): corrupt leaf, non-root leaf's nritems is 0: block=38506496, root=260, slot=0 [ 643.397609] BTRFS info (device sdg): leaf 38506496 total ptrs 0 free space 3995 [ 643.407075] assertion failed: 0, file: fs/btrfs/disk-io.c, line: 4078 [ 643.408425] ------------[ cut here ]------------ [ 643.409112] kernel BUG at fs/btrfs/ctree.h:3419! [ 643.409773] invalid opcode: 0000 [#1] PREEMPT SMP [ 643.410447] Modules linked in: dm_flakey dm_mod crc32c_generic btrfs xor raid6_pq ppdev psmouse acpi_cpufreq parport_pc evdev parport tpm_tis tpm_tis_core pcspkr serio_raw i2c_piix4 sg tpm i2c_core button processor loop autofs4 ext4 crc16 jbd2 mbcache sr_mod cdrom sd_mod ata_generic virtio_scsi ata_piix libata virtio_pci virtio_ring scsi_mod virtio e1000 floppy [ 643.414356] CPU: 11 PID: 32726 Comm: btrfs Not tainted 4.8.0-rc8-btrfs-next-35+ #1 [ 643.414356] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.1-0-gb3ef39f-prebuilt.qemu-project.org 04/01/2014 [ 643.414356] task: ffff880145e95b00 task.stack: ffff88014826c000 [ 643.414356] RIP: 0010:[<ffffffffa0352759>] [<ffffffffa0352759>] assfail.constprop.41+0x1c/0x1e [btrfs] [ 643.414356] RSP: 0018:ffff88014826fa28 EFLAGS: 00010292 [ 643.414356] RAX: 0000000000000039 RBX: ffff88014e2d7c38 RCX: 0000000000000001 [ 643.414356] RDX: ffff88023f4d2f58 RSI: ffffffff81806c63 RDI: 00000000ffffffff [ 643.414356] RBP: ffff88014826fa28 R08: 0000000000000001 R09: 0000000000000000 [ 643.414356] R10: ffff88014826f918 R11: ffffffff82f3c5ed R12: ffff880172910000 [ 643.414356] R13: ffff880233992230 R14: ffff8801a68a3310 R15: fffffffffffffff8 [ 643.414356] FS: 00007f9ca305e8c0(0000) GS:ffff88023f4c0000(0000) knlGS:0000000000000000 [ 643.414356] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 643.414356] CR2: 00007f9ca3071000 CR3: 000000015d01b000 CR4: 00000000000006e0 [ 643.414356] Stack: [ 643.414356] ffff88014826fa50 ffffffffa02d655a 000000000000000a ffff88014e2d7c38 [ 643.414356] 0000000000000000 ffff88014826faa8 ffffffffa02b72f3 ffff88014826fab8 [ 643.414356] 00ffffffa03228e4 0000000000000000 0000000000000000 ffff8801bbd4e000 [ 643.414356] Call Trace: [ 643.414356] [<ffffffffa02d655a>] btrfs_mark_buffer_dirty+0xdf/0xe5 [btrfs] [ 643.414356] [<ffffffffa02b72f3>] btrfs_copy_root+0x18a/0x1d1 [btrfs] [ 643.414356] [<ffffffffa0322921>] create_reloc_root+0x72/0x1ba [btrfs] [ 643.414356] [<ffffffffa03267c2>] btrfs_init_reloc_root+0x7b/0xa7 [btrfs] [ 643.414356] [<ffffffffa02d9e44>] record_root_in_trans+0xdf/0xed [btrfs] [ 643.414356] [<ffffffffa02db04e>] btrfs_record_root_in_trans+0x50/0x6a [btrfs] [ 643.414356] [<ffffffffa030ad2b>] create_subvol+0x472/0x773 [btrfs] [ 643.414356] [<ffffffffa030b406>] btrfs_mksubvol+0x3da/0x463 [btrfs] [ 643.414356] [<ffffffffa030b406>] ? btrfs_mksubvol+0x3da/0x463 [btrfs] [ 643.414356] [<ffffffff810781ac>] ? preempt_count_add+0x65/0x68 [ 643.414356] [<ffffffff811a6e97>] ? __mnt_want_write+0x62/0x77 [ 643.414356] [<ffffffffa030b55d>] btrfs_ioctl_snap_create_transid+0xce/0x187 [btrfs] [ 643.414356] [<ffffffffa030b67d>] btrfs_ioctl_snap_create+0x67/0x81 [btrfs] [ 643.414356] [<ffffffffa030ecfd>] btrfs_ioctl+0x508/0x20dd [btrfs] [ 643.414356] [<ffffffff81293e39>] ? __this_cpu_preempt_check+0x13/0x15 [ 643.414356] [<ffffffff81155eca>] ? handle_mm_fault+0x976/0x9ab [ 643.414356] [<ffffffff81091300>] ? arch_local_irq_save+0x9/0xc [ 643.414356] [<ffffffff8119a2b0>] vfs_ioctl+0x18/0x34 [ 643.414356] [<ffffffff8119a8e8>] do_vfs_ioctl+0x581/0x600 [ 643.414356] [<ffffffff814b9552>] ? entry_SYSCALL_64_fastpath+0x5/0xa8 [ 643.414356] [<ffffffff81093fe9>] ? trace_hardirqs_on_caller+0x17b/0x197 [ 643.414356] [<ffffffff8119a9be>] SyS_ioctl+0x57/0x79 [ 643.414356] [<ffffffff814b9565>] entry_SYSCALL_64_fastpath+0x18/0xa8 [ 643.414356] [<ffffffff81091b08>] ? trace_hardirqs_off_caller+0x3f/0xaa [ 643.414356] Code: 89 83 88 00 00 00 31 c0 5b 41 5c 41 5d 5d c3 55 89 f1 48 c7 c2 98 bc 35 a0 48 89 fe 48 c7 c7 05 be 35 a0 48 89 e5 e8 13 46 dd e0 <0f> 0b 55 89 f1 48 c7 c2 9f d3 35 a0 48 89 fe 48 c7 c7 7a d5 35 [ 643.414356] RIP [<ffffffffa0352759>] assfail.constprop.41+0x1c/0x1e [btrfs] [ 643.414356] RSP <ffff88014826fa28> [ 643.468267] ---[ end trace 6a1b3fb1a9d7d6e3 ]---
This can be easily reproduced by running xfstests with the integrity checker enabled.
--- fs/btrfs/disk-io.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
fs/btrfs/disk-io.c +12 -1
@@ -521,7 +521,15 @@ static noinline int check_leaf(struct btu32 nritems =btrfs_header_nritems (leaf);int slot; -if (nritems ==0 ) { +/* +* Extent buffers from a relocation tree have a owner field that +* corresponds to the subvolume tree they are based on. So just from an +* extent buffer alone we can not find out what is the id of the +* corresponding subvolume tree, so we can not figure out if the extent +* buffer corresponds to the root of the relocation tree or not. So skip +* this check for relocation trees. +*/ +if (nritems ==0 && !btrfs_header_flag (leaf,BTRFS_HEADER_FLAG_RELOC )) {struct btrfs_root *check_root; key.objectid =btrfs_header_owner (leaf);
@@ -549,6 +557,9 @@ static noinline int check_leaf(struct btreturn 0 ; } +if (nritems ==0 ) +return 0 ; +/* Check the 0 item */ if (btrfs_item_offset_nr (leaf,0 ) +btrfs_item_size_nr (leaf,0 ) !=BTRFS_LEAF_DATA_SIZE (root)) {
PATCH 37/245 btrfs: struct-funcs, constify readers
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Mahoney <[email protected]>
commit 1cbb1f454e5321e47fc1e6b233066c7ccc979d15 upstream.
We have reader helpers for most of the on-disk structures that use an extent_buffer and pointer as offset into the buffer that are read-only. We should mark them as const and, in turn, allow consumers of these interfaces to mark the buffers const as well.
No impact on code, but serves as documentation that a buffer is intended not to be modified.
--- fs/btrfs/ctree.h | 128 +++++++++++++++++++++------------------- fs/btrfs/extent_io.c | 24 ++++---- fs/btrfs/extent_io.h | 19 +++--- fs/btrfs/struct-funcs.c | 9 +-- 4 files changed, 91 insertions(+), 89 deletions(-)
fs/btrfs/ctree.h +66 -62
@@ -2138,7 +2138,7 @@ struct btrfs_ioctl_defrag_range_args {#define BTRFS_INODE_ROOT_ITEM_INIT (1 << 31)struct btrfs_map_token { -struct extent_buffer *eb; +const struct extent_buffer *eb;char *kaddr;unsigned long offset; };
@@ -2169,18 +2169,19 @@ static inline void btrfs_init_map_token sizeof(((type *)0)->member)))#define DECLARE_BTRFS_SETGET_BITS (bits) \ -u##bits btrfs_get_token_##bits(struct extent_buffer *eb, void *ptr, \ - unsigned long off, \ - struct btrfs_map_token *token); \ -void btrfs_set_token_##bits(struct extent_buffer *eb, void *ptr, \ +u##bits btrfs_get_token_##bits(const struct extent_buffer *eb, \ + const void *ptr, unsigned long off, \ + struct btrfs_map_token *token); \ +void btrfs_set_token_##bits(struct extent_buffer *eb, const void *ptr, \ unsigned long off, u##bits val, \ struct btrfs_map_token *token); \ -static inline u##bits btrfs_get_##bits(struct extent_buffer *eb, void *ptr, \ +static inline u##bits btrfs_get_##bits(const struct extent_buffer *eb, \ + const void *ptr, \ unsigned long off) \ { \ return btrfs_get_token_##bits(eb, ptr, off, NULL); \ } \ -static inline void btrfs_set_##bits(struct extent_buffer *eb, void *ptr, \ +static inline void btrfs_set_##bits(struct extent_buffer *eb, void *ptr,\ unsigned long off, u##bits val) \ { \ btrfs_set_token_##bits(eb, ptr, off, val, NULL); \
@@ -2192,7 +2193,8 @@ DECLARE_BTRFS_SETGET_BITS(32) DECLARE_BTRFS_SETGET_BITS(64)#define BTRFS_SETGET_FUNCS (name, type, member, bits) \ -static inline u##bits btrfs_##name(struct extent_buffer *eb, type *s) \ +static inline u##bits btrfs_##name(const struct extent_buffer *eb, \ + const type *s) \ { \ BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ return btrfs_get_##bits(eb, s, offsetof(type, member)); \
@@ -2203,7 +2205,8 @@ static inline void btrfs_set_##name(stru BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ btrfs_set_##bits(eb, s, offsetof(type, member), val); \ } \ -static inline u##bits btrfs_token_##name(struct extent_buffer *eb, type *s, \ +static inline u##bits btrfs_token_##name(const struct extent_buffer *eb,\ + const type *s, \ struct btrfs_map_token *token) \ { \ BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
@@ -2218,9 +2221,9 @@ static inline void btrfs_set_token_##nam }#define BTRFS_SETGET_HEADER_FUNCS (name, type, member, bits) \ -static inline u##bits btrfs_##name(struct extent_buffer *eb) \ +static inline u##bits btrfs_##name(const struct extent_buffer *eb) \ { \ - type *p = page_address(eb->pages[0]); \ + const type *p = page_address(eb->pages[0]); \ u##bits res = le##bits##_to_cpu(p->member); \ return res; \ } \
@@ -2232,7 +2235,7 @@ static inline void btrfs_set_##name(stru }#define BTRFS_SETGET_STACK_FUNCS (name, type, member, bits) \ -static inline u##bits btrfs_##name(type *s) \ +static inline u##bits btrfs_##name(const type *s) \ { \ return le##bits##_to_cpu(s->member); \ } \
@@ -2558,7 +2561,7 @@ static inline unsigned long btrfs_node_ksizeof (struct btrfs_key_ptr ) * nr; } -void btrfs_node_key (struct extent_buffer *eb, +void btrfs_node_key (const struct extent_buffer *eb,struct btrfs_disk_key *disk_key,int nr); static inline void btrfs_set_node_key(struct extent_buffer *eb,
@@ -2587,28 +2590,28 @@ static inline struct btrfs_item *btrfs_ireturn (struct btrfs_item *)btrfs_item_nr_offset (nr); } -static inline u32 btrfs_item_end (struct extent_buffer *eb, +static inline u32 btrfs_item_end (const struct extent_buffer *eb,struct btrfs_item *item) {return btrfs_item_offset (eb, item) +btrfs_item_size (eb, item); } -static inline u32 btrfs_item_end_nr (struct extent_buffer *eb,int nr) +static inline u32 btrfs_item_end_nr (const struct extent_buffer *eb,int nr) {return btrfs_item_end (eb,btrfs_item_nr (nr)); } -static inline u32 btrfs_item_offset_nr (struct extent_buffer *eb,int nr) +static inline u32 btrfs_item_offset_nr (const struct extent_buffer *eb,int nr) {return btrfs_item_offset (eb,btrfs_item_nr (nr)); } -static inline u32 btrfs_item_size_nr (struct extent_buffer *eb,int nr) +static inline u32 btrfs_item_size_nr (const struct extent_buffer *eb,int nr) {return btrfs_item_size (eb,btrfs_item_nr (nr)); } -static inline void btrfs_item_key (struct extent_buffer *eb, +static inline void btrfs_item_key (const struct extent_buffer *eb,struct btrfs_disk_key *disk_key,int nr) {struct btrfs_item *item =btrfs_item_nr (nr);
@@ -2644,8 +2647,8 @@ BTRFS_SETGET_STACK_FUNCS(stack_dir_name_ BTRFS_SETGET_STACK_FUNCS(stack_dir_transid, struct btrfs_dir_item, transid,64 ); -static inline void btrfs_dir_item_key (struct extent_buffer *eb, -struct btrfs_dir_item *item, +static inline void btrfs_dir_item_key (const struct extent_buffer *eb, +const struct btrfs_dir_item *item,struct btrfs_disk_key *key) { read_eb_member(eb, item, struct btrfs_dir_item, location, key);
@@ -2653,7 +2656,7 @@ static inline void btrfs_dir_item_key(ststatic inline void btrfs_set_dir_item_key (struct extent_buffer *eb,struct btrfs_dir_item *item, -struct btrfs_disk_key *key) +const struct btrfs_disk_key *key) { write_eb_member(eb, item, struct btrfs_dir_item, location, key); }
@@ -2665,8 +2668,8 @@ BTRFS_SETGET_FUNCS(free_space_bitmaps, s BTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header, generation,64 ); -static inline void btrfs_free_space_key (struct extent_buffer *eb, -struct btrfs_free_space_header *h, +static inline void btrfs_free_space_key (const struct extent_buffer *eb, +const struct btrfs_free_space_header *h,struct btrfs_disk_key *key) { read_eb_member(eb, h, struct btrfs_free_space_header, location, key);
@@ -2674,7 +2677,7 @@ static inline void btrfs_free_space_key(static inline void btrfs_set_free_space_key (struct extent_buffer *eb,struct btrfs_free_space_header *h, -struct btrfs_disk_key *key) +const struct btrfs_disk_key *key) { write_eb_member(eb, h, struct btrfs_free_space_header, location, key); }
@@ -2701,25 +2704,25 @@ static inline void btrfs_cpu_key_to_disk disk->objectid =cpu_to_le64 (cpu->objectid); } -static inline void btrfs_node_key_to_cpu (struct extent_buffer *eb, -struct btrfs_key *key,int nr) +static inline void btrfs_node_key_to_cpu (const struct extent_buffer *eb, +struct btrfs_key *key,int nr) {struct btrfs_disk_key disk_key;btrfs_node_key (eb, &disk_key, nr);btrfs_disk_key_to_cpu (key, &disk_key); } -static inline void btrfs_item_key_to_cpu (struct extent_buffer *eb, -struct btrfs_key *key,int nr) +static inline void btrfs_item_key_to_cpu (const struct extent_buffer *eb, +struct btrfs_key *key,int nr) {struct btrfs_disk_key disk_key;btrfs_item_key (eb, &disk_key, nr);btrfs_disk_key_to_cpu (key, &disk_key); } -static inline void btrfs_dir_item_key_to_cpu (struct extent_buffer *eb, -struct btrfs_dir_item *item, -struct btrfs_key *key) +static inline void btrfs_dir_item_key_to_cpu (const struct extent_buffer *eb, +const struct btrfs_dir_item *item, +struct btrfs_key *key) {struct btrfs_disk_key disk_key;btrfs_dir_item_key (eb, item, &disk_key);
@@ -2752,7 +2755,7 @@ BTRFS_SETGET_STACK_FUNCS(stack_header_nr nritems, 32); BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64); -static inline int btrfs_header_flag (struct extent_buffer *eb,u64 flag) +static inline int btrfs_header_flag (const struct extent_buffer *eb,u64 flag) {return (btrfs_header_flags (eb) & flag) == flag; }
@@ -2771,7 +2774,7 @@ static inline int btrfs_clear_header_flareturn (flags & flag) == flag; } -static inline int btrfs_header_backref_rev (struct extent_buffer *eb) +static inline int btrfs_header_backref_rev (const struct extent_buffer *eb) {u64 flags =btrfs_header_flags (eb);return flags >>BTRFS_BACKREF_REV_SHIFT ;
@@ -2791,12 +2794,12 @@ static inline unsigned long btrfs_headerreturn offsetof(struct btrfs_header , fsid); } -static inline unsigned long btrfs_header_chunk_tree_uuid (struct extent_buffer *eb) +static inline unsigned long btrfs_header_chunk_tree_uuid (const struct extent_buffer *eb) {return offsetof(struct btrfs_header , chunk_tree_uuid); } -static inline int btrfs_is_leaf (struct extent_buffer *eb) +static inline int btrfs_is_leaf (const struct extent_buffer *eb) {return btrfs_header_level (eb) ==0 ; }
@@ -2830,12 +2833,12 @@ BTRFS_SETGET_STACK_FUNCS(root_stransid, BTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item, rtransid,64 ); -static inline bool btrfs_root_readonly (struct btrfs_root *root) +static inline bool btrfs_root_readonly (const struct btrfs_root *root) {return (root->root_item.flags &cpu_to_le64 (BTRFS_ROOT_SUBVOL_RDONLY )) !=0 ; } -static inline bool btrfs_root_dead (struct btrfs_root *root) +static inline bool btrfs_root_dead (const struct btrfs_root *root) {return (root->root_item.flags &cpu_to_le64 (BTRFS_ROOT_SUBVOL_DEAD )) !=0 ; }
@@ -2892,51 +2895,51 @@ BTRFS_SETGET_STACK_FUNCS(backup_num_devi/* struct btrfs_balance_item */ BTRFS_SETGET_FUNCS(balance_flags, struct btrfs_balance_item, flags, 64); -static inline void btrfs_balance_data (struct extent_buffer *eb, -struct btrfs_balance_item *bi, +static inline void btrfs_balance_data (const struct extent_buffer *eb, +const struct btrfs_balance_item *bi,struct btrfs_disk_balance_args *ba) { read_eb_member(eb, bi, struct btrfs_balance_item, data, ba); }static inline void btrfs_set_balance_data (struct extent_buffer *eb, -struct btrfs_balance_item *bi, -struct btrfs_disk_balance_args *ba) +struct btrfs_balance_item *bi, +const struct btrfs_disk_balance_args *ba) { write_eb_member(eb, bi, struct btrfs_balance_item, data, ba); } -static inline void btrfs_balance_meta (struct extent_buffer *eb, -struct btrfs_balance_item *bi, +static inline void btrfs_balance_meta (const struct extent_buffer *eb, +const struct btrfs_balance_item *bi,struct btrfs_disk_balance_args *ba) { read_eb_member(eb, bi, struct btrfs_balance_item, meta, ba); }static inline void btrfs_set_balance_meta (struct extent_buffer *eb, -struct btrfs_balance_item *bi, -struct btrfs_disk_balance_args *ba) +struct btrfs_balance_item *bi, +const struct btrfs_disk_balance_args *ba) { write_eb_member(eb, bi, struct btrfs_balance_item, meta, ba); } -static inline void btrfs_balance_sys (struct extent_buffer *eb, -struct btrfs_balance_item *bi, +static inline void btrfs_balance_sys (const struct extent_buffer *eb, +const struct btrfs_balance_item *bi,struct btrfs_disk_balance_args *ba) { read_eb_member(eb, bi, struct btrfs_balance_item, sys, ba); }static inline void btrfs_set_balance_sys (struct extent_buffer *eb, -struct btrfs_balance_item *bi, -struct btrfs_disk_balance_args *ba) +struct btrfs_balance_item *bi, +const struct btrfs_disk_balance_args *ba) { write_eb_member(eb, bi, struct btrfs_balance_item, sys, ba); }static inline void btrfs_disk_balance_args_to_cpu (struct btrfs_balance_args *cpu, -struct btrfs_disk_balance_args *disk) +const struct btrfs_disk_balance_args *disk) {memset (cpu,0 ,sizeof (*cpu));
@@ -2954,7 +2957,7 @@ btrfs_disk_balance_args_to_cpu(struct btstatic inline void btrfs_cpu_balance_args_to_disk (struct btrfs_disk_balance_args *disk, -struct btrfs_balance_args *cpu) +const struct btrfs_balance_args *cpu) {memset (disk,0 ,sizeof (*disk));
@@ -3022,7 +3025,7 @@ BTRFS_SETGET_STACK_FUNCS(super_magic, st BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, uuid_tree_generation,64 ); -static inline int btrfs_super_csum_size (struct btrfs_super_block *s) +static inline int btrfs_super_csum_size (const struct btrfs_super_block *s) {u16 t =btrfs_super_csum_type (s);/*
@@ -3041,8 +3044,8 @@ static inline unsigned long btrfs_leaf_d* this returns the address of the start of the last item, * which is the stop of the leaf data stack */ -static inline unsigned int leaf_data_end (struct btrfs_root *root, -struct extent_buffer *leaf) +static inline unsigned int leaf_data_end (const struct btrfs_root *root, +const struct extent_buffer *leaf) {u32 nr =btrfs_header_nritems (leaf);
@@ -3067,7 +3070,7 @@ BTRFS_SETGET_STACK_FUNCS(stack_file_exte struct btrfs_file_extent_item, compression, 8);static inline unsigned long -btrfs_file_extent_inline_start (struct btrfs_file_extent_item *e) +btrfs_file_extent_inline_start (const struct btrfs_file_extent_item *e) {return (unsigned long )e +BTRFS_FILE_EXTENT_INLINE_DATA_START ; }
@@ -3101,8 +3104,9 @@ BTRFS_SETGET_FUNCS(file_extent_other_enc* size of any extent headers. If a file is compressed on disk, this is * the compressed size */ -static inline u32 btrfs_file_extent_inline_item_len (struct extent_buffer *eb, -struct btrfs_item *e) +static inline u32 btrfs_file_extent_inline_item_len ( +const struct extent_buffer *eb, +struct btrfs_item *e) {return btrfs_item_size (eb, e) -BTRFS_FILE_EXTENT_INLINE_DATA_START ; }
@@ -3110,9 +3114,9 @@ static inline u32 btrfs_file_extent_inli/* this returns the number of file bytes represented by the inline item. * If an item is compressed, this is the uncompressed size */ -static inline u32 btrfs_file_extent_inline_len (struct extent_buffer *eb, -int slot, -struct btrfs_file_extent_item *fi) +static inline u32 btrfs_file_extent_inline_len (const struct extent_buffer *eb, +int slot, +const struct btrfs_file_extent_item *fi) {struct btrfs_map_token token;
@@ -3134,8 +3138,8 @@ static inline u32 btrfs_file_extent_inli/* btrfs_dev_stats_item */ -static inline u64 btrfs_dev_stats_value (struct extent_buffer *eb, -struct btrfs_dev_stats_item *ptr, +static inline u64 btrfs_dev_stats_value (const struct extent_buffer *eb, +const struct btrfs_dev_stats_item *ptr,int index) {u64 val;
fs/btrfs/extent_io.c +11 -13
@@ -5111,9 +5111,8 @@ unlock_exit:return ret; } -void read_extent_buffer (struct extent_buffer *eb,void *dstv, -unsigned long start, -unsigned long len) +void read_extent_buffer (const struct extent_buffer *eb,void *dstv, +unsigned long start,unsigned long len) {size_t cur;size_t offset;
@@ -5142,9 +5141,9 @@ void read_extent_buffer(struct extent_bu } } -int read_extent_buffer_to_user (struct extent_buffer *eb,void __user *dstv, -unsigned long start, -unsigned long len) +int read_extent_buffer_to_user (const struct extent_buffer *eb, +void __user *dstv, +unsigned long start,unsigned long len) {size_t cur;size_t offset;
@@ -5179,10 +5178,10 @@ int read_extent_buffer_to_user(struct exreturn ret; } -int map_private_extent_buffer (struct extent_buffer *eb,unsigned long start, -unsigned long min_len,char **map, -unsigned long *map_start, -unsigned long *map_len) +int map_private_extent_buffer (const struct extent_buffer *eb, +unsigned long start,unsigned long min_len, +char **map,unsigned long *map_start, +unsigned long *map_len) {size_t offset = start & (PAGE_CACHE_SIZE -1 );char *kaddr;
@@ -5217,9 +5216,8 @@ int map_private_extent_buffer(struct extreturn 0 ; } -int memcmp_extent_buffer (struct extent_buffer *eb,const void *ptrv, -unsigned long start, -unsigned long len) +int memcmp_extent_buffer (const struct extent_buffer *eb,const void *ptrv, +unsigned long start,unsigned long len) {size_t cur;size_t offset;
fs/btrfs/extent_io.h +9 -10
@@ -291,14 +291,13 @@ static inline void extent_buffer_get(stratomic_inc (&eb->refs); } -int memcmp_extent_buffer (struct extent_buffer *eb,const void *ptrv, -unsigned long start, -unsigned long len); -void read_extent_buffer (struct extent_buffer *eb,void *dst, +int memcmp_extent_buffer (const struct extent_buffer *eb,const void *ptrv, +unsigned long start,unsigned long len); +void read_extent_buffer (const struct extent_buffer *eb,void *dst,unsigned long start,unsigned long len); -int read_extent_buffer_to_user (struct extent_buffer *eb,void __user *dst, -unsigned long start, +int read_extent_buffer_to_user (const struct extent_buffer *eb, +void __user *dst,unsigned long start,unsigned long len);void write_extent_buffer (struct extent_buffer *eb,const void *src,unsigned long start,unsigned long len);
@@ -317,10 +316,10 @@ int set_extent_buffer_uptodate(struct exint clear_extent_buffer_uptodate (struct extent_buffer *eb);int extent_buffer_uptodate (struct extent_buffer *eb);int extent_buffer_under_io (struct extent_buffer *eb); -int map_private_extent_buffer (struct extent_buffer *eb,unsigned long offset, -unsigned long min_len,char **map, -unsigned long *map_start, -unsigned long *map_len); +int map_private_extent_buffer (const struct extent_buffer *eb, +unsigned long offset,unsigned long min_len, +char **map,unsigned long *map_start, +unsigned long *map_len);int extent_range_clear_dirty_for_io (struct inode *inode,u64 start,u64 end);int extent_range_redirty_for_io (struct inode *inode,u64 start,u64 end); int extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end,
fs/btrfs/struct-funcs.c +5 -4
@@ -50,8 +50,8 @@ static inline void put_unaligned_le8(u8*/ #define DEFINE_BTRFS_SETGET_BITS (bits) \ -u##bits btrfs_get_token_##bits(struct extent_buffer *eb, void *ptr, \ - unsigned long off, \ +u##bits btrfs_get_token_##bits(const struct extent_buffer *eb, \ + const void *ptr, unsigned long off, \ struct btrfs_map_token *token) \ { \ unsigned long part_offset = (unsigned long)ptr; \
@@ -90,7 +90,8 @@ u##bits btrfs_get_token_##bits(struct exreturn res; \ } \ void btrfs_set_token_##bits(struct extent_buffer *eb, \ - void *ptr, unsigned long off, u##bits val, \ + const void *ptr, unsigned long off, \ + u##bits val, \ struct btrfs_map_token *token) \ { \ unsigned long part_offset = (unsigned long)ptr; \
@@ -133,7 +134,7 @@ DEFINE_BTRFS_SETGET_BITS(16) DEFINE_BTRFS_SETGET_BITS(32) DEFINE_BTRFS_SETGET_BITS(64) -void btrfs_node_key (struct extent_buffer *eb, +void btrfs_node_key (const struct extent_buffer *eb,struct btrfs_disk_key *disk_key,int nr) {unsigned long ptr =btrfs_node_key_ptr_offset (nr);
PATCH 38/245 btrfs: Refactor check_leaf function for later expansion
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit c3267bbaa9cae09b62960eafe33ad19196803285 upstream.
Current check_leaf() function does a good job checking key order and item offset/size.
However it only checks from slot 0 to the last but one slot, this is good but makes later expansion hard.
So this refactoring iterates from slot 0 to the last slot. For key comparison, it uses a key with all 0 as initial key, so all valid keys should be larger than that.
And for item size/offset checks, it compares current item end with previous item offset.
For slot 0, use leaf end as a special case.
This makes later item/key offset checks and item size checks easier to be implemented.
Also, makes check_leaf() to return -EUCLEAN other than -EIO to indicate error.
[bwh: Backported to 4.4:
- BTRFS_LEAF_DATA_SIZE() takes a root rather than an fs_info
- Adjust context]
--- fs/btrfs/disk-io.c | 50 +++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 23 deletions(-)
fs/btrfs/disk-io.c +27 -23
@@ -516,8 +516,9 @@ static int check_tree_block_fsid(struct static noinline int check_leaf(struct btrfs_root *root,struct extent_buffer *leaf) { +/* No valid key type is 0, so all key should be larger than this key */ +struct btrfs_key prev_key = {0 ,0 ,0 };struct btrfs_key key; -struct btrfs_key leaf_key;u32 nritems =btrfs_header_nritems (leaf);int slot;
@@ -550,7 +551,7 @@ static noinline int check_leaf(struct btCORRUPT ("non-root leaf's nritems is 0" , leaf, check_root,0 );free_extent_buffer (eb); -return -EIO ; +return -EUCLEAN ; }free_extent_buffer (eb); }
@@ -560,28 +561,23 @@ static noinline int check_leaf(struct btif (nritems ==0 )return 0 ; -/* Check the 0 item */ -if (btrfs_item_offset_nr (leaf,0 ) +btrfs_item_size_nr (leaf,0 ) != -BTRFS_LEAF_DATA_SIZE (root)) { -CORRUPT ("invalid item offset size pair" , leaf, root,0 ); -return -EIO ; - } -/* -* Check to make sure each items keys are in the correct order and their -* offsets make sense. We only have to loop through nritems-1 because -* we check the current slot against the next slot, which verifies the -* next slot's offset+size makes sense and that the current's slot -* offset is correct. +* Check the following things to make sure this is a good leaf, and +* leaf users won't need to bother with similar sanity checks: +* +* 1) key order +* 2) item offset and size +* No overlap, no hole, all inside the leaf. */ -for (slot =0 ; slot < nritems -1 ; slot++) { -btrfs_item_key_to_cpu (leaf, &leaf_key, slot); -btrfs_item_key_to_cpu (leaf, &key, slot +1 ); +for (slot =0 ; slot < nritems; slot++) { +u32 item_end_expected; + +btrfs_item_key_to_cpu (leaf, &key, slot);/* Make sure the keys are in the right order */ -if (btrfs_comp_cpu_keys (&leaf_key, &key) >=0 ) { +if (btrfs_comp_cpu_keys (&prev_key, &key) >=0 ) {CORRUPT ("bad key order" , leaf, root, slot); -return -EIO ; +return -EUCLEAN ; }/*
@@ -589,10 +585,14 @@ static noinline int check_leaf(struct bt* item data starts at the end of the leaf and grows towards the * front. */ -if (btrfs_item_offset_nr (leaf, slot) != -btrfs_item_end_nr (leaf, slot +1 )) { +if (slot ==0 ) + item_end_expected =BTRFS_LEAF_DATA_SIZE (root); +else + item_end_expected =btrfs_item_offset_nr (leaf, + slot -1 ); +if (btrfs_item_end_nr (leaf, slot) != item_end_expected) {CORRUPT ("slot offset bad" , leaf, root, slot); -return -EIO ; +return -EUCLEAN ; }/*
@@ -603,8 +603,12 @@ static noinline int check_leaf(struct btif (btrfs_item_end_nr (leaf, slot) >BTRFS_LEAF_DATA_SIZE (root)) {CORRUPT ("slot end outside of leaf" , leaf, root, slot); -return -EIO ; +return -EUCLEAN ; } + + prev_key.objectid = key.objectid; + prev_key.type = key.type; + prev_key.offset = key.offset; }return 0 ;
PATCH 39/245 btrfs: Check if item pointer overlaps with the item itself
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit 7f43d4affb2a254d421ab20b0cf65ac2569909fb upstream.
Function check_leaf() checks if any item pointer points outside of the leaf, but it doesn't check if the pointer overlaps with the item itself.
Normally only the last item may be the victim, but adding such check is never a bad idea anyway.
--- fs/btrfs/disk-io.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/btrfs/disk-io.c +7 -0
@@ -606,6 +606,13 @@ static noinline int check_leaf(struct btreturn -EUCLEAN ; } +/* Also check if the item pointer overlaps with btrfs item. */ +if (btrfs_item_nr_offset (slot) +sizeof (struct btrfs_item ) > +btrfs_item_ptr_offset (leaf, slot)) { +CORRUPT ("slot overlap with its data" , leaf, root, slot); +return -EUCLEAN ; + } + prev_key.objectid = key.objectid; prev_key.type = key.type; prev_key.offset = key.offset;
PATCH 40/245 btrfs: Add sanity check for EXTENT_DATA when reading out leaf
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit 40c3c40947324d9f40bf47830c92c59a9bbadf4a upstream.
Add extra checks for item with EXTENT_DATA type. This checks the following thing:
0) Key offset
All key offsets must be aligned to sectorsize.
Inline extent must have 0 for key offset.
1) Item size
Uncompressed inline file extent size must match item size. (Compressed inline file extent has no information about its on-disk size.) Regular/preallocated file extent size must be a fixed value.
2) Every member of regular file extent item
Including alignment for bytenr and offset, possible value for compression/encryption/type.
3) Type/compression/encode must be one of the valid values.
This should be the most comprehensive and strict check in the context of btrfs_item for EXTENT_DATA.
[ switch to BTRFS_FILE_EXTENT_TYPES, similar to what
BTRFS_COMPRESS_TYPES does ]
[bwh: Backported to 4.4:
- Use root->sectorsize instead of root->fs_info->sectorsize
- Adjust filename]
--- fs/btrfs/ctree.h | 1 + fs/btrfs/disk-io.c | 103 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+)
fs/btrfs/ctree.h +1 -0
@@ -874,6 +874,7 @@ struct btrfs_balance_item {#define BTRFS_FILE_EXTENT_INLINE 0#define BTRFS_FILE_EXTENT_REG 1#define BTRFS_FILE_EXTENT_PREALLOC 2 +#define BTRFS_FILE_EXTENT_TYPES 2struct btrfs_file_extent_item {/*
fs/btrfs/disk-io.c +103 -0
124 lines not on this page · raw message
PATCH 41/245 btrfs: Add checker for EXTENT_CSUM
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit 4b865cab96fe2a30ed512cf667b354bd291b3b0a upstream.
EXTENT_CSUM checker is a relatively easy one, only needs to check:
1) Objectid
Fixed to BTRFS_EXTENT_CSUM_OBJECTID
2) Key offset alignment
Must be aligned to sectorsize
3) Item size alignedment
Must be aligned to csum size
[bwh: Backported to 4.4: Use root->sectorsize instead of
root->fs_info->sectorsize]
--- fs/btrfs/disk-io.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
fs/btrfs/disk-io.c +24 -0
@@ -590,6 +590,27 @@ static int check_extent_data_item(structreturn 0 ; } +static int check_csum_item (struct btrfs_root *root,struct extent_buffer *leaf, +struct btrfs_key *key,int slot) +{ +u32 sectorsize = root->sectorsize; +u32 csumsize =btrfs_super_csum_size (root->fs_info->super_copy); + +if (key->objectid !=BTRFS_EXTENT_CSUM_OBJECTID ) { +CORRUPT ("invalid objectid for csum item" , leaf, root, slot); +return -EUCLEAN ; + } +if (!IS_ALIGNED (key->offset, sectorsize)) { +CORRUPT ("unaligned key offset for csum item" , leaf, root, slot); +return -EUCLEAN ; + } +if (!IS_ALIGNED (btrfs_item_size_nr (leaf, slot), csumsize)) { +CORRUPT ("unaligned csum item size" , leaf, root, slot); +return -EUCLEAN ; + } +return 0 ; +} +/* * Common point to switch the item-specific validation. */
@@ -603,6 +624,9 @@ static int check_leaf_item(struct btrfs_case BTRFS_EXTENT_DATA_KEY : ret =check_extent_data_item (root, leaf, key, slot);break ; +case BTRFS_EXTENT_CSUM_KEY : + ret =check_csum_item (root, leaf, key, slot); +break ; }return ret; }
PATCH 42/245 btrfs: Move leaf and node validation checker to tree-checker.c
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit 557ea5dd003d371536f6b4e8f7c8209a2b6fd4e3 upstream.
It's no doubt the comprehensive tree block checker will become larger, so moving them into their own files is quite reasonable.
[bwh: Backported to 4.4:
- The moved code is slightly different
- Adjust context]
--- fs/btrfs/Makefile | 2 +- fs/btrfs/disk-io.c | 284 +----------------------------------- fs/btrfs/tree-checker.c | 309 ++++++++++++++++++++++++++++++++++++++++ fs/btrfs/tree-checker.h | 26 ++++ 4 files changed, 340 insertions(+), 281 deletions(-) create mode 100644 fs/btrfs/tree-checker.c create mode 100644 fs/btrfs/tree-checker.h
fs/btrfs/Makefile +1 -1
@@ -9,7 +9,7 @@ btrfs-y += super.o ctree.o extent-tree.o export.o tree-log.o free-space-cache.o zlib.o lzo.o \ compression.o delayed-ref.o relocation.o delayed-inode.o scrub.o \ reada.o backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o \ - uuid-tree.o props.o hash.o + uuid-tree.o props.o hash.o tree-checker.o btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
fs/btrfs/disk-io.c +4 -280
312 lines not on this page · raw message
fs/btrfs/tree-checker.c new file +309 -0
309 lines not on this page · raw message
fs/btrfs/tree-checker.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright (C) Qu Wenruo 2017. All rights reserved. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License v2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program. +*/ + +#ifndef __BTRFS_TREE_CHECKER__ +#define __BTRFS_TREE_CHECKER__ + +#include "ctree.h" +#include "extent_io.h" + +int btrfs_check_leaf (struct btrfs_root *root,struct extent_buffer *leaf); +int btrfs_check_node (struct btrfs_root *root,struct extent_buffer *node); + +#endif
PATCH 43/245 btrfs: tree-checker: Enhance btrfs_check_node output
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit bba4f29896c986c4cec17bc0f19f2ce644fceae1 upstream.
Use inline function to replace macro since we don't need stringification.
(Macro still exists until all callers get updated)
And add more info about the error, and replace EIO with EUCLEAN.
For nr_items error, report if it's too large or too small, and output the valid value range.
For node block pointer, added a new alignment checker.
For key order, also output the next key to make the problem more obvious.
[bwh: Backported to 4.4:
- Use root->sectorsize instead of root->fs_info->sectorsize
- BTRFS_NODEPTRS_PER_BLOCK() takes a root instead of an fs_info, and yields a value of type size_t instead of unsigned int]
--- fs/btrfs/tree-checker.c | 68 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 7 deletions(-)
fs/btrfs/tree-checker.c +61 -7
@@ -37,6 +37,46 @@ btrfs_header_level(eb) == 0 ? "leaf" : "node", \ reason, btrfs_header_bytenr(eb), root->objectid, slot) +/* +* Error message should follow the following format: +* corrupt <type>: <identifier>, <reason>[, <bad_value>] +* +* @type: leaf or node +* @identifier: the necessary info to locate the leaf/node. +* It's recommened to decode key.objecitd/offset if it's +* meaningful. +* @reason: describe the error +* @bad_value: optional, it's recommened to output bad value and its +* expected value (range). +* +* Since comma is used to separate the components, only space is allowed +* inside each component. +*/ + +/* +* Append generic "corrupt leaf/node root=%llu block=%llu slot=%d: " to @fmt. +* Allows callers to customize the output. +*/ +__printf(4, 5) +static void generic_err (const struct btrfs_root *root, +const struct extent_buffer *eb,int slot, +const char *fmt, ...) +{ +struct va_format vaf; +va_list args; + +va_start (args, fmt); + + vaf.fmt = fmt; + vaf.va = &args; + +btrfs_crit (root->fs_info, +"corrupt %s: root=%llu block=%llu slot=%d, %pV" , +btrfs_header_level (eb) ==0 ?"leaf" :"node" , + root->objectid,btrfs_header_bytenr (eb), slot, &vaf); +va_end (args); +} +static int check_extent_data_item (struct btrfs_root *root,struct extent_buffer *leaf,struct btrfs_key *key,int slot)
@@ -282,9 +322,11 @@ int btrfs_check_node(struct btrfs_root *if (nr ==0 || nr >BTRFS_NODEPTRS_PER_BLOCK (root)) {btrfs_crit (root->fs_info, -"corrupt node: block %llu root %llu nritems %lu" , - node->start, root->objectid, nr); -return -EIO ; +"corrupt node: root=%llu block=%llu, nritems too %s, have %lu expect range [1,%zu]" , + root->objectid, node->start, + nr ==0 ?"small" :"large" , nr, +BTRFS_NODEPTRS_PER_BLOCK (root)); +return -EUCLEAN ; }for (slot =0 ; slot < nr -1 ; slot++) {
@@ -293,14 +335,26 @@ int btrfs_check_node(struct btrfs_root *btrfs_node_key_to_cpu (node, &next_key, slot +1 );if (!bytenr) { -CORRUPT ("invalid item slot" , node, root, slot); - ret = -EIO ; +generic_err (root, node, slot, +"invalid NULL node pointer" ); + ret = -EUCLEAN ; + goto out; + } +if (!IS_ALIGNED (bytenr, root->sectorsize)) { +generic_err (root, node, slot, +"unaligned pointer, have %llu should be aligned to %u" , + bytenr, root->sectorsize); + ret = -EUCLEAN ; goto out; }if (btrfs_comp_cpu_keys (&key, &next_key) >=0 ) { -CORRUPT ("bad key order" , node, root, slot); - ret = -EIO ; +generic_err (root, node, slot, +"bad key order, current (%llu %u %llu) next (%llu %u %llu)" , + key.objectid, key.type, key.offset, + next_key.objectid, next_key.type, + next_key.offset); + ret = -EUCLEAN ; goto out; } }
PATCH 44/245 btrfs: tree-checker: Fix false panic for sanity test
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit 69fc6cbbac542c349b3d350d10f6e394c253c81d upstream.
[BUG]
If we run btrfs with CONFIG_BTRFS_FS_RUN_SANITY_TESTS=y, it will instantly cause kernel panic like:
------
...
assertion failed: 0, file: fs/btrfs/disk-io.c, line: 3853
...
Call Trace: btrfs_mark_buffer_dirty+0x187/0x1f0 [btrfs] setup_items_for_insert+0x385/0x650 [btrfs] __btrfs_drop_extents+0x129a/0x1870 [btrfs]
...
-----
[Cause]
Btrfs will call btrfs_check_leaf() in btrfs_mark_buffer_dirty() to check if the leaf is valid with CONFIG_BTRFS_FS_RUN_SANITY_TESTS=y.
However quite some btrfs_mark_buffer_dirty() callers(*) don't really initialize its item data but only initialize its item pointers, leaving item data uninitialized.
This makes tree-checker catch uninitialized data as error, causing such panic.
*: These callers include but not limited tosetup_items_for_insert()btrfs_split_item()btrfs_expand_item()
[Fix]
Add a new parameter @check_item_data to btrfs_check_leaf(). With @check_item_data set to false, item data check will be skipped and fallback to old btrfs_check_leaf() behavior.
So we can still get early warning if we screw up item pointers, and avoid false panic.
--- fs/btrfs/disk-io.c | 10 ++++++++-- fs/btrfs/tree-checker.c | 27 ++++++++++++++++++++++----- fs/btrfs/tree-checker.h | 14 +++++++++++++- 3 files changed, 43 insertions(+), 8 deletions(-)
fs/btrfs/disk-io.c +8 -2
@@ -575,7 +575,7 @@ static int btree_readpage_end_io_hook(st* that we don't try and read the other copies of this block, just * return -EIO. */ -if (found_level ==0 &&btrfs_check_leaf (root, eb)) { +if (found_level ==0 &&btrfs_check_leaf_full (root, eb)) {set_bit (EXTENT_BUFFER_CORRUPT , &eb->bflags); ret = -EIO ; }
@@ -3702,7 +3702,13 @@ void btrfs_mark_buffer_dirty(struct exte buf->len, root->fs_info->dirty_metadata_batch);#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY -if (btrfs_header_level (buf) ==0 &&btrfs_check_leaf (root, buf)) { +/* +* Since btrfs_mark_buffer_dirty() can be called with item pointer set +* but item data not updated. +* So here we should only check item pointers, not item data. +*/ +if (btrfs_header_level (buf) ==0 && +btrfs_check_leaf_relaxed (root, buf)) {btrfs_print_leaf (root, buf);ASSERT (0 ); }
fs/btrfs/tree-checker.c +22 -5
@@ -195,7 +195,8 @@ static int check_leaf_item(struct btrfs_return ret; } -int btrfs_check_leaf (struct btrfs_root *root,struct extent_buffer *leaf) +static int check_leaf (struct btrfs_root *root,struct extent_buffer *leaf, +bool check_item_data) {struct btrfs_fs_info *fs_info = root->fs_info;/* No valid key type is 0, so all key should be larger than this key */
@@ -299,10 +300,15 @@ int btrfs_check_leaf(struct btrfs_root *return -EUCLEAN ; } -/* Check if the item size and content meet other criteria */ - ret =check_leaf_item (root, leaf, &key, slot); -if (ret <0 ) -return ret; +if (check_item_data) { +/* +* Check if the item size and content meet other +* criteria +*/ + ret =check_leaf_item (root, leaf, &key, slot); +if (ret <0 ) +return ret; + } prev_key.objectid = key.objectid; prev_key.type = key.type;
@@ -312,6 +318,17 @@ int btrfs_check_leaf(struct btrfs_root *return 0 ; } +int btrfs_check_leaf_full (struct btrfs_root *root,struct extent_buffer *leaf) +{ +return check_leaf (root, leaf, true); +} + +int btrfs_check_leaf_relaxed (struct btrfs_root *root, +struct extent_buffer *leaf) +{ +return check_leaf (root, leaf, false); +} +int btrfs_check_node (struct btrfs_root *root,struct extent_buffer *node) {unsigned long nr =btrfs_header_nritems (node);
fs/btrfs/tree-checker.h +13 -1
@@ -20,7 +20,19 @@#include "ctree.h" #include "extent_io.h" -int btrfs_check_leaf (struct btrfs_root *root,struct extent_buffer *leaf); +/* +* Comprehensive leaf checker. +* Will check not only the item pointers, but also every possible member +* in item data. +*/ +int btrfs_check_leaf_full (struct btrfs_root *root,struct extent_buffer *leaf); + +/* +* Less strict leaf checker. +* Will only check item pointers, not reading item data. +*/ +int btrfs_check_leaf_relaxed (struct btrfs_root *root, +struct extent_buffer *leaf);int btrfs_check_node (struct btrfs_root *root,struct extent_buffer *node);#endif
PATCH 45/245 btrfs: tree-checker: Add checker for dir item
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit ad7b0368f33cffe67fecd302028915926e50ef7e upstream.
Add checker for dir item, for key types DIR_ITEM, DIR_INDEX and XATTR_ITEM.
This checker does comprehensive checks for:
1) dir_item header and its data size
Against item boundary and maximum name/xattr length. This part is mostly the same as old verify_dir_item().
2) dir_type
Against maximum file types, and against key type.
Since XATTR key should only have FT_XATTR dir item, and normal dir item type should not have XATTR key.
The check between key->type and dir_type is newly introduced by this patch.
3) name hash
For XATTR and DIR_ITEM key, key->offset is name hash (crc32c). Check the hash of the name against the key to ensure it's correct.
The name hash check is only found in btrfs-progs before this patch.
[bwh: Backported to 4.4: BTRFS_MAX_XATTR_SIZE() takes a root instead of an
fs_info, and yields a value of type size_t instead of unsigned int]
--- fs/btrfs/tree-checker.c | 141 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+)
fs/btrfs/tree-checker.c +141 -0
@@ -30,6 +30,7 @@#include "tree-checker.h" #include "disk-io.h" #include "compression.h" +#include "hash.h" #define CORRUPT (reason, eb, root, slot) \ btrfs_crit(root->fs_info, \
@@ -176,6 +177,141 @@ static int check_csum_item(struct btrfs_ }/* +* Customized reported for dir_item, only important new info is key->objectid, +* which represents inode number +*/ +__printf(4, 5) +static void dir_item_err (const struct btrfs_root *root, +const struct extent_buffer *eb,int slot, +const char *fmt, ...) +{ +struct btrfs_key key; +struct va_format vaf; +va_list args; + +btrfs_item_key_to_cpu (eb, &key, slot); +va_start (args, fmt); + + vaf.fmt = fmt; + vaf.va = &args; + +btrfs_crit (root->fs_info, +"corrupt %s: root=%llu block=%llu slot=%d ino=%llu, %pV" , +btrfs_header_level (eb) ==0 ?"leaf" :"node" , root->objectid, +btrfs_header_bytenr (eb), slot, key.objectid, &vaf); +va_end (args); +} + +static int check_dir_item (struct btrfs_root *root, +struct extent_buffer *leaf, +struct btrfs_key *key,int slot) +{ +struct btrfs_dir_item *di; +u32 item_size =btrfs_item_size_nr (leaf, slot); +u32 cur =0 ; + + di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item); +while (cur < item_size) { +char namebuf[max (BTRFS_NAME_LEN ,XATTR_NAME_MAX )]; +u32 name_len; +u32 data_len; +u32 max_name_len; +u32 total_size; +u32 name_hash; +u8 dir_type; + +/* header itself should not cross item boundary */ +if (cur +sizeof (*di) > item_size) { +dir_item_err (root, leaf, slot, +"dir item header crosses item boundary, have %lu boundary %u" , + cur +sizeof (*di), item_size); +return -EUCLEAN ; + } + +/* dir type check */ + dir_type =btrfs_dir_type (leaf, di); +if (dir_type >=BTRFS_FT_MAX ) { +dir_item_err (root, leaf, slot, +"invalid dir item type, have %u expect [0, %u)" , + dir_type,BTRFS_FT_MAX ); +return -EUCLEAN ; + } + +if (key->type ==BTRFS_XATTR_ITEM_KEY && + dir_type !=BTRFS_FT_XATTR ) { +dir_item_err (root, leaf, slot, +"invalid dir item type for XATTR key, have %u expect %u" , + dir_type,BTRFS_FT_XATTR ); +return -EUCLEAN ; + } +if (dir_type ==BTRFS_FT_XATTR && + key->type !=BTRFS_XATTR_ITEM_KEY ) { +dir_item_err (root, leaf, slot, +"xattr dir type found for non-XATTR key" ); +return -EUCLEAN ; + } +if (dir_type ==BTRFS_FT_XATTR ) + max_name_len =XATTR_NAME_MAX ; +else + max_name_len =BTRFS_NAME_LEN ; + +/* Name/data length check */ + name_len =btrfs_dir_name_len (leaf, di); + data_len =btrfs_dir_data_len (leaf, di); +if (name_len > max_name_len) { +dir_item_err (root, leaf, slot, +"dir item name len too long, have %u max %u" , + name_len, max_name_len); +return -EUCLEAN ; + } +if (name_len + data_len >BTRFS_MAX_XATTR_SIZE (root)) { +dir_item_err (root, leaf, slot, +"dir item name and data len too long, have %u max %zu" , + name_len + data_len, +BTRFS_MAX_XATTR_SIZE (root)); +return -EUCLEAN ; + } + +if (data_len && dir_type !=BTRFS_FT_XATTR ) { +dir_item_err (root, leaf, slot, +"dir item with invalid data len, have %u expect 0" , + data_len); +return -EUCLEAN ; + } + + total_size =sizeof (*di) + name_len + data_len; + +/* header and name/data should not cross item boundary */ +if (cur + total_size > item_size) { +dir_item_err (root, leaf, slot, +"dir item data crosses item boundary, have %u boundary %u" , + cur + total_size, item_size); +return -EUCLEAN ; + } + +/* +* Special check for XATTR/DIR_ITEM, as key->offset is name +* hash, should match its name +*/ +if (key->type ==BTRFS_DIR_ITEM_KEY || + key->type ==BTRFS_XATTR_ITEM_KEY ) { +read_extent_buffer (leaf, namebuf, + (unsigned long )(di +1 ), name_len); + name_hash =btrfs_name_hash (namebuf, name_len); +if (key->offset != name_hash) { +dir_item_err (root, leaf, slot, +"name hash mismatch with key, have 0x%016x expect 0x%016llx" , + name_hash, key->offset); +return -EUCLEAN ; + } + } + cur += total_size; + di = (struct btrfs_dir_item *)((void *)di + total_size); + } +return 0 ; +} + +/* * Common point to switch the item-specific validation. */ static int check_leaf_item(struct btrfs_root *root,
@@ -191,6 +327,11 @@ static int check_leaf_item(struct btrfs_case BTRFS_EXTENT_CSUM_KEY : ret =check_csum_item (root, leaf, key, slot);break ; +case BTRFS_DIR_ITEM_KEY : +case BTRFS_DIR_INDEX_KEY : +case BTRFS_XATTR_ITEM_KEY : + ret =check_dir_item (root, leaf, key, slot); +break ; }return ret; }
PATCH 46/245 btrfs: tree-checker: use %zu format string for size_t
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
commit 7cfad65297bfe0aa2996cd72d21c898aa84436d9 upstream.
The return value of sizeof() is of type size_t, so we must print it using the %z format modifier rather than %l to avoid this warning on some architectures:
fs/btrfs/tree-checker.c: In function 'check_dir_item':fs/btrfs/tree-checker.c:273:50: error: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'u32' {aka 'unsigned int'} [-Werror=format=]
--- fs/btrfs/tree-checker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-checker.c +1 -1
@@ -223,7 +223,7 @@ static int check_dir_item(struct btrfs_r/* header itself should not cross item boundary */ if (cur +sizeof (*di) > item_size) {dir_item_err (root, leaf, slot, -"dir item header crosses item boundary, have %lu boundary %u" , +"dir item header crosses item boundary, have %zu boundary %u" , cur +sizeof (*di), item_size);return -EUCLEAN ; }
PATCH 47/245 btrfs: tree-check: reduce stack consumption in check_dir_item
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: David Sterba <[email protected]>
commit e2683fc9d219430f5b78889b50cde7f40efeba7b upstream.
I've noticed that the updated item checker stack consumption increased dramatically in 542f5385e20cf97447 ("btrfs: tree-checker: Add checker for dir item")
tree-checker.c:check_leaf +552 (176 -> 728)
The array is 255 bytes long, dynamic allocation would slow down the sanity checks so it's more reasonable to keep it on-stack. Moving the variable to the scope of use reduces the stack usage again
tree-checker.c:check_leaf -264 (728 -> 464)
--- fs/btrfs/tree-checker.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/tree-checker.c +2 -1
@@ -212,7 +212,6 @@ static int check_dir_item(struct btrfs_r di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);while (cur < item_size) { -char namebuf[max (BTRFS_NAME_LEN ,XATTR_NAME_MAX )];u32 name_len;u32 data_len;u32 max_name_len;
@@ -295,6 +294,8 @@ static int check_dir_item(struct btrfs_r*/ if (key->type ==BTRFS_DIR_ITEM_KEY || key->type ==BTRFS_XATTR_ITEM_KEY ) { +char namebuf[max (BTRFS_NAME_LEN ,XATTR_NAME_MAX )]; +read_extent_buffer (leaf, namebuf, (unsigned long )(di +1 ), name_len); name_hash =btrfs_name_hash (namebuf, name_len);
PATCH 48/245 btrfs: tree-checker: Verify block_group_item
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit fce466eab7ac6baa9d2dcd88abcf945be3d4a089 upstream.
A crafted image with invalid block group items could make free space cache code to cause panic.
We could detect such invalid block group item by checking:
1) Item size
Known fixed value.
2) Block group size (key.offset)
We have an upper limit on block group item (10G)
3) Chunk objectid
Known fixed value.
4) Type
Only 4 valid type values, DATA, METADATA, SYSTEM and DATA|METADATA. No more than 1 bit set for profile type.
5) Used space
No more than the block group size.
This should allow btrfs to detect and refuse to mount the crafted image.
[bwh: Backported to 4.4:
- In check_leaf_item(), pass root->fs_info to check_block_group_item()
- Include <linux/sizes.h> (in ctree.h, to match upstream)
- Adjust context]
--- fs/btrfs/ctree.h | 1 + fs/btrfs/tree-checker.c | 100 ++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.c | 2 +- fs/btrfs/volumes.h | 2 + 4 files changed, 104 insertions(+), 1 deletion(-)
fs/btrfs/ctree.h +1 -0
@@ -34,6 +34,7 @@#include <linux/pagemap.h> #include <linux/btrfs.h> #include <linux/workqueue.h> +#include <linux/sizes.h> #include "extent_io.h" #include "extent_map.h" #include "async-thread.h"
fs/btrfs/tree-checker.c +100 -0
118 lines not on this page · raw message
fs/btrfs/volumes.c +1 -1
@@ -4134,7 +4134,7 @@ static int __btrfs_alloc_chunk(struct btif (type &BTRFS_BLOCK_GROUP_DATA ) { max_stripe_size =1024 *1024 *1024 ; - max_chunk_size =10 * max_stripe_size; + max_chunk_size =BTRFS_MAX_DATA_CHUNK_SIZE ;if (!devs_max) devs_max =BTRFS_MAX_DEVS (info->chunk_root); }else if (type &BTRFS_BLOCK_GROUP_METADATA ) {
fs/btrfs/volumes.h +2 -0
@@ -24,6 +24,8 @@#include <linux/btrfs.h> #include "async-thread.h" +#define BTRFS_MAX_DATA_CHUNK_SIZE (10ULL * SZ_1G) +#define BTRFS_STRIPE_LEN (64 * 1024)struct buffer_head ;
PATCH 49/245 btrfs: tree-checker: Detect invalid and empty essential trees
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit ba480dd4db9f1798541eb2d1c423fc95feee8d36 upstream.
A crafted image has empty root tree block, which will later cause NULL pointer dereference.
The following trees should never be empty:
1) Tree root
Must contain at least root items for extent tree, device tree and fs tree
2) Chunk tree
Or we can't even bootstrap as it contains the mapping.
3) Fs tree
At least inode item for top level inode (.).
4) Device tree
Dev extents for chunks
5) Extent tree
Must have corresponding extent for each chunk.
If any of them is empty, we are sure the fs is corrupted and no need to mount it.
--- fs/btrfs/tree-checker.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
fs/btrfs/tree-checker.c +14 -1
@@ -456,9 +456,22 @@ static int check_leaf(struct btrfs_root* skip this check for relocation trees. */ if (nritems ==0 && !btrfs_header_flag (leaf,BTRFS_HEADER_FLAG_RELOC )) { +u64 owner =btrfs_header_owner (leaf);struct btrfs_root *check_root; - key.objectid =btrfs_header_owner (leaf); +/* These trees must never be empty */ +if (owner ==BTRFS_ROOT_TREE_OBJECTID || + owner ==BTRFS_CHUNK_TREE_OBJECTID || + owner ==BTRFS_EXTENT_TREE_OBJECTID || + owner ==BTRFS_DEV_TREE_OBJECTID || + owner ==BTRFS_FS_TREE_OBJECTID || + owner ==BTRFS_DATA_RELOC_TREE_OBJECTID ) { +generic_err (root, leaf,0 , +"invalid root, root %llu must never be empty" , + owner); +return -EUCLEAN ; + } + key.objectid = owner; key.type =BTRFS_ROOT_ITEM_KEY ; key.offset = (u64)-1 ;
PATCH 50/245 btrfs: validate type when reading a chunk
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Gu Jinxiang <[email protected]>
commit 315409b0098fb2651d86553f0436b70502b29bb2 upstream.
Reported in https://bugzilla.kernel.org/show_bug.cgi?id=199839, with an image that has an invalid chunk type but does not return an error.
Add chunk type check in btrfs_check_chunk_valid, to detect the wrong type combinations.
--- fs/btrfs/volumes.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
fs/btrfs/volumes.c +28 -0
@@ -5815,6 +5815,8 @@ static int btrfs_check_chunk_valid(strucu16 num_stripes;u16 sub_stripes;u64 type; +u64 features; +bool mixed = false; length =btrfs_chunk_length (leaf, chunk); stripe_len =btrfs_chunk_stripe_len (leaf, chunk);
@@ -5855,6 +5857,32 @@ static int btrfs_check_chunk_valid(struc btrfs_chunk_type(leaf, chunk));return -EIO ; } + +if ((type &BTRFS_BLOCK_GROUP_TYPE_MASK ) ==0 ) { +btrfs_err (root->fs_info,"missing chunk type flag: 0x%llx" , type); +return -EIO ; + } + +if ((type &BTRFS_BLOCK_GROUP_SYSTEM ) && + (type & (BTRFS_BLOCK_GROUP_METADATA |BTRFS_BLOCK_GROUP_DATA ))) { +btrfs_err (root->fs_info, +"system chunk with data or metadata type: 0x%llx" , type); +return -EIO ; + } + + features =btrfs_super_incompat_flags (root->fs_info->super_copy); +if (features &BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS ) + mixed = true; + +if (!mixed) { +if ((type &BTRFS_BLOCK_GROUP_METADATA ) && + (type &BTRFS_BLOCK_GROUP_DATA )) { +btrfs_err (root->fs_info, +"mixed chunk type in non-mixed mode: 0x%llx" , type); +return -EIO ; + } + } + if ((type & BTRFS_BLOCK_GROUP_RAID10 && sub_stripes != 2) || (type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes < 1) || (type & BTRFS_BLOCK_GROUP_RAID5 && num_stripes < 2) ||
PATCH 51/245 btrfs: Check that each block group has corresponding chunk at mount time
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit 514c7dca85a0bf40be984dab0b477403a6db901f upstream.
A crafted btrfs image with incorrect chunk<->block group mapping will trigger a lot of unexpected things as the mapping is essential.
Although the problem can be caught by block group item checker added in "btrfs: tree-checker: Verify block_group_item", it's still not sufficient. A sufficiently valid block group item can pass the check added by the mentioned patch but could fail to match the existing chunk.
This patch will add extra block group -> chunk mapping check, to ensure we have a completely matching (start, len, flags) chunk for each block group at mount time.
Here we reuse the original helper find_first_block_group(), which is already doing the basic bg -> chunk checks, adding further checks of the start/len and type flags.
--- fs/btrfs/extent-tree.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
fs/btrfs/extent-tree.c +27 -1
@@ -8556,6 +8556,8 @@ static int find_first_block_group(structint ret =0 ;struct btrfs_key found_key;struct extent_buffer *leaf; +struct btrfs_block_group_item bg; +u64 flags;int slot; ret =btrfs_search_slot (NULL , root, key, path,0 ,0 );
@@ -8590,8 +8592,32 @@ static int find_first_block_group(struct"logical %llu len %llu found bg but no related chunk" , found_key.objectid, found_key.offset); ret = -ENOENT ; + }else if (em->start != found_key.objectid || + em->len != found_key.offset) { +btrfs_err (root->fs_info, +"block group %llu len %llu mismatch with chunk %llu len %llu" , + found_key.objectid, found_key.offset, + em->start, em->len); + ret = -EUCLEAN ; }else { - ret =0 ; +read_extent_buffer (leaf, &bg, +btrfs_item_ptr_offset (leaf, slot), +sizeof (bg)); + flags =btrfs_block_group_flags (&bg) & +BTRFS_BLOCK_GROUP_TYPE_MASK ; + +if (flags != (em->map_lookup->type & +BTRFS_BLOCK_GROUP_TYPE_MASK )) { +btrfs_err (root->fs_info, +"block group %llu len %llu type flags 0x%llx mismatch with chunk type flags 0x%llx" , + found_key.objectid, + found_key.offset, flags, + (BTRFS_BLOCK_GROUP_TYPE_MASK & + em->map_lookup->type)); + ret = -EUCLEAN ; + }else { + ret =0 ; + } }free_extent_map (em); goto out;
PATCH 52/245 btrfs: Verify that every chunk has corresponding block group at mount time
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit 7ef49515fa6727cb4b6f2f5b0ffbc5fc20a9f8c6 upstream.
If a crafted image has missing block group items, it could cause unexpected behavior and breaks the assumption of 1:1 chunk<->block group mapping.
Although we have the block group -> chunk mapping check, we still need chunk -> block group mapping check.
This patch will do extra check to ensure each chunk has its corresponding block group.
--- fs/btrfs/extent-tree.c | 58 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-)
fs/btrfs/extent-tree.c +57 -1
@@ -8819,6 +8819,62 @@ btrfs_create_block_group_cache(struct btreturn cache; } + +/* +* Iterate all chunks and verify that each of them has the corresponding block +* group +*/ +static int check_chunk_block_group_mappings (struct btrfs_fs_info *fs_info) +{ +struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree; +struct extent_map *em; +struct btrfs_block_group_cache *bg; +u64 start =0 ; +int ret =0 ; + +while (1 ) { +read_lock (&map_tree->map_tree.lock); +/* +* lookup_extent_mapping will return the first extent map +* intersecting the range, so setting @len to 1 is enough to +* get the first chunk. +*/ + em =lookup_extent_mapping (&map_tree->map_tree, start,1 ); +read_unlock (&map_tree->map_tree.lock); +if (!em) +break ; + + bg =btrfs_lookup_block_group (fs_info, em->start); +if (!bg) { +btrfs_err (fs_info, +"chunk start=%llu len=%llu doesn't have corresponding block group" , + em->start, em->len); + ret = -EUCLEAN ; +free_extent_map (em); +break ; + } +if (bg->key.objectid != em->start || + bg->key.offset != em->len || + (bg->flags &BTRFS_BLOCK_GROUP_TYPE_MASK ) != + (em->map_lookup->type &BTRFS_BLOCK_GROUP_TYPE_MASK )) { +btrfs_err (fs_info, +"chunk start=%llu len=%llu flags=0x%llx doesn't match block group start=%llu len=%llu flags=0x%llx" , + em->start, em->len, + em->map_lookup->type &BTRFS_BLOCK_GROUP_TYPE_MASK , + bg->key.objectid, bg->key.offset, + bg->flags &BTRFS_BLOCK_GROUP_TYPE_MASK ); + ret = -EUCLEAN ; +free_extent_map (em); +btrfs_put_block_group (bg); +break ; + } + start = em->start + em->len; +free_extent_map (em); +btrfs_put_block_group (bg); + } +return ret; +} +int btrfs_read_block_groups (struct btrfs_root *root) {struct btrfs_path *path;
@@ -8981,7 +9037,7 @@ int btrfs_read_block_groups(struct btrfs }init_global_block_rsv (info); - ret =0 ; + ret =check_chunk_block_group_mappings (info); error:btrfs_free_path (path);return ret;
PATCH 53/245 btrfs: tree-checker: Check level for leaves and nodes
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit f556faa46eb4e96d0d0772e74ecf66781e132f72 upstream.
Although we have tree level check at tree read runtime, it's completely based on its parent level.
We still need to do accurate level check to avoid invalid tree blocks sneak into kernel space.
The check itself is simple, for leaf its level should always be 0. For nodes its level should be in range [1, BTRFS_MAX_LEVEL - 1].
[bwh: Backported to 4.4:
- Pass root instead of fs_info to generic_err()
- Adjust context]
--- fs/btrfs/tree-checker.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
fs/btrfs/tree-checker.c +14 -0
@@ -447,6 +447,13 @@ static int check_leaf(struct btrfs_rootu32 nritems =btrfs_header_nritems (leaf);int slot; +if (btrfs_header_level (leaf) !=0 ) { +generic_err (root, leaf,0 , +"invalid level for leaf, have %d expect 0" , +btrfs_header_level (leaf)); +return -EUCLEAN ; + } +/* * Extent buffers from a relocation tree have a owner field that * corresponds to the subvolume tree they are based on. So just from an
@@ -589,9 +596,16 @@ int btrfs_check_node(struct btrfs_root *unsigned long nr =btrfs_header_nritems (node);struct btrfs_key key, next_key;int slot; +int level =btrfs_header_level (node);u64 bytenr;int ret =0 ; +if (level <=0 || level >=BTRFS_MAX_LEVEL ) { +generic_err (root, node,0 , +"invalid level for node, have %d expect [1, %d]" , + level,BTRFS_MAX_LEVEL -1 ); +return -EUCLEAN ; + }if (nr ==0 || nr >BTRFS_NODEPTRS_PER_BLOCK (root)) { btrfs_crit(root->fs_info, "corrupt node: root=%llu block=%llu, nritems too %s, have %lu expect range [1,%zu]",
PATCH 54/245 btrfs: tree-checker: Fix misleading group system information
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Shaokun Zhang <[email protected]>
commit 761333f2f50ccc887aa9957ae829300262c0d15b upstream.
block_group_err shows the group system as a decimal value with a '0x' prefix, which is somewhat misleading.
Fix it to print hexadecimal, as was intended.
--- fs/btrfs/tree-checker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-checker.c +1 -1
@@ -399,7 +399,7 @@ static int check_block_group_item(struct type != (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA)) { block_group_err(fs_info, leaf, slot, -"invalid type, have 0x%llx (%lu bits set) expect either 0x%llx, 0x%llx, 0x%llu or 0x%llx", +"invalid type, have 0x%llx (%lu bits set) expect either 0x%llx, 0x%llx, 0x%llx or 0x%llx", type, hweight64(type), BTRFS_BLOCK_GROUP_DATA, BTRFS_BLOCK_GROUP_METADATA, BTRFS_BLOCK_GROUP_SYSTEM,
PATCH 55/245 btrfs: ensure that a DUP or RAID1 block group has exactly two stripes
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Thumshirn <[email protected]>
commit 349ae63f40638a28c6fce52e8447c2d14b84cc0c upstream.
We recently had a customer issue with a corrupted filesystem. When trying to mount this image btrfs panicked with a division by zero in calc_stripe_length().
The corrupt chunk had a 'num_stripes' value of 1. calc_stripe_length() takes this value and divides it by the number of copies the RAID profile is expected to have to calculate the amount of data stripes. As a DUP profile is expected to have 2 copies this division resulted in 1/2 = 0. Later then the 'data_stripes' variable is used as a divisor in the stripe length calculation which results in a division by 0 and thus a kernel panic.
When encountering a filesystem with a DUP block group and a 'num_stripes' value unequal to 2, refuse mounting as the image is corrupted and will lead to unexpected behaviour.
Code inspection showed a RAID1 block group has the same issues.
--- fs/btrfs/volumes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +2 -2
@@ -5884,10 +5884,10 @@ static int btrfs_check_chunk_valid(struc }if ((type &BTRFS_BLOCK_GROUP_RAID10 && sub_stripes !=2 ) || - (type &BTRFS_BLOCK_GROUP_RAID1 && num_stripes <1 ) || + (type &BTRFS_BLOCK_GROUP_RAID1 && num_stripes !=2 ) || (type &BTRFS_BLOCK_GROUP_RAID5 && num_stripes <2 ) || (type &BTRFS_BLOCK_GROUP_RAID6 && num_stripes <3 ) || - (type &BTRFS_BLOCK_GROUP_DUP && num_stripes >2 ) || + (type &BTRFS_BLOCK_GROUP_DUP && num_stripes !=2 ) || ((type &BTRFS_BLOCK_GROUP_PROFILE_MASK ) ==0 && num_stripes !=1 )) { btrfs_err(root->fs_info,
PATCH 56/245 dm: do not override error code returned from dm_get_device()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Vivek Goyal <[email protected]>
commit e80d1c805a3b2f0ad2081369be5dc5deedd5ee59 upstream.
Some of the device mapper targets override the error code returned by dm_get_device() and return either -EINVAL or -ENXIO. There is nothing gained by this override. It is better to propagate the returned error code unchanged to caller.
This work was motivated by hitting an issue where the underlying device was busy but -EINVAL was being returned. After this change we get -EBUSY instead and it is easier to figure out the problem.
---
drivers/md/dm-crypt.c +3 -1
@@ -1762,11 +1762,13 @@ static int crypt_ctr(struct dm_target *t } cc->iv_offset = tmpll; -if (dm_get_device (ti, argv[3 ],dm_table_get_mode (ti->table), &cc->dev)) { + ret =dm_get_device (ti, argv[3 ],dm_table_get_mode (ti->table), &cc->dev); +if (ret) { ti->error ="Device lookup failed" ; goto bad; } + ret = -EINVAL ;if (sscanf (argv[4 ],"%llu%c" , &tmpll, &dummy) !=1 ) { ti->error ="Invalid device sector" ; goto bad;
drivers/md/dm-delay.c +11 -5
@@ -129,6 +129,7 @@ static int delay_ctr(struct dm_target *tstruct delay_c *dc;unsigned long long tmpll;char dummy; +int ret;if (argc !=3 && argc !=6 ) { ti->error ="requires exactly 3 or 6 arguments" ;
@@ -143,6 +144,7 @@ static int delay_ctr(struct dm_target *t dc->reads = dc->writes =0 ; + ret = -EINVAL ;if (sscanf (argv[1 ],"%llu%c" , &tmpll, &dummy) !=1 ) { ti->error ="Invalid device sector" ; goto bad;
@@ -154,12 +156,14 @@ static int delay_ctr(struct dm_target *t goto bad; } -if (dm_get_device (ti, argv[0 ],dm_table_get_mode (ti->table), - &dc->dev_read)) { + ret =dm_get_device (ti, argv[0 ],dm_table_get_mode (ti->table), + &dc->dev_read); +if (ret) { ti->error ="Device lookup failed" ; goto bad; } + ret = -EINVAL ; dc->dev_write =NULL ;if (argc ==3 ) goto out;
@@ -175,13 +179,15 @@ static int delay_ctr(struct dm_target *t goto bad_dev_read; } -if (dm_get_device (ti, argv[3 ],dm_table_get_mode (ti->table), - &dc->dev_write)) { + ret =dm_get_device (ti, argv[3 ],dm_table_get_mode (ti->table), + &dc->dev_write); +if (ret) { ti->error ="Write device lookup failed" ; goto bad_dev_read; } out: + ret = -EINVAL ; dc->kdelayd_wq =alloc_workqueue ("kdelayd" ,WQ_MEM_RECLAIM ,0 );if (!dc->kdelayd_wq) {DMERR ("Couldn't start kdelayd" );
@@ -208,7 +214,7 @@ bad_dev_read:dm_put_device (ti, dc->dev_read); bad:kfree (dc); -return -EINVAL ; +return ret; }static void delay_dtr (struct dm_target *ti)
drivers/md/dm-flakey.c +4 -2
@@ -183,6 +183,7 @@ static int flakey_ctr(struct dm_target * devname =dm_shift_arg (&as); + r = -EINVAL ;if (sscanf (dm_shift_arg (&as),"%llu%c" , &tmpll, &dummy) !=1 ) { ti->error ="Invalid device sector" ; goto bad;
@@ -211,7 +212,8 @@ static int flakey_ctr(struct dm_target *if (r) goto bad; -if (dm_get_device (ti, devname,dm_table_get_mode (ti->table), &fc->dev)) { + r =dm_get_device (ti, devname,dm_table_get_mode (ti->table), &fc->dev); +if (r) { ti->error ="Device lookup failed" ; goto bad; }
@@ -224,7 +226,7 @@ static int flakey_ctr(struct dm_target * bad:kfree (fc); -return -EINVAL ; +return r; }static void flakey_dtr (struct dm_target *ti)
drivers/md/dm-linear.c +5 -2
@@ -30,6 +30,7 @@ static int linear_ctr(struct dm_target *struct linear_c *lc;unsigned long long tmp;char dummy; +int ret;if (argc !=2 ) { ti->error ="Invalid argument count" ;
@@ -42,13 +43,15 @@ static int linear_ctr(struct dm_target *return -ENOMEM ; } + ret = -EINVAL ;if (sscanf (argv[1 ],"%llu%c" , &tmp, &dummy) !=1 ) { ti->error ="dm-linear: Invalid device sector" ; goto bad; } lc->start = tmp; -if (dm_get_device (ti, argv[0 ],dm_table_get_mode (ti->table), &lc->dev)) { + ret =dm_get_device (ti, argv[0 ],dm_table_get_mode (ti->table), &lc->dev); +if (ret) { ti->error ="dm-linear: Device lookup failed" ; goto bad; }
@@ -61,7 +64,7 @@ static int linear_ctr(struct dm_target * bad:kfree (lc); -return -EINVAL ; +return ret; }static void linear_dtr (struct dm_target *ti)
drivers/md/dm-raid1.c +5 -3
@@ -923,16 +923,18 @@ static int get_mirror(struct mirror_set {unsigned long long offset;char dummy; +int ret;if (sscanf (argv[1 ],"%llu%c" , &offset, &dummy) !=1 ) { ti->error ="Invalid offset" ;return -EINVAL ; } -if (dm_get_device (ti, argv[0 ],dm_table_get_mode (ti->table), - &ms->mirror[mirror].dev)) { + ret =dm_get_device (ti, argv[0 ],dm_table_get_mode (ti->table), + &ms->mirror[mirror].dev); +if (ret) { ti->error ="Device lookup failure" ; -return -ENXIO ; +return ret; } ms->mirror[mirror].ms = ms;
drivers/md/dm-stripe.c +5 -3
@@ -75,13 +75,15 @@ static int get_stripe(struct dm_target * {unsigned long long start;char dummy; +int ret;if (sscanf (argv[1 ],"%llu%c" , &start, &dummy) !=1 )return -EINVAL ; -if (dm_get_device (ti, argv[0 ],dm_table_get_mode (ti->table), - &sc->stripe[stripe].dev)) -return -ENXIO ; + ret =dm_get_device (ti, argv[0 ],dm_table_get_mode (ti->table), + &sc->stripe[stripe].dev); +if (ret) +return ret; sc->stripe[stripe].physical_start = start;
PATCH 57/245 dm flakey: return -EINVAL on interval bounds error in flakey_ctr()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Wei Yongjun <[email protected]>
commit bff7e067ee518f9ed7e1cbc63e4c9e01670d0b71 upstream.
Fix to return error code -EINVAL instead of 0, as is done elsewhere in this function.
--- drivers/md/dm-flakey.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/md/dm-flakey.c +2 -0
@@ -200,11 +200,13 @@ static int flakey_ctr(struct dm_target *if (!(fc->up_interval + fc->down_interval)) { ti->error ="Total (up + down) interval is zero" ; + r = -EINVAL ; goto bad; }if (fc->up_interval + fc->down_interval < fc->up_interval) { ti->error ="Interval overflow" ; + r = -EINVAL ; goto bad; }
PATCH 58/245 dm flakey: fix reads to be issued if drop_writes configured
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mike Snitzer <[email protected]>
commit 299f6230bc6d0ccd5f95bb0fb865d80a9c7d5ccc upstream.
v4.8-rc3 commit 99f3c90d0d ("dm flakey: error READ bios during the down_interval") overlooked the 'drop_writes' feature, which is meant to allow reads to be issued rather than errored, during the down_interval.
--- drivers/md/dm-flakey.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
drivers/md/dm-flakey.c +16 -11
@@ -291,15 +291,13 @@ static int flakey_map(struct dm_target * pb->bio_submitted = true;/* -* Map reads as normal only if corrupt_bio_byte set. +* Error reads if neither corrupt_bio_byte or drop_writes are set. +* Otherwise, flakey_end_io() will decide if the reads should be modified. */ if (bio_data_dir (bio) ==READ ) { -/* If flags were specified, only corrupt those that match. */ -if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw ==READ ) && -all_corrupt_bio_flags_match (bio, fc)) - goto map_bio; -else +if (!fc->corrupt_bio_byte && !test_bit (DROP_WRITES , &fc->flags))return -EIO ; + goto map_bio; }/*
@@ -336,14 +334,21 @@ static int flakey_end_io(struct dm_targestruct flakey_c *fc = ti->private;struct per_bio_data *pb =dm_per_bio_data (bio,sizeof (struct per_bio_data )); -/* -* Corrupt successful READs while in down state. -*/ if (!error && pb->bio_submitted && (bio_data_dir (bio) ==READ )) { -if (fc->corrupt_bio_byte) +if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw ==READ ) && +all_corrupt_bio_flags_match (bio, fc)) { +/* +* Corrupt successful matching READs while in down state. +*/ corrupt_bio_data (bio, fc); -else + + }else if (!test_bit (DROP_WRITES , &fc->flags)) { +/* +* Error read during the down_interval if drop_writes +* wasn't configured. +*/ return -EIO ; + } }return error;
PATCH 59/245 dm flakey: check for null arg_name in parse_features()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Goldwyn Rodrigues <[email protected]>
commit 7690e25302dc7d0cd42b349e746fe44b44a94f2b upstream.
One can crash dm-flakey by specifying more feature arguments than the number of features supplied. Checking for null in arg_name avoids this.
dmsetup create flakey-test --table "0 66076080 flakey /dev/sdb9 0 0 180 2 drop_writes"
--- drivers/md/dm-flakey.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/md/dm-flakey.c +5 -0
@@ -69,6 +69,11 @@ static int parse_features(struct dm_arg_ arg_name =dm_shift_arg (as); argc--; +if (!arg_name) { + ti->error ="Insufficient feature arguments" ; +return -EINVAL ; + } +/* * drop_writes */
PATCH 60/245 x86/pti/efi: broken conversion from efi to kernel page table
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Pavel Tatashin <[email protected]>
In entry_64.S we have code like this:
/* Unconditionally use kernel CR3 for do_nmi() */
/* %rax is saved above, so OK to clobber here */
ALTERNATIVE "jmp 2f", "movq %cr3, %rax", X86_FEATURE_KAISER
/* If PCID enabled, NOFLUSH now and NOFLUSH on return */
ALTERNATIVE "", "bts $63, %rax", X86_FEATURE_PCID
pushq %rax
/* mask off "user" bit of pgd address and 12 PCID bits: */
andq $(~(X86_CR3_PCID_ASID_MASK | KAISER_SHADOW_PGD_OFFSET)), %rax
movq %rax, %cr32:
/* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
call do_nmiWith this instruction:
andq $(~(X86_CR3_PCID_ASID_MASK | KAISER_SHADOW_PGD_OFFSET)), %rax
We unconditionally switch from whatever our CR3 was to kernel page table. But, in arch/x86/platform/efi/efi_64.c We temporarily set a different page table, that does not have the kernel page table with 0x1000 offset from it.
Look in efi_thunk() and efi_thunk_set_virtual_address_map().
So, while CR3 points to the other page table, we get an NMI interrupt, and clear 0x1000 from CR3, resulting in a bogus CR3 if the 0x1000 bit was set.
The efi page table comes from realmode/rm/trampoline_64.S:
arch/x86/realmode/rm/trampoline_64.S
141 .bss
142 .balign PAGE_SIZE
143 GLOBAL(trampoline_pgd) .space PAGE_SIZE
Notice: alignment is PAGE_SIZE, so after applying KAISER_SHADOW_PGD_OFFSET which equal to PAGE_SIZE, we can get a different page table.
But, even if we fix alignment, here the trampoline binary is later copied into dynamically allocated memory in reserve_real_mode(), so we need to fix that place as well.
--- arch/x86/include/asm/kaiser.h | 10 ++++++++++ arch/x86/realmode/init.c | 4 +++- arch/x86/realmode/rm/trampoline_64.S | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-)
arch/x86/include/asm/kaiser.h +10 -0
@@ -19,6 +19,16 @@#define KAISER_SHADOW_PGD_OFFSET 0x1000 +#ifdef CONFIG_PAGE_TABLE_ISOLATION +/* +* A page table address must have this alignment to stay the same when +* KAISER_SHADOW_PGD_OFFSET mask is applied +*/ +#define KAISER_KERNEL_PGD_ALIGNMENT (KAISER_SHADOW_PGD_OFFSET << 1) +#else +#define KAISER_KERNEL_PGD_ALIGNMENT PAGE_SIZE +#endif +#ifdef __ASSEMBLY__#ifdef CONFIG_PAGE_TABLE_ISOLATION
arch/x86/realmode/init.c +3 -1
@@ -4,6 +4,7 @@#include <asm/cacheflush.h> #include <asm/pgtable.h> #include <asm/realmode.h> +#include <asm/kaiser.h> struct real_mode_header *real_mode_header;u32 *trampoline_cr4_features;
@@ -15,7 +16,8 @@ void __init reserve_real_mode(void)size_t size =PAGE_ALIGN (real_mode_blob_end - real_mode_blob);/* Has to be under 1M so we can execute real-mode AP code. */ - mem =memblock_find_in_range (0 ,1 <<20 , size,PAGE_SIZE ); + mem =memblock_find_in_range (0 ,1 <<20 , size, +KAISER_KERNEL_PGD_ALIGNMENT );if (!mem)panic ("Cannot allocate trampoline\n" );
arch/x86/realmode/rm/trampoline_64.S +2 -1
@@ -30,6 +30,7 @@ #include <asm/msr.h> #include <asm/segment.h> #include <asm/processor-flags.h> +#include <asm/kaiser.h> #include "realmode.h" .text
@@ -139,7 +140,7 @@ tr_gdt: tr_gdt_end: .bss - .balign PAGE_SIZE + .balign KAISER_KERNEL_PGD_ALIGNMENT GLOBAL(trampoline_pgd) .space PAGE_SIZE .balign 8
PATCH 61/245 batman-adv: Fix DAT candidate selection on little endian systems
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 4cc4a1708903f404d2ca0dfde30e71e052c6cbc9 upstream.
The distributed arp table is using a DHT to store and retrieve MAC address information for an IP address. This is done using unicast messages to selected peers. The potential peers are looked up using the IP address and the VID.
While the IP address is always stored in big endian byte order, this is not the case of the VID. It can (depending on the host system) either be big endian or little endian. The host must therefore always convert it to big endian to ensure that all devices calculate the same peers for the same lookup data.
--- net/batman-adv/distributed-arp-table.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/batman-adv/distributed-arp-table.c +3 -1
@@ -207,9 +207,11 @@ static uint32_t batadv_hash_dat(const vo {uint32_t hash =0 ;const struct batadv_dat_entry *dat = data; +__be16 vid; hash =batadv_hash_bytes (hash, &dat->ip,sizeof (dat->ip)); - hash =batadv_hash_bytes (hash, &dat->vid,sizeof (dat->vid)); + vid =htons (dat->vid); + hash =batadv_hash_bytes (hash, &vid,sizeof (vid)); hash += (hash <<3 ); hash ^= (hash >>11 );
PATCH 62/245 netfilter: ctnetlink: netns exit must wait for callbacks
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit 18a110b022a5c02e7dc9f6109d0bd93e58ac6ebb upstream.
Curtis Taylor and Jon Maxwell reported and debugged a crash on 3.10 based kernel.
Crash occurs in ctnetlink_conntrack_events because net->nfnl socket is NULL. The nfnl socket was set to NULL by netns destruction running on another cpu.
The exiting network namespace calls the relevant destructors in the following order:
1. ctnetlink_net_exit_batch
This nulls out the event callback pointer in struct netns.
2. nfnetlink_net_exit_batch
This nulls net->nfnl socket and frees it.
3. nf_conntrack_cleanup_net_list
This removes all remaining conntrack entries.
This is order is correct. The only explanation for the crash so ar is:
cpu1: conntrack is dying, eviction occurs:
-> nf_ct_delete()
-> nf_conntrack_event_report \
-> nf_conntrack_eventmask_report
-> notify->fcn() (== ctnetlink_conntrack_events).cpu1: a. fetches rcu protected pointer to obtain ctnetlink event callback.
b. gets interrupted.
cpu2: runs netns exit handlers:
a runs ctnetlink destructor, event cb pointer set to NULL. b runs nfnetlink destructor, nfnl socket is closed and set to NULL.
cpu1: c. resumes and trips over NULL net->nfnl.
Problem appears to be that ctnetlink_net_exit_batch only prevents future callers of nf_conntrack_eventmask_report() from obtaining the callback. It doesn't wait of other cpus that might have already obtained the callbacks address.
I don't see anything in upstream kernels that would prevent similar
crash: We need to wait for all cpus to have exited the event callback.
--- net/netfilter/nf_conntrack_netlink.c | 3 +++ 1 file changed, 3 insertions(+)
net/netfilter/nf_conntrack_netlink.c +3 -0
@@ -3225,6 +3225,9 @@ static void __net_exit ctnetlink_net_exilist_for_each_entry (net, net_exit_list, exit_list)ctnetlink_net_exit (net); + +/* wait for other cpus until they are done with ctnl_notifiers */ +synchronize_rcu (); }static struct pernet_operations ctnetlink_net_ops = {
PATCH 63/245 taskstats: fix data-race
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
commit 0b8d616fb5a8ffa307b1d3af37f55c15dae14f28 upstream.
When assiging and testing taskstats in taskstats_exit() there's a race when setting up and reading sig->stats when a thread-group with more than one thread exits:
write to 0xffff8881157bbe10 of 8 bytes by task 7951 on cpu 0:
taskstats_tgid_alloc kernel/taskstats.c:567 [inline] taskstats_exit+0x6b7/0x717 kernel/taskstats.c:596 do_exit+0x2c2/0x18e0 kernel/exit.c:864 do_group_exit+0xb4/0x1c0 kernel/exit.c:983 get_signal+0x2a2/0x1320 kernel/signal.c:2734 do_signal+0x3b/0xc00 arch/x86/kernel/signal.c:815 exit_to_usermode_loop+0x250/0x2c0 arch/x86/entry/common.c:159 prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline] syscall_return_slowpath arch/x86/entry/common.c:274 [inline] do_syscall_64+0x2d7/0x2f0 arch/x86/entry/common.c:299 entry_SYSCALL_64_after_hwframe+0x44/0xa9
read to 0xffff8881157bbe10 of 8 bytes by task 7949 on cpu 1:
taskstats_tgid_alloc kernel/taskstats.c:559 [inline] taskstats_exit+0xb2/0x717 kernel/taskstats.c:596 do_exit+0x2c2/0x18e0 kernel/exit.c:864 do_group_exit+0xb4/0x1c0 kernel/exit.c:983 __do_sys_exit_group kernel/exit.c:994 [inline] __se_sys_exit_group kernel/exit.c:992 [inline] __x64_sys_exit_group+0x2e/0x30 kernel/exit.c:992 do_syscall_64+0xcf/0x2f0 arch/x86/entry/common.c:296 entry_SYSCALL_64_after_hwframe+0x44/0xa9
Fix this by using smp_load_acquire() and smp_store_release().
--- kernel/taskstats.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
kernel/taskstats.c +19 -11
@@ -591,25 +591,33 @@ static int taskstats_user_cmd(struct sk_static struct taskstats *taskstats_tgid_alloc (struct task_struct *tsk) {struct signal_struct *sig = tsk->signal; -struct taskstats *stats; +struct taskstats *stats_new, *stats; -if (sig->stats ||thread_group_empty (tsk)) - goto ret; +/* Pairs with smp_store_release() below. */ + stats =smp_load_acquire (&sig->stats); +if (stats ||thread_group_empty (tsk)) +return stats;/* No problem if kmem_cache_zalloc() fails */ - stats =kmem_cache_zalloc (taskstats_cache,GFP_KERNEL ); + stats_new =kmem_cache_zalloc (taskstats_cache,GFP_KERNEL );spin_lock_irq (&tsk->sighand->siglock); -if (!sig->stats) { - sig->stats = stats; - stats =NULL ; + stats = sig->stats; +if (!stats) { +/* +* Pairs with smp_store_release() above and order the +* kmem_cache_zalloc(). +*/ +smp_store_release (&sig->stats, stats_new); + stats = stats_new; + stats_new =NULL ; }spin_unlock_irq (&tsk->sighand->siglock); -if (stats) -kmem_cache_free (taskstats_cache, stats); -ret: -return sig->stats; +if (stats_new) +kmem_cache_free (taskstats_cache, stats_new); + +return stats; }/* Send pid data out on exit */
PATCH 64/245 dm btree: increase rebalance threshold in __rebalance2()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Hou Tao <[email protected]>
commit 474e559567fa631dea8fb8407ab1b6090c903755 upstream.
We got the following warnings from thin_check during thin-pool setup:
$ thin_check /dev/vdb
examining superblock
examining devices tree
missing devices: [1, 84]
too few entries in btree_node: 41, expected at least 42 (block 138, max_entries = 126)
examining mapping treeThe phenomenon is the number of entries in one node of details_info tree is less than (max_entries / 3). And it can be easily reproduced by the following procedures:
$ new a thin pool
$ presume the max entries of details_info tree is 126
$ new 127 thin devices (e.g. 1~127) to make the root node being full
and then split
$ remove the first 43 (e.g. 1~43) thin devices to make the children
reblance repeatedly
$ stop the thin pool
$ thin_checkThe root cause is that the B-tree removal procedure in __rebalance2() doesn't guarantee the invariance: the minimal number of entries in non-root node should be >= (max_entries / 3).
Simply fix the problem by increasing the rebalance threshold to make sure the number of entries in each child will be greater than or equal to (max_entries / 3 + 1), so no matter which child is used for removal, the number will still be valid.
--- drivers/md/persistent-data/dm-btree-remove.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/md/persistent-data/dm-btree-remove.c +7 -1
@@ -203,7 +203,13 @@ static void __rebalance2(struct dm_btreestruct btree_node *right = r->n;uint32_t nr_left =le32_to_cpu (left->header.nr_entries);uint32_t nr_right =le32_to_cpu (right->header.nr_entries); -unsigned threshold =2 *merge_threshold (left) +1 ; +/* +* Ensure the number of entries in each child will be greater +* than or equal to (max_entries / 3 + 1), so no matter which +* child is used for removal, the number will still be not +* less than (max_entries / 3). +*/ +unsigned int threshold =2 * (merge_threshold (left) +1 );if (nr_left + nr_right < threshold) {/*
PATCH 65/245 dm thin metadata: Add support for a pre-commit callback
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nikos Tsironis <[email protected]>
commit ecda7c0280e6b3398459dc589b9a41c1adb45529 upstream.
Add support for one pre-commit callback which is run right before the metadata are committed.
This allows the thin provisioning target to run a callback before the metadata are committed and is required by the next commit.
[bwh: Backported to 3.16:
- Open-code pmd_write_{lock_in_core,unlock}()
- Adjust context]
--- drivers/md/dm-thin-metadata.c | 29 +++++++++++++++++++++++++++++ drivers/md/dm-thin-metadata.h | 7 +++++++ 2 files changed, 36 insertions(+)
drivers/md/dm-thin-metadata.c +29 -0
@@ -198,6 +198,15 @@ struct dm_pool_metadata { bool fail_io:1;/* +* Pre-commit callback. +* +* This allows the thin provisioning target to run a callback before +* the metadata are committed. +*/ +dm_pool_pre_commit_fn pre_commit_fn; +void *pre_commit_context; + +/* * Reading the space map roots can fail, so we read it into these * buffers before the superblock is locked and updated. */
@@ -784,6 +793,14 @@ static int __commit_transaction(struct d*/ BUILD_BUG_ON (sizeof (struct thin_disk_superblock ) >512 ); +if (pmd->pre_commit_fn) { + r = pmd->pre_commit_fn (pmd->pre_commit_context); +if (r <0 ) { +DMERR ("pre-commit callback failed" ); +return r; + } + } + r =__write_changed_details (pmd);if (r <0 )return r;
@@ -844,6 +861,8 @@ struct dm_pool_metadata *dm_pool_metadat pmd->fail_io = false; pmd->bdev = bdev; pmd->data_block_size = data_block_size; + pmd->pre_commit_fn =NULL ; + pmd->pre_commit_context =NULL ; r =__create_persistent_data_objects (pmd, format_device);if (r) {
@@ -1789,6 +1808,16 @@ int dm_pool_register_metadata_threshold(return r; } +void dm_pool_register_pre_commit_callback (struct dm_pool_metadata *pmd, +dm_pool_pre_commit_fn fn, +void *context) +{ +down_write (&pmd->root_lock); + pmd->pre_commit_fn = fn; + pmd->pre_commit_context = context; +up_write (&pmd->root_lock); +} +int dm_pool_metadata_set_needs_check (struct dm_pool_metadata *pmd) {int r;
drivers/md/dm-thin-metadata.h +7 -0
@@ -213,6 +213,13 @@ int dm_pool_register_metadata_threshold(int dm_pool_metadata_set_needs_check (struct dm_pool_metadata *pmd);bool dm_pool_metadata_needs_check (struct dm_pool_metadata *pmd); +/* Pre-commit callback */ +typedef int (*dm_pool_pre_commit_fn )(void *context); + +void dm_pool_register_pre_commit_callback (struct dm_pool_metadata *pmd, +dm_pool_pre_commit_fn fn, +void *context); +/*----------------------------------------------------------------*/ #endif
PATCH 66/245 pinctrl: baytrail: Relax GPIO request rules
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mika Westerberg <[email protected]>
commit f8323b6bb2cc7d26941d4838dd4375952980a88a upstream.
Zotac ZBOX PI320, a Baytrail based mini-PC, has power button connected to a GPIO pin and it is exposed to the operating system as Windows 8 button array. This is implemented in Linux as a driver using gpio_keys.
However, BIOS on this particula machine forgot to mux the pin to be a GPIO instead of native function, which results following message to be seen on the console:
byt_gpio INT33FC:02: pin 16 cannot be used as GPIO.
This causes power button to not work as the driver was not able to request the GPIO it needs.
So instead of completely preventing this we allow turning the pin as GPIO but issue warning that something might be wrong.
--- drivers/pinctrl/pinctrl-baytrail.c | 35 +++++++++++++++--------- 1 file changed, 22 insertions(+), 13 deletions(-)
drivers/pinctrl/pinctrl-baytrail.c +22 -13
@@ -160,40 +160,49 @@ static void __iomem *byt_gpio_reg(structreturn vg->reg_base + reg_offset + reg; } -static bool is_special_pin (struct byt_gpio *vg,unsigned offset) +static u32 byt_get_gpio_mux (struct byt_gpio *vg,unsigned offset) {/* SCORE pin 92-93 */ if (!strcmp (vg->range->name,BYT_SCORE_ACPI_UID ) && offset >=92 && offset <=93 ) -return true; +return 1 ;/* SUS pin 11-21 */ if (!strcmp (vg->range->name,BYT_SUS_ACPI_UID ) && offset >=11 && offset <=21 ) -return true; +return 1 ; -return false; +return 0 ; }static int byt_gpio_request (struct gpio_chip *chip,unsigned offset) {struct byt_gpio *vg =to_byt_gpio (chip);void __iomem *reg =byt_gpio_reg (chip, offset,BYT_CONF0_REG ); -u32 value; -bool special; +u32 value, gpio_mux;/* * In most cases, func pin mux 000 means GPIO function. * But, some pins may have func pin mux 001 represents -* GPIO function. Only allow user to export pin with -* func pin mux preset as GPIO function by BIOS/FW. +* GPIO function. +* +* Because there are devices out there where some pins were not +* configured correctly we allow changing the mux value from +* request (but print out warning about that). */ value =readl (reg) &BYT_PIN_MUX ; - special =is_special_pin (vg, offset); -if ((special && value !=1 ) || (!special && value)) { -dev_err (&vg->pdev->dev, -"pin %u cannot be used as GPIO.\n" , offset); -return -EINVAL ; + gpio_mux =byt_get_gpio_mux (vg, offset); +if (WARN_ON (gpio_mux != value)) { +unsigned long flags; + +spin_lock_irqsave (&vg->lock, flags); + value =readl (reg) & ~BYT_PIN_MUX ; + value |= gpio_mux; +writel (value, reg); +spin_unlock_irqrestore (&vg->lock, flags); + +dev_warn (&vg->pdev->dev, +"pin %u forcibly re-configured as GPIO\n" , offset); }pm_runtime_get (&vg->pdev->dev);
PATCH 67/245 pinctrl: baytrail: Clear interrupt triggering from pins that are in GPIO mode
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mika Westerberg <[email protected]>
commit 95f0972c7e4cbf3fc68160131c5ac2f033481d00 upstream.
If the pin is already configured as GPIO and it has any of the triggering flags set, we may get spurious interrupts depending on the state of the pin.
Prevent this by clearing the triggering flags on such pins. However, if the pin is also configured as "direct IRQ" we leave the flags as is. Otherwise it will prevent interrupts that are routed directly to IO-APIC.
[bwh: Backported to 3.16:
- Add definition of BYT_DIRECT_IRQ_EN
- Adjust filename]
---
drivers/pinctrl/pinctrl-baytrail.c +30 -7
@@ -44,6 +44,7 @@/* BYT_CONF0_REG register bits */ #define BYT_IODEN BIT(31) +#define BYT_DIRECT_IRQ_EN BIT(27)#define BYT_TRIG_NEG BIT(26)#define BYT_TRIG_POS BIT(25)#define BYT_TRIG_LVL BIT(24)
@@ -160,6 +161,19 @@ static void __iomem *byt_gpio_reg(structreturn vg->reg_base + reg_offset + reg; } +static void byt_gpio_clear_triggering (struct byt_gpio *vg,unsigned offset) +{ +void __iomem *reg =byt_gpio_reg (&vg->chip, offset,BYT_CONF0_REG ); +unsigned long flags; +u32 value; + +spin_lock_irqsave (&vg->lock, flags); + value =readl (reg); + value &= ~(BYT_TRIG_POS |BYT_TRIG_NEG |BYT_TRIG_LVL ); +writel (value, reg); +spin_unlock_irqrestore (&vg->lock, flags); +} +static u32 byt_get_gpio_mux (struct byt_gpio *vg,unsigned offset) {/* SCORE pin 92-93 */
@@ -213,14 +227,8 @@ static int byt_gpio_request(struct gpio_static void byt_gpio_free (struct gpio_chip *chip,unsigned offset) {struct byt_gpio *vg =to_byt_gpio (chip); -void __iomem *reg =byt_gpio_reg (&vg->chip, offset,BYT_CONF0_REG ); -u32 value; - -/* clear interrupt triggering */ - value =readl (reg); - value &= ~(BYT_TRIG_POS |BYT_TRIG_NEG |BYT_TRIG_LVL ); -writel (value, reg); +byt_gpio_clear_triggering (vg, offset);pm_runtime_put (&vg->pdev->dev); }
@@ -496,6 +504,21 @@ static void byt_gpio_irq_init_hw(struct {void __iomem *reg;u32 base, value; +int i; + +/* +* Clear interrupt triggers for all pins that are GPIOs and +* do not use direct IRQ mode. This will prevent spurious +* interrupts from misconfigured pins. +*/ +for (i =0 ; i < vg->chip.ngpio; i++) { + value =readl (byt_gpio_reg (&vg->chip, i,BYT_CONF0_REG )); +if ((value &BYT_PIN_MUX ) ==byt_get_gpio_mux (vg, i) && + !(value &BYT_DIRECT_IRQ_EN )) { +byt_gpio_clear_triggering (vg, i); +dev_dbg (&vg->pdev->dev,"disabling GPIO %d\n" , i); + } + }/* clear interrupt status trigger registers */ for (base =0 ; base < vg->chip.ngpio; base +=32 ) {
PATCH 68/245 pinctrl: baytrail: Rework interrupt handling
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mika Westerberg <[email protected]>
commit 31e4329f99062a06dca5a493bb4495a63b2dc6ba upstream.
Instead of handling everything in the driver's first level interrupt handler, we can take advantage of already existing flow handlers that are provided by the IRQ core.
This changes the functionality a bit also. Previously the driver looped over pending interrupts in a single loop, restarting the loop if some interrupt changed state. This caused problem with Lenovo Thinkpad 10 digitizer that it was not able to deassert the interrupt before the driver disabled the interrupt for good (looplimit was exhausted).
Rework the interrupt handling logic a bit so that we provide proper mask, ack and unmask operations in terms of Baytrail GPIO hardware and loop over pending interrupts only once. If the interrupt remains asserted the first level handler will be re-triggered automatically.
[bwh: Backported to 3.16 as dependency of commit 39ce8150a079
"pinctrl: baytrail: Serialize all register access":
- Adjust filename, context]
--- drivers/pinctrl/pinctrl-baytrail.c | 100 +++++++++++++---------- 1 file changed, 56 insertions(+), 44 deletions(-)
drivers/pinctrl/pinctrl-baytrail.c +56 -44
@@ -251,23 +251,13 @@ static int byt_irq_type(struct irq_data*/ value &= ~(BYT_TRIG_POS |BYT_TRIG_NEG |BYT_TRIG_LVL ); -switch (type) { -case IRQ_TYPE_LEVEL_HIGH : - value |=BYT_TRIG_LVL ; -case IRQ_TYPE_EDGE_RISING : - value |=BYT_TRIG_POS ; -break ; -case IRQ_TYPE_LEVEL_LOW : - value |=BYT_TRIG_LVL ; -case IRQ_TYPE_EDGE_FALLING : - value |=BYT_TRIG_NEG ; -break ; -case IRQ_TYPE_EDGE_BOTH : - value |= (BYT_TRIG_NEG |BYT_TRIG_POS ); -break ; - }writel (value, reg); +if (type &IRQ_TYPE_EDGE_BOTH ) +__irq_set_handler_locked (d->irq, handle_edge_irq); +else if (type &IRQ_TYPE_LEVEL_MASK ) +__irq_set_handler_locked (d->irq, handle_level_irq); +spin_unlock_irqrestore (&vg->lock, flags);return 0 ;
@@ -421,54 +411,75 @@ static void byt_gpio_irq_handler(unsignestruct irq_data *data =irq_desc_get_irq_data (desc);struct byt_gpio *vg =irq_data_get_irq_handler_data (data);struct irq_chip *chip =irq_data_get_irq_chip (data); -u32 base, pin, mask; +u32 base, pin;void __iomem *reg; -u32 pending; +unsigned long pending;unsigned virq; -int looplimit =0 ;/* check from GPIO controller which pin triggered the interrupt */ for (base =0 ; base < vg->chip.ngpio; base +=32 ) { - reg =byt_gpio_reg (&vg->chip, base,BYT_INT_STAT_REG ); - -while ((pending =readl (reg))) { - pin =__ffs (pending); - mask =BIT (pin); -/* Clear before handling so we can't lose an edge */ -writel (mask, reg); - + pending =readl (reg); +for_each_set_bit (pin, &pending,32 ) { virq =irq_find_mapping (vg->domain, base + pin);generic_handle_irq (virq); - -/* In case bios or user sets triggering incorretly a pin -* might remain in "interrupt triggered" state. -*/ -if (looplimit++ >32 ) { -dev_err (&vg->pdev->dev, -"Gpio %d interrupt flood, disabling\n" , - base + pin); - - reg =byt_gpio_reg (&vg->chip, base + pin, -BYT_CONF0_REG ); - mask =readl (reg); - mask &= ~(BYT_TRIG_NEG |BYT_TRIG_POS | -BYT_TRIG_LVL ); -writel (mask, reg); - mask =readl (reg);/* flush */ -break ; - } } } chip->irq_eoi (data); } +static void byt_irq_ack (struct irq_data *d) +{ +struct gpio_chip *gc =irq_data_get_irq_chip_data (d); +struct byt_gpio *vg =to_byt_gpio (gc); +unsigned offset =irqd_to_hwirq (d); +void __iomem *reg; + + reg =byt_gpio_reg (&vg->chip, offset,BYT_INT_STAT_REG ); +writel (BIT (offset %32 ), reg); +} +static void byt_irq_unmask (struct irq_data *d) { +struct gpio_chip *gc =irq_data_get_irq_chip_data (d); +struct byt_gpio *vg =to_byt_gpio (gc); +unsigned offset =irqd_to_hwirq (d); +unsigned long flags; +void __iomem *reg; +u32 value; + +spin_lock_irqsave (&vg->lock, flags); + + reg =byt_gpio_reg (&vg->chip, offset,BYT_CONF0_REG ); + value =readl (reg); + +switch (irqd_get_trigger_type (d)) { +case IRQ_TYPE_LEVEL_HIGH : + value |=BYT_TRIG_LVL ; +case IRQ_TYPE_EDGE_RISING : + value |=BYT_TRIG_POS ; +break ; +case IRQ_TYPE_LEVEL_LOW : + value |=BYT_TRIG_LVL ; +case IRQ_TYPE_EDGE_FALLING : + value |=BYT_TRIG_NEG ; +break ; +case IRQ_TYPE_EDGE_BOTH : + value |= (BYT_TRIG_NEG |BYT_TRIG_POS ); +break ; + } + +writel (value, reg); + +spin_unlock_irqrestore (&vg->lock, flags); }static void byt_irq_mask (struct irq_data *d) { +struct gpio_chip *gc =irq_data_get_irq_chip_data (d); +struct byt_gpio *vg =to_byt_gpio (gc); + +byt_gpio_clear_triggering (vg,irqd_to_hwirq (d)); }static int byt_irq_reqres (struct irq_data *d)
@@ -493,6 +504,7 @@ static void byt_irq_relres(struct irq_dastatic struct irq_chip byt_irqchip = { .name ="BYT-GPIO" , + .irq_ack = byt_irq_ack, .irq_mask = byt_irq_mask, .irq_unmask = byt_irq_unmask, .irq_set_type = byt_irq_type,
PATCH 69/245 pinctrl: baytrail: Serialize all register access
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mika Westerberg <[email protected]>
commit 39ce8150a079e3ae6ed9abf26d7918a558ef7c19 upstream.
There is a hardware issue in Intel Baytrail where concurrent GPIO register access might result reads of 0xffffffff and writes might get dropped completely.
Prevent this from happening by taking the serializing lock in all places where it is possible that more than one thread might be accessing the hardware concurrently.
--- drivers/pinctrl/pinctrl-baytrail.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/pinctrl/pinctrl-baytrail.c +16 -5
@@ -194,6 +194,9 @@ static int byt_gpio_request(struct gpio_struct byt_gpio *vg =to_byt_gpio (chip);void __iomem *reg =byt_gpio_reg (chip, offset,BYT_CONF0_REG );u32 value, gpio_mux; +unsigned long flags; + +spin_lock_irqsave (&vg->lock, flags);/* * In most cases, func pin mux 000 means GPIO function.
@@ -207,18 +210,16 @@ static int byt_gpio_request(struct gpio_ value =readl (reg) &BYT_PIN_MUX ; gpio_mux =byt_get_gpio_mux (vg, offset);if (WARN_ON (gpio_mux != value)) { -unsigned long flags; - -spin_lock_irqsave (&vg->lock, flags); value =readl (reg) & ~BYT_PIN_MUX ; value |= gpio_mux;writel (value, reg); -spin_unlock_irqrestore (&vg->lock, flags);dev_warn (&vg->pdev->dev,"pin %u forcibly re-configured as GPIO\n" , offset); } +spin_unlock_irqrestore (&vg->lock, flags); +pm_runtime_get (&vg->pdev->dev);return 0 ;
@@ -266,7 +267,15 @@ static int byt_irq_type(struct irq_datastatic int byt_gpio_get (struct gpio_chip *chip,unsigned offset) {void __iomem *reg =byt_gpio_reg (chip, offset,BYT_VAL_REG ); -return readl (reg) &BYT_LEVEL ; +struct byt_gpio *vg =to_byt_gpio (chip); +unsigned long flags; +u32 val; + +spin_lock_irqsave (&vg->lock, flags); + val =readl (reg); +spin_unlock_irqrestore (&vg->lock, flags); + +return val &BYT_LEVEL ; }static void byt_gpio_set (struct gpio_chip *chip,unsigned offset,int value)
@@ -435,8 +444,10 @@ static void byt_irq_ack(struct irq_dataunsigned offset =irqd_to_hwirq (d);void __iomem *reg; +spin_lock (&vg->lock); reg =byt_gpio_reg (&vg->chip, offset,BYT_INT_STAT_REG );writel (BIT (offset %32 ), reg); +spin_unlock (&vg->lock); }static void byt_irq_unmask (struct irq_data *d)
PATCH 70/245 pinctrl: baytrail: Really serialize all register accesses
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit 40ecab551232972a39cdd8b6f17ede54a3fdb296 upstream.
Commit 39ce8150a079 ("pinctrl: baytrail: Serialize all register access") added a spinlock around all register accesses because:
"There is a hardware issue in Intel Baytrail where concurrent GPIO register
access might result reads of 0xffffffff and writes might get dropped completely."
Testing has shown that this does not catch all cases, there are still 2 problems remaining
1) The original fix uses a spinlock per byt_gpio device / struct, additional testing has shown that this is not sufficient concurent accesses to 2 different GPIO banks also suffer from the same problem.
This commit fixes this by moving to a single global lock.
2) The original fix did not add a lock around the register accesses in the suspend/resume handling.
Since pinctrl-baytrail.c is using normal suspend/resume handlers, interrupts are still enabled during suspend/resume handling. Nothing should be using the GPIOs when they are being taken down, _but_ the GPIOs themselves may still cause interrupts, which are likely to use (read) the triggering GPIO. So we need to protect against concurrent GPIO register accesses in the suspend/resume handlers too.
This commit fixes this by adding the missing spin_lock / unlock calls.
The 2 fixes together fix the Acer Switch 10 SW5-012 getting completely confused after a suspend resume. The DSDT for this device has a bug in its _LID method which reprograms the home and power button trigger- flags requesting both high and low _level_ interrupts so the IRQs for these 2 GPIOs continuously fire. This combined with the saving of registers during suspend, triggers concurrent GPIO register accesses resulting in saving 0xffffffff as pconf0 value during suspend and then when restoring this on resume the pinmux settings get all messed up, resulting in various I2C busses being stuck, the wifi no longer working and often the tablet simply not coming out of suspend at all.
[bwh: Backported to 3.16:
- Drop changes in functions that don't exist here
- Delete local pointers to byt_gpio that become unused
- Adjust filename, context]
---
drivers/pinctrl/pinctrl-baytrail.c +22 -27
@@ -140,13 +140,14 @@ struct byt_gpio {struct gpio_chip chip;struct irq_domain *domain;struct platform_device *pdev; -spinlock_t lock;void __iomem *reg_base;struct pinctrl_gpio_range *range; };#define to_byt_gpio (c) container_of(c, struct byt_gpio, chip) +static DEFINE_RAW_SPINLOCK (byt_lock); +static void __iomem *byt_gpio_reg (struct gpio_chip *chip,unsigned offset,int reg) {
@@ -167,11 +168,11 @@ static void byt_gpio_clear_triggering(stunsigned long flags;u32 value; -spin_lock_irqsave (&vg->lock, flags); +raw_spin_lock_irqsave (&byt_lock, flags); value =readl (reg); value &= ~(BYT_TRIG_POS |BYT_TRIG_NEG |BYT_TRIG_LVL );writel (value, reg); -spin_unlock_irqrestore (&vg->lock, flags); +raw_spin_unlock_irqrestore (&byt_lock, flags); }static u32 byt_get_gpio_mux (struct byt_gpio *vg,unsigned offset)
@@ -196,7 +197,7 @@ static int byt_gpio_request(struct gpio_u32 value, gpio_mux;unsigned long flags; -spin_lock_irqsave (&vg->lock, flags); +raw_spin_lock_irqsave (&byt_lock, flags);/* * In most cases, func pin mux 000 means GPIO function.
@@ -218,7 +219,7 @@ static int byt_gpio_request(struct gpio_ "pin %u forcibly re-configured as GPIO\n", offset); } -spin_unlock_irqrestore (&vg->lock, flags); +raw_spin_unlock_irqrestore (&byt_lock, flags);pm_runtime_get (&vg->pdev->dev);
@@ -244,7 +245,7 @@ static int byt_irq_type(struct irq_dataif (offset >= vg->chip.ngpio)return -EINVAL ; -spin_lock_irqsave (&vg->lock, flags); +raw_spin_lock_irqsave (&byt_lock, flags); value =readl (reg);/* For level trigges the BYT_TRIG_POS and BYT_TRIG_NEG bits
@@ -259,7 +260,7 @@ static int byt_irq_type(struct irq_dataelse if (type &IRQ_TYPE_LEVEL_MASK )__irq_set_handler_locked (d->irq, handle_level_irq); -spin_unlock_irqrestore (&vg->lock, flags); +raw_spin_unlock_irqrestore (&byt_lock, flags);return 0 ; }
@@ -267,25 +268,23 @@ static int byt_irq_type(struct irq_datastatic int byt_gpio_get (struct gpio_chip *chip,unsigned offset) {void __iomem *reg =byt_gpio_reg (chip, offset,BYT_VAL_REG ); -struct byt_gpio *vg =to_byt_gpio (chip);unsigned long flags;u32 val; -spin_lock_irqsave (&vg->lock, flags); +raw_spin_lock_irqsave (&byt_lock, flags); val =readl (reg); -spin_unlock_irqrestore (&vg->lock, flags); +raw_spin_unlock_irqrestore (&byt_lock, flags);return val &BYT_LEVEL ; }static void byt_gpio_set (struct gpio_chip *chip,unsigned offset,int value) { -struct byt_gpio *vg =to_byt_gpio (chip);void __iomem *reg =byt_gpio_reg (chip, offset,BYT_VAL_REG );unsigned long flags;u32 old_val; -spin_lock_irqsave (&vg->lock, flags); +raw_spin_lock_irqsave (&byt_lock, flags); old_val =readl (reg);
@@ -294,23 +293,22 @@ static void byt_gpio_set(struct gpio_chielse writel (old_val & ~BYT_LEVEL , reg); -spin_unlock_irqrestore (&vg->lock, flags); +raw_spin_unlock_irqrestore (&byt_lock, flags); }static int byt_gpio_direction_input (struct gpio_chip *chip,unsigned offset) { -struct byt_gpio *vg =to_byt_gpio (chip);void __iomem *reg =byt_gpio_reg (chip, offset,BYT_VAL_REG );unsigned long flags;u32 value; -spin_lock_irqsave (&vg->lock, flags); +raw_spin_lock_irqsave (&byt_lock, flags); value =readl (reg) |BYT_DIR_MASK ; value &= ~BYT_INPUT_EN ;/* active low */ writel (value, reg); -spin_unlock_irqrestore (&vg->lock, flags); +raw_spin_unlock_irqrestore (&byt_lock, flags);return 0 ; }
@@ -318,12 +316,11 @@ static int byt_gpio_direction_input(strustatic int byt_gpio_direction_output (struct gpio_chip *chip,unsigned gpio,int value) { -struct byt_gpio *vg =to_byt_gpio (chip);void __iomem *reg =byt_gpio_reg (chip, gpio,BYT_VAL_REG );unsigned long flags;u32 reg_val; -spin_lock_irqsave (&vg->lock, flags); +raw_spin_lock_irqsave (&byt_lock, flags); reg_val =readl (reg) |BYT_DIR_MASK ; reg_val &= ~(BYT_OUTPUT_EN |BYT_INPUT_EN );
@@ -333,7 +330,7 @@ static int byt_gpio_direction_output(strelse writel (reg_val & ~BYT_LEVEL , reg); -spin_unlock_irqrestore (&vg->lock, flags); +raw_spin_unlock_irqrestore (&byt_lock, flags);return 0 ; }
@@ -345,7 +342,7 @@ static void byt_gpio_dbg_show(struct sequnsigned long flags;u32 conf0, val, offs; -spin_lock_irqsave (&vg->lock, flags); +raw_spin_lock_irqsave (&byt_lock, flags);for (i =0 ; i < vg->chip.ngpio; i++) {const char *pull_str =NULL ;
@@ -406,7 +403,7 @@ static void byt_gpio_dbg_show(struct seqseq_puts (s,"\n" ); } -spin_unlock_irqrestore (&vg->lock, flags); +raw_spin_unlock_irqrestore (&byt_lock, flags); }static int byt_gpio_to_irq (struct gpio_chip *chip,unsigned offset)
@@ -444,10 +441,10 @@ static void byt_irq_ack(struct irq_dataunsigned offset =irqd_to_hwirq (d);void __iomem *reg; -spin_lock (&vg->lock); +raw_spin_lock (&byt_lock); reg =byt_gpio_reg (&vg->chip, offset,BYT_INT_STAT_REG );writel (BIT (offset %32 ), reg); -spin_unlock (&vg->lock); +raw_spin_unlock (&byt_lock); }static void byt_irq_unmask (struct irq_data *d)
@@ -459,7 +456,7 @@ static void byt_irq_unmask(struct irq_davoid __iomem *reg;u32 value; -spin_lock_irqsave (&vg->lock, flags); +raw_spin_lock_irqsave (&byt_lock, flags); reg =byt_gpio_reg (&vg->chip, offset,BYT_CONF0_REG ); value =readl (reg);
@@ -482,7 +479,7 @@ static void byt_irq_unmask(struct irq_dawritel (value, reg); -spin_unlock_irqrestore (&vg->lock, flags); +raw_spin_unlock_irqrestore (&byt_lock, flags); }static void byt_irq_mask (struct irq_data *d)
@@ -613,8 +610,6 @@ static int byt_gpio_probe(struct platforif (IS_ERR (vg->reg_base))return PTR_ERR (vg->reg_base); -spin_lock_init (&vg->lock); - gc = &vg->chip; gc->label =dev_name (&pdev->dev); gc->owner =THIS_MODULE ;
PATCH 71/245 netfilter: nf_tables: missing sanitization in data from userspace
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
commit 71df14b0ce094be46d105b5a3ededd83b8e779a0 upstream.
Do not assume userspace always sends us NFT_DATA_VALUE for bitwise and cmp expressions. Although NFT_DATA_VERDICT does not make any sense, it is still possible to handcraft a netlink message using this incorrect data type.
--- net/netfilter/nft_bitwise.c | 19 ++++++++++++++----- net/netfilter/nft_cmp.c | 12 ++++++++++-- 2 files changed, 24 insertions(+), 7 deletions(-)
net/netfilter/nft_bitwise.c +14 -5
@@ -86,16 +86,25 @@ static int nft_bitwise_init(const struct err =nft_data_init (NULL , &priv->mask, &d1, tb[NFTA_BITWISE_MASK ]);if (err <0 )return err; -if (d1.len != priv->len) -return -EINVAL ; +if (d1.len != priv->len) { + err = -EINVAL ; + goto err1; + } err =nft_data_init (NULL , &priv->xor, &d2, tb[NFTA_BITWISE_XOR ]);if (err <0 ) -return err; -if (d2.len != priv->len) -return -EINVAL ; + goto err1; +if (d2.len != priv->len) { + err = -EINVAL ; + goto err2; + }return 0 ; +err2: +nft_data_uninit (&priv->xor, d2.type); +err1: +nft_data_uninit (&priv->mask, d1.type); +return err; }static int nft_bitwise_dump (struct sk_buff *skb,const struct nft_expr *expr)
net/netfilter/nft_cmp.c +10 -2
@@ -201,10 +201,18 @@ nft_cmp_select_ops(const struct nft_ctxif (err <0 )return ERR_PTR (err); +if (desc.type !=NFT_DATA_VALUE ) { + err = -EINVAL ; + goto err1; + } +if (desc.len <=sizeof (u32) && op ==NFT_CMP_EQ )return &nft_cmp_fast_ops; -else -return &nft_cmp_ops; + +return &nft_cmp_ops; +err1: +nft_data_uninit (&data, desc.type); +return ERR_PTR (-EINVAL ); }static struct nft_expr_type nft_cmp_type__read_mostly = {
PATCH 72/245 netfilter: nf_tables: validate NFT_DATA_VALUE after nft_data_init()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
commit 0d2c96af797ba149e559c5875c0151384ab6dd14 upstream.
Userspace might bogusly sent NFT_DATA_VERDICT in several netlink attributes that assume NFT_DATA_VALUE. Moreover, make sure that error path invokes nft_data_release() to decrement the reference count on the chain object.
[bwh: Backported to 3.16:
- Drop changes in nft_get_set_elem(), nft_range
- Call nft_data_uninit() instead of nft_data_release()
- Adjust context]
---
net/netfilter/nft_bitwise.c +2 -2
@@ -86,7 +86,7 @@ static int nft_bitwise_init(const struct err =nft_data_init (NULL , &priv->mask, &d1, tb[NFTA_BITWISE_MASK ]);if (err <0 )return err; -if (d1.len != priv->len) { +if (d1.type !=NFT_DATA_VALUE || d1.len != priv->len) { err = -EINVAL ; goto err1; }
@@ -94,7 +94,7 @@ static int nft_bitwise_init(const struct err =nft_data_init (NULL , &priv->xor, &d2, tb[NFTA_BITWISE_XOR ]);if (err <0 ) goto err1; -if (d2.len != priv->len) { +if (d2.type !=NFT_DATA_VALUE || d2.len != priv->len) { err = -EINVAL ; goto err2; }
net/netfilter/nft_cmp.c +6 -0
@@ -84,6 +84,12 @@ static int nft_cmp_init(const struct nftif (desc.len >U8_MAX )return -ERANGE ; +if (desc.type !=NFT_DATA_VALUE ) { + err = -EINVAL ; +nft_data_uninit (&priv->data, desc.type); +return err; + } + priv->len = desc.len;return 0 ; }
PATCH 73/245 netfilter: bridge: make sure to pull arp header in br_nf_forward_arp()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 5604285839aaedfb23ebe297799c6e558939334d upstream.
syzbot is kind enough to remind us we need to call skb_may_pull()
BUG: KMSAN: uninit-value in br_nf_forward_arp+0xe61/0x1230 net/bridge/br_netfilter_hooks.c:665 CPU: 1 PID: 11631 Comm: syz-executor.1 Not tainted 5.4.0-rc8-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: <IRQ> __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x1c9/0x220 lib/dump_stack.c:118 kmsan_report+0x128/0x220 mm/kmsan/kmsan_report.c:108 __msan_warning+0x64/0xc0 mm/kmsan/kmsan_instr.c:245 br_nf_forward_arp+0xe61/0x1230 net/bridge/br_netfilter_hooks.c:665 nf_hook_entry_hookfn include/linux/netfilter.h:135 [inline] nf_hook_slow+0x18b/0x3f0 net/netfilter/core.c:512 nf_hook include/linux/netfilter.h:260 [inline] NF_HOOK include/linux/netfilter.h:303 [inline] __br_forward+0x78f/0xe30 net/bridge/br_forward.c:109 br_flood+0xef0/0xfe0 net/bridge/br_forward.c:234 br_handle_frame_finish+0x1a77/0x1c20 net/bridge/br_input.c:162 nf_hook_bridge_pre net/bridge/br_input.c:245 [inline] br_handle_frame+0xfb6/0x1eb0 net/bridge/br_input.c:348 __netif_receive_skb_core+0x20b9/0x51a0 net/core/dev.c:4830 __netif_receive_skb_one_core net/core/dev.c:4927 [inline] __netif_receive_skb net/core/dev.c:5043 [inline] process_backlog+0x610/0x13c0 net/core/dev.c:5874 napi_poll net/core/dev.c:6311 [inline] net_rx_action+0x7a6/0x1aa0 net/core/dev.c:6379 __do_softirq+0x4a1/0x83a kernel/softirq.c:293 do_softirq_own_stack+0x49/0x80 arch/x86/entry/entry_64.S:1091 </IRQ> do_softirq kernel/softirq.c:338 [inline] __local_bh_enable_ip+0x184/0x1d0 kernel/softirq.c:190 local_bh_enable+0x36/0x40 include/linux/bottom_half.h:32 rcu_read_unlock_bh include/linux/rcupdate.h:688 [inline] __dev_queue_xmit+0x38e8/0x4200 net/core/dev.c:3819 dev_queue_xmit+0x4b/0x60 net/core/dev.c:3825 packet_snd net/packet/af_packet.c:2959 [inline] packet_sendmsg+0x8234/0x9100 net/packet/af_packet.c:2984 sock_sendmsg_nosec net/socket.c:637 [inline] sock_sendmsg net/socket.c:657 [inline] __sys_sendto+0xc44/0xc70 net/socket.c:1952 __do_sys_sendto net/socket.c:1964 [inline] __se_sys_sendto+0x107/0x130 net/socket.c:1960 __x64_sys_sendto+0x6e/0x90 net/socket.c:1960 do_syscall_64+0xb6/0x160 arch/x86/entry/common.c:291 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x45a679 Code: ad b6 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 7b b6 fb ff c3 66 2e 0f 1f 84 00 00 00 00 RSP: 002b:00007f0a3c9e5c78 EFLAGS: 00000246 ORIG_RAX: 000000000000002c RAX: ffffffffffffffda RBX: 0000000000000006 RCX: 000000000045a679 RDX: 000000000000000e RSI: 0000000020000200 RDI: 0000000000000003 RBP: 000000000075bf20 R08: 00000000200000c0 R09: 0000000000000014 R10: 0000000000000000 R11: 0000000000000246 R12: 00007f0a3c9e66d4 R13: 00000000004c8ec1 R14: 00000000004dfe28 R15: 00000000ffffffff
Uninit was created at:
kmsan_save_stack_with_flags mm/kmsan/kmsan.c:149 [inline] kmsan_internal_poison_shadow+0x5c/0x110 mm/kmsan/kmsan.c:132 kmsan_slab_alloc+0x97/0x100 mm/kmsan/kmsan_hooks.c:86 slab_alloc_node mm/slub.c:2773 [inline] __kmalloc_node_track_caller+0xe27/0x11a0 mm/slub.c:4381 __kmalloc_reserve net/core/skbuff.c:141 [inline] __alloc_skb+0x306/0xa10 net/core/skbuff.c:209 alloc_skb include/linux/skbuff.h:1049 [inline] alloc_skb_with_frags+0x18c/0xa80 net/core/skbuff.c:5662 sock_alloc_send_pskb+0xafd/0x10a0 net/core/sock.c:2244 packet_alloc_skb net/packet/af_packet.c:2807 [inline] packet_snd net/packet/af_packet.c:2902 [inline] packet_sendmsg+0x63a6/0x9100 net/packet/af_packet.c:2984 sock_sendmsg_nosec net/socket.c:637 [inline] sock_sendmsg net/socket.c:657 [inline] __sys_sendto+0xc44/0xc70 net/socket.c:1952 __do_sys_sendto net/socket.c:1964 [inline] __se_sys_sendto+0x107/0x130 net/socket.c:1960 __x64_sys_sendto+0x6e/0x90 net/socket.c:1960 do_syscall_64+0xb6/0x160 arch/x86/entry/common.c:291 entry_SYSCALL_64_after_hwframe+0x44/0xa9
--- net/bridge/br_netfilter.c | 3 +++ 1 file changed, 3 insertions(+)
net/bridge/br_netfilter.c +3 -0
@@ -850,6 +850,9 @@ static unsigned int br_nf_forward_arp(conf_bridge_pull_encap_header (skb); } +if (unlikely (!pskb_may_pull (skb,sizeof (struct arphdr )))) +return NF_DROP ; +if (arp_hdr (skb)->ar_pln !=4 ) {if (IS_VLAN_ARP (skb))nf_bridge_push_encap_header (skb);
PATCH 74/245 HID: uhid: Fix returning EPOLLOUT from uhid_char_poll
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Marcel Holtmann <[email protected]>
commit be54e7461ffdc5809b67d2aeefc1ddc9a91470c7 upstream.
Always return EPOLLOUT from uhid_char_poll to allow polling /dev/uhid for writable state.
--- drivers/hid/uhid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/uhid.c +1 -1
@@ -726,7 +726,7 @@ static unsigned int uhid_char_poll(strucif (uhid->head != uhid->tail)return POLLIN |POLLRDNORM ; -return 0 ; +return POLLOUT |POLLWRNORM ; }static const struct file_operations uhid_fops = {
PATCH 75/245 gpio: Fix error message on out-of-range GPIO in lookup table
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Geert Uytterhoeven <[email protected]>
commit d935bd50dd14a7714cbdba9a76435dbb56edb1ae upstream.
When a GPIO offset in a lookup table is out-of-range, the printed error message (1) does not include the actual out-of-range value, and (2) contains an off-by-one error in the upper bound.
Avoid user confusion by also printing the actual GPIO offset, and correcting the upper bound of the range.
While at it, use "%u" for unsigned int.
Sample impact:
-requested GPIO 0 is out of range [0..32] for chip e6052000.gpio
+requested GPIO 0 (45) is out of range [0..31] for chip e6052000.gpio--- drivers/gpio/gpiolib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib.c +3 -2
@@ -2743,8 +2743,9 @@ static struct gpio_desc *gpiod_find(struif (chip->ngpio <= p->chip_hwnum) {dev_err (dev, -"requested GPIO %d is out of range [0..%d] for chip %s\n" , - idx, chip->ngpio, chip->label); +"requested GPIO %u (%u) is out of range [0..%u] for chip %s\n" , + idx, p->chip_hwnum, chip->ngpio -1 , + chip->label);return ERR_PTR (-EINVAL ); }
PATCH 76/245 neighbour: remove neigh_cleanup() method
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit f394722fb0d0f701119368959d7cd0ecbc46363a upstream.
neigh_cleanup() has not been used for seven years, and was a wrong design.
Messing with shared pointer in bond_neigh_init() without proper memory barriers would at least trigger syzbot complains eventually.
It is time to remove this stuff.
---
drivers/net/bonding/bond_main.c +0 -9
@@ -3431,19 +3431,10 @@ static int bond_neigh_init(struct neighbreturn 0 ; parms.neigh_setup =NULL ; - parms.neigh_cleanup =NULL ; ret = slave_ops->ndo_neigh_setup (slave->dev, &parms);if (ret)return ret; -/* -* Assign slave's neigh_cleanup to neighbour in case cleanup is called -* after the last slave has been detached. Assumes that all slaves -* utilize the same neigh_cleanup (true at this writing as only user -* is ipoib). -*/ - n->parms->neigh_cleanup = parms.neigh_cleanup; -if (!parms.neigh_setup)return 0 ;
include/net/neighbour.h +0 -1
@@ -71,7 +71,6 @@ struct neigh_parms {struct net_device *dev;struct neigh_parms *next;int (*neigh_setup)(struct neighbour *); -void (*neigh_cleanup)(struct neighbour *);struct neigh_table *tbl;void *sysctl_table;
net/core/neighbour.c +0 -3
@@ -103,9 +103,6 @@ static int neigh_blackhole(struct neighbstatic void neigh_cleanup_and_release (struct neighbour *neigh) { -if (neigh->parms->neigh_cleanup) - neigh->parms->neigh_cleanup (neigh); -__neigh_notify (neigh,RTM_DELNEIGH ,0 );neigh_release (neigh); }
PATCH 77/245 bonding: fix bond_neigh_init()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 9e99bfefdbce2e23ef37487a3bcb4adf90a791d1 upstream.
1) syzbot reported an uninit-value in bond_neigh_setup() [1]
bond_neigh_setup() uses a temporary on-stack 'struct neigh_parms parms', but only clears parms.neigh_setup field.
A stacked bonding device would then enter bond_neigh_setup() and read garbage from parms->dev.
If we get really unlucky and garbage is matching @dev, then we could recurse and eventually crash.
Let's make sure the whole structure is cleared to avoid surprises.
2) bond_neigh_setup() can be called while another cpu manipulates the master device, removing or adding a slave.
We need at least rcu protection to prevent use-after-free.
Note: Prior code does not support a stack of bonding devices,
this patch does not attempt to fix this, and leave a comment instead.
[1]
BUG: KMSAN: uninit-value in bond_neigh_setup+0xa4/0x110 drivers/net/bonding/bond_main.c:3655 CPU: 0 PID: 11256 Comm: syz-executor.0 Not tainted 5.4.0-rc8-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: <IRQ> __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x1c9/0x220 lib/dump_stack.c:118 kmsan_report+0x128/0x220 mm/kmsan/kmsan_report.c:108 __msan_warning+0x57/0xa0 mm/kmsan/kmsan_instr.c:245 bond_neigh_setup+0xa4/0x110 drivers/net/bonding/bond_main.c:3655 bond_neigh_init+0x216/0x4b0 drivers/net/bonding/bond_main.c:3626 ___neigh_create+0x169e/0x2c40 net/core/neighbour.c:613 __neigh_create+0xbd/0xd0 net/core/neighbour.c:674 ip6_finish_output2+0x149a/0x2670 net/ipv6/ip6_output.c:113 __ip6_finish_output+0x83d/0x8f0 net/ipv6/ip6_output.c:142 ip6_finish_output+0x2db/0x420 net/ipv6/ip6_output.c:152 NF_HOOK_COND include/linux/netfilter.h:294 [inline] ip6_output+0x5d3/0x720 net/ipv6/ip6_output.c:175 dst_output include/net/dst.h:436 [inline] NF_HOOK include/linux/netfilter.h:305 [inline] mld_sendpack+0xebd/0x13d0 net/ipv6/mcast.c:1682 mld_send_cr net/ipv6/mcast.c:1978 [inline] mld_ifc_timer_expire+0x116b/0x1680 net/ipv6/mcast.c:2477 call_timer_fn+0x232/0x530 kernel/time/timer.c:1404 expire_timers kernel/time/timer.c:1449 [inline] __run_timers+0xd60/0x1270 kernel/time/timer.c:1773 run_timer_softirq+0x2d/0x50 kernel/time/timer.c:1786 __do_softirq+0x4a1/0x83a kernel/softirq.c:293 invoke_softirq kernel/softirq.c:375 [inline] irq_exit+0x230/0x280 kernel/softirq.c:416 exiting_irq+0xe/0x10 arch/x86/include/asm/apic.h:536 smp_apic_timer_interrupt+0x48/0x70 arch/x86/kernel/apic/apic.c:1138 apic_timer_interrupt+0x2e/0x40 arch/x86/entry/entry_64.S:835 </IRQ> RIP: 0010:kmsan_free_page+0x18d/0x1c0 mm/kmsan/kmsan_shadow.c:439 Code: 4c 89 ff 44 89 f6 e8 82 0d ee ff 65 ff 0d 9f 26 3b 60 65 8b 05 98 26 3b 60 85 c0 75 24 e8 5b f6 35 ff 4c 89 6d d0 ff 75 d0 9d <48> 83 c4 10 5b 41 5c 41 5d 41 5e 41 5f 5d c3 0f 0b 0f 0b 0f 0b 0f RSP: 0018:ffffb328034af818 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff13 RAX: 0000000000000000 RBX: ffffe2d7471f8360 RCX: 0000000000000000 RDX: ffffffffadea7000 RSI: 0000000000000004 RDI: ffff93496fcda104 RBP: ffffb328034af850 R08: ffff934a47e86d00 R09: ffff93496fc41900 R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000001 R13: 0000000000000246 R14: 0000000000000000 R15: ffffe2d7472225c0 free_pages_prepare mm/page_alloc.c:1138 [inline] free_pcp_prepare mm/page_alloc.c:1230 [inline] free_unref_page_prepare+0x1d9/0x770 mm/page_alloc.c:3025 free_unref_page mm/page_alloc.c:3074 [inline] free_the_page mm/page_alloc.c:4832 [inline] __free_pages+0x154/0x230 mm/page_alloc.c:4840 __vunmap+0xdac/0xf20 mm/vmalloc.c:2277 __vfree mm/vmalloc.c:2325 [inline] vfree+0x7c/0x170 mm/vmalloc.c:2355 copy_entries_to_user net/ipv6/netfilter/ip6_tables.c:883 [inline] get_entries net/ipv6/netfilter/ip6_tables.c:1041 [inline] do_ip6t_get_ctl+0xfa4/0x1030 net/ipv6/netfilter/ip6_tables.c:1709 nf_sockopt net/netfilter/nf_sockopt.c:104 [inline] nf_getsockopt+0x481/0x4e0 net/netfilter/nf_sockopt.c:122 ipv6_getsockopt+0x264/0x510 net/ipv6/ipv6_sockglue.c:1400 tcp_getsockopt+0x1c6/0x1f0 net/ipv4/tcp.c:3688 sock_common_getsockopt+0x13f/0x180 net/core/sock.c:3110 __sys_getsockopt+0x533/0x7b0 net/socket.c:2129 __do_sys_getsockopt net/socket.c:2144 [inline] __se_sys_getsockopt+0xe1/0x100 net/socket.c:2141 __x64_sys_getsockopt+0x62/0x80 net/socket.c:2141 do_syscall_64+0xb6/0x160 arch/x86/entry/common.c:291 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x45d20a Code: b8 34 01 00 00 0f 05 48 3d 01 f0 ff ff 0f 83 8d 8b fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 49 89 ca b8 37 00 00 00 0f 05 <48> 3d 01 f0 ff ff 0f 83 6a 8b fb ff c3 66 0f 1f 84 00 00 00 00 00 RSP: 002b:0000000000a6f618 EFLAGS: 00000212 ORIG_RAX: 0000000000000037 RAX: ffffffffffffffda RBX: 0000000000a6f640 RCX: 000000000045d20a RDX: 0000000000000041 RSI: 0000000000000029 RDI: 0000000000000003 RBP: 0000000000717cc0 R08: 0000000000a6f63c R09: 0000000000004000 R10: 0000000000a6f740 R11: 0000000000000212 R12: 0000000000000003 R13: 0000000000000000 R14: 0000000000000029 R15: 0000000000715b00
Local variable description: ----parms@bond_neigh_init Variable was created at:
bond_neigh_init+0x8c/0x4b0 drivers/net/bonding/bond_main.c:3617 bond_neigh_init+0x8c/0x4b0 drivers/net/bonding/bond_main.c:3617
--- drivers/net/bonding/bond_main.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-)
drivers/net/bonding/bond_main.c +21 -10
@@ -3421,24 +3421,35 @@ static int bond_neigh_init(struct neighbconst struct net_device_ops *slave_ops;struct neigh_parms parms;struct slave *slave; -int ret; +int ret =0 ; - slave =bond_first_slave (bond); +rcu_read_lock (); + slave =bond_first_slave_rcu (bond);if (!slave) -return 0 ; + goto out; slave_ops = slave->dev->netdev_ops;if (!slave_ops->ndo_neigh_setup) -return 0 ; + goto out; - parms.neigh_setup =NULL ; +/* TODO: find another way [1] to implement this. +* Passing a zeroed structure is fragile, +* but at least we do not pass garbage. +* +* [1] One way would be that ndo_neigh_setup() never touch +* struct neigh_parms, but propagate the new neigh_setup() +* back to ___neigh_create() / neigh_parms_alloc() +*/ +memset (&parms,0 ,sizeof (parms)); ret = slave_ops->ndo_neigh_setup (slave->dev, &parms); -if (ret) -return ret; -if (!parms.neigh_setup) -return 0 ; +if (ret) + goto out; -return parms.neigh_setup (n); +if (parms.neigh_setup) + ret = parms.neigh_setup (n); +out: +rcu_read_unlock (); +return ret; }/*
PATCH 78/245 af_packet: set defaule value for tmo
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mao Wenan <[email protected]>
commit b43d1f9f7067c6759b1051e8ecb84e82cef569fe upstream.
There is softlockup when using TPACKET_V3:
...
NMI watchdog: BUG: soft lockup - CPU#2 stuck for 60010ms! (__irq_svc) from [<c0558a0c>] (_raw_spin_unlock_irqrestore+0x44/0x54) (_raw_spin_unlock_irqrestore) from [<c027b7e8>] (mod_timer+0x210/0x25c) (mod_timer) from [<c0549c30>] (prb_retire_rx_blk_timer_expired+0x68/0x11c) (prb_retire_rx_blk_timer_expired) from [<c027a7ac>] (call_timer_fn+0x90/0x17c)
(call_timer_fn) from [<c027ab6c>] (run_timer_softirq+0x2d4/0x2fc) (run_timer_softirq) from [<c021eaf4>] (__do_softirq+0x218/0x318) (__do_softirq) from [<c021eea0>] (irq_exit+0x88/0xac) (irq_exit) from [<c0240130>] (msa_irq_exit+0x11c/0x1d4) (msa_irq_exit) from [<c0209cf0>] (handle_IPI+0x650/0x7f4) (handle_IPI) from [<c02015bc>] (gic_handle_irq+0x108/0x118) (gic_handle_irq) from [<c0558ee4>] (__irq_usr+0x44/0x5c)
...
If __ethtool_get_link_ksettings() is failed in prb_calc_retire_blk_tmo(), msec and tmo will be zero, so tov_in_jiffies is zero and the timer expire for retire_blk_timer is turn to mod_timer(&pkc->retire_blk_timer, jiffies + 0),
which will trigger cpu usage of softirq is 100%.
--- net/packet/af_packet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/packet/af_packet.c +2 -1
@@ -608,7 +608,8 @@ static int prb_calc_retire_blk_tmo(struc msec =1 ; div = speed /1000 ; } - } + }else +return DEFAULT_PRB_RETIRE_TOV ; mbits = (blk_size_in_bytes *8 ) / (1024 *1024 );
PATCH 79/245 ACPI: PM: Avoid attaching ACPI PM domain to certain devices
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Rafael J. Wysocki" <[email protected]>
commit b9ea0bae260f6aae546db224daa6ac1bd9d94b91 upstream.
Certain ACPI-enumerated devices represented as platform devices in Linux, like fans, require special low-level power management handling implemented by their drivers that is not in agreement with the ACPI PM domain behavior. That leads to problems with managing ACPI fans during system-wide suspend and resume.
For this reason, make acpi_dev_pm_attach() skip the affected devices by adding a list of device IDs to avoid to it and putting the IDs of the affected devices into that list.
--- drivers/acpi/device_pm.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/acpi/device_pm.c +11 -1
@@ -1041,9 +1041,19 @@ static struct dev_pm_domain acpi_general*/ int acpi_dev_pm_attach (struct device *dev,bool power_on) { +/* +* Skip devices whose ACPI companions match the device IDs below, +* because they require special power management handling incompatible +* with the generic ACPI PM domain. +*/ +static const struct acpi_device_id special_pm_ids[] = { + {"PNP0C0B" , },/* Generic ACPI fan */ + {"INT3404" , },/* Fan */ + {} + };struct acpi_device *adev =ACPI_COMPANION (dev); -if (!adev) +if (!adev || !acpi_match_device_ids (adev, special_pm_ids))return -ENODEV ;if (dev->pm_domain)
PATCH 80/245 scsi: iscsi: qla4xxx: fix double free in probe
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
commit fee92f25777789d73e1936b91472e9c4644457c8 upstream.
On this error path we call qla4xxx_mem_free() and then the caller also calls qla4xxx_free_adapter() which calls qla4xxx_mem_free(). It leads to a couple double frees:
drivers/scsi/qla4xxx/ql4_os.c:8856 qla4xxx_probe_adapter() warn: 'ha->chap_dma_pool' double freed drivers/scsi/qla4xxx/ql4_os.c:8856 qla4xxx_probe_adapter() warn: 'ha->fw_ddb_dma_pool' double freed
--- drivers/scsi/qla4xxx/ql4_os.c | 1 - 1 file changed, 1 deletion(-)
drivers/scsi/qla4xxx/ql4_os.c +0 -1
@@ -4269,7 +4269,6 @@ static int qla4xxx_mem_alloc(struct scsireturn QLA_SUCCESS ; mem_alloc_error_exit: -qla4xxx_mem_free (ha);return QLA_ERROR ; }
PATCH 81/245 staging: gigaset: fix general protection fault on probe
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 53f35a39c3860baac1e5ca80bf052751cfb24a99 upstream.
Fix a general protection fault when accessing the endpoint descriptors which could be triggered by a malicious device due to missing sanity checks on the number of endpoints.
--- drivers/isdn/gigaset/usb-gigaset.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/isdn/gigaset/usb-gigaset.c +5 -0
@@ -693,6 +693,11 @@ static int gigaset_probe(struct usb_intereturn -ENODEV ; } +if (hostif->desc.bNumEndpoints <2 ) { +dev_err (&interface->dev,"missing endpoints\n" ); +return -ENODEV ; + } +dev_info (&udev->dev,"%s: Device matched ... !\n" , __func__);/* allocate memory for our device state and initialize it */
PATCH 82/245 staging: gigaset: fix illegal free on probe errors
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 84f60ca7b326ed8c08582417493982fe2573a9ad upstream.
The driver failed to initialise its receive-buffer pointer, something which could lead to an illegal free on late probe errors.
Fix this by making sure to clear all driver data at allocation.
--- drivers/isdn/gigaset/usb-gigaset.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/isdn/gigaset/usb-gigaset.c +1 -5
@@ -578,8 +578,7 @@ static int gigaset_initcshw(struct cards {struct usb_cardstate *ucs; - cs->hw.usb = ucs = -kmalloc (sizeof (struct usb_cardstate ),GFP_KERNEL ); + cs->hw.usb = ucs =kzalloc (sizeof (struct usb_cardstate ),GFP_KERNEL );if (!ucs) {pr_err ("out of memory\n" );return -ENOMEM ;
@@ -591,9 +590,6 @@ static int gigaset_initcshw(struct cards ucs->bchars[3 ] =0 ; ucs->bchars[4 ] =0x11 ; ucs->bchars[5 ] =0x13 ; - ucs->bulk_out_buffer =NULL ; - ucs->bulk_out_urb =NULL ; - ucs->read_urb =NULL ;tasklet_init (&cs->write_tasklet, gigaset_modem_fill, (unsigned long ) cs);
PATCH 83/245 staging: gigaset: add endpoint-type sanity check
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit ed9ed5a89acba51b82bdff61144d4e4a4245ec8a upstream.
Add missing endpoint-type sanity checks to probe.
This specifically prevents a warning in USB core on URB submission when fuzzing USB descriptors.
--- drivers/isdn/gigaset/usb-gigaset.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/isdn/gigaset/usb-gigaset.c +12 -0
@@ -713,6 +713,12 @@ static int gigaset_probe(struct usb_inte endpoint = &hostif->endpoint[0 ].desc; +if (!usb_endpoint_is_bulk_out (endpoint)) { +dev_err (&interface->dev,"missing bulk-out endpoint\n" ); + retval = -ENODEV ; + goto error; + } + buffer_size =le16_to_cpu (endpoint->wMaxPacketSize); ucs->bulk_out_size = buffer_size; ucs->bulk_out_endpointAddr = endpoint->bEndpointAddress;
@@ -732,6 +738,12 @@ static int gigaset_probe(struct usb_inte endpoint = &hostif->endpoint[1 ].desc; +if (!usb_endpoint_is_int_in (endpoint)) { +dev_err (&interface->dev,"missing int-in endpoint\n" ); + retval = -ENODEV ; + goto error; + } + ucs->busy =0 ; ucs->read_urb =usb_alloc_urb (0 ,GFP_KERNEL );
PATCH 84/245 usb: core: urb: fix URB structure initialization function
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Emiliano Ingrassia <[email protected]>
commit 1cd17f7f0def31e3695501c4f86cd3faf8489840 upstream.
Explicitly initialize URB structure urb_list field in usb_init_urb(). This field can be potentially accessed uninitialized and its initialization is coherent with the usage of list_del_init() in usb_hcd_unlink_urb_from_ep() and usb_giveback_urb_bh() and its explicit initialization in usb_hcd_submit_urb() error path.
--- drivers/usb/core/urb.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/core/urb.c +1 -0
@@ -40,6 +40,7 @@ void usb_init_urb(struct urb *urb)if (urb) {memset (urb,0 ,sizeof (*urb));kref_init (&urb->kref); +INIT_LIST_HEAD (&urb->urb_list);INIT_LIST_HEAD (&urb->anchor_list); } }
PATCH 85/245 usb: mon: Fix a deadlock in usbmon between mmap and read
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Pete Zaitcev <[email protected]>
commit 19e6317d24c25ee737c65d1ffb7483bdda4bb54a upstream.
The problem arises because our read() function grabs a lock of the circular buffer, finds something of interest, then invokes copy_to_user() straight from the buffer, which in turn takes mm->mmap_sem. In the same time, the callback mon_bin_vma_fault() is invoked under mm->mmap_sem. It attempts to take the fetch lock and deadlocks.
This patch does away with protecting of our page list with any semaphores, and instead relies on the kernel not close the device while mmap is active in a process.
In addition, we prohibit re-sizing of a buffer while mmap is active. This way, when (now unlocked) fault is processed, it works with the page that is intended to be mapped-in, and not some other random page. Note that this may have an ABI impact, but hopefully no legitimate program is this wrong.
--- drivers/usb/mon/mon_bin.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)
drivers/usb/mon/mon_bin.c +21 -11
@@ -1034,12 +1034,18 @@ static long mon_bin_ioctl(struct file *fmutex_lock (&rp->fetch_lock);spin_lock_irqsave (&rp->b_lock, flags); -mon_free_buff (rp->b_vec, rp->b_size/CHUNK_SIZE ); -kfree (rp->b_vec); - rp->b_vec = vec; - rp->b_size = size; - rp->b_read = rp->b_in = rp->b_out = rp->b_cnt =0 ; - rp->cnt_lost =0 ; +if (rp->mmap_active) { +mon_free_buff (vec, size/CHUNK_SIZE ); +kfree (vec); + ret = -EBUSY ; + }else { +mon_free_buff (rp->b_vec, rp->b_size/CHUNK_SIZE ); +kfree (rp->b_vec); + rp->b_vec = vec; + rp->b_size = size; + rp->b_read = rp->b_in = rp->b_out = rp->b_cnt =0 ; + rp->cnt_lost =0 ; + }spin_unlock_irqrestore (&rp->b_lock, flags);mutex_unlock (&rp->fetch_lock); }
@@ -1211,13 +1217,21 @@ mon_bin_poll(struct file *file, struct pstatic void mon_bin_vma_open (struct vm_area_struct *vma) {struct mon_reader_bin *rp = vma->vm_private_data; +unsigned long flags; + +spin_lock_irqsave (&rp->b_lock, flags); rp->mmap_active++; +spin_unlock_irqrestore (&rp->b_lock, flags); }static void mon_bin_vma_close (struct vm_area_struct *vma) { +unsigned long flags; +struct mon_reader_bin *rp = vma->vm_private_data; +spin_lock_irqsave (&rp->b_lock, flags); rp->mmap_active--; +spin_unlock_irqrestore (&rp->b_lock, flags); }/*
@@ -1229,16 +1243,12 @@ static int mon_bin_vma_fault(struct vm_aunsigned long offset, chunk_idx;struct page *pageptr; -mutex_lock (&rp->fetch_lock); offset = vmf->pgoff <<PAGE_SHIFT ; -if (offset >= rp->b_size) { -mutex_unlock (&rp->fetch_lock); +if (offset >= rp->b_size)return VM_FAULT_SIGBUS ; - } chunk_idx = offset /CHUNK_SIZE ; pageptr = rp->b_vec[chunk_idx].pg;get_page (pageptr); -mutex_unlock (&rp->fetch_lock); vmf->page = pageptr;return 0 ; }
PATCH 86/245 USB: serial: io_edgeport: fix epic endpoint lookup
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 7c5a2df3367a2c4984f1300261345817d95b71f8 upstream.
Make sure to use the current alternate setting when looking up the endpoints on epic devices to avoid binding to an invalid interface.
Failing to do so could cause the driver to misbehave or trigger a WARN() in usb_submit_urb() that kernels with panic_on_warn set would choke on.
--- drivers/usb/serial/io_edgeport.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/usb/serial/io_edgeport.c +6 -4
@@ -2859,16 +2859,18 @@ static int edge_startup(struct usb_seria response =0 ;if (edge_serial->is_epic) { +struct usb_host_interface *alt; + + alt = serial->interface->cur_altsetting; +/* EPIC thing, set up our interrupt polling now and our read * urb, so that the device knows it really is connected. */ interrupt_in_found = bulk_in_found = bulk_out_found = false; -for (i =0 ; i < serial->interface->altsetting[0 ] - .desc.bNumEndpoints; ++i) { +for (i =0 ; i < alt->desc.bNumEndpoints; ++i) {struct usb_endpoint_descriptor *endpoint;int buffer_size; - endpoint = &serial->interface->altsetting[0 ]. - endpoint[i].desc; + endpoint = &alt->endpoint[i].desc; buffer_size =usb_endpoint_maxp (endpoint);if (!interrupt_in_found && (usb_endpoint_is_int_in (endpoint))) {
PATCH 87/245 USB: idmouse: fix interface sanity checks
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 59920635b89d74b9207ea803d5e91498d39e8b69 upstream.
Make sure to use the current alternate setting when verifying the interface descriptors to avoid binding to an invalid interface.
Failing to do so could cause the driver to misbehave or trigger a WARN() in usb_submit_urb() that kernels with panic_on_warn set would choke on.
--- drivers/usb/misc/idmouse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/misc/idmouse.c +1 -1
@@ -342,7 +342,7 @@ static int idmouse_probe(struct usb_inteint result;/* check if we have gotten the data or the hid interface */ - iface_desc = &interface->altsetting[0 ]; + iface_desc = interface->cur_altsetting;if (iface_desc->desc.bInterfaceClass !=0x0A )return -ENODEV ;
PATCH 88/245 USB: adutux: fix interface sanity check
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 3c11c4bed02b202e278c0f5c319ae435d7fb9815 upstream.
Make sure to use the current alternate setting when verifying the interface descriptors to avoid binding to an invalid interface.
Failing to do so could cause the driver to misbehave or trigger a WARN() in usb_submit_urb() that kernels with panic_on_warn set would choke on.
--- drivers/usb/misc/adutux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/misc/adutux.c +1 -1
@@ -682,7 +682,7 @@ static int adu_probe(struct usb_interfacinit_waitqueue_head (&dev->read_wait);init_waitqueue_head (&dev->write_wait); - iface_desc = &interface->altsetting[0 ]; + iface_desc = interface->cur_altsetting;/* set up the endpoint information */ for (i =0 ; i < iface_desc->desc.bNumEndpoints; ++i) {
PATCH 89/245 USB: atm: ueagle-atm: add missing endpoint check
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 09068c1ad53fb077bdac288869dec2435420bdc4 upstream.
Make sure that the interrupt interface has an endpoint before trying to access its endpoint descriptors to avoid dereferencing a NULL pointer.
The driver binds to the interrupt interface with interface number 0, but must not assume that this interface or its current alternate setting are the first entries in the corresponding configuration arrays.
--- drivers/usb/atm/ueagle-atm.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/usb/atm/ueagle-atm.c +12 -6
@@ -2167,10 +2167,11 @@ resubmit:/* * Start the modem : init the data and start kernel thread */ -static int uea_boot (struct uea_softc *sc) +static int uea_boot (struct uea_softc *sc,struct usb_interface *intf) { -int ret, size;struct intr_pkt *intr; +int ret = -ENOMEM ; +int size;uea_enters (INS_TO_USBDEV (sc));
@@ -2195,6 +2196,11 @@ static int uea_boot(struct uea_softc *scif (UEA_CHIP_VERSION (sc) ==ADI930 )load_XILINX_firmware (sc); +if (intf->cur_altsetting->desc.bNumEndpoints <1 ) { + ret = -ENODEV ; + goto err0; + } + intr =kmalloc (size,GFP_KERNEL );if (!intr) { uea_err(INS_TO_USBDEV(sc),
@@ -2211,8 +2217,7 @@ static int uea_boot(struct uea_softc *scusb_fill_int_urb (sc->urb_int, sc->usb_dev,usb_rcvintpipe (sc->usb_dev,UEA_INTR_PIPE ), intr, size, uea_intr, sc, - sc->usb_dev->actconfig->interface[0 ]->altsetting[0 ]. - endpoint[0 ].desc.bInterval); + intf->cur_altsetting->endpoint[0 ].desc.bInterval); ret =usb_submit_urb (sc->urb_int,GFP_KERNEL );if (ret <0 ) {
@@ -2227,6 +2232,7 @@ static int uea_boot(struct uea_softc *sc sc->kthread =kthread_create (uea_kthread, sc,"ueagle-atm" );if (IS_ERR (sc->kthread)) {uea_err (INS_TO_USBDEV (sc),"failed to create thread\n" ); + ret =PTR_ERR (sc->kthread); goto err2; }
@@ -2241,7 +2247,7 @@ err1:kfree (intr); err0:uea_leaves (INS_TO_USBDEV (sc)); -return -ENOMEM ; +return ret; }/*
@@ -2604,7 +2610,7 @@ static int uea_bind(struct usbatm_data *if (ret <0 ) goto error; - ret =uea_boot (sc); + ret =uea_boot (sc, intf);if (ret <0 ) goto error_rm_grp;
PATCH 90/245 staging: rtl8188eu: fix interface sanity check
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 74ca34118a0e05793935d804ccffcedd6eb56596 upstream.
Make sure to use the current alternate setting when verifying the interface descriptors to avoid binding to an invalid interface.
Failing to do so could cause the driver to misbehave or trigger a WARN() in usb_submit_urb() that kernels with panic_on_warn set would choke on.
--- drivers/staging/rtl8188eu/os_dep/usb_intf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8188eu/os_dep/usb_intf.c +1 -1
@@ -141,7 +141,7 @@ static struct dvobj_priv *usb_dvobj_init phost_conf = pusbd->actconfig; pconf_desc = &phost_conf->desc; - phost_iface = &usb_intf->altsetting[0 ]; + phost_iface = usb_intf->cur_altsetting; piface_desc = &phost_iface->desc; pdvobjpriv->NumInterfaces = pconf_desc->bNumInterfaces;
PATCH 91/245 staging: rtl8712: fix interface sanity check
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit c724f776f048538ecfdf53a52b7a522309f5c504 upstream.
Make sure to use the current alternate setting when verifying the interface descriptors to avoid binding to an invalid interface.
Failing to do so could cause the driver to misbehave or trigger a WARN() in usb_submit_urb() that kernels with panic_on_warn set would choke on.
--- drivers/staging/rtl8712/usb_intf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8712/usb_intf.c +1 -1
@@ -269,7 +269,7 @@ static uint r8712_usb_dvobj_init(struct pdev_desc = &pusbd->descriptor; phost_conf = pusbd->actconfig; pconf_desc = &phost_conf->desc; - phost_iface = &pintf->altsetting[0 ]; + phost_iface = pintf->cur_altsetting; piface_desc = &phost_iface->desc; pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;if (pusbd->speed ==USB_SPEED_HIGH ) {
PATCH 92/245 gpiolib: fix up emulated open drain outputs
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Russell King <[email protected]>
commit 256efaea1fdc4e38970489197409a26125ee0aaa upstream.
gpiolib has a corner case with open drain outputs that are emulated. When such outputs are outputting a logic 1, emulation will set the hardware to input mode, which will cause gpiod_get_direction() to report that it is in input mode. This is different from the behaviour with a true open-drain output.
Unify the semantics here.
--- drivers/gpio/gpiolib.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpio/gpiolib.c +8 -0
@@ -273,6 +273,14 @@ int gpiod_get_direction(const struct gpi chip =gpiod_to_chip (desc); offset =gpio_chip_hwgpio (desc); +/* +* Open drain emulation using input mode may incorrectly report +* input here, fix that up. +*/ +if (test_bit (FLAG_OPEN_DRAIN , &desc->flags) && +test_bit (FLAG_IS_OUT , &desc->flags)) +return 0 ; +if (!chip->get_direction)return status;
PATCH 93/245 virtio-balloon: fix managed page counts when migrating pages between zones
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand <[email protected]>
commit 63341ab03706e11a31e3dd8ccc0fbc9beaf723f0 upstream.
In case we have to migrate a ballon page to a newpage of another zone, the managed page count of both zones is wrong. Paired with memory offlining (which will adjust the managed page count), we can trigger kernel crashes and all kinds of different symptoms.
One way to reproduce:
1. Start a QEMU guest with 4GB, no NUMA
2. Hotplug a 1GB DIMM and online the memory to ZONE_NORMAL
3. Inflate the balloon to 1GB
4. Unplug the DIMM (be quick, otherwise unmovable data ends up on it)
5. Observe /proc/zoneinfo
Node 0, zone Normal
pages free 16810
min 24848885473806
low 18471592959183339
high 36918337032892872
spanned 262144
present 262144
managed 18446744073709533486
6. Do anything that requires some memory (e.g., inflate the balloon some
more). The OOM goes crazy and the system crashes
[ 238.324946] Out of memory: Killed process 537 (login) total-vm:27584kB, anon-rss:860kB, file-rss:0kB, shmem-rss:00
[ 238.338585] systemd invoked oom-killer: gfp_mask=0x100cca(GFP_HIGHUSER_MOVABLE), order=0, oom_score_adj=0
[ 238.339420] CPU: 0 PID: 1 Comm: systemd Tainted: G D W 5.4.0-next-20191204+ #75
[ 238.340139] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.0-59-gc9ba5276e321-prebuilt.qemu4
[ 238.341121] Call Trace:
[ 238.341337] dump_stack+0x8f/0xd0
[ 238.341630] dump_header+0x61/0x5ea
[ 238.341942] oom_kill_process.cold+0xb/0x10
[ 238.342299] out_of_memory+0x24d/0x5a0
[ 238.342625] __alloc_pages_slowpath+0xd12/0x1020
[ 238.343024] __alloc_pages_nodemask+0x391/0x410
[ 238.343407] pagecache_get_page+0xc3/0x3a0
[ 238.343757] filemap_fault+0x804/0xc30
[ 238.344083] ? ext4_filemap_fault+0x28/0x42
[ 238.344444] ext4_filemap_fault+0x30/0x42
[ 238.344789] __do_fault+0x37/0x1a0
[ 238.345087] __handle_mm_fault+0x104d/0x1ab0
[ 238.345450] handle_mm_fault+0x169/0x360
[ 238.345790] do_user_addr_fault+0x20d/0x490
[ 238.346154] do_page_fault+0x31/0x210
[ 238.346468] async_page_fault+0x43/0x50
[ 238.346797] RIP: 0033:0x7f47eba4197e
[ 238.347110] Code: Bad RIP value.
[ 238.347387] RSP: 002b:00007ffd7c0c1890 EFLAGS: 00010293
[ 238.347834] RAX: 0000000000000002 RBX: 000055d196a20a20 RCX: 00007f47eba4197e
[ 238.348437] RDX: 0000000000000033 RSI: 00007ffd7c0c18c0 RDI: 0000000000000004
[ 238.349047] RBP: 00007ffd7c0c1c20 R08: 0000000000000000 R09: 0000000000000033
[ 238.349660] R10: 00000000ffffffff R11: 0000000000000293 R12: 0000000000000001
[ 238.350261] R13: ffffffffffffffff R14: 0000000000000000 R15: 00007ffd7c0c18c0
[ 238.350878] Mem-Info:
[ 238.351085] active_anon:3121 inactive_anon:51 isolated_anon:0
[ 238.351085] active_file:12 inactive_file:7 isolated_file:0
[ 238.351085] unevictable:0 dirty:0 writeback:0 unstable:0
[ 238.351085] slab_reclaimable:5565 slab_unreclaimable:10170
[ 238.351085] mapped:3 shmem:111 pagetables:155 bounce:0
[ 238.351085] free:720717 free_pcp:2 free_cma:0
[ 238.353757] Node 0 active_anon:12484kB inactive_anon:204kB active_file:48kB inactive_file:28kB unevictable:0kB iss
[ 238.355979] Node 0 DMA free:11556kB min:36kB low:48kB high:60kB reserved_highatomic:0KB active_anon:152kB inactivB
[ 238.358345] lowmem_reserve[]: 0 2955 2884 2884 2884
[ 238.358761] Node 0 DMA32 free:2677864kB min:7004kB low:10028kB high:13052kB reserved_highatomic:0KB active_anon:0B
[ 238.361202] lowmem_reserve[]: 0 0 72057594037927865 72057594037927865 72057594037927865
[ 238.361888] Node 0 Normal free:193448kB min:99395541895224kB low:73886371836733356kB high:147673348131571488kB reB
[ 238.364765] lowmem_reserve[]: 0 0 0 0 0
[ 238.365101] Node 0 DMA: 7*4kB (U) 5*8kB (UE) 6*16kB (UME) 2*32kB (UM) 1*64kB (U) 2*128kB (UE) 3*256kB (UME) 2*512B
[ 238.366379] Node 0 DMA32: 0*4kB 1*8kB (U) 2*16kB (UM) 2*32kB (UM) 2*64kB (UM) 1*128kB (U) 1*256kB (U) 1*512kB (U)B
[ 238.367654] Node 0 Normal: 1985*4kB (UME) 1321*8kB (UME) 844*16kB (UME) 524*32kB (UME) 300*64kB (UME) 138*128kB (B
[ 238.369184] Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=2048kB
[ 238.369915] 130 total pagecache pages
[ 238.370241] 0 pages in swap cache
[ 238.370533] Swap cache stats: add 0, delete 0, find 0/0
[ 238.370981] Free swap = 0kB
[ 238.371239] Total swap = 0kB
[ 238.371488] 1048445 pages RAM
[ 238.371756] 0 pages HighMem/MovableOnly
[ 238.372090] 306992 pages reserved
[ 238.372376] 0 pages cma reserved
[ 238.372661] 0 pages hwpoisonedIn another instance (older kernel), I was able to observe this (negative page count :/):
[ 180.896971] Offlined Pages 32768 [ 182.667462] Offlined Pages 32768 [ 184.408117] Offlined Pages 32768 [ 186.026321] Offlined Pages 32768 [ 187.684861] Offlined Pages 32768 [ 189.227013] Offlined Pages 32768 [ 190.830303] Offlined Pages 32768 [ 190.833071] Built 1 zonelists, mobility grouping on. Total pages: -36920272750453009
In another instance (older kernel), I was no longer able to start any process:
[root@vm ~]# [ 214.348068] Offlined Pages 32768
[ 215.973009] Offlined Pages 32768 cat /proc/meminfo -bash: fork: Cannot allocate memory [root@vm ~]# cat /proc/meminfo -bash: fork: Cannot allocate memory
Fix it by properly adjusting the managed page count when migrating if the zone changed. The managed page count of the zones now looks after unplug of the DIMM (and after deflating the balloon) just like before inflating the balloon (and plugging+onlining the DIMM).
We'll temporarily modify the totalram page count. If this ever becomes a problem, we can fine tune by providing helpers that don't touch the totalram pages (e.g., adjust_zone_managed_page_count()).
Please note that fixing up the managed page count is only necessary when we adjusted the managed page count when inflating - only if we don't have VIRTIO_BALLOON_F_DEFLATE_ON_OOM. With that feature, the managed page count is not touched when inflating/deflating.
[bwh: Backported to 3.16: Deflate-on-OOM is not supported at all so don't
check that flag]
---
drivers/virtio/virtio_balloon.c +10 -0
@@ -403,6 +403,16 @@ static int virtballoon_migratepage(strucget_page (newpage);/* balloon reference */ +/* +* When we migrate a page to a different zone and adjusted the +* managed page count when inflating, we have to fixup the count of +* both involved zones. +*/ +if (page_zone (page) !=page_zone (newpage)) { +adjust_managed_page_count (page,1 ); +adjust_managed_page_count (newpage,-1 ); + } +/* balloon's page migration 1st step -- inflate "newpage" */ spin_lock_irqsave (&vb_dev_info->pages_lock, flags);balloon_page_insert (newpage, mapping, &vb_dev_info->pages);
PATCH 94/245 HID: Fix slab-out-of-bounds read in hid_field_extract
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Alan Stern <[email protected]>
commit 8ec321e96e056de84022c032ffea253431a83c3c upstream.
The syzbot fuzzer found a slab-out-of-bounds bug in the HID report handler. The bug was caused by a report descriptor which included a field with size 12 bits and count 4899, for a total size of 7349 bytes.
The usbhid driver uses at most a single-page 4-KB buffer for reports. In the test there wasn't any problem about overflowing the buffer, since only one byte was received from the device. Rather, the bug occurred when the HID core tried to extract the data from the report fields, which caused it to try reading data beyond the end of the allocated buffer.
This patch fixes the problem by rejecting any report whose total length exceeds the HID_MAX_BUFFER_SIZE limit (minus one byte to allow for a possible report index). In theory a device could have a report longer than that, but if there was such a thing we wouldn't handle it correctly anyway.
--- drivers/hid/hid-core.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/hid/hid-core.c +6 -0
@@ -248,6 +248,12 @@ static int hid_add_field(struct hid_pars offset = report->size; report->size += parser->global.report_size * parser->global.report_count; +/* Total size check: Allow for possible report index byte */ +if (report->size > (HID_MAX_BUFFER_SIZE -1 ) <<3 ) { +hid_err (parser->device,"report is too long\n" ); +return -1 ; + } +if (!parser->local.usage_index)/* Ignore padding fields */ return 0 ;
PATCH 95/245 xhci: handle some XHCI_TRUST_TX_LENGTH quirks cases as default behaviour.
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mathias Nyman <[email protected]>
commit 7ff11162808cc2ec66353fc012c58bb449c892c3 upstream.
xhci driver claims it needs XHCI_TRUST_TX_LENGTH quirk for both Broadcom/Cavium and a Renesas xHC controllers.
The quirk was inteded for handling false "success" complete event for transfers that had data left untransferred.
These transfers should complete with "short packet" events instead.
In these two new cases the false "success" completion is reported after a "short packet" if the TD consists of several TRBs. xHCI specs 4.10.1.1.2 say remaining TRBs should report "short packet" as well after the first short packet in a TD, but this issue seems so common it doesn't make sense to add the quirk for all vendors.
Turn these events into short packets automatically instead.
This gets rid of the "The WARN Successful completion on short TX for slot 1 ep 1: needs XHCI_TRUST_TX_LENGTH quirk" warning in many cases.
--- drivers/usb/host/xhci-ring.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/host/xhci-ring.c +2 -1
@@ -2345,7 +2345,8 @@ static int handle_tx_event(struct xhci_hcase COMP_SUCCESS :if (EVENT_TRB_LEN (le32_to_cpu (event->transfer_len)) ==0 )break ; -if (xhci->quirks &XHCI_TRUST_TX_LENGTH ) +if (xhci->quirks &XHCI_TRUST_TX_LENGTH || + ep_ring->last_td_was_short) trb_comp_code =COMP_SHORT_TX ;else xhci_warn_ratelimited(xhci,
PATCH 96/245 xhci: make sure interrupts are restored to correct state
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mathias Nyman <[email protected]>
commit bd82873f23c9a6ad834348f8b83f3b6a5bca2c65 upstream.
spin_unlock_irqrestore() might be called with stale flags after reading port status, possibly restoring interrupts to a incorrect state.
If a usb2 port just finished resuming while the port status is read the spin lock will be temporary released and re-acquired in a separate function. The flags parameter is passed as value instead of a pointer, not updating flags properly before the final spin_unlock_irqrestore() is called.
--- drivers/usb/host/xhci-hub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/host/xhci-hub.c +4 -4
@@ -580,7 +580,7 @@ static u32 xhci_get_port_status(struct u struct xhci_bus_state *bus_state, __le32 __iomem **port_array, u16 wIndex, u32 raw_port_status, - unsigned long flags) + unsigned long *flags) __releases(&xhci->lock) __acquires(&xhci->lock) {
@@ -670,12 +670,12 @@ static u32 xhci_get_port_status(struct uxhci_set_link_state (xhci, port_array, wIndex,XDEV_U0 ); -spin_unlock_irqrestore (&xhci->lock, flags); +spin_unlock_irqrestore (&xhci->lock, *flags); time_left =wait_for_completion_timeout ( &bus_state->rexit_done[wIndex],msecs_to_jiffies (XHCI_MAX_REXIT_TIMEOUT_MS )); -spin_lock_irqsave (&xhci->lock, flags); +spin_lock_irqsave (&xhci->lock, *flags);if (time_left) { slot_id = xhci_find_slot_id_by_port(hcd,
@@ -834,7 +834,7 @@ int xhci_hub_control(struct usb_hcd *hcdbreak ; } status =xhci_get_port_status (hcd, bus_state, port_array, - wIndex, temp, flags); + wIndex, temp, &flags);if (status ==0xffffffff ) goto error;
PATCH 97/245 usb: dwc3: pci: Add PCI ID for Intel Braswell
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Alan Cox <[email protected]>
commit 7d643664ea559b36188cae264047ce3c9bfec3a2 upstream.
The device controller is the same but it has different PCI ID. Add this new ID to the driver's list of supported IDs.
--- drivers/usb/dwc3/dwc3-pci.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/dwc3/dwc3-pci.c +2 -0
@@ -30,6 +30,7 @@#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd#define PCI_DEVICE_ID_INTEL_BYT 0x0f37#define PCI_DEVICE_ID_INTEL_MRFLD 0x119e +#define PCI_DEVICE_ID_INTEL_BSW 0x22B7struct dwc3_pci {struct device *dev;
@@ -183,6 +184,7 @@ static const struct pci_device_id dwc3_pPCI_DEVICE (PCI_VENDOR_ID_SYNOPSYS ,PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 ), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), }, { } /* Terminating Entry */
PATCH 98/245 usb: dwc3: pci: add support for Intel Sunrise Point PCH
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Heikki Krogerus <[email protected]>
commit 84a2b61b6eb94036093531cdabc448dddfbae45a upstream.
Add PCI IDs for Intel Sunrise Point PCH.
--- drivers/usb/dwc3/dwc3-pci.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/dwc3/dwc3-pci.c +4 -0
@@ -31,6 +31,8 @@#define PCI_DEVICE_ID_INTEL_BYT 0x0f37#define PCI_DEVICE_ID_INTEL_MRFLD 0x119e#define PCI_DEVICE_ID_INTEL_BSW 0x22B7 +#define PCI_DEVICE_ID_INTEL_SPTLP 0x9d30 +#define PCI_DEVICE_ID_INTEL_SPTH 0xa130struct dwc3_pci {struct device *dev;
@@ -187,6 +189,8 @@ static const struct pci_device_id dwc3_p { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), }, { } /* Terminating Entry */ };MODULE_DEVICE_TABLE (pci, dwc3_pci_id_table);
PATCH 99/245 usb: dwc3: pci: add support for Intel Broxton SOC
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Heikki Krogerus <[email protected]>
commit b4c580a43d520b7812c0fd064fbab929ce2f1da0 upstream.
PCI IDs for Broxton based platforms.
--- drivers/usb/dwc3/dwc3-pci.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/dwc3/dwc3-pci.c +4 -0
@@ -33,6 +33,8 @@#define PCI_DEVICE_ID_INTEL_BSW 0x22B7#define PCI_DEVICE_ID_INTEL_SPTLP 0x9d30#define PCI_DEVICE_ID_INTEL_SPTH 0xa130 +#define PCI_DEVICE_ID_INTEL_BXT 0x0aaa +#define PCI_DEVICE_ID_INTEL_APL 0x5aaastruct dwc3_pci {struct device *dev;
@@ -191,6 +193,8 @@ static const struct pci_device_id dwc3_p { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), }, { } /* Terminating Entry */ };MODULE_DEVICE_TABLE (pci, dwc3_pci_id_table);
PATCH 100/245 usb: dwc3: pci: add ID for one more Intel Broxton platform
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Heikki Krogerus <[email protected]>
commit 1ffb4d5cc78a3a99109ff0808ce6915de07a0588 upstream.
BXT-M is a Intel Broxton SoC based platform with unique PCI ID.
--- drivers/usb/dwc3/dwc3-pci.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/dwc3/dwc3-pci.c +2 -0
@@ -34,6 +34,7 @@#define PCI_DEVICE_ID_INTEL_SPTLP 0x9d30#define PCI_DEVICE_ID_INTEL_SPTH 0xa130#define PCI_DEVICE_ID_INTEL_BXT 0x0aaa +#define PCI_DEVICE_ID_INTEL_BXT_M 0x1aaa#define PCI_DEVICE_ID_INTEL_APL 0x5aaastruct dwc3_pci {
@@ -194,6 +195,7 @@ static const struct pci_device_id dwc3_p { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), }, { } /* Terminating Entry */ };
PATCH 101/245 usb: dwc3: pci: add Intel Kabylake PCI ID
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Heikki Krogerus <[email protected]>
commit 4491ed5042f0419b22a4b08331adb54af31e2caa upstream.
Intel Kabylake PCH has the same DWC3 than Intel Sunrisepoint. Add the new ID to the supported devices.
--- drivers/usb/dwc3/dwc3-pci.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/dwc3/dwc3-pci.c +2 -0
@@ -36,6 +36,7 @@#define PCI_DEVICE_ID_INTEL_BXT 0x0aaa#define PCI_DEVICE_ID_INTEL_BXT_M 0x1aaa#define PCI_DEVICE_ID_INTEL_APL 0x5aaa +#define PCI_DEVICE_ID_INTEL_KBP 0xa2b0struct dwc3_pci {struct device *dev;
@@ -197,6 +198,7 @@ static const struct pci_device_id dwc3_p { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBP), }, { } /* Terminating Entry */ };MODULE_DEVICE_TABLE (pci, dwc3_pci_id_table);
PATCH 102/245 usb: dwc3: pci: add Intel Gemini Lake PCI ID
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Heikki Krogerus <[email protected]>
commit 8f8983a5683623b62b339d159573f95a1fce44f3 upstream.
Intel Gemini Lake SoC has the same DWC3 than Broxton. Add the new ID to the supported Devices.
--- drivers/usb/dwc3/dwc3-pci.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/dwc3/dwc3-pci.c +2 -0
@@ -37,6 +37,7 @@#define PCI_DEVICE_ID_INTEL_BXT_M 0x1aaa#define PCI_DEVICE_ID_INTEL_APL 0x5aaa#define PCI_DEVICE_ID_INTEL_KBP 0xa2b0 +#define PCI_DEVICE_ID_INTEL_GLK 0x31aastruct dwc3_pci {struct device *dev;
@@ -199,6 +200,7 @@ static const struct pci_device_id dwc3_p { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBP), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_GLK), }, { } /* Terminating Entry */ };MODULE_DEVICE_TABLE (pci, dwc3_pci_id_table);
PATCH 103/245 usb: dwc3: pci: add Intel Cannonlake PCI IDs
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Heikki Krogerus <[email protected]>
commit 682179592e48fa66056fbad1a86604be4992f885 upstream.
Intel Cannonlake PCH has the same DWC3 than Intel Sunrisepoint. Add the new IDs to the supported devices.
--- drivers/usb/dwc3/dwc3-pci.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/dwc3/dwc3-pci.c +4 -0
@@ -38,6 +38,8 @@#define PCI_DEVICE_ID_INTEL_APL 0x5aaa#define PCI_DEVICE_ID_INTEL_KBP 0xa2b0#define PCI_DEVICE_ID_INTEL_GLK 0x31aa +#define PCI_DEVICE_ID_INTEL_CNPLP 0x9dee +#define PCI_DEVICE_ID_INTEL_CNPH 0xa36estruct dwc3_pci {struct device *dev;
@@ -201,6 +203,8 @@ static const struct pci_device_id dwc3_p { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBP), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_GLK), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPLP), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPH), }, { } /* Terminating Entry */ };MODULE_DEVICE_TABLE (pci, dwc3_pci_id_table);
PATCH 104/245 usb: dwc3: pci: add support for Intel IceLake
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Heikki Krogerus <[email protected]>
commit 00908693c481f7298adf8cf4d2ff3dfbea8c375f upstream.
PCI IDs for Intel IceLake.
--- drivers/usb/dwc3/dwc3-pci.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/dwc3/dwc3-pci.c +2 -0
@@ -40,6 +40,7 @@#define PCI_DEVICE_ID_INTEL_GLK 0x31aa#define PCI_DEVICE_ID_INTEL_CNPLP 0x9dee#define PCI_DEVICE_ID_INTEL_CNPH 0xa36e +#define PCI_DEVICE_ID_INTEL_ICLLP 0x34eestruct dwc3_pci {struct device *dev;
@@ -205,6 +206,7 @@ static const struct pci_device_id dwc3_p { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_GLK), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPLP), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPH), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICLLP), }, { } /* Terminating Entry */ };MODULE_DEVICE_TABLE (pci, dwc3_pci_id_table);
PATCH 105/245 usb: dwc3: pci: add support for Comet Lake PCH ID
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Felipe Balbi <[email protected]>
commit 7ae622c978db6b2e28b4fced6ecd2a174492059d upstream.
This patch simply adds a new PCI Device ID
[bwh: Backported to 3.16:
- No properties support
- Adjust context, indentation]
--- drivers/usb/dwc3/dwc3-pci.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/dwc3/dwc3-pci.c +2 -0
@@ -37,6 +37,7 @@#define PCI_DEVICE_ID_INTEL_BXT_M 0x1aaa#define PCI_DEVICE_ID_INTEL_APL 0x5aaa#define PCI_DEVICE_ID_INTEL_KBP 0xa2b0 +#define PCI_DEVICE_ID_INTEL_CMLH 0x02ee#define PCI_DEVICE_ID_INTEL_GLK 0x31aa#define PCI_DEVICE_ID_INTEL_CNPLP 0x9dee#define PCI_DEVICE_ID_INTEL_CNPH 0xa36e
@@ -197,6 +198,7 @@ static const struct pci_device_id dwc3_p { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CMLH), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT), },
PATCH 106/245 usb: dwc3: pci: Add Support for Intel Elkhart Lake Devices
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Felipe Balbi <[email protected]>
commit dbb0569de852fb4576d6f62078d515f989a181ca upstream.
This patch simply adds a new PCI Device ID
[bwh: Backported to 3.16:
- No properties support
- Adjust context, indentation]
--- drivers/usb/dwc3/dwc3-pci.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/dwc3/dwc3-pci.c +2 -0
@@ -42,6 +42,7 @@#define PCI_DEVICE_ID_INTEL_CNPLP 0x9dee#define PCI_DEVICE_ID_INTEL_CNPH 0xa36e#define PCI_DEVICE_ID_INTEL_ICLLP 0x34ee +#define PCI_DEVICE_ID_INTEL_EHLLP 0x4b7estruct dwc3_pci {struct device *dev;
@@ -209,6 +210,7 @@ static const struct pci_device_id dwc3_p { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPLP), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPH), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICLLP), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EHLLP), }, { } /* Terminating Entry */ };MODULE_DEVICE_TABLE (pci, dwc3_pci_id_table);
PATCH 107/245 usb: dwc3: pci: add support for TigerLake Devices
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Felipe Balbi <[email protected]>
commit b3649dee5fbb0f6585010e6e9313dfcbb075b22b upstream.
This patch adds the necessary PCI ID for TGP-LP devices.
[bwh: Backported to 3.16:
- No properties support
- Adjust context, indentation]
--- drivers/usb/dwc3/dwc3-pci.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/dwc3/dwc3-pci.c +2 -0
@@ -43,6 +43,7 @@#define PCI_DEVICE_ID_INTEL_CNPH 0xa36e#define PCI_DEVICE_ID_INTEL_ICLLP 0x34ee#define PCI_DEVICE_ID_INTEL_EHLLP 0x4b7e +#define PCI_DEVICE_ID_INTEL_TGPLP 0xa0eestruct dwc3_pci {struct device *dev;
@@ -211,6 +212,7 @@ static const struct pci_device_id dwc3_p { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPH), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICLLP), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EHLLP), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TGPLP), }, { } /* Terminating Entry */ };MODULE_DEVICE_TABLE (pci, dwc3_pci_id_table);
PATCH 108/245 usb: dwc3: pci: add ID for the Intel Comet Lake -H variant
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Heikki Krogerus <[email protected]>
commit 3c3caae4cd6e122472efcf64759ff6392fb6bce2 upstream.
The original ID that was added for Comet Lake PCH was actually for the -LP (low power) variant even though the constant for it said CMLH. Changing that while at it.
[bwh: Backported to 3.16:
- No properties support
- Adjust context, indentation]
--- drivers/usb/dwc3/dwc3-pci.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/dwc3/dwc3-pci.c +3 -1
@@ -37,7 +37,8 @@#define PCI_DEVICE_ID_INTEL_BXT_M 0x1aaa#define PCI_DEVICE_ID_INTEL_APL 0x5aaa#define PCI_DEVICE_ID_INTEL_KBP 0xa2b0 -#define PCI_DEVICE_ID_INTEL_CMLH 0x02ee +#define PCI_DEVICE_ID_INTEL_CMLLP 0x02ee +#define PCI_DEVICE_ID_INTEL_CMLH 0x06ee#define PCI_DEVICE_ID_INTEL_GLK 0x31aa#define PCI_DEVICE_ID_INTEL_CNPLP 0x9dee#define PCI_DEVICE_ID_INTEL_CNPH 0xa36e
@@ -200,6 +201,7 @@ static const struct pci_device_id dwc3_p { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CMLLP), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CMLH), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), },
PATCH 109/245 tty: serial: msm_serial: Fix lockup for sysrq and oops
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Leo Yan <[email protected]>
commit 0e4f7f920a5c6bfe5e851e989f27b35a0cc7fb7e upstream.
As the commit 677fe555cbfb ("serial: imx: Fix recursive locking bug") has mentioned the uart driver might cause recursive locking between normal printing and the kernel debugging facilities (e.g. sysrq and oops). In the commit it gave out suggestion for fixing recursive locking issue: "The solution is to avoid locking in the sysrq case and trylock in the oops_in_progress case."
This patch follows the suggestion (also used the exactly same code with other serial drivers, e.g. amba-pl011.c) to fix the recursive locking issue, this can avoid stuck caused by deadlock and print out log for sysrq and oops.
--- drivers/tty/serial/msm_serial.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/tty/serial/msm_serial.c +11 -2
@@ -857,6 +857,7 @@ static void msm_console_write(struct construct msm_port *msm_port;int num_newlines =0 ;bool replaced = false; +int locked =1 ;BUG_ON (co->index <0 || co->index >=UART_NR );
@@ -869,7 +870,13 @@ static void msm_console_write(struct con num_newlines++; count += num_newlines; -spin_lock (&port->lock); +if (port->sysrq) + locked =0 ; +else if (oops_in_progress) + locked =spin_trylock (&port->lock); +else +spin_lock (&port->lock); +if (msm_port->is_uartdm)reset_dm_count (port, count);
@@ -906,7 +913,9 @@ static void msm_console_write(struct conmsm_write (port, *bf, msm_port->is_uartdm ?UARTDM_TF :UART_TF ); i += num_chars; } -spin_unlock (&port->lock); + +if (locked) +spin_unlock (&port->lock); }static int __init msm_console_setup (struct console *co,char *options)
PATCH 110/245 IB/mlx4: Avoid executing gid task when device is being removed
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Moni Shoua <[email protected]>
commit 4bf9715f184969dc703bde7be94919995024a6a9 upstream.
When device is being removed (e.g during VPI port link type change from ETH to IB), tasks for gid table changes should not be executed.
Flush the current queue of tasks and block further tasks from entering the queue.
--- drivers/infiniband/hw/mlx4/main.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/infiniband/hw/mlx4/main.c +9 -0
@@ -1395,6 +1395,9 @@ static void update_gids_task(struct workint err;struct mlx4_dev *dev = gw->dev->dev; +if (!gw->dev->ib_active) +return ; + mailbox =mlx4_alloc_cmd_mailbox (dev);if (IS_ERR (mailbox)) {pr_warn ("update gid table failed %ld\n" ,PTR_ERR (mailbox));
@@ -1425,6 +1428,9 @@ static void reset_gids_task(struct work_int err;struct mlx4_dev *dev = gw->dev->dev; +if (!gw->dev->ib_active) +return ; + mailbox =mlx4_alloc_cmd_mailbox (dev);if (IS_ERR (mailbox)) {pr_warn ("reset gid table failed\n" );
@@ -2363,6 +2369,9 @@ static void mlx4_ib_remove(struct mlx4_dstruct mlx4_ib_dev *ibdev = ibdev_ptr;int p; + ibdev->ib_active = false; +flush_workqueue (wq); +mlx4_ib_close_sriov (ibdev);mlx4_ib_mad_cleanup (ibdev);ib_unregister_device (&ibdev->ib_dev);
PATCH 111/245 IB/mlx4: Follow mirror sequence of device add during device removal
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Parav Pandit <[email protected]>
commit 89f988d93c62384758b19323c886db917a80c371 upstream.
Current code device add sequence is:
ib_register_device()ib_mad_init()init_sriov_init()register_netdev_notifier()
Therefore, the remove sequence should be,
unregister_netdev_notifier()close_sriov()mad_cleanup()ib_unregister_device()
However it is not above.
Hence, make do above remove sequence.
---
drivers/infiniband/hw/mlx4/main.c +4 -3
@@ -2372,15 +2372,16 @@ static void mlx4_ib_remove(struct mlx4_d ibdev->ib_active = false;flush_workqueue (wq); -mlx4_ib_close_sriov (ibdev); -mlx4_ib_mad_cleanup (ibdev); -ib_unregister_device (&ibdev->ib_dev);if (ibdev->iboe.nb.notifier_call) {if (unregister_netdevice_notifier (&ibdev->iboe.nb))pr_warn ("failure unregistering notifier\n" ); ibdev->iboe.nb.notifier_call =NULL ; } +mlx4_ib_close_sriov (ibdev); +mlx4_ib_mad_cleanup (ibdev); +ib_unregister_device (&ibdev->ib_dev); +mlx4_qp_release_range (dev, ibdev->steer_qpn_base, ibdev->steer_qpn_count);kfree (ibdev->ib_uc_qpns_bitmap);
PATCH 112/245 HID: hid-input: clear unmapped usages
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 4f3882177240a1f55e45a3d241d3121341bead78 upstream.
We should not be leaving half-mapped usages with potentially invalid keycodes, as that may confuse hidinput_find_key() when the key is located by index, which may end up feeding way too large keycode into the VT keyboard handler and cause OOB write there:
BUG: KASAN: global-out-of-bounds in clear_bit include/asm-generic/bitops-instrumented.h:56 [inline] BUG: KASAN: global-out-of-bounds in kbd_keycode drivers/tty/vt/keyboard.c:1411 [inline] BUG: KASAN: global-out-of-bounds in kbd_event+0xe6b/0x3790 drivers/tty/vt/keyboard.c:1495 Write of size 8 at addr ffffffff89a1b2d8 by task syz-executor108/1722 ... kbd_keycode drivers/tty/vt/keyboard.c:1411 [inline] kbd_event+0xe6b/0x3790 drivers/tty/vt/keyboard.c:1495 input_to_handler+0x3b6/0x4c0 drivers/input/input.c:118 input_pass_values.part.0+0x2e3/0x720 drivers/input/input.c:145 input_pass_values drivers/input/input.c:949 [inline] input_set_keycode+0x290/0x320 drivers/input/input.c:954 evdev_handle_set_keycode_v2+0xc4/0x120 drivers/input/evdev.c:882 evdev_do_ioctl drivers/input/evdev.c:1150 [inline]
--- drivers/hid/hid-input.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/hid/hid-input.c +12 -4
@@ -947,9 +947,15 @@ static void hidinput_configure_usage(str } mapped: -if (device->driver->input_mapped && device->driver->input_mapped (device, - hidinput, field, usage, &bit, &max) <0 ) - goto ignore; +if (device->driver->input_mapped && + device->driver->input_mapped (device, hidinput, field, usage, + &bit, &max) <0 ) { +/* +* The driver indicated that no further generic handling +* of the usage is desired. +*/ +return ; + }set_bit (usage->type, input->evbit);
@@ -1008,9 +1014,11 @@ mapped:set_bit (MSC_SCAN , input->mscbit); } -ignore:return ; +ignore: + usage->type =0 ; + usage->code =0 ; }void hidinput_hid_event (struct hid_device *hid,struct hid_field *field,struct hid_usage *usage,__s32 value)
PATCH 113/245 btrfs: do not call synchronize_srcu() in inode_tree_del
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
commit f72ff01df9cf5db25c76674cac16605992d15467 upstream.
Testing with the new fsstress uncovered a pretty nasty deadlock with lookup and snapshot deletion.
Process A
unlink
-> final iput
-> inode_tree_del
-> synchronize_srcu(subvol_srcu)
Process Bbtrfs_lookup <- srcu_read_lock() acquired here
-> btrfs_iget
-> find inode that has I_FREEING set
-> __wait_on_freeing_inode()We're holding the srcu_read_lock() while doing the iget in order to make sure our fs root doesn't go away, and then we are waiting for the inode to finish freeing. However because the free'ing process is doing a synchronize_srcu() we deadlock.
Fix this by dropping the synchronize_srcu() in inode_tree_del(). We don't need people to stop accessing the fs root at this point, we're only adding our empty root to the dead roots list.
A larger much more invasive fix is forthcoming to address how we deal with fs roots, but this fixes the immediate problem.
---
fs/btrfs/inode.c +0 -1
@@ -5140,7 +5140,6 @@ static void inode_tree_del(struct inodespin_unlock (&root->inode_lock);if (empty &&btrfs_root_refs (&root->root_item) ==0 ) { -synchronize_srcu (&root->fs_info->subvol_srcu);spin_lock (&root->inode_lock); empty =RB_EMPTY_ROOT (&root->inode_tree);spin_unlock (&root->inode_lock);
PATCH 114/245 Btrfs: fix removal logic of the tree mod log that leads to use-after-free issues
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
commit 6609fee8897ac475378388238456c84298bff802 upstream.
When a tree mod log user no longer needs to use the tree it calls btrfs_put_tree_mod_seq() to remove itself from the list of users and delete all no longer used elements of the tree's red black tree, which should be all elements with a sequence number less then our equals to the caller's sequence number. However the logic is broken because it can delete and free elements from the red black tree that have a sequence number greater then the caller's sequence number:
1) At a point in time we have sequence numbers 1, 2, 3 and 4 in the tree mod log;
2) The task which got assigned the sequence number 1 calls btrfs_put_tree_mod_seq();
3) Sequence number 1 is deleted from the list of sequence numbers;
4) The current minimum sequence number is computed to be the sequence number 2;
5) A task using sequence number 2 is at tree_mod_log_rewind() and gets a pointer to one of its elements from the red black tree through a call to tree_mod_log_search();
6) The task with sequence number 1 iterates the red black tree of tree modification elements and deletes (and frees) all elements with a sequence number less then or equals to 2 (the computed minimum sequence number) - it ends up only leaving elements with sequence numbers of 3 and 4;
7) The task with sequence number 2 now uses the pointer to its element, already freed by the other task, at __tree_mod_log_rewind(), resulting in a use-after-free issue. When CONFIG_DEBUG_PAGEALLOC=y it produces a trace like the following:
[16804.546854] general protection fault: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC PTI [16804.547451] CPU: 0 PID: 28257 Comm: pool Tainted: G W 5.4.0-rc8-btrfs-next-51 #1 [16804.548059] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.0-0-ga698c8995f-prebuilt.qemu.org 04/01/2014 [16804.548666] RIP: 0010:rb_next+0x16/0x50 (...) [16804.550581] RSP: 0018:ffffb948418ef9b0 EFLAGS: 00010202 [16804.551227] RAX: 6b6b6b6b6b6b6b6b RBX: ffff90e0247f6600 RCX: 6b6b6b6b6b6b6b6b [16804.551873] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff90e0247f6600 [16804.552504] RBP: ffff90dffe0d4688 R08: 0000000000000001 R09: 0000000000000000 [16804.553136] R10: ffff90dffa4a0040 R11: 0000000000000000 R12: 000000000000002e [16804.553768] R13: ffff90e0247f6600 R14: 0000000000001663 R15: ffff90dff77862b8 [16804.554399] FS: 00007f4b197ae700(0000) GS:ffff90e036a00000(0000) knlGS:0000000000000000 [16804.555039] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [16804.555683] CR2: 00007f4b10022000 CR3: 00000002060e2004 CR4: 00000000003606f0 [16804.556336] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [16804.556968] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [16804.557583] Call Trace: [16804.558207] __tree_mod_log_rewind+0xbf/0x280 [btrfs] [16804.558835] btrfs_search_old_slot+0x105/0xd00 [btrfs] [16804.559468] resolve_indirect_refs+0x1eb/0xc70 [btrfs] [16804.560087] ? free_extent_buffer.part.19+0x5a/0xc0 [btrfs] [16804.560700] find_parent_nodes+0x388/0x1120 [btrfs] [16804.561310] btrfs_check_shared+0x115/0x1c0 [btrfs] [16804.561916] ? extent_fiemap+0x59d/0x6d0 [btrfs] [16804.562518] extent_fiemap+0x59d/0x6d0 [btrfs] [16804.563112] ? __might_fault+0x11/0x90 [16804.563706] do_vfs_ioctl+0x45a/0x700 [16804.564299] ksys_ioctl+0x70/0x80 [16804.564885] ? trace_hardirqs_off_thunk+0x1a/0x20 [16804.565461] __x64_sys_ioctl+0x16/0x20 [16804.566020] do_syscall_64+0x5c/0x250 [16804.566580] entry_SYSCALL_64_after_hwframe+0x49/0xbe [16804.567153] RIP: 0033:0x7f4b1ba2add7 (...) [16804.568907] RSP: 002b:00007f4b197adc88 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 [16804.569513] RAX: ffffffffffffffda RBX: 00007f4b100210d8 RCX: 00007f4b1ba2add7 [16804.570133] RDX: 00007f4b100210d8 RSI: 00000000c020660b RDI: 0000000000000003 [16804.570726] RBP: 000055de05a6cfe0 R08: 0000000000000000 R09: 00007f4b197add44 [16804.571314] R10: 0000000000000000 R11: 0000000000000246 R12: 00007f4b197add48 [16804.571905] R13: 00007f4b197add40 R14: 00007f4b100210d0 R15: 00007f4b197add50 (...) [16804.575623] ---[ end trace 87317359aad4ba50 ]---
Fix this by making btrfs_put_tree_mod_seq() skip deletion of elements that have a sequence number equals to the computed minimum sequence number, and not just elements with a sequence number greater then that minimum.
--- fs/btrfs/ctree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/ctree.c +1 -1
@@ -418,7 +418,7 @@ void btrfs_put_tree_mod_seq(struct btrfsfor (node =rb_first (tm_root); node; node = next) { next =rb_next (node); tm = container_of(node, struct tree_mod_elem, node); -if (tm->seq > min_seq) +if (tm->seq >= min_seq)continue ;rb_erase (node, tm_root);kfree (tm);
PATCH 115/245 btrfs: abort transaction after failed inode updates in create_subvol
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
commit c7e54b5102bf3614cadb9ca32d7be73bad6cecf0 upstream.
We can just abort the transaction here, and in fact do that for every other failure in this function except these two cases.
[bwh: Backported to 3.16:
- Add root as second argument to btrfs_abort_transaction()
- Adjust context]
--- fs/btrfs/ioctl.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/btrfs/ioctl.c +8 -2
@@ -580,12 +580,18 @@ static noinline int create_subvol(structbtrfs_i_size_write (dir, dir->i_size + namelen *2 ); ret =btrfs_update_inode (trans, root, dir); -BUG_ON (ret); +if (ret) { +btrfs_abort_transaction (trans, root, ret); + goto fail; + } ret =btrfs_add_root_ref (trans, root->fs_info->tree_root, objectid, root->root_key.objectid,btrfs_ino (dir), index, name, namelen); -BUG_ON (ret); +if (ret) { +btrfs_abort_transaction (trans, root, ret); + goto fail; + } ret = btrfs_uuid_tree_add(trans, root->fs_info->uuid_root, root_item.uuid, BTRFS_UUID_KEY_SUBVOL,
PATCH 116/245 btrfs: handle ENOENT in btrfs_uuid_tree_iterate
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
commit 714cd3e8cba6841220dce9063a7388a81de03825 upstream.
If we get an -ENOENT back from btrfs_uuid_iter_rem when iterating the uuid tree we'll just continue and do btrfs_next_item(). However we've done a btrfs_release_path() at this point and no longer have a valid path. So increment the key and go back and do a normal search.
--- fs/btrfs/uuid-tree.c | 2 ++ 1 file changed, 2 insertions(+)
fs/btrfs/uuid-tree.c +2 -0
@@ -333,6 +333,8 @@ again_search_slot: }if (ret <0 && ret != -ENOENT ) goto out; + key.offset++; + goto again_search_slot; } item_size -=sizeof (subid_le); offset +=sizeof (subid_le);
PATCH 117/245 btrfs: skip log replay on orphaned roots
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
commit 9bc574de590510eff899c3ca8dbaf013566b5efe upstream.
My fsstress modifications coupled with generic/475 uncovered a failure to mount and replay the log if we hit a orphaned root. We do not want to replay the log for an orphan root, but it's completely legitimate to have an orphaned root with a log attached. Fix this by simply skipping replaying the log. We still need to pin it's root node so that we do not overwrite it while replaying other logs, as we re-read the log root at every stage of the replay.
[bwh: Backported to 3.16:
- Pass fs_info->extent_root, instead of fs_info, as first argument to btrfs_pin_extent_for_log_replay()
- Adjust context]
---
fs/btrfs/tree-log.c +22 -2
@@ -4583,9 +4583,29 @@ again: wc.replay_dest =btrfs_read_fs_root_no_name (fs_info, &tmp_key);if (IS_ERR (wc.replay_dest)) { ret =PTR_ERR (wc.replay_dest); + +/* +* We didn't find the subvol, likely because it was +* deleted. This is ok, simply skip this log and go to +* the next one. +* +* We need to exclude the root because we can't have +* other log replays overwriting this log as we'll read +* it back in a few more times. This will keep our +* block from being modified, and we'll just bail for +* each subsequent pass. +*/ +if (ret == -ENOENT ) + ret =btrfs_pin_extent_for_log_replay ( + fs_info->extent_root, + log->node->start, + log->node->len);free_extent_buffer (log->node);free_extent_buffer (log->commit_root);kfree (log); + +if (!ret) + goto next;btrfs_error (fs_info, ret,"Couldn't read target root " "for tree log recovery." ); goto error;
@@ -4600,7 +4620,6 @@ again: path); } - key.offset = found_key.offset -1 ; wc.replay_dest->log_root =NULL ;free_extent_buffer (log->node);free_extent_buffer (log->commit_root);
@@ -4608,9 +4627,10 @@ again:if (ret) goto error; - +next:if (found_key.offset ==0 )break ; + key.offset = found_key.offset -1 ; }btrfs_release_path (path);
PATCH 118/245 btrfs: do not leak reloc root if we fail to read the fs root
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
commit ca1aa2818a53875cfdd175fb5e9a2984e997cce9 upstream.
If we fail to read the fs root corresponding with a reloc root we'll just break out and free the reloc roots. But we remove our current reloc_root from this list higher up, which means we'll leak this reloc_root. Fix this by adding ourselves back to the reloc_roots list so we are properly cleaned up.
--- fs/btrfs/relocation.c | 1 + 1 file changed, 1 insertion(+)
fs/btrfs/relocation.c +1 -0
@@ -4449,6 +4449,7 @@ int btrfs_recover_relocation(struct btrf reloc_root->root_key.offset);if (IS_ERR (fs_root)) { err =PTR_ERR (fs_root); +list_add_tail (&reloc_root->root_list, &reloc_roots); goto out_free; }
PATCH 119/245 Btrfs: fix infinite loop during nocow writeback due to race
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
commit de7999afedff02c6631feab3ea726a0e8f8c3d40 upstream.
When starting writeback for a range that covers part of a preallocated extent, due to a race with writeback for another range that also covers another part of the same preallocated extent, we can end up in an infinite loop.
Consider the following example where for inode 280 we have two dirty ranges:
range A, from 294912 to 303103, 8192 bytes
range B, from 348160 to 438271, 90112 bytes
and we have the following file extent item layout for our inode:
leaf 38895616 gen 24544 total ptrs 29 free space 13820 owner 5
(...)
item 27 key (280 108 200704) itemoff 14598 itemsize 53
extent data disk bytenr 0 nr 0 type 1 (regular)
extent data offset 0 nr 94208 ram 94208
item 28 key (280 108 294912) itemoff 14545 itemsize 53
extent data disk bytenr 10433052672 nr 81920 type 2 (prealloc)
extent data offset 0 nr 81920 ram 81920Then the following happens:
1) Writeback starts for range B (from 348160 to 438271), execution of run_delalloc_nocow() starts;
2) The first iteration of run_delalloc_nocow()'s whil loop leaves us at the extent item at slot 28, pointing to the prealloc extent item covering the range from 294912 to 376831. This extent covers part of our range;
3) An ordered extent is created against that extent, covering the file range from 348160 to 376831 (28672 bytes);
4) We adjust 'cur_offset' to 376832 and move on to the next iteration of the while loop;
5) The call to btrfs_lookup_file_extent() leaves us at the same leaf, pointing to slot 29, 1 slot after the last item (the extent item we processed in the previous iteration);
6) Because we are a slot beyond the last item, we call btrfs_next_leaf(), which releases the search path before doing a another search for the last key of the leaf (280 108 294912);
7) Right after btrfs_next_leaf() released the path, and before it did another search for the last key of the leaf, writeback for the range A (from 294912 to 303103) completes (it was previously started at some point);
8) Upon completion of the ordered extent for range A, the prealloc extent we previously found got split into two extent items, one covering the range from 294912 to 303103 (8192 bytes), with a type of regular extent (and no longer prealloc) and another covering the range from 303104 to 376831 (73728 bytes), with a type of prealloc and an offset of 8192 bytes. So our leaf now has the following layout:
leaf 38895616 gen 24544 total ptrs 31 free space 13664 owner 5
(...)
item 27 key (280 108 200704) itemoff 14598 itemsize 53
extent data disk bytenr 0 nr 0 type 1
extent data offset 0 nr 8192 ram 94208
item 28 key (280 108 208896) itemoff 14545 itemsize 53
extent data disk bytenr 10433142784 nr 86016 type 1
extent data offset 0 nr 86016 ram 86016
item 29 key (280 108 294912) itemoff 14492 itemsize 53
extent data disk bytenr 10433052672 nr 81920 type 1
extent data offset 0 nr 8192 ram 81920
item 30 key (280 108 303104) itemoff 14439 itemsize 53
extent data disk bytenr 10433052672 nr 81920 type 2
extent data offset 8192 nr 73728 ram 819209) After btrfs_next_leaf() returns, we have our path pointing to that same leaf and at slot 30, since it has a key we didn't have before and it's the first key greater then the key that was previously the last key of the leaf (key (280 108 294912));
10) The extent item at slot 30 covers the range from 303104 to 376831 which is in our target range, so we process it, despite having already created an ordered extent against this extent for the file range from 348160 to 376831. This is because we skip to the next extent item only if its end is less than or equals to the start of our delalloc range, and not less than or equals to the current offset ('cur_offset');
11) As a result we compute 'num_bytes' as:
num_bytes = min(end + 1, extent_end) - cur_offset;
= min(438271 + 1, 376832) - 376832 = 012) We then call create_io_em() for a 0 bytes range starting at offset
376832;
13) Then create_io_em() enters an infinite loop because its calls to
btrfs_drop_extent_cache() do nothing due to the 0 length range
passed to it. So no existing extent maps that cover the offset
376832 get removed, and therefore calls to add_extent_mapping()
return -EEXIST, resulting in an infinite loop. This loop from
create_io_em() is the following:
do {
btrfs_drop_extent_cache(BTRFS_I(inode), em->start,
em->start + em->len - 1, 0);
write_lock(&em_tree->lock);
ret = add_extent_mapping(em_tree, em, 1);
write_unlock(&em_tree->lock);
/*
* The caller has taken lock_extent(), who could race with us
* to add em?
*/
} while (ret == -EEXIST);Also, each call to btrfs_drop_extent_cache() triggers a warning because the start offset passed to it (376832) is smaller then the end offset (376832 - 1) passed to it by -1, due to the 0 length:
[258532.052621] ------------[ cut here ]------------ [258532.052643] WARNING: CPU: 0 PID: 9987 at fs/btrfs/file.c:602 btrfs_drop_extent_cache+0x3f4/0x590 [btrfs] (...) [258532.052672] CPU: 0 PID: 9987 Comm: fsx Tainted: G W 5.4.0-rc7-btrfs-next-64 #1 [258532.052673] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.0-0-ga698c8995f-prebuilt.qemu.org 04/01/2014 [258532.052691] RIP: 0010:btrfs_drop_extent_cache+0x3f4/0x590 [btrfs] (...) [258532.052695] RSP: 0018:ffffb4be0153f860 EFLAGS: 00010287 [258532.052700] RAX: ffff975b445ee360 RBX: ffff975b44eb3e08 RCX: 0000000000000000 [258532.052700] RDX: 0000000000038fff RSI: 0000000000039000 RDI: ffff975b445ee308 [258532.052700] RBP: 0000000000038fff R08: 0000000000000000 R09: 0000000000000001 [258532.052701] R10: ffff975b513c5c10 R11: 00000000e3c0cfa9 R12: 0000000000039000 [258532.052703] R13: ffff975b445ee360 R14: 00000000ffffffef R15: ffff975b445ee308 [258532.052705] FS: 00007f86a821de80(0000) GS:ffff975b76a00000(0000) knlGS:0000000000000000 [258532.052707] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [258532.052708] CR2: 00007fdacf0f3ab4 CR3: 00000001f9d26002 CR4: 00000000003606f0 [258532.052712] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [258532.052717] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [258532.052717] Call Trace: [258532.052718] ? preempt_schedule_common+0x32/0x70 [258532.052722] ? ___preempt_schedule+0x16/0x20 [258532.052741] create_io_em+0xff/0x180 [btrfs] [258532.052767] run_delalloc_nocow+0x942/0xb10 [btrfs] [258532.052791] btrfs_run_delalloc_range+0x30b/0x520 [btrfs] [258532.052812] ? find_lock_delalloc_range+0x221/0x250 [btrfs] [258532.052834] writepage_delalloc+0xe4/0x140 [btrfs] [258532.052855] __extent_writepage+0x110/0x4e0 [btrfs] [258532.052876] extent_write_cache_pages+0x21c/0x480 [btrfs] [258532.052906] extent_writepages+0x52/0xb0 [btrfs] [258532.052911] do_writepages+0x23/0x80 [258532.052915] __filemap_fdatawrite_range+0xd2/0x110 [258532.052938] btrfs_fdatawrite_range+0x1b/0x50 [btrfs] [258532.052954] start_ordered_ops+0x57/0xa0 [btrfs] [258532.052973] ? btrfs_sync_file+0x225/0x490 [btrfs] [258532.052988] btrfs_sync_file+0x225/0x490 [btrfs] [258532.052997] __x64_sys_msync+0x199/0x200 [258532.053004] do_syscall_64+0x5c/0x250 [258532.053007] entry_SYSCALL_64_after_hwframe+0x49/0xbe [258532.053010] RIP: 0033:0x7f86a7dfd760 (...) [258532.053014] RSP: 002b:00007ffd99af0368 EFLAGS: 00000246 ORIG_RAX: 000000000000001a [258532.053016] RAX: ffffffffffffffda RBX: 0000000000000ec9 RCX: 00007f86a7dfd760 [258532.053017] RDX: 0000000000000004 RSI: 000000000000836c RDI: 00007f86a8221000 [258532.053019] RBP: 0000000000021ec9 R08: 0000000000000003 R09: 00007f86a812037c [258532.053020] R10: 0000000000000001 R11: 0000000000000246 R12: 00000000000074a3 [258532.053021] R13: 00007f86a8221000 R14: 000000000000836c R15: 0000000000000001 [258532.053032] irq event stamp: 1653450494 [258532.053035] hardirqs last enabled at (1653450493): [<ffffffff9dec69f9>] _raw_spin_unlock_irq+0x29/0x50 [258532.053037] hardirqs last disabled at (1653450494): [<ffffffff9d4048ea>] trace_hardirqs_off_thunk+0x1a/0x20 [258532.053039] softirqs last enabled at (1653449852): [<ffffffff9e200466>] __do_softirq+0x466/0x6bd [258532.053042] softirqs last disabled at (1653449845): [<ffffffff9d4c8a0c>] irq_exit+0xec/0x120 [258532.053043] ---[ end trace 8476fce13d9ce20a ]---
Which results in flooding dmesg/syslog since btrfs_drop_extent_cache() uses WARN_ON() and not WARN_ON_ONCE().
So fix this issue by changing run_delalloc_nocow()'s loop to move to the next extent item when the current extent item ends at at offset less than or equals to the current offset instead of the start offset.
---
fs/btrfs/inode.c +5 -1
@@ -1283,7 +1283,11 @@ next_slot:btrfs_file_extent_num_bytes (leaf, fi); disk_num_bytes =btrfs_file_extent_disk_num_bytes (leaf, fi); -if (extent_end <= start) { +/* +* If the extent we got ends before our current offset, +* skip to the next extent. +*/ +if (extent_end <= cur_offset) { path->slots[0 ]++; goto next_slot; }
PATCH 120/245 btrfs: Remove redundant btrfs_release_path from btrfs_unlink_subvol
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Lu Fengqi <[email protected]>
commit 5b7d687ad5913a56b6a8788435d7a53990b4176d upstream.
Although it is safe to call this on already released paths with no locks held or extent buffers, removing the redundant btrfs_release_path is reasonable.
[bwh: Backported to 3.16 as dependency of commit d49d3287e74f
"btrfs: fix invalid removal of root ref"]
--- fs/btrfs/inode.c | 1 - 1 file changed, 1 deletion(-)
fs/btrfs/inode.c +0 -1
@@ -4031,7 +4031,6 @@ int btrfs_unlink_subvol(struct btrfs_tra leaf = path->nodes[0 ];btrfs_item_key_to_cpu (leaf, &key, path->slots[0 ]); -btrfs_release_path (path); index = key.offset; }btrfs_release_path (path);
PATCH 121/245 btrfs: do not delete mismatched root refs
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
commit 423a716cd7be16fb08690760691befe3be97d3fc upstream.
btrfs_del_root_ref() will simply WARN_ON() if the ref doesn't match in any way, and then continue to delete the reference. This shouldn't happen, we have these values because there's more to the reference than the original root and the sub root. If any of these checks fail, return -ENOENT.
--- fs/btrfs/root-tree.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fs/btrfs/root-tree.c +6 -4
@@ -373,11 +373,13 @@ again: leaf = path->nodes[0 ]; ref =btrfs_item_ptr (leaf, path->slots[0 ], struct btrfs_root_ref); - -WARN_ON (btrfs_root_ref_dirid (leaf, ref) != dirid); -WARN_ON (btrfs_root_ref_name_len (leaf, ref) != name_len); ptr = (unsigned long )(ref +1 ); -WARN_ON (memcmp_extent_buffer (leaf, name, ptr, name_len)); +if ((btrfs_root_ref_dirid (leaf, ref) != dirid) || + (btrfs_root_ref_name_len (leaf, ref) != name_len) || +memcmp_extent_buffer (leaf, name, ptr, name_len)) { + err = -ENOENT ; + goto out; + } *sequence =btrfs_root_ref_sequence (leaf, ref); ret =btrfs_del_item (trans, tree_root, path);
PATCH 122/245 btrfs: check rw_devices, not num_devices for balance
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
commit b35cf1f0bf1f2b0b193093338414b9bd63b29015 upstream.
The fstest btrfs/154 reports
[ 8675.381709] BTRFS: Transaction aborted (error -28) [ 8675.383302] WARNING: CPU: 1 PID: 31900 at fs/btrfs/block-group.c:2038 btrfs_create_pending_block_groups+0x1e0/0x1f0 [btrfs] [ 8675.390925] CPU: 1 PID: 31900 Comm: btrfs Not tainted 5.5.0-rc6-default+ #935 [ 8675.392780] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.0-59-gc9ba527-rebuilt.opensuse.org 04/01/2014 [ 8675.395452] RIP: 0010:btrfs_create_pending_block_groups+0x1e0/0x1f0 [btrfs] [ 8675.402672] RSP: 0018:ffffb2090888fb00 EFLAGS: 00010286 [ 8675.404413] RAX: 0000000000000000 RBX: ffff92026dfa91c8 RCX: 0000000000000001 [ 8675.406609] RDX: 0000000000000000 RSI: ffffffff8e100899 RDI: ffffffff8e100971 [ 8675.408775] RBP: ffff920247c61660 R08: 0000000000000000 R09: 0000000000000000 [ 8675.410978] R10: 0000000000000000 R11: 0000000000000000 R12: 00000000ffffffe4 [ 8675.412647] R13: ffff92026db74000 R14: ffff920247c616b8 R15: ffff92026dfbc000 [ 8675.413994] FS: 00007fd5e57248c0(0000) GS:ffff92027d800000(0000) knlGS:0000000000000000 [ 8675.416146] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 8675.417833] CR2: 0000564aa51682d8 CR3: 000000006dcbc004 CR4: 0000000000160ee0 [ 8675.419801] Call Trace: [ 8675.420742] btrfs_start_dirty_block_groups+0x355/0x480 [btrfs] [ 8675.422600] btrfs_commit_transaction+0xc8/0xaf0 [btrfs] [ 8675.424335] reset_balance_state+0x14a/0x190 [btrfs] [ 8675.425824] btrfs_balance.cold+0xe7/0x154 [btrfs] [ 8675.427313] ? kmem_cache_alloc_trace+0x235/0x2c0 [ 8675.428663] btrfs_ioctl_balance+0x298/0x350 [btrfs] [ 8675.430285] btrfs_ioctl+0x466/0x2550 [btrfs] [ 8675.431788] ? mem_cgroup_charge_statistics+0x51/0xf0 [ 8675.433487] ? mem_cgroup_commit_charge+0x56/0x400 [ 8675.435122] ? do_raw_spin_unlock+0x4b/0xc0 [ 8675.436618] ? _raw_spin_unlock+0x1f/0x30 [ 8675.438093] ? __handle_mm_fault+0x499/0x740 [ 8675.439619] ? do_vfs_ioctl+0x56e/0x770 [ 8675.441034] do_vfs_ioctl+0x56e/0x770 [ 8675.442411] ksys_ioctl+0x3a/0x70 [ 8675.443718] ? trace_hardirqs_off_thunk+0x1a/0x1c [ 8675.445333] __x64_sys_ioctl+0x16/0x20 [ 8675.446705] do_syscall_64+0x50/0x210 [ 8675.448059] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 8675.479187] BTRFS: error (device vdb) in btrfs_create_pending_block_groups:2038: errno=-28 No space left
We now use btrfs_can_overcommit() to see if we can flip a block group read only. Before this would fail because we weren't taking into account the usable un-allocated space for allocating chunks. With my patches we were allowed to do the balance, which is technically correct.
The test is trying to start balance on degraded mount. So now we're trying to allocate a chunk and cannot because we want to allocate a RAID1 chunk, but there's only 1 device that's available for usage. This results in an ENOSPC.
But we shouldn't even be making it this far, we don't have enough devices to restripe. The problem is we're using btrfs_num_devices(), that also includes missing devices. That's not actually what we want, we need to use rw_devices.
The chunk_mutex is not needed here, rw_devices changes only in device add, remove or replace, all are excluded by EXCL_OP mechanism.
--- fs/btrfs/volumes.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/btrfs/volumes.c +5 -1
@@ -3248,7 +3248,11 @@ int btrfs_balance(struct btrfs_balance_c } } - num_devices = fs_info->fs_devices->num_devices; +/* +* rw_devices will not change at the moment, device add/delete/replace +* are excluded by EXCL_OP +*/ + num_devices = fs_info->fs_devices->rw_devices;btrfs_dev_replace_lock (&fs_info->dev_replace);if (btrfs_dev_replace_is_ongoing (&fs_info->dev_replace)) {BUG_ON (num_devices <1 );
PATCH 123/245 ext4: check for directory entries too close to block end
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
commit 109ba779d6cca2d519c5dd624a3276d03e21948e upstream.
ext4_check_dir_entry() currently does not catch a case when a directory entry ends so close to the block end that the header of the next directory entry would not fit in the remaining space. This can lead to directory iteration code trying to access address beyond end of current buffer head leading to oops.
--- fs/ext4/dir.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/ext4/dir.c +5 -0
@@ -78,6 +78,11 @@ int __ext4_check_dir_entry(const char *f error_msg ="rec_len is too small for name_len" ; else if (unlikely(((char *) de - buf) + rlen > size)) error_msg ="directory entry overrun" ; + else if (unlikely(((char *) de - buf) + rlen > + size - EXT4_DIR_REC_LEN(1) && + ((char *) de - buf) + rlen != size)) { + error_msg ="directory entry too close to block end" ; + } else if (unlikely(le32_to_cpu(de->inode) > le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count))) error_msg ="inode out of bounds" ;
PATCH 124/245 powerpc/irq: fix stack overflow verification
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Christophe Leroy <[email protected]>
commit 099bc4812f09155da77eeb960a983470249c9ce1 upstream.
Before commit 0366a1c70b89 ("powerpc/irq: Run softirqs off the top of the irq stack"), check_stack_overflow() was called by do_IRQ(), before switching to the irq stack.
In that commit, do_IRQ() was renamed __do_irq(), and is now executing on the irq stack, so check_stack_overflow() has just become almost useless.
Move check_stack_overflow() call in do_IRQ() to do the check while still on the current stack.
--- arch/powerpc/kernel/irq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kernel/irq.c +2 -2
@@ -471,8 +471,6 @@ void __do_irq(struct pt_regs *regs)trace_irq_entry (regs); -check_stack_overflow (); -/* * Query the platform PIC for the interrupt & ack it. *
@@ -504,6 +502,8 @@ void do_IRQ(struct pt_regs *regs) irqtp = hardirq_ctx[raw_smp_processor_id ()]; sirqtp = softirq_ctx[raw_smp_processor_id ()]; +check_stack_overflow (); +/* Already there ? */ if (unlikely (curtp == irqtp || curtp == sirqtp)) {__do_irq (regs);
PATCH 125/245 6pack,mkiss: fix possible deadlock
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 5c9934b6767b16ba60be22ec3cbd4379ad64170d upstream.
We got another syzbot report [1] that tells us we must use write_lock_irq()/write_unlock_irq() to avoid possible deadlock.
[1]
WARNING: inconsistent lock state
5.5.0-rc1-syzkaller #0 Not tainted
--------------------------------
inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-R} usage.
syz-executor826/9605 [HC1[1]:SC0[0]:HE0:SE1] takes:ffffffff8a128718 (disc_data_lock){+-..}, at: sp_get.isra.0+0x1d/0xf0 drivers/net/ppp/ppp_synctty.c:138 {HARDIRQ-ON-W} state was registered at:
lock_acquire+0x190/0x410 kernel/locking/lockdep.c:4485 __raw_write_lock_bh include/linux/rwlock_api_smp.h:203 [inline] _raw_write_lock_bh+0x33/0x50 kernel/locking/spinlock.c:319 sixpack_close+0x1d/0x250 drivers/net/hamradio/6pack.c:657 tty_ldisc_close.isra.0+0x119/0x1a0 drivers/tty/tty_ldisc.c:489 tty_set_ldisc+0x230/0x6b0 drivers/tty/tty_ldisc.c:585 tiocsetd drivers/tty/tty_io.c:2337 [inline] tty_ioctl+0xe8d/0x14f0 drivers/tty/tty_io.c:2597 vfs_ioctl fs/ioctl.c:47 [inline] file_ioctl fs/ioctl.c:545 [inline] do_vfs_ioctl+0x977/0x14e0 fs/ioctl.c:732 ksys_ioctl+0xab/0xd0 fs/ioctl.c:749 __do_sys_ioctl fs/ioctl.c:756 [inline] __se_sys_ioctl fs/ioctl.c:754 [inline] __x64_sys_ioctl+0x73/0xb0 fs/ioctl.c:754 do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294 entry_SYSCALL_64_after_hwframe+0x49/0xbe irq event stamp: 3946 hardirqs last enabled at (3945): [<ffffffff87c86e43>] __raw_spin_unlock_irq include/linux/spinlock_api_smp.h:168 [inline] hardirqs last enabled at (3945): [<ffffffff87c86e43>] _raw_spin_unlock_irq+0x23/0x80 kernel/locking/spinlock.c:199 hardirqs last disabled at (3946): [<ffffffff8100675f>] trace_hardirqs_off_thunk+0x1a/0x1c arch/x86/entry/thunk_64.S:42 softirqs last enabled at (2658): [<ffffffff86a8b4df>] spin_unlock_bh include/linux/spinlock.h:383 [inline] softirqs last enabled at (2658): [<ffffffff86a8b4df>] clusterip_netdev_event+0x46f/0x670 net/ipv4/netfilter/ipt_CLUSTERIP.c:222 softirqs last disabled at (2656): [<ffffffff86a8b22b>] spin_lock_bh include/linux/spinlock.h:343 [inline] softirqs last disabled at (2656): [<ffffffff86a8b22b>] clusterip_netdev_event+0x1bb/0x670 net/ipv4/netfilter/ipt_CLUSTERIP.c:196
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
----
lock(disc_data_lock);
<Interrupt>
lock(disc_data_lock);*** DEADLOCK ***
5 locks held by syz-executor826/9605:
#0: ffff8880a905e198 (&tty->legacy_mutex){+.+.}, at: tty_lock+0xc7/0x130 drivers/tty/tty_mutex.c:19
#1: ffffffff899a56c0 (rcu_read_lock){....}, at: mutex_spin_on_owner+0x0/0x330 kernel/locking/mutex.c:413
#2: ffff8880a496a2b0 (&(&i->lock)->rlock){-.-.}, at: spin_lock include/linux/spinlock.h:338 [inline]
#2: ffff8880a496a2b0 (&(&i->lock)->rlock){-.-.}, at: serial8250_interrupt+0x2d/0x1a0 drivers/tty/serial/8250/8250_core.c:116 #3: ffffffff8c104048 (&port_lock_key){-.-.}, at: serial8250_handle_irq.part.0+0x24/0x330 drivers/tty/serial/8250/8250_port.c:1823 #4: ffff8880a905e090 (&tty->ldisc_sem){++++}, at: tty_ldisc_ref+0x22/0x90 drivers/tty/tty_ldisc.c:288
stack backtrace: CPU: 1 PID: 9605 Comm: syz-executor826 Not tainted 5.5.0-rc1-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: <IRQ> __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x197/0x210 lib/dump_stack.c:118 print_usage_bug.cold+0x327/0x378 kernel/locking/lockdep.c:3101 valid_state kernel/locking/lockdep.c:3112 [inline] mark_lock_irq kernel/locking/lockdep.c:3309 [inline] mark_lock+0xbb4/0x1220 kernel/locking/lockdep.c:3666 mark_usage kernel/locking/lockdep.c:3554 [inline] __lock_acquire+0x1e55/0x4a00 kernel/locking/lockdep.c:3909 lock_acquire+0x190/0x410 kernel/locking/lockdep.c:4485 __raw_read_lock include/linux/rwlock_api_smp.h:149 [inline] _raw_read_lock+0x32/0x50 kernel/locking/spinlock.c:223 sp_get.isra.0+0x1d/0xf0 drivers/net/ppp/ppp_synctty.c:138 sixpack_write_wakeup+0x25/0x340 drivers/net/hamradio/6pack.c:402 tty_wakeup+0xe9/0x120 drivers/tty/tty_io.c:536 tty_port_default_wakeup+0x2b/0x40 drivers/tty/tty_port.c:50 tty_port_tty_wakeup+0x57/0x70 drivers/tty/tty_port.c:387 uart_write_wakeup+0x46/0x70 drivers/tty/serial/serial_core.c:104 serial8250_tx_chars+0x495/0xaf0 drivers/tty/serial/8250/8250_port.c:1761 serial8250_handle_irq.part.0+0x2a2/0x330 drivers/tty/serial/8250/8250_port.c:1834 serial8250_handle_irq drivers/tty/serial/8250/8250_port.c:1820 [inline] serial8250_default_handle_irq+0xc0/0x150 drivers/tty/serial/8250/8250_port.c:1850 serial8250_interrupt+0xf1/0x1a0 drivers/tty/serial/8250/8250_core.c:126 __handle_irq_event_percpu+0x15d/0x970 kernel/irq/handle.c:149 handle_irq_event_percpu+0x74/0x160 kernel/irq/handle.c:189 handle_irq_event+0xa7/0x134 kernel/irq/handle.c:206 handle_edge_irq+0x25e/0x8d0 kernel/irq/chip.c:830 generic_handle_irq_desc include/linux/irqdesc.h:156 [inline] do_IRQ+0xde/0x280 arch/x86/kernel/irq.c:250 common_interrupt+0xf/0xf arch/x86/entry/entry_64.S:607 </IRQ> RIP: 0010:cpu_relax arch/x86/include/asm/processor.h:685 [inline] RIP: 0010:mutex_spin_on_owner+0x247/0x330 kernel/locking/mutex.c:579 Code: c3 be 08 00 00 00 4c 89 e7 e8 e5 06 59 00 4c 89 e0 48 c1 e8 03 42 80 3c 38 00 0f 85 e1 00 00 00 49 8b 04 24 a8 01 75 96 f3 90 <e9> 2f fe ff ff 0f 0b e8 0d 19 09 00 84 c0 0f 85 ff fd ff ff 48 c7 RSP: 0018:ffffc90001eafa20 EFLAGS: 00000246 ORIG_RAX: ffffffffffffffd7 RAX: 0000000000000000 RBX: ffff88809fd9e0c0 RCX: 1ffffffff13266dd RDX: 0000000000000000 RSI: 0000000000000008 RDI: 0000000000000000 RBP: ffffc90001eafa60 R08: 1ffff11013d22898 R09: ffffed1013d22899 R10: ffffed1013d22898 R11: ffff88809e9144c7 R12: ffff8880a905e138 R13: ffff88809e9144c0 R14: 0000000000000000 R15: dffffc0000000000 mutex_optimistic_spin kernel/locking/mutex.c:673 [inline] __mutex_lock_common kernel/locking/mutex.c:962 [inline] __mutex_lock+0x32b/0x13c0 kernel/locking/mutex.c:1106 mutex_lock_nested+0x16/0x20 kernel/locking/mutex.c:1121 tty_lock+0xc7/0x130 drivers/tty/tty_mutex.c:19 tty_release+0xb5/0xe90 drivers/tty/tty_io.c:1665 __fput+0x2ff/0x890 fs/file_table.c:280 ____fput+0x16/0x20 fs/file_table.c:313 task_work_run+0x145/0x1c0 kernel/task_work.c:113 exit_task_work include/linux/task_work.h:22 [inline] do_exit+0x8e7/0x2ef0 kernel/exit.c:797 do_group_exit+0x135/0x360 kernel/exit.c:895 __do_sys_exit_group kernel/exit.c:906 [inline] __se_sys_exit_group kernel/exit.c:904 [inline] __x64_sys_exit_group+0x44/0x50 kernel/exit.c:904 do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x43fef8 Code: Bad RIP value. RSP: 002b:00007ffdb07d2338 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7 RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 000000000043fef8 RDX: 0000000000000000 RSI: 000000000000003c RDI: 0000000000000000 RBP: 00000000004bf730 R08: 00000000000000e7 R09: ffffffffffffffd0 R10: 00000000004002c8 R11: 0000000000000246 R12: 0000000000000001 R13: 00000000006d1180 R14: 0000000000000000 R15: 0000000000000000
--- drivers/net/hamradio/6pack.c | 4 ++-- drivers/net/hamradio/mkiss.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/hamradio/6pack.c +2 -2
@@ -685,10 +685,10 @@ static void sixpack_close(struct tty_str {struct sixpack *sp; -write_lock_bh (&disc_data_lock); +write_lock_irq (&disc_data_lock); sp = tty->disc_data; tty->disc_data =NULL ; -write_unlock_bh (&disc_data_lock); +write_unlock_irq (&disc_data_lock);if (!sp)return ;
drivers/net/hamradio/mkiss.c +2 -2
@@ -811,10 +811,10 @@ static void mkiss_close(struct tty_struc {struct mkiss *ax; -write_lock_bh (&disc_data_lock); +write_lock_irq (&disc_data_lock); ax = tty->disc_data; tty->disc_data =NULL ; -write_unlock_bh (&disc_data_lock); +write_unlock_irq (&disc_data_lock);if (!ax)return ;
PATCH 126/245 tcp: do not send empty skb from tcp_write_xmit()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 1f85e6267caca44b30c54711652b0726fadbb131 upstream.
Backport of commit fdfc5c8594c2 ("tcp: remove empty skb from write queue in error cases") in linux-4.14 stable triggered various bugs. One of them has been fixed in commit ba2ddb43f270 ("tcp: Don't dequeue SYN/FIN-segments from write-queue"), but we still have crashes in some occasions.
Root-cause is that when tcp_sendmsg() has allocated a fresh skb and could not append a fragment before being blocked in sk_stream_wait_memory(), tcp_write_xmit() might be called and decide to send this fresh and empty skb.
Sending an empty packet is not only silly, it might have caused many issues we had in the past with tp->packets_out being out of sync.
--- net/ipv4/tcp_output.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/ipv4/tcp_output.c +8 -0
@@ -1992,6 +1992,14 @@ static bool tcp_write_xmit(struct sock * unlikely(tso_fragment(sk, skb, limit, mss_now, gfp))) break; +/* Argh, we hit an empty skb(), presumably a thread +* is sleeping in sendmsg()/sk_stream_wait_memory(). +* We do not want to send a pure-ack packet and have +* a strange looking rtx queue with empty packet(s). +*/ +if (TCP_SKB_CB (skb)->end_seq ==TCP_SKB_CB (skb)->seq) +break ; +TCP_SKB_CB (skb)->when = tcp_time_stamp;if (unlikely (tcp_transmit_skb (sk, skb,1 , gfp)))
PATCH 127/245 ALSA: pcm: Avoid possible info leaks from PCM stream buffers
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit add9d56d7b3781532208afbff5509d7382fb6efe upstream.
The current PCM code doesn't initialize explicitly the buffers allocated for PCM streams, hence it might leak some uninitialized kernel data or previous stream contents by mmapping or reading the buffer before actually starting the stream.
Since this is a common problem, this patch simply adds the clearance of the buffer data at hw_params callback. Although this does only zero-clear no matter which format is used, which doesn't mean the silence for some formats, but it should be OK because the intention is just to clear the previous data on the buffer.
--- sound/core/pcm_native.c | 4 ++++ 1 file changed, 4 insertions(+)
sound/core/pcm_native.c +4 -0
@@ -459,6 +459,10 @@ static int snd_pcm_hw_params(struct snd_while (runtime->boundary *2 <=LONG_MAX - runtime->buffer_size) runtime->boundary *=2 ; +/* clear the buffer for avoiding possible kernel info leaks */ +if (runtime->dma_area) +memset (runtime->dma_area,0 , runtime->dma_bytes); +snd_pcm_timer_resolution_change (substream);snd_pcm_set_state (substream,SNDRV_PCM_STATE_SETUP );
PATCH 128/245 ALSA: hda/ca0132 - Avoid endless loop
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit cb04fc3b6b076f67d228a0b7d096c69ad486c09c upstream.
Introduce a timeout to dspio_clear_response_queue() so that it won't be caught in an endless loop even if the hardware doesn't respond properly.
--- sound/pci/hda/patch_ca0132.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
sound/pci/hda/patch_ca0132.c +3 -2
@@ -1271,13 +1271,14 @@ struct scp_msg {static void dspio_clear_response_queue (struct hda_codec *codec) { +unsigned long timeout = jiffies +msecs_to_jiffies (1000 );unsigned int dummy =0 ; -int status =-1 ; +int status;/* clear all from the response queue */ do { status =dspio_read (codec, &dummy); - }while (status ==0 ); + }while (status ==0 &&time_before (jiffies, timeout)); }static int dspio_get_response_data (struct hda_codec *codec)
PATCH 129/245 ASoC: wm8962: fix lambda value
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Shengjiu Wang <[email protected]>
commit 556672d75ff486e0b6786056da624131679e0576 upstream.
According to user manual, it is required that FLL_LAMBDA > 0 in all cases (Integer and Franctional modes).
--- sound/soc/codecs/wm8962.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/wm8962.c +2 -2
@@ -2795,7 +2795,7 @@ static int fll_factors(struct _fll_div *if (target % Fref ==0 ) { fll_div->theta =0 ; - fll_div->lambda =0 ; + fll_div->lambda =1 ; }else { gcd_fll =gcd (target, fratio * Fref);
@@ -2865,7 +2865,7 @@ static int wm8962_set_fll(struct snd_socreturn -EINVAL ; } -if (fll_div.theta || fll_div.lambda) +if (fll_div.theta) fll1 |=WM8962_FLL_FRAC ;/* Stop the FLL while we reconfigure */
PATCH 130/245 tty: link tty and port before configuring it as console
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Sudip Mukherjee <[email protected]>
commit fb2b90014d782d80d7ebf663e50f96d8c507a73c upstream.
There seems to be a race condition in tty drivers and I could see on many boot cycles a NULL pointer dereference as tty_init_dev() tries to do 'tty->port->itty = tty' even though tty->port is NULL. 'tty->port' will be set by the driver and if the driver has not yet done it before we open the tty device we can get to this situation. By adding some extra debug prints, I noticed that:
6.650130: uart_add_one_port
6.663849: register_console
6.664846: tty_open
6.674391: tty_init_dev
6.675456: tty_port_link_device
uart_add_one_port() registers the console, as soon as it registers, the userspace tries to use it and that leads to tty_open() but uart_add_one_port() has not yet done tty_port_link_device() and so tty->port is not yet configured when control reaches tty_init_dev().
Further look into the code and tty_port_link_device() is done by uart_add_one_port(). After registering the console uart_add_one_port() will call tty_port_register_device_attr_serdev() and tty_port_link_device() is called from this.
Call add tty_port_link_device() before uart_configure_port() is done and add a check in tty_port_link_device() so that it only links the port if it has not been done yet.
--- drivers/tty/serial/serial_core.c | 1 + drivers/tty/tty_port.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/tty/serial/serial_core.c +1 -0
@@ -2639,6 +2639,7 @@ int uart_add_one_port(struct uart_driverlockdep_set_class (&uport->lock, &port_lock_key); } +tty_port_link_device (port, drv->tty_driver, uport->line);uart_configure_port (drv, state, uport);/*
drivers/tty/tty_port.c +2 -1
@@ -49,7 +49,8 @@ void tty_port_link_device(struct tty_por {if (WARN_ON (index >= driver->num))return ; - driver->ports[index] = port; +if (!driver->ports[index]) + driver->ports[index] = port; }EXPORT_SYMBOL_GPL (tty_port_link_device);
PATCH 131/245 USB: EHCI: Do not return -EPIPE when hub is disconnected
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Erkka Talvitie <[email protected]>
commit 64cc3f12d1c7dd054a215bc1ff9cc2abcfe35832 upstream.
When disconnecting a USB hub that has some child device(s) connected to it (such as a USB mouse), then the stack tries to clear halt and reset device(s) which are _already_ physically disconnected.
The issue has been reproduced with:
CPU: IMX6D5EYM10AD or MCIMX6D5EYM10AE.
SW: U-Boot 2019.07 and kernel 4.19.40.
CPU: HP Proliant Microserver Gen8.
SW: Linux version 4.2.3-300.fc23.x86_64
In this situation there will be error bit for MMF active yet the CERR equals EHCI_TUNE_CERR + halt. Existing implementation interprets this as a stall [1] (chapter 8.4.5).
The possible conditions when the MMF will be active + halt can be found from [2] (Table 4-13).
Fix for the issue is to check whether MMF is active and PID Code is IN before checking for the stall. If these conditions are true then it is not a stall.
What happens after the fix is that when disconnecting a hub with attached device(s) the situation is not interpret as a stall.
[1] [https://www.usb.org/document-library/usb-20-specification, usb_20.pdf]
[2] [https://www.intel.com/content/dam/www/public/us/en/documents/
technical-specifications/ehci-specification-for-usb.pdf]
--- drivers/usb/host/ehci-q.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/usb/host/ehci-q.c +12 -1
@@ -40,6 +40,10 @@/*-------------------------------------------------------------------------*/ +/* PID Codes that are used here, from EHCI specification, Table 3-16. */ +#define PID_CODE_IN 1 +#define PID_CODE_SETUP 2 +/* fill a qtd, returning how much of the buffer we were able to queue up */ static int
@@ -199,7 +203,7 @@ static int qtd_copy_status (int status = -EINPROGRESS ;/* count IN/OUT bytes, not SETUP (even short packets) */ -if (likely (QTD_PID (token) !=2 )) +if (likely (QTD_PID (token) !=PID_CODE_SETUP )) urb->actual_length += length -QTD_LENGTH (token);/* don't modify error codes */
@@ -215,6 +219,13 @@ static int qtd_copy_status (if (token &QTD_STS_BABBLE ) {/* FIXME "must" disable babbling device's port too */ status = -EOVERFLOW ; +/* +* When MMF is active and PID Code is IN, queue is halted. +* EHCI Specification, Table 4-13. +*/ + }else if ((token &QTD_STS_MMF ) && + (QTD_PID (token) ==PID_CODE_IN )) { + status = -EPROTO ;/* CERR nonzero + halt --> stall */ }else if (QTD_CERR (token)) { status = -EPIPE ;
PATCH 132/245 usbip: Fix error path of vhci_recv_ret_submit()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Suwan Kim <[email protected]>
commit aabb5b833872524eaf28f52187e5987984982264 upstream.
If a transaction error happens in vhci_recv_ret_submit(), event handler closes connection and changes port status to kick hub_event. Then hub tries to flush the endpoint URBs, but that causes infinite loop between usb_hub_flush_endpoint() and vhci_urb_dequeue() because "vhci_priv" in vhci_urb_dequeue() was already released by vhci_recv_ret_submit() before a transmission error occurred. Thus, vhci_urb_dequeue() terminates early and usb_hub_flush_endpoint() continuously calls vhci_urb_dequeue().
The root cause of this issue is that vhci_recv_ret_submit() terminates early without giving back URB when transaction error occurs in vhci_recv_ret_submit(). That causes the error URB to still be linked at endpoint list without “vhci_priv".
So, in the case of transaction error in vhci_recv_ret_submit(), unlink URB from the endpoint, insert proper error code in urb->status and give back URB.
--- drivers/staging/usbip/vhci_rx.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/staging/usbip/vhci_rx.c +9 -4
@@ -88,16 +88,21 @@ static void vhci_recv_ret_submit(structusbip_pack_pdu (pdu, urb,USBIP_RET_SUBMIT ,0 );/* recv transfer buffer */ -if (usbip_recv_xbuff (ud, urb) <0 ) -return ; +if (usbip_recv_xbuff (ud, urb) <0 ) { + urb->status = -EPROTO ; + goto error; + }/* recv iso_packet_descriptor */ -if (usbip_recv_iso (ud, urb) <0 ) -return ; +if (usbip_recv_iso (ud, urb) <0 ) { + urb->status = -EPROTO ; + goto error; + }/* restore the padding in iso packets */ usbip_pad_iso (ud, urb); +error:if (usbip_dbg_flag_vhci_rx)usbip_dump_urb (urb);
PATCH 133/245 kvm: x86: Host feature SSBD doesn't imply guest feature SPEC_CTRL_SSBD
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jim Mattson <[email protected]>
commit 396d2e878f92ec108e4293f1c77ea3bc90b414ff upstream.
The host reports support for the synthetic feature X86_FEATURE_SSBD when any of the three following hardware features are set:
CPUID.(EAX=7,ECX=0):EDX.SSBD[bit 31] CPUID.80000008H:EBX.AMD_SSBD[bit 24] CPUID.80000008H:EBX.VIRT_SSBD[bit 25]
Either of the first two hardware features implies the existence of the IA32_SPEC_CTRL MSR, but CPUID.80000008H:EBX.VIRT_SSBD[bit 25] does not. Therefore, CPUID.(EAX=7,ECX=0):EDX.SSBD[bit 31] should only be set in the guest if CPUID.(EAX=7,ECX=0):EDX.SSBD[bit 31] or CPUID.80000008H:EBX.AMD_SSBD[bit 24] is set on the host.
--- arch/x86/kvm/cpuid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/cpuid.c +2 -1
@@ -400,7 +400,8 @@ static inline int __do_cpuid_ent(struct entry->edx |=F (SPEC_CTRL );if (boot_cpu_has (X86_FEATURE_STIBP )) entry->edx |=F (INTEL_STIBP ); -if (boot_cpu_has (X86_FEATURE_SSBD )) +if (boot_cpu_has (X86_FEATURE_SPEC_CTRL_SSBD ) || +boot_cpu_has (X86_FEATURE_AMD_SSBD )) entry->edx |=F (SPEC_CTRL_SSBD );/* * We emulate ARCH_CAPABILITIES in software even
PATCH 134/245 net: stmmac: 16KB buffer must be 16 byte aligned
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jose Abreu <[email protected]>
commit 8605131747e7e1fd8f6c9f97a00287aae2b2c640 upstream.
The 16KB RX Buffer must also be 16 byte aligned. Fix it.
--- drivers/net/ethernet/stmicro/stmmac/common.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/common.h +2 -3
@@ -270,9 +270,8 @@ struct dma_features {unsigned int enh_desc; }; -/* GMAC TX FIFO is 8K, Rx FIFO is 16K */ -#define BUF_SIZE_16KiB 16384 -/* RX Buffer size must be < 8191 and multiple of 4/8/16 bytes */ +/* RX Buffer size must be multiple of 4/8/16 bytes */ +#define BUF_SIZE_16KiB 16368#define BUF_SIZE_8KiB 8188#define BUF_SIZE_4KiB 4096#define BUF_SIZE_2KiB 2048
PATCH 135/245 net: stmmac: Enable 16KB buffer size
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jose Abreu <[email protected]>
commit b2f3a481c4cd62f78391b836b64c0a6e72b503d2 upstream.
XGMAC supports maximum MTU that can go to 16KB. Lets add this check in the calculation of RX buffer size.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -1
@@ -904,7 +904,9 @@ static int stmmac_set_bfsize(int mtu, in {int ret = bufsize; -if (mtu >= BUF_SIZE_4KiB) +if (mtu >= BUF_SIZE_8KiB) + ret = BUF_SIZE_16KiB; +else if (mtu >= BUF_SIZE_4KiB) ret = BUF_SIZE_8KiB;else if (mtu >= BUF_SIZE_2KiB) ret = BUF_SIZE_4KiB;
PATCH 136/245 netfilter: ebtables: convert BUG_ONs to WARN_ONs
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit fc6a5d0601c5ac1d02f283a46f60b87b2033e5ca upstream.
All of these conditions are not fatal and should have been WARN_ONs from the get-go.
Convert them to WARN_ONs and bail out.
--- net/bridge/netfilter/ebtables.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
net/bridge/netfilter/ebtables.c +18 -9
@@ -1603,7 +1603,8 @@ static int compat_match_to_user(struct eint off =ebt_compat_match_offset (match, m->match_size);compat_uint_t msize = m->match_size - off; -BUG_ON (off >= m->match_size); +if (WARN_ON (off >= m->match_size)) +return -EINVAL ;if (copy_to_user (cm->u.name, match->name,strlen (match->name) +1 ) ||put_user (msize, &cm->match_size))
@@ -1630,7 +1631,8 @@ static int compat_target_to_user(structint off =xt_compat_target_offset (target);compat_uint_t tsize = t->target_size - off; -BUG_ON (off >= t->target_size); +if (WARN_ON (off >= t->target_size)) +return -EINVAL ;if (copy_to_user (cm->u.name, target->name,strlen (target->name) +1 ) ||put_user (tsize, &cm->match_size))
@@ -1858,7 +1860,8 @@ static int ebt_buf_add(struct ebt_entrieif (state->buf_kern_start ==NULL ) goto count_only; -BUG_ON (state->buf_kern_offset + sz > state->buf_kern_len); +if (WARN_ON (state->buf_kern_offset + sz > state->buf_kern_len)) +return -EINVAL ;memcpy (state->buf_kern_start + state->buf_kern_offset, data, sz);
@@ -1871,7 +1874,8 @@ static int ebt_buf_add_pad(struct ebt_en {char *b = state->buf_kern_start; -BUG_ON (b && state->buf_kern_offset > state->buf_kern_len); +if (WARN_ON (b && state->buf_kern_offset > state->buf_kern_len)) +return -EINVAL ;if (b !=NULL && sz >0 )memset (b + state->buf_kern_offset,0 , sz);
@@ -1949,8 +1953,10 @@ static int compat_mtw_from_user(struct c pad =XT_ALIGN (size_kern) - size_kern;if (pad >0 && dst) { -BUG_ON (state->buf_kern_len <= pad); -BUG_ON (state->buf_kern_offset - (match_size + off) + size_kern > state->buf_kern_len - pad); +if (WARN_ON (state->buf_kern_len <= pad)) +return -EINVAL ; +if (WARN_ON (state->buf_kern_offset - (match_size + off) + size_kern > state->buf_kern_len - pad)) +return -EINVAL ;memset (dst + size_kern,0 , pad); }return off + match_size;
@@ -2001,7 +2007,8 @@ static int ebt_size_mwt(struct compat_ebif (ret <0 )return ret; -BUG_ON (ret < match32->match_size); +if (WARN_ON (ret < match32->match_size)) +return -EINVAL ; growth += ret - match32->match_size; growth +=ebt_compat_entry_padsize ();
@@ -2116,7 +2123,8 @@ static int size_entry_mwt(struct ebt_ent startoff = state->buf_user_offset - startoff; -BUG_ON (*total < startoff); +if (WARN_ON (*total < startoff)) +return -EINVAL ; *total -= startoff;return 0 ; }
@@ -2246,7 +2254,8 @@ static int compat_do_replace(struct net state.buf_kern_len = size64; ret =compat_copy_entries (entries_tmp, tmp.entries_size, &state); -BUG_ON (ret <0 );/* parses same data again */ +if (WARN_ON (ret <0 )) + goto out_unlock;vfree (entries_tmp); tmp.entries_size = size64;
PATCH 137/245 netfilter: ebtables: compat: reject all padding in matches/watchers
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit e608f631f0ba5f1fc5ee2e260a3a35d13107cbfe upstream.
syzbot reported following splat:
BUG: KASAN: vmalloc-out-of-bounds in size_entry_mwt net/bridge/netfilter/ebtables.c:2063 [inline] BUG: KASAN: vmalloc-out-of-bounds in compat_copy_entries+0x128b/0x1380 net/bridge/netfilter/ebtables.c:2155 Read of size 4 at addr ffffc900004461f4 by task syz-executor267/7937 CPU: 1 PID: 7937 Comm: syz-executor267 Not tainted 5.5.0-rc1-syzkaller #0 size_entry_mwt net/bridge/netfilter/ebtables.c:2063 [inline] compat_copy_entries+0x128b/0x1380 net/bridge/netfilter/ebtables.c:2155 compat_do_replace+0x344/0x720 net/bridge/netfilter/ebtables.c:2249 compat_do_ebt_set_ctl+0x22f/0x27e net/bridge/netfilter/ebtables.c:2333 [..]
Because padding isn't considered during computation of ->buf_user_offset, "total" is decremented by fewer bytes than it should.
Therefore, the first part of
if (*total < sizeof(*entry) || entry->next_offset < sizeof(*entry))
will pass, -- it should not have. This causes oob access:entry->next_offset is past the vmalloced size.
Reject padding and check that computed user offset (sum of ebt_entry structure plus all individual matches/watchers/targets) is same value that userspace gave us as the offset of the next entry.
--- net/bridge/netfilter/ebtables.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
net/bridge/netfilter/ebtables.c +16 -17
@@ -1855,7 +1855,7 @@ static int ebt_buf_count(struct ebt_entr }static int ebt_buf_add (struct ebt_entries_buf_state *state, -void *data,unsigned int sz) +const void *data,unsigned int sz) {if (state->buf_kern_start ==NULL ) goto count_only;
@@ -1889,7 +1889,7 @@ enum compat_mwt { EBT_COMPAT_TARGET, }; -static int compat_mtw_from_user (struct compat_ebt_entry_mwt *mwt, +static int compat_mtw_from_user (const struct compat_ebt_entry_mwt *mwt,enum compat_mwt compat_mwt,struct ebt_entries_buf_state *state,const unsigned char *base)
@@ -1966,22 +1966,23 @@ static int compat_mtw_from_user(struct c* return size of all matches, watchers or target, including necessary * alignment and padding. */ -static int ebt_size_mwt (struct compat_ebt_entry_mwt *match32, +static int ebt_size_mwt (const struct compat_ebt_entry_mwt *match32,unsigned int size_left,enum compat_mwt type,struct ebt_entries_buf_state *state,const void *base) { +const char *buf = (const char *)match32;int growth =0 ; -char *buf;if (size_left ==0 )return 0 ; - buf = (char *) match32; - -while (size_left >=sizeof (*match32)) { + do { struct ebt_entry_match *match_kern; int ret; + if (size_left < sizeof(*match32)) + return -EINVAL; + match_kern = (struct ebt_entry_match *) state->buf_kern_start; if (match_kern) { char *tmp;
@@ -2018,22 +2019,18 @@ static int ebt_size_mwt(struct compat_ebif (match_kern) match_kern->match_size = ret; -/* rule should have no remaining data after target */ -if (type ==EBT_COMPAT_TARGET && size_left) -return -EINVAL ; - match32 = (struct compat_ebt_entry_mwt *) buf; - } + }while (size_left);return growth; }/* called for all ebt_entry structures. */ -static int size_entry_mwt (struct ebt_entry *entry,const unsigned char *base, +static int size_entry_mwt (const struct ebt_entry *entry,const unsigned char *base,unsigned int *total,struct ebt_entries_buf_state *state) { -unsigned int i, j, startoff, new_offset =0 ; +unsigned int i, j, startoff, next_expected_off, new_offset =0 ;/* stores match/watchers/targets & offset of next struct ebt_entry: */ unsigned int offsets[4 ];unsigned int *offsets_update =NULL ;
@@ -2121,11 +2118,13 @@ static int size_entry_mwt(struct ebt_entreturn ret; } - startoff = state->buf_user_offset - startoff; + next_expected_off = state->buf_user_offset - startoff; +if (next_expected_off != entry->next_offset) +return -EINVAL ; -if (WARN_ON (*total < startoff)) +if (*total < entry->next_offset)return -EINVAL ; - *total -= startoff; + *total -= entry->next_offset;return 0 ; }
PATCH 138/245 platform/x86: hp-wmi: Make buffer for HPWMI_FEATURE2_QUERY 128 bytes
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit 133b2acee3871ae6bf123b8fe34be14464aa3d2c upstream.
At least on the HP Envy x360 15-cp0xxx model the WMI interface for HPWMI_FEATURE2_QUERY requires an outsize of at least 128 bytes, otherwise it fails with an error code 5 (HPWMI_RET_INVALID_PARAMETERS):
Dec 06 00:59:38 kernel: hp_wmi: query 0xd returned error 0x5
We do not care about the contents of the buffer, we just want to know if the HPWMI_FEATURE2_QUERY command is supported.
This commits bumps the buffer size, fixing the error.
--- drivers/platform/x86/hp-wmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/hp-wmi.c +1 -1
@@ -309,7 +309,7 @@ static int __init hp_wmi_bios_2008_laterstatic int __init hp_wmi_bios_2009_later (void ) { -int state =0 ; +u8 state[128 ];int ret =hp_wmi_perform_query (HPWMI_FEATURE2_QUERY ,0 , &state,sizeof (state),sizeof (state));if (!ret)
PATCH 139/245 mod_devicetable: fix PHY module format
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Russell King <[email protected]>
commit d2ed49cf6c13e379c5819aa5ac20e1f9674ebc89 upstream.
When a PHY is probed, if the top bit is set, we end up requesting a module with the string "mdio:-10101110000000100101000101010001" - the top bit is printed to a signed -1 value. This leads to the module not being loaded.
Fix the module format string and the macro generating the values for it to ensure that we only print unsigned types and the top bit is always 0/1. We correctly end up with "mdio:10101110000000100101000101010001".
--- include/linux/mod_devicetable.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/mod_devicetable.h +2 -2
@@ -497,9 +497,9 @@ struct platform_device_id {#define MDIO_MODULE_PREFIX "mdio:" -#define MDIO_ID_FMT "%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d" +#define MDIO_ID_FMT "%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u%u"#define MDIO_ID_ARGS (_id) \ - (_id)>>31, ((_id)>>30) & 1, ((_id)>>29) & 1, ((_id)>>28) & 1, \ + ((_id)>>31) & 1, ((_id)>>30) & 1, ((_id)>>29) & 1, ((_id)>>28) & 1, \ ((_id)>>27) & 1, ((_id)>>26) & 1, ((_id)>>25) & 1, ((_id)>>24) & 1, \ ((_id)>>23) & 1, ((_id)>>22) & 1, ((_id)>>21) & 1, ((_id)>>20) & 1, \ ((_id)>>19) & 1, ((_id)>>18) & 1, ((_id)>>17) & 1, ((_id)>>16) & 1, \
PATCH 140/245 x86/efistub: Disable paging at mixed mode entry
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ard Biesheuvel <[email protected]>
commit 4911ee401b7ceff8f38e0ac597cbf503d71e690c upstream.
The EFI mixed mode entry code goes through the ordinary startup_32() routine before jumping into the kernel's EFI boot code in 64-bit mode. The 32-bit startup code must be entered with paging disabled, but this is not documented as a requirement for the EFI handover protocol, and so we should disable paging explicitly when entering the kernel from 32-bit EFI firmware.
--- arch/x86/boot/compressed/head_64.S | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86/boot/compressed/head_64.S +5 -0
@@ -216,6 +216,11 @@ ENTRY(efi32_stub_entry) leal efi32_config(%ebp), %eax movl %eax, efi_config(%ebp) + /* Disable paging */ + movl %cr0, %eax + btrl $X86_CR0_PG_BIT, %eax + movl %eax, %cr0 + jmp startup_32 ENDPROC(efi32_stub_entry) #endif
PATCH 141/245 ALSA: ice1724: Fix sleep-in-atomic in Infrasonic Quartet support code
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 0aec96f5897ac16ad9945f531b4bef9a2edd2ebd upstream.
Jia-Ju Bai reported a possible sleep-in-atomic scenario in the ice1724 driver with Infrasonic Quartet support code: namely, ice->set_rate callback gets called inside ice->reg_lock spinlock, while the callback in quartet.c holds ice->gpio_mutex.
This patch fixes the invalid call: it simply moves the calls of ice->set_rate and ice->set_mclk callbacks outside the spinlock.
--- sound/pci/ice1712/ice1724.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
sound/pci/ice1712/ice1724.c +6 -3
@@ -663,6 +663,7 @@ static int snd_vt1724_set_pro_rate(strucunsigned long flags;unsigned char mclk_change;unsigned int i, old_rate; +bool call_set_rate = false;if (rate > ice->hw_rates->list[ice->hw_rates->count -1 ])return -EINVAL ;
@@ -686,7 +687,7 @@ static int snd_vt1724_set_pro_rate(struc* setting clock rate for internal clock mode */ old_rate = ice->get_rate (ice);if (force || (old_rate != rate)) - ice->set_rate (ice, rate); + call_set_rate = true;else if (rate == ice->cur_rate) {spin_unlock_irqrestore (&ice->reg_lock, flags);return 0 ;
@@ -694,12 +695,14 @@ static int snd_vt1724_set_pro_rate(struc } ice->cur_rate = rate; +spin_unlock_irqrestore (&ice->reg_lock, flags); + +if (call_set_rate) + ice->set_rate (ice, rate);/* setting master clock */ mclk_change = ice->set_mclk (ice, rate); -spin_unlock_irqrestore (&ice->reg_lock, flags); -if (mclk_change && ice->gpio.i2s_mclk_changed) ice->gpio.i2s_mclk_changed (ice);if (ice->gpio.set_pro_rate)
PATCH 142/245 locks: print unsigned ino in /proc/locks
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
commit 98ca480a8f22fdbd768e3dad07024c8d4856576c upstream.
An ino is unsigned, so display it as such in /proc/locks.
--- fs/locks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/locks.c +1 -1
@@ -2488,7 +2488,7 @@ static void lock_get_status(struct seq_f inode->i_sb->s_id, inode->i_ino);#else /* userspace relies on this representation of dev_t ;-( */ -seq_printf (f,"%d %02x:%02x:%ld " , fl_pid, +seq_printf (f,"%d %02x:%02x:%lu " , fl_pid,MAJOR (inode->i_sb->s_dev),MINOR (inode->i_sb->s_dev), inode->i_ino);#endif
PATCH 143/245 netfilter: arp_tables: init netns pointer in xt_tgchk_param struct
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit 1b789577f655060d98d20ed0c6f9fbd469d6ba63 upstream.
We get crash when the targets checkentry function tries to make use of the network namespace pointer for arptables.
When the net pointer got added back in 2010, only ip/ip6/ebtables were changed to initialize it, so arptables has this set to NULL.
This isn't a problem for normal arptables because no existing arptables target has a checkentry function that makes use of par->net.
However, direct users of the setsockopt interface can provide any target they want as long as its registered for ARP or UNPSEC protocols.
syzkaller managed to send a semi-valid arptables rule for RATEEST target which is enough to trigger NULL deref:
kasan: GPF could be caused by NULL-ptr deref or user memory access
general protection fault: 0000 [#1] PREEMPT SMP KASAN RIP: xt_rateest_tg_checkentry+0x11d/0xb40 net/netfilter/xt_RATEEST.c:109 [..] xt_check_target+0x283/0x690 net/netfilter/x_tables.c:1019 check_target net/ipv4/netfilter/arp_tables.c:399 [inline] find_check_entry net/ipv4/netfilter/arp_tables.c:422 [inline] translate_table+0x1005/0x1d70 net/ipv4/netfilter/arp_tables.c:572 do_replace net/ipv4/netfilter/arp_tables.c:977 [inline] do_arpt_set_ctl+0x310/0x640 net/ipv4/netfilter/arp_tables.c:1456
--- net/ipv4/netfilter/arp_tables.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
net/ipv4/netfilter/arp_tables.c +16 -11
@@ -480,11 +480,12 @@ static int mark_source_chains(const strureturn 1 ; } -static inline int check_target (struct arpt_entry *e,const char *name) +static int check_target (struct arpt_entry *e,struct net *net,const char *name) {struct xt_entry_target *t =arpt_get_target (e);int ret;struct xt_tgchk_param par = { + .net = net, .table = name, .entryinfo = e, .target = t->u.kernel.target,
@@ -502,8 +503,9 @@ static inline int check_target(struct arreturn 0 ; } -static inline int -find_check_entry (struct arpt_entry *e,const char *name,unsigned int size) +static int +find_check_entry (struct arpt_entry *e,struct net *net,const char *name, +unsigned int size) {struct xt_entry_target *t;struct xt_target *target;
@@ -519,7 +521,7 @@ find_check_entry(struct arpt_entry *e, c } t->u.kernel.target = target; - ret =check_target (e, name); + ret =check_target (e, net, name);if (ret) goto err;return 0 ;
@@ -617,7 +619,9 @@ static inline void cleanup_entry(struct/* Checks and translates the user-supplied table segment (held in * newinfo). */ -static int translate_table (struct xt_table_info *newinfo,void *entry0, +static int translate_table (struct net *net, +struct xt_table_info *newinfo, +void *entry0,const struct arpt_replace *repl) {struct arpt_entry *iter;
@@ -692,7 +696,7 @@ static int translate_table(struct xt_tab/* Finally, each sanity check must pass */ i =0 ; xt_entry_foreach(iter, entry0, newinfo->size) { - ret =find_check_entry (iter, repl->name, repl->size); + ret =find_check_entry (iter, net, repl->name, repl->size);if (ret !=0 )break ; ++i;
@@ -1100,7 +1104,7 @@ static int do_replace(struct net *net, c goto free_newinfo; } - ret =translate_table (newinfo, loc_cpu_entry, &tmp); + ret =translate_table (net, newinfo, loc_cpu_entry, &tmp);if (ret !=0 ) goto free_newinfo;
@@ -1287,7 +1291,8 @@ compat_copy_entry_from_user(struct compa } } -static int translate_compat_table (struct xt_table_info **pinfo, +static int translate_compat_table (struct net *net, +struct xt_table_info **pinfo,void **pentry0,const struct compat_arpt_replace *compatr) {
@@ -1356,7 +1361,7 @@ static int translate_compat_table(struct repl.num_counters =0 ; repl.counters =NULL ; repl.size = newinfo->size; - ret =translate_table (newinfo, entry1, &repl); + ret =translate_table (net, newinfo, entry1, &repl);if (ret) goto free_newinfo;
@@ -1412,7 +1417,7 @@ static int compat_do_replace(struct net goto free_newinfo; } - ret =translate_compat_table (&newinfo, &loc_cpu_entry, &tmp); + ret =translate_compat_table (net, &newinfo, &loc_cpu_entry, &tmp);if (ret !=0 ) goto free_newinfo;
@@ -1685,7 +1690,7 @@ struct xt_table *arpt_register_table(str loc_cpu_entry = newinfo->entries[raw_smp_processor_id ()];memcpy (loc_cpu_entry, repl->entries, repl->size); - ret =translate_table (newinfo, loc_cpu_entry, repl); + ret =translate_table (net, newinfo, loc_cpu_entry, repl);duprintf ("arpt_register_table: translate table gives %d\n" , ret);if (ret !=0 ) goto out_free;
PATCH 144/245 tty: always relink the port
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Sudip Mukherjee <[email protected]>
commit 273f632912f1b24b642ba5b7eb5022e43a72f3b5 upstream.
If the serial device is disconnected and reconnected, it re-enumerates properly but does not link it. fwiw, linking means just saving the port index, so allow it always as there is no harm in saving the same value again even if it tries to relink with the same port.
--- drivers/tty/tty_port.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/tty/tty_port.c +1 -2
@@ -49,8 +49,7 @@ void tty_port_link_device(struct tty_por {if (WARN_ON (index >= driver->num))return ; -if (!driver->ports[index]) - driver->ports[index] = port; + driver->ports[index] = port; }EXPORT_SYMBOL_GPL (tty_port_link_device);
PATCH 145/245 USB: core: fix check for duplicate endpoints
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 3e4f8e21c4f27bcf30a48486b9dcc269512b79ff upstream.
Amend the endpoint-descriptor sanity checks to detect all duplicate endpoint addresses in a configuration.
Commit 0a8fd1346254 ("USB: fix problems with duplicate endpoint addresses") added a check for duplicate endpoint addresses within a single alternate setting, but did not look for duplicate addresses in other interfaces.
The current check would also not detect all duplicate addresses when one endpoint is as a (bi-directional) control endpoint.
This specifically avoids overwriting the endpoint entries in struct usb_device when enabling a duplicate endpoint, something which could potentially lead to crashes or leaks, for example, when endpoints are later disabled.
--- drivers/usb/core/config.c | 70 ++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 12 deletions(-)
drivers/usb/core/config.c +58 -12
@@ -169,9 +169,58 @@ static const unsigned short super_speed_ [USB_ENDPOINT_XFER_INT] = 1024, }; -static int usb_parse_endpoint (struct device *ddev,int cfgno,int inum, -int asnum,struct usb_host_interface *ifp,int num_ep, -unsigned char *buffer,int size) +static bool endpoint_is_duplicate (struct usb_endpoint_descriptor *e1, +struct usb_endpoint_descriptor *e2) +{ +if (e1->bEndpointAddress == e2->bEndpointAddress) +return true; + +if (usb_endpoint_xfer_control (e1) ||usb_endpoint_xfer_control (e2)) { +if (usb_endpoint_num (e1) ==usb_endpoint_num (e2)) +return true; + } + +return false; +} + +/* +* Check for duplicate endpoint addresses in other interfaces and in the +* altsetting currently being parsed. +*/ +static bool config_endpoint_is_duplicate (struct usb_host_config *config, +int inum,int asnum,struct usb_endpoint_descriptor *d) +{ +struct usb_endpoint_descriptor *epd; +struct usb_interface_cache *intfc; +struct usb_host_interface *alt; +int i, j, k; + +for (i =0 ; i < config->desc.bNumInterfaces; ++i) { + intfc = config->intf_cache[i]; + +for (j =0 ; j < intfc->num_altsetting; ++j) { + alt = &intfc->altsetting[j]; + +if (alt->desc.bInterfaceNumber == inum && + alt->desc.bAlternateSetting != asnum) +continue ; + +for (k =0 ; k < alt->desc.bNumEndpoints; ++k) { + epd = &alt->endpoint[k].desc; + +if (endpoint_is_duplicate (epd, d)) +return true; + } + } + } + +return false; +} + +static int usb_parse_endpoint (struct device *ddev,int cfgno, +struct usb_host_config *config,int inum,int asnum, +struct usb_host_interface *ifp,int num_ep, +unsigned char *buffer,int size) {unsigned char *buffer0 = buffer;struct usb_endpoint_descriptor *d;
@@ -208,13 +257,10 @@ static int usb_parse_endpoint(struct dev goto skip_to_next_endpoint_or_interface_descriptor;/* Check for duplicate endpoint addresses */ -for (i =0 ; i < ifp->desc.bNumEndpoints; ++i) { -if (ifp->endpoint[i].desc.bEndpointAddress == - d->bEndpointAddress) { -dev_warn (ddev,"config %d interface %d altsetting %d has a duplicate endpoint with address 0x%X, skipping\n" , - cfgno, inum, asnum, d->bEndpointAddress); - goto skip_to_next_endpoint_or_interface_descriptor; - } +if (config_endpoint_is_duplicate (config, inum, asnum, d)) { +dev_warn (ddev,"config %d interface %d altsetting %d has a duplicate endpoint with address 0x%X, skipping\n" , + cfgno, inum, asnum, d->bEndpointAddress); + goto skip_to_next_endpoint_or_interface_descriptor; } endpoint = &ifp->endpoint[ifp->desc.bNumEndpoints];
@@ -481,8 +527,8 @@ static int usb_parse_interface(struct deif (((struct usb_descriptor_header *) buffer)->bDescriptorType ==USB_DT_INTERFACE )break ; - retval =usb_parse_endpoint (ddev, cfgno, inum, asnum, alt, - num_ep, buffer, size); + retval =usb_parse_endpoint (ddev, cfgno, config, inum, asnum, + alt, num_ep, buffer, size);if (retval <0 )return retval; ++n;