Skip to contentSkip to conversation

3.16.62-rc1 review

PATCH In review Ben Hutchings 5 participants 338 messages Dec 9, 2018 – Dec 16, 2018 Page 1 of 3

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover 3.16.62-rc1 review

This is the start of the stable review cycle for the 3.16.62 release. There are 328 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 Fri Dec 14 18:00:00 UTC 2018. 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.

-------------

Aaron Knister (1):
IB/ipoib: Avoid a race condition between start_xmit and cm_rep_handler
[816e846c2eb9129a3e0afa5f920c8bbc71efecaa]

Aaron Ma (1):
Input: elantech - enable middle button of touchpad on ThinkPad P72
[91a97507323e1ad4bfc10f4a5922e67cdaf8b3cd]

Akihiro Tsukada (1):
media: dvb-usb-v2/gl861: ensure USB message buffers DMA'able
[86f65c218123c4e36fd855fbbc38147ffaf29974]

Al Viro (1):
cachefiles: fix the race between cachefiles_bury_object() and rmdir(2)
[169b803397499be85bdd1e3d07d6f5e3d4bd669e]

Alan Stern (6):
USB: fix error handling in usb_driver_claim_interface()
[bd729f9d67aa9a303d8925bb8c4f06af25f407d1]
USB: fix the usbfs flag sanitization for control transfers
[665c365a77fbfeabe52694aedf3446d5f2f1ce42]
USB: handle NULL config in usb_find_alt_setting()
[c9a4cb204e9eb7fa7dfbe3f7d3a674fa530aa193]
USB: leave LPM alone if possible when binding/unbinding interface drivers
[6fb650d43da3e7054984dc548eaa88765a94d49f]
USB: net2280: Fix erroneous synchronization change
[dec3c23c9aa1815f07d98ae0375b4cbc10971e13]
USB: remove LPM management from usb_driver_claim_interface()
[c183813fcee44a249339b7c46e1ad271ca1870aa]

Alexander Aring (4):
mac802154: tx: cleanup crc calculation
[b7eec52bcb7ab93a8cce0f718f42fa17d6d91745]
mac802154: tx: use put_unaligned_le16 for copy crc
[061ef8f915988839b12460c47ebfcf3700e124f0]
net: 6lowpan: fix reserved space for single frames
[ac74f87c789af40936a80131c4759f3e72579c3a]
net: mac802154: tx: expand tailroom if necessary
[f9c52831133050c6b82aa8b6831c92da2bbf2a0b]

Anand Jain (1):
btrfs: rename total_bytes to avoid confusion
[3c1dbdf54a31f4f049a33214c3096595988786bf]

Andi Kleen (2):
x86/spectre: Add missing family 6 check to microcode check
[1ab534e85c93945f7862378d8c8adcf408205b19]
x86/speculation/l1tf: Increase l1tf memory limit for Nehalem+
[cc51e5428ea54f575d49cfcede1d4cb3a72b4ec4]

Andrei Otcheretianski (1):
cfg80211: reg: Init wiphy_idx in regulatory_hint_core()
[24f33e64fcd0d50a4b1a8e5b41bd0257aa66b0e8]

Andrey Ryabinin (1):

      fuse: Don't access pipe->buffers without pipe_lock()
         [a2477b0e67c52f4364a47c3ad70902bc2a61bd4c]

Andy Lutomirski (1):
x86/vdso: Fix asm constraints on vDSO syscall fallbacks
[715bd9d12f84d8f5cc8ad21d888f9bc304a8eb0b]

Anssi Hannula (1):
net: macb: do not disable MDIO bus at open/close time
[0da70f808029476001109b6cb076737bc04cea2e]

Arunk Khandavalli (1):

      cfg80211: nl80211_update_ft_ies() to validate NL80211_ATTR_IE
         [4f0223bfe9c3e62d8f45a85f1ef1b18a8a263ef9]

Ashish Samant (1):

      ocfs2: fix locking for res->tracking and dlm->tracking_list
         [cbe355f57c8074bc4f452e5b6e35509044c6fa23]

Ashok Raj (1):
x86/microcode/intel: Check microcode revision before updating sibling threads
[c182d2b7d0ca48e0d6ff16f7d883161238c447ed]

Aurelien Aptel (1):
smb2: fix missing files in root share directory listing
[0595751f267994c3c7027377058e4185b3a28e75]

Bart Van Assche (4):
IB/srpt: Support HCAs with more than two ports
[e620ebfc228dcbef7519e3d16f43c6c6f1a1d0cb]
scsi: core: Avoid that SCSI device removal through sysfs triggers a deadlock
[0ee223b2e1f67cb2de9c0e3247c510d846e74d63]
scsi: sysfs: Introduce sysfs_{un,}break_active_protection()
[2afc9166f79b8f6da5f347f48515215ceee4ae37]
scsi: target/iscsi: Make iscsit_ta_authentication() respect the output buffer size
[35bea5c84fd13c643cce63f0b5cd4b148f8c901d]

Ben Hutchings (1):
USB: yurex: Fix buffer over-read in yurex_write()
[7e10f14ebface44a48275c8d6dc1caae3668d5a9]

Benjamin Herrenschmidt (1):
powerpc/powernv/pci: Work around races in PCI bridge enabling
[db2173198b9513f7add8009f225afa1f1c79bcc6]

Bhaktipriya Shridhar (1):
bcache: Remove deprecated create_workqueue
[81baf90af2dcc8259e99e2f236024524b55313fc]

Bin Yang (1):
pstore: Fix incorrect persistent ram buffer mapping
[831b624df1b420c8f9281ed1307a8db23afb72df]

Boris Ostrovsky (1):
x86/EISA: Don't probe EISA bus for Xen PV guests
[6a92b11169a65b3f8cc512c75a252cbd0d096ba0]

Borislav Petkov (1):
x86/microcode/intel: Add a helper which gives the microcode revision
[4167709bbf826512a52ebd6aafda2be104adaec9]

Catalin Marinas (1):
cpuidle: Do not access cpuidle_devices when !CONFIG_CPU_IDLE
[9bd616e3dbedfc103f158197c8ad93678849b1ed]

Chirantan Ekbote (1):
9p/net: Fix zero-copy path in the 9p virtio transport
[d28c756caee6e414d9ba367d0b92da24145af2a8]

Christian Brauner (1):
getxattr: use correct xattr length
[82c9a927bc5df6e06b72d206d24a9d10cced4eb5]

Christophe JAILLET (1):
serial: pxa: Fix an error handling path in 'serial_pxa_probe()'
[95a0e656580fab3128c7bee5f660c50784f53651]

Christophe Leroy (1):
serial: cpm_uart: return immediately from console poll
[be28c1e3ca29887e207f0cbcd294cefe5074bab6]

Claudio Imbrenda (1):
s390/kvm: fix deadlock when killed by oom
[306d6c49ac9ded11114cb53b0925da52f2c2ada1]

Colin Ian King (2):
leds: max8997: use mode when calling max8997_led_set_mode
[7a5de56db902ea632a0ff0c2b47481d278db645f]
staging: rts5208: fix missing error check on call to rtsx_write_register
[c5fae4f4fd28189b1062fb8ef7b21fec37cb8b17]

Corey Minyard (1):
ipmi: Move BT capabilities detection to the detect call
[c86ba91be75702c013bbf7379542920b6920e98f]

Dan Carpenter (16):
CIFS: fix wrapping bugs in num_entries()
[56446f218af1133c802dad8e9e116f07f381846c]
cifs: integer overflow in in SMB2_ioctl()
[2d204ee9d671327915260071c19350d84344e096]
cifs: prevent integer overflow in nxt_dir_entry()
[8ad8aa353524d89fa2e09522f3078166ff78ec42]
drm/panel: type promotion bug in s6e8aa0_read_mtp_id()
[cd0e0ca69109d025b1a1b6609f70682db62138b0]
fbdev: omapfb: off by one in omapfb_register_client()
[5ec1ec35b2979b59d0b33381e7c9aac17e159d16]
hwmon: (nct6775) Set weight source to zero correctly
[e3f3d7ab00cd459d0f7a839758a4542f4d4b8ac8]
mei: bus: type promotion bug in mei_nfc_if_version()
[b40b3e9358fbafff6a4ba0f4b9658f6617146f9c]
net: sched: act_ipt: check for underflow in __tcf_ipt_init()
[aeadd93f2b0a609f603ac33e574b97a9832d1b90]
pinctrl: freescale: off by one in imx1_pinconf_group_dbg_show()
[19da44cd33a3a6ff7c97fff0189999ff15b241e4]
pinctrl: imx: off by one in imx_pinconf_group_dbg_show()
[b4859f3edb47825f62d1b2efdd75fe7945996f49]
powerpc: Fix size calculation using resource_size()
[c42d3be0c06f0c1c416054022aa535c08a1f9b39]
rndis_wlan: potential buffer overflow in rndis_wlan_auth_indication()
[ae636fb1554833ee5133ca47bf4b2791b6739c52]
scsi: aic94xx: fix an error code in aic94xx_init()
[0756c57bce3d26da2592d834d8910b6887021701]
uio: potential double frees if __uio_register_device() fails
[f019f07ecf6a6b8bd6d7853bce70925d90af02d1]
vmci: type promotion bug in qp_host_get_user_memory()
[7fb2fd4e25fc1fb10dcb30b5519de257cfeae84c]
x86/paravirt: Fix some warning messages
[571d0563c8881595f4ab027aef9ed1c55e3e7b7c]

Daniel Black (1):
mm: madvise(MADV_DODUMP): allow hugetlbfs pages
[d41aa5252394c065d1f04d1ceea885b70d00c9c6]

Daniel Borkmann (2):
bpf, net: add skb_mac_header_len helper
[0daf4349406074fc03e4889ba5e97e6fb5311bab]
crypto: memzero_explicit - make sure to clear out sensitive data
[7185ad2672a7d50bc384de0e38d90b75d99f3d82]

Daniel Drake (1):
PCI: Reprogram bridge prefetch registers on resume
[083874549fdfefa629dfa752785e20427dde1511]

Daniel Mack (2):
libertas: call into generic suspend code before turning off power
[4f666675cdff0b986195413215eb062b7da6586f]
libertas: fix suspend and resume for SDIO connected cards
[7444a8092906ed44c09459780c56ba57043e39b1]

Darrick J. Wong (1):
xfs: don't fail when converting shortform attr to long form during ATTR_REPLACE
[7b38460dc8e4eafba06c78f8e37099d3b34d473c]

Dave Chinner (1):
percpu_counter: batch size aware __percpu_counter_compare()
[80188b0d77d7426b494af739ac129e0e684acb84]

Dave Martin (1):
arm64: KVM: Tighten guest core register access from userspace
[d26c25a9d19b5976b319af528886f89cf455692d]

David Ahern (1):
net/ipv6: Fix index counter for unicast addresses in in6_dump_addrs
[4ba4c566ba8448a05e6257e0b98a21f1a0d55315]

Denis Drozdov (1):
IB/IPoIB: Set ah valid flag in multicast send flow
[75da96067ade4e7854379ec2f7834f3497652b1a]

Dexuan Cui (1):
Drivers: hv: vmbus: Use get/put_cpu() in vmbus_connect()
[41e270f6898e7502be9fd6920ee0a108ca259d36]

Douglas Anderson (1):
pinctrl: msm: Fix msm_config_group_get() to be compliant
[05e0c828955c1cab58dd71a04539442e5375d917]

Emil Lundmark (1):
drm: udl: Destroy framebuffer only if it was initialized
[fcb74da1eb8edd3a4ef9b9724f88ed709d684227]

Eric Biggers (5):
KEYS: encrypted: fix buffer overread in valid_master_desc()
[794b4bc292f5d31739d89c0202c54e7dc9bc3add]
crypto: ablkcipher - fix crash flushing dcache in error path
[318abdfbe708aaaa652c79fb500e9bd60521f9dc]
crypto: blkcipher - fix crash flushing dcache in error path
[0868def3e4100591e7a1fdbf3eed1439cc8f7ca3]
crypto: vmac - require a block cipher with 128-bit block size
[73bf20ef3df262026c3470241ae4ac8196943ffa]
crypto: vmac - separate tfm and request context
[bb29648102335586e9a66289a1d98a0cb392b6e5]

Eric Dumazet (3):
ipv6: fix possible use-after-free in ip6_xmit()
[bbd6528d28c1b8e80832b3b018ec402b6f5c3215]
net: make skb_partial_csum_set() more robust against overflows
[52b5d6f5dcf0e5201392f7d417148ccb537dbf6f]
rtnl: limit IFLA_NUM_TX_QUEUES and IFLA_NUM_RX_QUEUES to 4096
[0e1d6eca5113858ed2caea61a5adc03c595f6096]

Eric W. Biederman (1):
ipv6: Compute net once in raw6_send_hdrinc
[adb28c9d3371c845c7a28bfd4fb163aca0d0dc37]

Ethan Lien (1):
btrfs: use correct compare function of dirty_metadata_bytes
[d814a49198eafa6163698bdd93961302f3a877a4]

Eugeniy Paltsev (1):
drm: fb-helper: Reject all pixel format changing requests
[db05c481977599236f12a85e55de9f5ab37b0a2c]

Evgenii Lepikhin (1):
ISCSI: fix minor memory leak
[a928d28d4487402e6bd18bea1b8cc2b2ec6e6d8f]

Felipe Balbi (1):
usb: gadget: udc: net2280: do not rely on 'driver' argument
[bfd0ed576dbf9cc71af7dbe42841fc9246524961]

Felix Fietkau (1):
mac80211: fix setting IEEE80211_KEY_FLAG_RX_MGMT for AP mode keys
[211710ca74adf790b46ab3867fcce8047b573cd1]

Filippo Sironi (1):
x86/microcode: Update the new microcode revision unconditionally
[8da38ebaad23fe1b0c4a205438676f6356607cfc]

Florian Fainelli (6):
asix: Check for supported Wake-on-LAN modes
[c4ce446e33d7a0e978256ac6fea4c80e59d9de5f]
ax88179_178a: Check for supported Wake-on-LAN modes
[5ba6b4aa9a410c5e2c6417df52b5e2118ea9b467]
r8152: Check for supported Wake-on-LAN Modes
[f2750df1548bd8a2b060eb609fc43ca82811af4c]
smsc75xx: Check for Wake-on-LAN modes
[9c734b2769a73eea2e9e9767c0e0bf839ff23679]
smsc95xx: Check for Wake-on-LAN modes
[c530c471ba37bdd9fe1c7185b01455c00ae606fb]
sr9800: Check for supported Wake-on-LAN modes
[c5cb93e994ffb43b7b3b1ff10b9f928f54574a36]

Florian Schmaus (1):
bcache: do not assign in if condition in bcache_init()
[16c1fdf4cfd6c0091e59b93ec2cb7e99973f8244]

Florian Westphal (1):
netfilter: nf_tables: fix register ordering
[d209df3e7f7002d9099fdb0f6df0f972b4386a63]

Geert Uytterhoeven (5):
spi: rspi: Fix interrupted DMA transfers
[8dbbaa47b96f6ea5f09f922b4effff3c505cd8cf]
spi: rspi: Fix invalid SPI use during system suspend
[c1ca59c22c56930b377a665fdd1b43351887830b]
spi: rspi: Fix leaking of unused DMA descriptors
[3819bc8752367eae0d72fa1c473dc88ea45631a7]
spi: rspi: Handle dmaengine_prep_slave_sg() failures gracefully
[85912a88c1ebcad04a5cfec971771195ce8d6691]
spi: sh-msiof: Add more register documentation
[2e2b36872d7b45b1f88a590283b14c67931b777f]

Greg Edwards (2):
block: move bio_integrity_{intervals,bytes} into blkdev.h
[359f642700f2ff05d9c94cd9216c97af7b8e9553]
scsi: virtio_scsi: fix pi_bytes{out,in} on 4 KiB block size devices
[cdcdcaae8450a975e7d07e1bfec21f9b8c016d0c]

Greg Hackmann (1):
arm64: mm: check for upper PAGE_SHIFT bits in pfn_valid()
[5ad356eabc47d26a92140a0c4b20eba471c10de3]

Guenter Roeck (3):
hwmon: (nct6775) Fix access to fan pulse registers
[c793279c77035053e67937f5743c6ebfc303e7c5]
mfd: sm501: Set coherent_dma_mask when creating subdevices
[2f606da78230f09cf1a71fde6ee91d0c710fa2b2]
of: unittest: Disable interrupt node tests for old world MAC systems
[8894891446c9380709451b99ab45c5c53adfd2fc]

Guillaume Nault (1):
pppoe: fix reception of frames with no mac header
[8540827ebac6b654ab2f69c8fbce9e4fbd6304a0]

Guoju Fang (1):
bcache: add separate workqueue for journal_write to avoid deadlock
[0f843e65d9eef4936929bb036c5f771fb261eea4]

Gustavo A. R. Silva (9):
ASoC: wm8994: Fix missing break in switch
[ad0eaee6195db1db1749dd46b9e6f4466793d178]
ASoC: wm8994: Mark expected switch fall-through
[2cea1542859bc812f1ec51ea71c06e927e5b922e]
IB/ucm: Fix Spectre v1 vulnerability
[0295e39595e1146522f2722715dba7f7fba42217]
RDMA/ucma: Fix Spectre v1 vulnerability
[a3671a4f973ee9d9621d60166cc3b037c397d604]
hwmon: (nct6775) Fix potential Spectre v1
[d49dbfade96d5b0863ca8a90122a805edd5ef50a]
misc: hmc6352: fix potential Spectre v1
[de916736aaaadddbd6061472969f667b14204aa9]
ptp: fix Spectre v1 vulnerability
[efa61c8cf2950ab5c0e66cff3cabe2a2b24e81ba]
tty: vt_ioctl: fix potential Spectre v1
[e97267cb4d1ee01ca0929638ec0fcbb0904f903d]
usb: gadget: storage: Fix Spectre v1 vulnerability
[9ae24af3669111d418242caec8dd4ebd9ba26860]

H. Nikolaus Schaller (2):
power: generic-adc-battery: check for duplicate properties copied from iio channels
[a427503edaaed9b75ed9746a654cece7e93e60a8]
power: generic-adc-battery: fix out-of-bounds write when copying channel properties
[932d47448c3caa0fa99e84d7f5bc302aa286efd8]

Haishuang Yan (1):
vxlan: fix a potential issue when create a new vxlan fdb entry.
[17b463654f41f0aa334efd5a6efeab8a6e9496f7]

Han Xu (1):
mtd: fsl-quadspi: fix macro collision problems with READ/WRITE
[04850c4d8613127a9b488321c0ad83bff7519311]

Hangbin Liu (2):
igmp: fix incorrect unsolicit report count after link down and up
[ff06525fcb8ae3c302ac1319bf6c07c026dea964]
igmp: fix incorrect unsolicit report count when join group
[4fb7253e4f9a8f06a986a3b317e2f79d9b43d552]

Hari Bathini (1):
powerpc/fadump: handle crash memory ranges array index overflow
[1bd6a1c4b80a28d975287630644e6b47d0f977a5]

Heiner Kallweit (1):
r8169: fix NAPI handling under high load
[6b839b6cf9eada30b086effb51e5d6076bafc761]

Hiromitsu Yamasaki (1):
spi: sh-msiof: Fix handling of write value for SISTR register
[31a5fae4c5a009898da6d177901d5328051641ff]

Huacai Chen (1):
MIPS: Change definition of cpu_relax() for Loongson-3
[a30718868915fbb991a9ae9e45594b059f28e9ae]

Ido Schimmel (1):
team: Forbid enslaving team device to itself
[471b83bd8bbe4e89743683ef8ecb78f7029d8288]

Imre Deak (1):
drm/i915/bdw: Increase IPS disable timeout to 100ms
[acb3ef0ee40ea657280a4a11d9f60eb2937c0dca]

Jani Nikula (1):
drm/i915: set DP Main Stream Attribute for color range on DDI platforms
[dc5977da99ea28094b8fa4e9bacbd29bedc41de5]

Jann Horn (6):
RDMA/ucma: check fd type in ucma_migrate_id()
[0d23ba6034b9cf48b8918404367506da3e4b3ee5]
mm/vmstat.c: skip NR_TLB_REMOTE_FLUSH* properly
[58bc4c34d249bf1bc50730a9a209139347cfacfe]
mtdchar: fix overflows in adjustment of count
[6c6bc9ea84d0008024606bf5ba10519e20d851bf]
proc: restrict kernel stack dumps to root
[f8a00cef17206ecd1b30d3d9f99e10d9fa707aa7]
reiserfs: fix broken xattr handling (heap corruption, bad retval)
[a13f085d111e90469faf2d9965eb39b11c114d7e]
x86/process: Don't mix user/kernel regs in 64bit __show_regs()
[9fe6299dde587788f245e9f7a5a1b296fad4e8c7]

Javier Martinez Canillas (1):
media: omap3isp: zero-initialize the isp cam_xclk{a,b} initial data
[2ec7debd44b49927a6e2861521994cc075a389ed]

Jean Delvare (1):
ACPI / bus: Only call dmi_check_system() on X86
[5d128fbd8b20f8a48cb13c3eced789d1f9573ecd]

Jens Axboe (2):
bcache: don't embed 'return' statements in closure macros
[77b5a08427e87514c33730afc18cd02c9475e2c3]
nbd: don't allow invalid blocksize settings
[bc811f05d77f47059c197a98b6ad242eb03999cb]

Jeremy Cline (2):
ext4: fix spectre gadget in ext4_mb_regular_allocator()
[1a5d5e5d51e75a5bca67dadbcea8c841934b7b85]
fs/quota: Fix spectre gadget in do_quotactl
[7b6924d94a60c6b8c1279ca003e8744e6cd9e8b1]

Jia-Ju Bai (2):
usb: host: u132-hcd: Fix a sleep-in-atomic-context bug in u132_get_frame()
[6d4f268fa132742fe96dad22307c68d237356d88]
usb: misc: uss720: Fix two sleep-in-atomic-context bugs
[bc8acc214d3f1cafebcbcd101a695bbac716595d]

Jiangyiwen (1):
9p/virtio: fix off-by-one error in sg list bounds check
[23cba9cbde0bba05d772b335fe5f66aa82b9ad19]

Jiri Olsa (2):
perf/core: Protect PMU device removal with a 'pmu_bus_running' check, to fix CONFIG_DEBUG_TEST_DRIVER_REMOVE=y kernel panic
[0933840acf7b65d6d30a5b6089d882afea57aca3]
perf/ring_buffer: Prevent concurent ring buffer access
[cd6fb677ce7e460c25bdd66f689734102ec7d642]

Joel Fernandes (1):
mm: shmem.c: Correctly annotate new inodes for lockdep
[b45d71fb89ab8adfe727b9d0ee188ed58582a647]

Johan Hovold (8):
EDAC, i7core: Fix memleaks and use-after-free on probe and remove
[6c974d4dfafe5e9ee754f2a6fba0eb1864f1649e]
EDAC: Fix memleak in module init error path
[4708aa85d50cc6e962dfa8acf5ad4e0d290a21db]
USB: serial: io_ti: fix array underflow in completion handler
[691a03cfe8ca483f9c48153b869d354e4ae3abef]
USB: serial: kobil_sct: fix modem-status error handling
[a420b5d939ee58f1d950f0ea782834056520aeaa]
USB: serial: simple: add Motorola Tetra MTP6550 id
[f5fad711c06e652f90f581fc7c2caee327c33d31]
USB: serial: ti_usb_3410_5052: fix array underflow in completion handler
[5dfdd24eb3d39d815bc952ae98128e967c9bba49]
tty: fix termios input-speed encoding
[fada18c48d774b9e837928ecdce6a5d5fdd11ee7]
tty: fix termios input-speed encoding when using BOTHER
[1cee38f0363a88db374e50b232ca17b9a4c12fa0]

John Johansen (1):
apparmor: remove no-op permission check in policy_unpack
[c037bd615885f1d9d3bdb48531bace79fae1505d]

John Ogness (1):
USB: serial: sierra: fix potential deadlock at close
[e60870012e5a35b1506d7b376fddfb30e9da0b27]

Jon Hunter (1):
ARM: tegra: Fix Tegra30 Cardhu PCA954x reset
[6e1811900b6fe6f2b4665dba6bd6ed32c6b98575]

Josef Bacik (1):
Btrfs: fix btrfs_write_inode vs delayed iput deadlock
[3c4276936f6fbe52884b4ea4e6cc120b890a0f9f]

Julian Wiedmann (1):
s390/qdio: reset old sbal_state flags
[64e03ff72623b8c2ea89ca3cb660094e019ed4ae]

Junxiao Bi (1):
ocfs2: fix ocfs2 read block panic
[234b69e3e089d850a98e7b3145bd00e9b52b1111]

K. Y. Srinivasan (1):
Tools: hv: Fix a bug in the key delete code
[86503bd35dec0ce363e9fdbf5299927422ed3899]

Kees Cook (1):
pstore/ram: Fix failure-path memory leak in ramoops_init
[bac6f6cda206ad7cbe0c73c35e494377ce9c4749]

Kirill Tkhai (1):
fuse: Add missed unlock_page() to fuse_readpages_fill()
[109728ccc5933151c68d1106e4065478a487a323]

Ladislav Michl (2):
video: udlfb: Fix unaligned access
[115e77597efcc94cb1f6cbb7df5cf7ce8feb8632]
video: udlfb: Remove noisy warnings
[de4b74bda8e87a4ed45ebc2c26cc3e2eaae38429]

Lars-Peter Clausen (2):
iio: ad9523: Fix displayed phase
[5a4e33c1c53ae7d4425f7d94e60e4458a37b349e]
iio: ad9523: Fix return value for ad952x_store()
[9a5094ca29ea9b1da301b31fd377c0c0c4c23034]

Leonard Crestez (1):
crypto: mxs-dcp - Fix wait logic on chan threads
[d80771c08363ad7fbf0f56f5301e7ca65065c582]

Li Dongyang (1):
ext4: don't mark mmp buffer head dirty
[fe18d649891d813964d3aaeebad873f281627fbc]

Liang Chen (1):
bcache: explicitly destroy mutex while exiting
[330a4db89d39a6b43f36da16824eaa7a7509d34d]

Linus Torvalds (2):
Make file credentials available to the seqfile interfaces
[34dbbcdbf63360661ff7bda6c5f52f99ac515f92]
mremap: properly flush TLB before releasing the page
[eb66ae030829605d61fbef1909ce310e29f78821]

Lior David (1):
wil6210: missing length check in wmi_set_ie
[b5a8ffcae4103a9d823ea3aa3a761f65779fbe2a]

Lukas Wunner (3):
PCI: hotplug: Don't leak pci_slot on registration failure
[4ce6435820d1f1cc2c2788e232735eb244bcc8a3]
PCI: pciehp: Fix unprotected list iteration in IRQ handler
[1204e35bedf4e5015cda559ed8c84789a6dae24e]
PCI: pciehp: Fix use-after-free on unplug
[281e878eab191cce4259abbbf1a0322e3adae02c]

Lyude Paul (1):
drm/nouveau/drm/nouveau: Use pm_runtime_get_noresume() in connector_detect()
[6833fb1ec120bf078e1a527c573a09d4de286224]

Maciej W. Rozycki (3):

      MIPS: Correct the 64-bit DSP accumulator register size
         [f5958b4cf4fc38ed4583ab83fb7c4cd1ab05f47b]
      MIPS: memset: Fix CPU_DADDI_WORKAROUNDS `small_fixup' regression
         [148b9aba99e0bbadf361747d21456e1589015f74]
      binfmt_elf: Respect error return from `regset->active'
         [2f819db565e82e5f73cd42b39925098986693378]

Mahesh Salgaonkar (2):
powerpc/pseries: Avoid using the size greater than RTAS_ERROR_LOG_MAX.
[74e96bf44f430cf7a01de19ba6cf49b361cdfd6e]
powerpc/pseries: Fix endianness while restoring of r3 in MCE handler.
[cd813e1cd7122f2c261dce5b54d1e0c97f80e1a5]

Marcel Ziswiler (1):
spi: tegra20-slink: explicitly enable/disable clock
[7001cab1dabc0b72b2b672ef58a90ab64f5e2343]

Mario Limonciello (1):
platform/x86: alienware-wmi: Correct a memory leak
[ff0e9f26288d2daee4950f42b37a3d3d30d36ec1]

Martin Kaiser (1):
mtd: rawnand: mxc: remove __init qualifier from mxcnd_probe_dt
[24f0ae995deb728076e3ea93fea1949a9775debf]

Masami Hiramatsu (1):
kprobes: Make list and blacklist root user read only
[f2a3ab36077222437b4826fc76111caa14562b7c]

Mathias Nyman (3):
usb: Avoid use-after-free by flushing endpoints early in usb_set_interface()
[f9a5b4f58b280c1d26255376713c132f93837621]
usb: Don't die twice if PCI xhci host is not responding in resume
[f3dc41c5d22b2ca14a0802a65d8cdc33a3882d4e]
xhci: Add missing CAS workaround for Intel Sunrise Point xHCI
[ffe84e01bb1b38c7eb9c6b6da127a6c136d251df]

Mathieu OTHACEHE (1):
USB: serial: ti_usb_3410_5052: use functions rather than macros
[d8d841e8332779fae2b18420d39ef407ea3729da]

Matthias Brugger (1):
tty: fix typo in comment of tty_termios_encode_baud_rate
[a1d51aa2214cea3f91611893610a2f769cada0e7]

Mauricio Faria de Oliveira (2):
partitions/aix: append null character to print data from disk
[d43fdae7bac2def8c4314b5a49822cb7f08a45f1]
partitions/aix: fix usage of uninitialized lv_info and lvname structures
[14cb2c8a6c5dae57ee3e2da10fa3db2b9087e39e]

Mauro Carvalho Chehab (1):
media: rtl28xxu: be sure that it won't go past the array size
[845b978a871bff3707eee611b32e4be0b9a94dd2]

Max Filippov (2):

      xtensa: increase ranges in ___invalidate_{i,d}cache_all
         [fec3259c9f747c039f90e99570540114c8d81a14]
      xtensa: limit offsets in __loop_cache_{all,page}
         [be75de25251f7cf3e399ca1f584716a95510d24a]

Maxence Duprès (1):
USB: add quirk for WORLDE Controller KS49 or Prodipe MIDI 49C USB controller
[9b83a1c301ad6d24988a128c69b42cbaaf537d82]

Mian Yousaf Kaukab (1):
usb: gadget: net2280: fix pullup handling
[11bece5e063ca567e631c6ea3b1611c10dbc3282]

Michael Bringmann (1):
powerpc/pseries: Fix unitialized timer reset on migration
[8604895a34d92f5e186ceb931b0d1b384030ea3d]

Michael Büsch (2):
b43/leds: Ensure NUL-termination of LED name string
[2aa650d1950fce94f696ebd7db30b8830c2c946f]
b43legacy/leds: Ensure NUL-termination of LED name string
[4d77a89e3924b12f4a5628b21237e57ab4703866]

Mika Båtsman (1):
media: gl861: fix probe of dvb_usb_gl861
[48db0089bff6f9154f6bd98ce7a6ae3786fa8ebe]

Mike Christie (1):
iscsi target: fix session creation failure handling
[26abc916a898d34c5ad159315a2f683def3c5555]

Mike Snitzer (1):
dm cache metadata: save in-core policy_hint_size to on-disk superblock
[fd2fa95416188a767a63979296fa3e169a9ef5ec]

Miklos Szeredi (3):
fuse: Fix oops at process_init_reply()
[e8f3bd773d22f488724dffb886a1618da85c2966]
fuse: don't wake up reserved req in fuse_conn_kill()
[0c4dd4ba1426c599072511dcf95a15ee5e12725b]
fuse: flush requests on umount
[580640ba5d331eb5631a5de46941c98f5ed90886]

Mikulas Patocka (13):
dm: disable CRYPTO_TFM_REQ_MAY_SLEEP to fix a GFP_KERNEL recursion deadlock
[432061b3da64e488be3403124a72a9250bbe96d4]
fb: fix lost console when the user unplugs a USB adapter
[8c5b044299951acd91e830a688dd920477ea1eda]
mach64: detect the dot clock divider correctly on sparc
[76ebebd2464c5c8a4453c98b6dbf9c95a599e810]
udl-kms: change down_interruptible to down
[8456b99c16d193c4c3b7df305cf431e027f0189c]
udl-kms: fix crash due to uninitialized memory
[09a00abe3a9941c2715ca83eb88172cd2f54d8fd]
udl-kms: handle allocation failure
[542bb9788a1f485eb1a2229178f665d8ea166156]
udlfb: don't switch if we are switching to the same videomode
[564f1807379298dfdb12ed0d5b25fcb89c238527]
udlfb: fix display corruption of the last line
[4e705e17ce3409a1f492cfd5dadcf6a4f6075842]
udlfb: fix semaphore value leak
[9d0aa601e4cd9c0892f90d36e8488d79b72f4073]
udlfb: handle allocation failure
[080fb5240bdcabed7387b814139c3ea172d59fc5]
udlfb: make a local copy of fb_ops
[2c29cfc3eaf11779176bf41475cfca49bccba11c]
udlfb: set line_length in dlfb_ops_set_par
[0ac319b7af1bb24a33365d0ec82a2f56a59b2a78]
udlfb: set optimal write delay
[bb24153a3f13dd0dbc1f8055ad97fe346d598f66]

Nadav Amit (1):
x86/mm: Use WRITE_ONCE() when setting PTEs
[9bc4f28af75a91aea0ae383f50b0a430c4509303]

Nicholas Mc Guire (3):
ALSA: snd-aoa: add of_node_put() in error path
[222bce5eb88d1af656419db04bcd84b2419fb900]
ARM: hisi: handle of_iomap and fix missing of_node_put
[d396cb185c0337aae5664b250cdd9a73f6eb1503]
cifs: check kmalloc before use
[126c97f4d0d1b5b956e8b0740c81a2b2a2ae548c]

Nicholas Piggin (1):
mm: move tlb_table_flush to tlb_flush_mmu_free
[db7ddef301128dad394f1c0f77027f86ee9a4edb]

Oliver Neukum (3):
USB: usbdevfs: restore warning for nonsensical flags
[81e0403b26d94360abd1f6a57311337973bc82cd]
USB: usbdevfs: sanitize flags more
[7a68d9fb851012829c29e770621905529bd9490b]
usb: uas: add support for more quirk flags
[42d1c6d4a06a77b3ab206a919b9050c3080f3a71]

Olle Liljenzin (1):
platform/x86: ideapad-laptop: Add Y520-15IKBN to no_hw_rfkill
[5d9f40b56630a8702b5f7a61a770f9b73aa07464]

Ondrej Mosnáček (1):
audit: Fix extended comparison of GID/EGID
[af85d1772e31fed34165a1b3decef340cf4080c0]

Paolo Abeni (2):
ip6_tunnel: be careful when accessing the inner header
[76c0ddd8c3a683f6e2c6e60e11dc1a1558caf4bc]
ip_tunnel: be careful when accessing the inner header
[ccfec9e5cb2d48df5a955b7bf47f7782157d3bc2]

Parav Pandit (1):
RDMA/cma: Protect cma dev list with lock
[954a8e3aea87e896e320cf648c1a5bbe47de443e]

Paul Mackerras (1):
KVM: PPC: Book3S HV: Don't truncate HPTE index in xlate function
[46dec40fb741f00f1864580130779aeeaf24fb3d]

Pavel Tikhomirov (1):
mm: cleancache: fix corruption on missed inode invalidation
[6ff38bd40230af35e446239396e5fc8ebd6a5248]

Peter Zijlstra (3):

      mm/tlb: Remove tlb_remove_table() non-concurrent condition
         [a6f572084fbee8b30f91465f4a085d7a90901c57]
      perf/core: Fix perf_pmu_unregister() locking
         [a9f9772114c8b07ae75bcb3654bd017461248095]
      x86/percpu: Fix this_cpu_read()
         [b59167ac7bafd804c91e49ad53c6d33a7394d4c8]

Piaojun (1):
fs/9p/xattr.c: catch the error of p9_client_clunk when setting xattr failed
[3111784bee81591ea2815011688d28b65df03627]

Prarit Bhargava (1):
x86/microcode: Make sure boot_cpu_data.microcode is up-to-date
[370a132bb2227ff76278f98370e0e701d86ff752]

Punit Agrawal (2):
KVM: arm/arm64: Skip updating PMD entry if no change
[86658b819cd0a9aa584cd84453ed268a6f013770]
KVM: arm/arm64: Skip updating PTE entry if no change
[976d34e2dab10ece5ea8fe7090b7692913f89084]

Rafael J. Wysocki (1):
PM / core: Clear the direct_complete flag on errors
[69e445ab8b66a9f30519842ef18be555d3ee9b51]

Rian Hunter (1):
x86/process: Re-export start_thread()
[dc76803e57cc86589c4efcb5362918f9b0c0436f]

Richard Weinberger (4):
ubifs: Check data node size before truncate
[95a22d2084d72ea067d8323cc85677dba5d97cae]
ubifs: Check for name being NULL while mounting
[37f31b6ca4311b94d985fb398a72e5399ad57925]
ubifs: Fix memory leak in lprobs self-check
[eef19816ada3abd56d9f20c88794cc2fea83ebb2]
ubifs: Fix synced_i_size calculation for xattr inodes
[59965593205fa4044850d35ee3557cf0b7edcd14]

Roopa Prabhu (2):
vxlan: add new fdb alloc and create helpers
[25e20e730d56471cffa25419bf2a66078bd55330]
vxlan: fix default fdb entry netlink notify ordering during netdev create
[0241b836732f5f43c3f0fd9e9073c1fb24ea6757]

Sabrina Dubroca (2):
ipv6: fix cleanup ordering for pingv6 registration
[a03dc36bdca6b614651fedfcd8559cf914d2d21d]
net: ipv4: update fnhe_pmtu when first hop's MTU changes
[af7d6cce53694a88d6a1bb60c9a239a6a5144459]

Sagi Grimberg (1):
iscsi-target: nullify session in failed login sequence
[a0b3b9b2409b409c677f7eb1e0485b816a5848f7]

Sebastian Ott (1):
s390/pci: fix out of bounds access during irq setup
[866f3576a72b2233a76dffb80290f8086dc49e17]

Shahed Shaikh (1):
qlcnic: fix Tx descriptor corruption on 82xx devices
[c333fa0c4f220f8f7ea5acd6b0ebf3bf13fd684d]

Shenghui Wang (1):
dm cache: destroy migration_cache if cache target registration failed
[c7cd55504a5b0fc826a2cd9540845979d24ae542]

Shuah Khan (1):
usb: usbip: Fix BUG: KASAN: slab-out-of-bounds in vhci_hub_control()
[81f7567c51ad97668d1c3a48e8ecc482e64d4161]

Shubhrajyoti Datta (1):
i2c: xiic: Make the start and the byte count write atomic
[ae7304c3ea28a3ba47a7a8312c76c654ef24967e]

Simon Vincent (1):
ieee802154: 6lowpan: ensure header compression does not corrupt ipv6 header
[f19f4f9525cf32f97341fac20ce66392e86a1b67]

Steffen Klassert (1):
xfrm: Validate address prefix lengths in the xfrm selector.
[07bf7908950a8b14e81aa1807e3c667eab39287a]

Steve French (4):
SMB3: Backup intent flag missing for directory opens with backupuid mounts
[5e19697b56a64004e2d0ff1bb952ea05493c088f]
cifs: add missing debug entries for kconfig options
[950132afd59385caf6e2b84e5235d069fa10681d]
smb3: check for and properly advertise directory lease support
[f801568332321e2b1e7a8bd26c3e4913a312a2ec]
smb3: fill in statfs fsid and correct namelen
[21ba3845b59c733a79ed4fe1c4f3732e7ece9df7]

Steve Wise (3):
RDMA/cxgb4: Only call CQ completion handler if it is armed
[678ea9b5baab6800692b249bdba77c3c07261d61]
iw_cxgb4: atomically flush the qp
[bc52e9ca74b9a395897bb640c6671b2cbf716032]
iw_cxgb4: only allow 1 flush on user qps
[308aa2b8f7b7db3332a7d41099fd37851fb793b2]

Steven Rostedt (3):
tracing/blktrace: Fix to allow setting same value
[757d9140072054528b13bbe291583d9823cde195]
tracing: Do not call start/stop() functions when tracing_on does not change
[f143641bfef9a4a60c57af30de26c63057e7e695]
uprobes: Use synchronize_rcu() not synchronize_sched()
[016f8ffc48cb01d1e7701649c728c5d2e737d295]

Sven Eckelmann (8):
ath10k: prevent active scans on potential unusable channels
[3f259111583801013cb605bb4414aa529adccf1c]
batman-adv: Place kref_get for softif_vlan near use
[df28ca6bb3282a4c8dc5b65f60b0136fc190ee52]
batman-adv: Prevent duplicated gateway_node entry
[dff9bc42ab0b2d38c5e90ddd79b238fed5b4c7ad]
batman-adv: Prevent duplicated global TT entry
[e7136e48ffdfb9f37b0820f619380485eb407361]
batman-adv: Prevent duplicated nc_node entry
[fa122fec8640eb7186ce5a41b83a4c1744ceef8f]
batman-adv: Prevent duplicated softif_vlan entry
[94cb82f594ed86be303398d6dfc7640a6f1d45d4]
batman-adv: Prevent duplicated tvlv handler
[ae3cdc97dc10c7a3b31f297dab429bfb774c9ccb]
batman-adv: Use kref_get for batadv_nc_get_nc_node
[0de32ceee156787429035c974316f4e5098cf722]

Sylwester Nawrocki (1):
media: exynos4-is: Prevent NULL pointer dereference in __isp_video_try_fmt()
[7c1b9a5aeed91bef98988ac0fcf38c8c1f4f9a3a]

Taehee Yoo (1):
netfilter: nft_set: fix allocation size overflow in privsize callback.
[4ef360dd6a65f6ef337645e1b65e744034754b19]

Takashi Iwai (9):
ALSA: cs5535audio: Fix invalid endian conversion
[69756930f2de0457d51db7d505a1e4f40e9fd116]
ALSA: memalloc: Don't exceed over the requested size
[dfef01e150824b0e6da750cacda8958188d29aea]
ALSA: seq: Fix poll() error return
[a49a71f6e25da2acc637fcd31e73debd96ca18f8]
ALSA: virmidi: Fix too long output trigger loop
[50e9ffb1996a5d11ff5040a266585bad4ceeca0a]
ALSA: vx222: Fix invalid endian conversions
[fff71a4c050ba46e305d910c837b99ba1728135e]
ALSA: vx: Fix possible transfer overflow
[874e1f6fad9a5184b67f4cee37c1335cd2cc5677]
ALSA: vxpocket: Fix invalid endian conversions
[3acd3e3bab95ec3622ff98da313290ee823a0f68]
EDAC: i7core: Return proper error codes for kzalloc() errors
[e97d7e38162dc305b4734a316ca758a2bbd1fa6e]
platform/x86: ideapad-laptop: Apply no_hw_rfkill to Y20-15IKBM, too
[58e73aa177850babb947555257fd4f79e5275cf1]

Takashi Sakamoto (1):
ALSA: bebob: use address returned by kmalloc() instead of kernel stack for streaming DMA mapping
[493626f2d87a74e6dbea1686499ed6e7e600484e]

Thadeu Lima de Souza Cascardo (1):
xfrm6: call kfree_skb when skb is toobig
[215ab0f021c9fea3c18b75e7d522400ee6a49990]

Theodore Ts'o (6):
ext4: avoid divide by zero fault when deleting corrupted inline directories
[4d982e25d0bdc83d8c64e66fdeca0b89240b3b85]
ext4: check for NUL characters in extended attribute's name
[7d95178c77014dbd8dce36ee40bbbc5e6c121ff5]
ext4: check to make sure the rename(2)'s destination is not freed
[b50282f3241acee880514212d88b6049fb5039c8]
ext4: fix online resize's handling of a too-small final block group
[f0a459dec5495a3580f8d784555e6f8f3bf7f263]
ext4: fix online resizing for bigalloc file systems with a 1k block size
[5f8c10936fab2b69a487400f2872902e597dd320]
ext4: prevent online resize with backup superblock
[011fa99404bea3f5d897c4983f6bd51170e3b18f]

Thomas Gleixner (3):
alarmtimer: Prevent overflow for relative nanosleep
[5f936e19cc0ef97dbe3a56e9498922ad5ba1edef]
posix-timers: Sanitize overrun handling
[78c9c4dfbf8c04883941445a195276bb4bb92c76]
x86/boot: Move EISA setup to a separate file
[f7eaf6e00fd581043bb540dfe865f1d81769b189]

Thomas Petazzoni (2):

      ARM: 8799/1: mm: fix pci_ioremap_io() offset check
         [3a58ac65e2d7969bcdf1b6acb70fa4d12a88e53e]
      PCI: mvebu: Fix I/O space end address calculation
         [dfd0309fd7b30a5baffaf47b2fccb88b46d64d69]

Thomas Werschlein (1):
cifs: connect to servername instead of IP for IPC$ share
[395a2076b4064f97d3fce03af15210ff2a7bb7f9]

Tim Anderson (1):
USB: Add quirk to support DJI CineSSD
[f45681f9becaa65111ed0a691ccf080a0cd5feb8]

Tomas Bortoli (3):
9p: fix multiple NULL-pointer-dereferences
[10aa14527f458e9867cf3d2cc6b8cb0f6704448b]
net/9p/client.c: version pointer uninitialized
[7913690dcc5e18e235769fd87c34143072f5dbea]
net/9p/trans_fd.c: fix race-condition by flushing workqueue before the kfree()
[430ac66eb4c5b5c4eb846b78ebf65747510b30f1]

Tomi Valkeinen (1):
fbdev/omapfb: fix omapfb_memory_read infoleak
[1bafcbf59fed92af58955024452f45430d3898c5]

Tycho Andersen (1):
uart: fix race between uart_put_char() and uart_shutdown()
[a5ba1d95e46ecaea638ddd7cd144107c783acb5d]

Vaibhav Nagarnaik (1):
ring-buffer: Allow for rescheduling when removing pages
[83f365554e47997ec68dc4eca3f5dce525cd15c3]

Varka Bhadram (1):
mac802154: common tx error path
[f55889128a776b51581394b20abd0b470304cf95]

Vignesh R (2):
pwm: tiehrpwm: Don't use emulation mode bits to control PWM output
[aa49d628f6e016bcec8c6f8e704b9b18ee697329]
pwm: tiehrpwm: Fix disabling of output of PWMs
[38dabd91ff0bde33352ca3cc65ef515599b77a05]

Vineet Gupta (1):
ARC: clone syscall to setp r25 as thread pointer
[c58a584f05e35d1d4342923cd7aac07d9c3d3d16]

Vitaly Kuznetsov (2):
tools: hv: fcopy: set 'error' in case an unknown operation was requested
[c2d68afba86d1ff01e7300c68bc16a9234dcd8e9]
xen-netfront: fix queue name setting
[2d408c0d4574b01b9ed45e02516888bf925e11a9]

Wei Wang (2):

      ipv6: take rcu lock in rawv6_send_hdrinc()
         [a688caa34beb2fd2a92f1b6d33e40cde433ba160]
      l2tp: use sk_dst_check() to avoid race on sk->sk_dst_cache
         [6d37fa49da1e8db8fb1995be22ac837ca41ac8a8]

Willy Tarreau (1):
ALSA: emu10k1: fix possible info leak to userspace on SNDRV_EMU10K1_IOCTL_INFO
[49434c6c575d2008c0abbc93e615019f39e01252]

Yelena Krivosheev (1):
net: mvneta: fix mtu change on port without link
[8466baf788ec3e18836bd9c91ba0b1a07af25878]

Young_X (1):
cdrom: fix improper type cast, which can leat to information leak.
[e4f3aa2e1e67bb48dfbaaf1cad59013d5a5bc276]

Yu Zhao (1):
regulator: fix crash caused by null driver data
[fb6de923ca3358a91525552b4907d4cb38730bdd]

YueHaibing (2):

      pinctrl: berlin: fix 'pctrl->functions' allocation in berlin_pinctrl_build_state
         [b5031b7db77dc47f474f0efc2b2552c32b7bb59d]
      xfrm: fix 'passing zero to ERR_PTR()' warning
         [934ffce1343f22ed5e2d0bd6da4440f4848074de]
 Makefile                                           |   4 +-
 arch/arc/kernel/process.c                          |  20 +
 arch/arm/boot/dts/tegra30-cardhu.dtsi              |   1 +
 arch/arm/kvm/mmu.c                                 |  42 ++-
 arch/arm/mach-hisi/hotplug.c                       |  19 +-
 arch/arm/mm/ioremap.c                              |   2 +-
 arch/arm64/kvm/guest.c                             |  45 +++
 arch/arm64/mm/init.c                               |   6 +-
 arch/mips/include/asm/processor.h                  |  15 +-
 arch/mips/kernel/ptrace.c                          |   2 +-
 arch/mips/kernel/ptrace32.c                        |   2 +-
 arch/mips/lib/memset.S                             |   4 +-
 arch/powerpc/include/asm/fadump.h                  |   3 -
 arch/powerpc/kernel/fadump.c                       |  92 ++++-
 arch/powerpc/kvm/book3s_64_mmu_hv.c                |   2 +-
 arch/powerpc/mm/numa.c                             |   4 +-
 arch/powerpc/platforms/powernv/pci-ioda.c          |  37 ++
 arch/powerpc/platforms/pseries/ras.c               |   4 +-
 arch/powerpc/sysdev/mpic_msgr.c                    |   2 +-
 arch/s390/include/asm/qdio.h                       |   1 -
 arch/s390/mm/fault.c                               |   2 +
 arch/s390/pci/pci.c                                |   2 +
 arch/x86/include/asm/kdebug.h                      |  12 +-
 arch/x86/include/asm/microcode_intel.h             |  15 +
 arch/x86/include/asm/percpu.h                      |   8 +-
 arch/x86/include/asm/pgtable_64.h                  |  16 +-
 arch/x86/include/asm/processor.h                   |   4 +-
 arch/x86/kernel/Makefile                           |   1 +
 arch/x86/kernel/cpu/bugs.c                         |  46 ++-
 arch/x86/kernel/cpu/common.c                       |   1 +
 arch/x86/kernel/cpu/intel.c                        |  14 +-
 arch/x86/kernel/cpu/microcode/amd.c                |  22 +-
 arch/x86/kernel/cpu/microcode/intel.c              |  31 +-
 arch/x86/kernel/cpu/microcode/intel_early.c        |  33 +-
 arch/x86/kernel/dumpstack_32.c                     |   2 +-
 arch/x86/kernel/dumpstack_64.c                     |   2 +-
 arch/x86/kernel/paravirt.c                         |   4 +-
 arch/x86/kernel/process_32.c                       |   4 +-
 arch/x86/kernel/process_64.c                       |  11 +-
 arch/x86/kernel/traps.c                            |  13 -
 arch/x86/mm/kmemcheck/error.c                      |   2 +-
 arch/x86/mm/pgtable.c                              |   6 +-
 arch/x86/vdso/vclock_gettime.c                     |  18 +-
 arch/xtensa/include/asm/cacheasm.h                 |  69 ++--
 block/bio-integrity.c                              |  26 --
 block/partitions/aix.c                             |  13 +-
 crypto/ablkcipher.c                                |  57 ++-
 crypto/blkcipher.c                                 |  54 ++-
 crypto/cts.c                                       |   3 +-
 crypto/sha1_generic.c                              |   2 +-
 crypto/sha256_generic.c                            |   5 +-
 crypto/sha512_generic.c                            |   2 +-
 crypto/tgr192.c                                    |   4 +-
 crypto/vmac.c                                      | 412 +++++++++------------
 crypto/wp512.c                                     |   8 +-
 drivers/acpi/bus.c                                 |  13 +-
 drivers/base/power/main.c                          |   5 +-
 drivers/block/nbd.c                                |   3 +
 drivers/cdrom/cdrom.c                              |   2 +-
 drivers/char/ipmi/ipmi_bt_sm.c                     |  92 ++---
 drivers/crypto/mxs-dcp.c                           |  53 +--
 drivers/edac/edac_mc_sysfs.c                       |   6 +-
 drivers/edac/i7core_edac.c                         |  24 +-
 drivers/gpu/drm/drm_fb_helper.c                    |  91 ++---
 drivers/gpu/drm/i915/i915_reg.h                    |   1 +
 drivers/gpu/drm/i915/intel_ddi.c                   |   4 +
 drivers/gpu/drm/i915/intel_display.c               |   8 +-
 drivers/gpu/drm/nouveau/nouveau_connector.c        |  20 +-
 drivers/gpu/drm/panel/panel-s6e8aa0.c              |   2 +-
 drivers/gpu/drm/udl/udl_fb.c                       |  10 +-
 drivers/gpu/drm/udl/udl_main.c                     |  35 +-
 drivers/hv/connection.c                            |   8 +-
 drivers/hwmon/nct6775.c                            |  28 +-
 drivers/i2c/busses/i2c-xiic.c                      |   4 +
 drivers/iio/frequency/ad9523.c                     |   4 +-
 drivers/infiniband/core/cma.c                      |  12 +-
 drivers/infiniband/core/ucm.c                      |   3 +
 drivers/infiniband/core/ucma.c                     |   9 +
 drivers/infiniband/hw/cxgb4/ev.c                   |   1 +
 drivers/infiniband/hw/cxgb4/qp.c                   |  62 +++-
 drivers/infiniband/hw/cxgb4/t4.h                   |  11 +
 drivers/infiniband/ulp/ipoib/ipoib_cm.c            |   2 +
 drivers/infiniband/ulp/ipoib/ipoib_multicast.c     |   1 +
 drivers/infiniband/ulp/srpt/ib_srpt.c              |   6 +-
 drivers/infiniband/ulp/srpt/ib_srpt.h              |   4 +-
 drivers/input/mouse/elantech.c                     |   2 +
 drivers/leds/leds-max8997.c                        |   2 +-
 drivers/md/bcache/bcache.h                         |   1 +
 drivers/md/bcache/closure.h                        |   3 -
 drivers/md/bcache/io.c                             |   1 +
 drivers/md/bcache/journal.c                        |   8 +-
 drivers/md/bcache/request.c                        |  14 +-
 drivers/md/bcache/super.c                          |  29 +-
 drivers/md/dm-cache-metadata.c                     |   3 +-
 drivers/md/dm-cache-target.c                       |   5 +-
 drivers/md/dm-crypt.c                              |   8 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.c |  11 +-
 drivers/media/platform/omap3isp/isp.c              |   2 +-
 drivers/media/usb/dvb-usb-v2/gl861.c               |  17 +-
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c            |   2 +-
 drivers/mfd/sm501.c                                |   1 +
 drivers/misc/hmc6352.c                             |   2 +
 drivers/misc/mei/nfc.c                             |   2 +-
 drivers/misc/vmw_vmci/vmci_queue_pair.c            |   4 +-
 drivers/mtd/mtdchar.c                              |  10 +-
 drivers/mtd/nand/mxc_nand.c                        |   4 +-
 drivers/mtd/spi-nor/fsl-quadspi.c                  |  20 +-
 drivers/net/ethernet/cadence/macb.c                |  10 +-
 drivers/net/ethernet/marvell/mvneta.c              |   1 -
 drivers/net/ethernet/qlogic/qlcnic/qlcnic.h        |   8 +-
 .../net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c    |   3 +-
 .../net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.h    |   3 +-
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_hw.h     |   3 +-
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c     |  12 +-
 drivers/net/ethernet/realtek/r8169.c               |   8 +-
 drivers/net/ppp/pppoe.c                            |   3 +
 drivers/net/team/team.c                            |   5 +
 drivers/net/usb/asix_common.c                      |   3 +
 drivers/net/usb/ax88179_178a.c                     |   3 +
 drivers/net/usb/r8152.c                            |   3 +
 drivers/net/usb/smsc75xx.c                         |   3 +
 drivers/net/usb/smsc95xx.c                         |   3 +
 drivers/net/usb/sr9800.c                           |   3 +
 drivers/net/vxlan.c                                | 103 ++++--
 drivers/net/wireless/ath/ath10k/mac.c              |   7 +
 drivers/net/wireless/ath/wil6210/wmi.c             |   7 +-
 drivers/net/wireless/b43/leds.c                    |   2 +-
 drivers/net/wireless/b43legacy/leds.c              |   2 +-
 drivers/net/wireless/libertas/dev.h                |   1 +
 drivers/net/wireless/libertas/if_sdio.c            |  34 +-
 drivers/net/wireless/rndis_wlan.c                  |   2 +
 drivers/net/xen-netfront.c                         |   2 +-
 drivers/of/selftest.c                              |  28 +-
 drivers/pci/host/pci-mvebu.c                       |   2 +-
 drivers/pci/hotplug/pci_hotplug_core.c             |   9 +
 drivers/pci/hotplug/pciehp.h                       |   1 +
 drivers/pci/hotplug/pciehp_core.c                  |   5 +
 drivers/pci/hotplug/pciehp_hpc.c                   |  18 +-
 drivers/pci/pci.c                                  |  27 +-
 drivers/pinctrl/berlin/berlin.c                    |  13 +-
 drivers/pinctrl/pinctrl-imx.c                      |   2 +-
 drivers/pinctrl/pinctrl-imx1-core.c                |   2 +-
 drivers/pinctrl/pinctrl-msm.c                      |  10 +-
 drivers/platform/x86/alienware-wmi.c               |   1 +
 drivers/platform/x86/ideapad-laptop.c              |   7 +
 drivers/power/generic-adc-battery.c                |  25 +-
 drivers/ptp/ptp_chardev.c                          |   4 +
 drivers/pwm/pwm-tiehrpwm.c                         |  13 +-
 drivers/regulator/core.c                           |   3 +-
 drivers/s390/cio/qdio_main.c                       |   5 +-
 drivers/scsi/aic94xx/aic94xx_init.c                |   4 +-
 drivers/scsi/scsi_sysfs.c                          |  20 +-
 drivers/scsi/virtio_scsi.c                         |   6 +-
 drivers/spi/spi-rspi.c                             | 140 +++++--
 drivers/spi/spi-sh-msiof.c                         |  57 ++-
 drivers/spi/spi-tegra20-slink.c                    |  31 +-
 drivers/staging/rts5208/sd.c                       |   2 +-
 drivers/staging/usbip/vhci_hcd.c                   |  43 ++-
 drivers/target/iscsi/iscsi_target_login.c          |  35 +-
 drivers/target/iscsi/iscsi_target_tpg.c            |   3 +-
 drivers/tty/serial/cpm_uart/cpm_uart_core.c        |  10 +-
 drivers/tty/serial/pxa.c                           |   3 +-
 drivers/tty/serial/serial_core.c                   |  17 +-
 drivers/tty/tty_ioctl.c                            |  15 +-
 drivers/tty/vt/vt_ioctl.c                          |   4 +
 drivers/uio/uio.c                                  |   3 +-
 drivers/usb/core/devio.c                           |  24 +-
 drivers/usb/core/driver.c                          |  50 +--
 drivers/usb/core/hcd-pci.c                         |   2 -
 drivers/usb/core/message.c                         |  11 +
 drivers/usb/core/quirks.c                          |   7 +
 drivers/usb/core/usb.c                             |   2 +
 drivers/usb/gadget/f_mass_storage.c                |   3 +
 drivers/usb/gadget/net2280.c                       |  36 +-
 drivers/usb/host/u132-hcd.c                        |   2 +-
 drivers/usb/host/xhci-pci.c                        |   2 +
 drivers/usb/misc/uss720.c                          |   4 +-
 drivers/usb/misc/yurex.c                           |   5 +-
 drivers/usb/serial/io_ti.h                         |   2 +-
 drivers/usb/serial/kobil_sct.c                     |  12 +-
 drivers/usb/serial/sierra.c                        |   4 +-
 drivers/usb/serial/ti_usb_3410_5052.c              |  13 +-
 drivers/usb/serial/ti_usb_3410_5052.h              |   2 -
 drivers/usb/serial/usb-serial-simple.c             |   3 +-
 drivers/usb/storage/scsiglue.c                     |   9 +
 drivers/usb/storage/uas.c                          |  20 +
 drivers/usb/storage/unusual_devs.h                 |   7 +
 drivers/video/fbdev/aty/atyfb.h                    |   3 +-
 drivers/video/fbdev/aty/atyfb_base.c               |   7 +-
 drivers/video/fbdev/aty/mach64_ct.c                |  10 +-
 drivers/video/fbdev/core/fbmem.c                   |  38 +-
 drivers/video/fbdev/omap/omapfb_main.c             |   2 +-
 drivers/video/fbdev/omap2/omapfb/omapfb-ioctl.c    |   5 +-
 drivers/video/fbdev/udlfb.c                        | 140 ++++---
 fs/9p/xattr.c                                      |   6 +-
 fs/binfmt_elf.c                                    |   2 +-
 fs/btrfs/disk-io.c                                 |  10 +-
 fs/btrfs/inode.c                                   |  25 --
 fs/btrfs/super.c                                   |   1 -
 fs/btrfs/volumes.c                                 |  10 +-
 fs/cachefiles/namei.c                              |   2 +-
 fs/cifs/cifs_debug.c                               |  30 +-
 fs/cifs/cifsfs.c                                   |  20 +-
 fs/cifs/connect.c                                  |   9 +-
 fs/cifs/inode.c                                    |   2 +
 fs/cifs/readdir.c                                  |  11 +-
 fs/cifs/sess.c                                     |   6 +
 fs/cifs/smb2ops.c                                  |  23 +-
 fs/cifs/smb2pdu.c                                  |  40 +-
 fs/cifs/smb2pdu.h                                  |  11 +
 fs/ext4/dir.c                                      |  20 +-
 fs/ext4/inline.c                                   |   4 +-
 fs/ext4/mballoc.c                                  |   4 +-
 fs/ext4/mmp.c                                      |   1 -
 fs/ext4/namei.c                                    |   6 +
 fs/ext4/resize.c                                   |  45 ++-
 fs/ext4/xattr.c                                    |   2 +
 fs/fuse/cuse.c                                     |   2 +-
 fs/fuse/dev.c                                      |   7 +-
 fs/fuse/file.c                                     |   1 +
 fs/fuse/fuse_i.h                                   |   2 -
 fs/fuse/inode.c                                    |  37 +-
 fs/ocfs2/buffer_head_io.c                          |   1 +
 fs/ocfs2/dlm/dlmmaster.c                           |   4 +-
 fs/proc/base.c                                     |  14 +
 fs/pstore/ram.c                                    |  29 +-
 fs/pstore/ram_core.c                               |  17 +-
 fs/quota/quota.c                                   |   5 +-
 fs/reiserfs/xattr.c                                |   6 +-
 fs/seq_file.c                                      |   7 +-
 fs/sysfs/file.c                                    |  44 +++
 fs/ubifs/journal.c                                 |  16 +-
 fs/ubifs/lprops.c                                  |   8 +-
 fs/ubifs/super.c                                   |   3 +
 fs/xattr.c                                         |   2 +-
 fs/xfs/xfs_attr.c                                  |   9 +-
 include/crypto/vmac.h                              |  63 ----
 include/linux/blkdev.h                             |  38 ++
 include/linux/cpuidle.h                            |   3 +
 include/linux/netdevice.h                          |   7 +
 include/linux/percpu_counter.h                     |  13 +-
 include/linux/posix-timers.h                       |   4 +-
 include/linux/seq_file.h                           |  13 +-
 include/linux/skbuff.h                             |   5 +
 include/linux/sysfs.h                              |  14 +
 include/linux/usb.h                                |   2 +-
 include/net/ip_fib.h                               |   1 +
 include/net/netfilter/nf_tables.h                  |   4 +-
 include/video/udlfb.h                              |   5 +-
 kernel/auditsc.c                                   |   8 +-
 kernel/events/core.c                               |  15 +-
 kernel/kprobes.c                                   |   4 +-
 kernel/posix-cpu-timers.c                          |   2 +-
 kernel/posix-timers.c                              |  31 +-
 kernel/sched/idle.c                                |   2 +-
 kernel/time/alarmtimer.c                           |   3 +-
 kernel/trace/blktrace.c                            |   4 +
 kernel/trace/ring_buffer.c                         |   2 +
 kernel/trace/trace.c                               |   4 +-
 kernel/trace/trace_uprobe.c                        |   2 +-
 lib/percpu_counter.c                               |   6 +-
 mm/huge_memory.c                                   |   6 +-
 mm/madvise.c                                       |   2 +-
 mm/memory.c                                        |  15 +-
 mm/mremap.c                                        |  21 +-
 mm/shmem.c                                         |   2 +
 mm/truncate.c                                      |   8 +-
 mm/vmstat.c                                        |   3 +
 net/9p/client.c                                    |   2 +-
 net/9p/trans_fd.c                                  |   7 +-
 net/9p/trans_rdma.c                                |   3 +
 net/9p/trans_virtio.c                              |  13 +-
 net/batman-adv/gateway_client.c                    |  11 +-
 net/batman-adv/main.c                              |   8 +-
 net/batman-adv/network-coding.c                    |  34 +-
 net/batman-adv/soft-interface.c                    |  27 +-
 net/batman-adv/translation-table.c                 |   6 +-
 net/core/dev.c                                     |  28 +-
 net/core/rtnetlink.c                               |   6 +
 net/core/skbuff.c                                  |  12 +-
 net/ieee802154/6lowpan_rtnl.c                      | 140 +++++--
 net/ipv4/fib_frontend.c                            |   4 +
 net/ipv4/fib_semantics.c                           |  50 +++
 net/ipv4/igmp.c                                    |   8 +-
 net/ipv4/ip_tunnel.c                               |   9 +
 net/ipv6/addrconf.c                                |   6 +-
 net/ipv6/af_inet6.c                                |   4 +-
 net/ipv6/ip6_output.c                              |   3 +-
 net/ipv6/ip6_tunnel.c                              |  13 +-
 net/ipv6/raw.c                                     |  34 +-
 net/ipv6/xfrm6_output.c                            |   2 +
 net/l2tp/l2tp_core.c                               |   2 +-
 net/mac80211/cfg.c                                 |   2 +-
 net/mac802154/tx.c                                 |  35 +-
 net/netfilter/nf_tables_api.c                      |  10 +-
 net/netfilter/nft_hash.c                           |   2 +-
 net/netfilter/nft_rbtree.c                         |   2 +-
 net/sched/act_ipt.c                                |   2 +-
 net/wireless/nl80211.c                             |   1 +
 net/wireless/reg.c                                 |   1 +
 net/xfrm/xfrm_policy.c                             |   5 +-
 net/xfrm/xfrm_user.c                               |  12 +
 security/apparmor/policy_unpack.c                  |  32 --
 security/keys/encrypted-keys/encrypted.c           |  31 +-
 sound/aoa/core/gpio-feature.c                      |   4 +-
 sound/core/memalloc.c                              |   8 +-
 sound/core/seq/oss/seq_oss.c                       |   2 +-
 sound/core/seq/seq_clientmgr.c                     |   2 +-
 sound/core/seq/seq_virmidi.c                       |  10 +
 sound/drivers/vx/vx_pcm.c                          |   6 +-
 sound/firewire/bebob/bebob_maudio.c                |  24 +-
 sound/pci/cs5535audio/cs5535audio.h                |   6 +-
 sound/pci/cs5535audio/cs5535audio_pcm.c            |   4 +-
 sound/pci/emu10k1/emufx.c                          |   2 +-
 sound/pci/vx222/vx222_ops.c                        |  20 +-
 sound/pcmcia/vx/vxp_ops.c                          |  22 +-
 sound/soc/codecs/wm8994.c                          |   1 +
 tools/hv/hv_fcopy_daemon.c                         |   1 +
 tools/hv/hv_kvp_daemon.c                           |   2 +-
 319 files changed, 2983 insertions(+), 1647 deletions(-)
Signature · 3 lines
Ben Hutchings
The generation of random numbers is too important to be left to chance.
                                                       - Robert Coveyou
#1 lore raw

PATCH 1/328 EDAC: Fix memleak in module init error path

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Johan Hovold <[email protected]>

commit 4708aa85d50cc6e962dfa8acf5ad4e0d290a21db upstream.

Make sure to use put_device() to free the initialised struct device so that resources managed by driver core also gets released in the event of a registration failure.

Cc Denis Kirjanov <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
Cc linux-edac <[email protected]>
Fixes 2d56b109e3a5 ("EDAC: Handle error path in edac_mc_sysfs_init() properly")
[bwh: Backported to 3.16: adjust context]
---
 drivers/edac/edac_mc_sysfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/edac/edac_mc_sysfs.c +3 -3
@@ -1161,14 +1161,14 @@ int __init edac_mc_sysfs_init(void)
 
 	err = device_add(mci_pdev);
 	if (err < 0)
-		goto out_dev_free;
+		goto out_put_device;
 
 	edac_dbg(0, "device %s created\n", dev_name(mci_pdev));
 
 	return 0;
 
- out_dev_free:
-	kfree(mci_pdev);
+ out_put_device:
+	put_device(mci_pdev);
  out_put_sysfs:
 	edac_put_sysfs_subsys();
  out:
#2 lore raw

PATCH 2/328 EDAC: i7core: Return proper error codes for kzalloc() errors

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <[email protected]>

commit e97d7e38162dc305b4734a316ca758a2bbd1fa6e upstream.

... instead of possibly uninitialized return value.

---
 drivers/edac/i7core_edac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/edac/i7core_edac.c +2 -2
@@ -1177,7 +1177,7 @@ static int i7core_create_sysfs_devices(s
 
 	pvt->addrmatch_dev = kzalloc(sizeof(*pvt->addrmatch_dev), GFP_KERNEL);
 	if (!pvt->addrmatch_dev)
-		return rc;
+		return -ENOMEM;
 
 	pvt->addrmatch_dev->type = &addrmatch_type;
 	pvt->addrmatch_dev->bus = mci->dev.bus;
@@ -1198,7 +1198,7 @@ static int i7core_create_sysfs_devices(s
 		if (!pvt->chancounts_dev) {
 			put_device(pvt->addrmatch_dev);
 			device_del(pvt->addrmatch_dev);
-			return rc;
+			return -ENOMEM;
 		}
 
 		pvt->chancounts_dev->type = &all_channel_counts_type;
#3 lore raw

PATCH 3/328 EDAC, i7core: Fix memleaks and use-after-free on probe and remove

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Johan Hovold <[email protected]>

commit 6c974d4dfafe5e9ee754f2a6fba0eb1864f1649e upstream.

Make sure to free and deregister the addrmatch and chancounts devices allocated during probe in all error paths. Also fix use-after-free in a probe error path and in the remove success path where the devices were being put before before deregistration.

Cc Mauro Carvalho Chehab <[email protected]>
Cc linux-edac <[email protected]>
Fixes 356f0a30860d ("i7core_edac: change the mem allocation scheme to make Documentation/kobject.txt happy")
---
 drivers/edac/i7core_edac.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/edac/i7core_edac.c +15 -7
@@ -1190,15 +1190,14 @@ static int i7core_create_sysfs_devices(s
 
 	rc = device_add(pvt->addrmatch_dev);
 	if (rc < 0)
-		return rc;
+		goto err_put_addrmatch;
 
 	if (!pvt->is_registered) {
 		pvt->chancounts_dev = kzalloc(sizeof(*pvt->chancounts_dev),
 					      GFP_KERNEL);
 		if (!pvt->chancounts_dev) {
-			put_device(pvt->addrmatch_dev);
-			device_del(pvt->addrmatch_dev);
-			return -ENOMEM;
+			rc = -ENOMEM;
+			goto err_del_addrmatch;
 		}
 
 		pvt->chancounts_dev->type = &all_channel_counts_type;
@@ -1212,9 +1211,18 @@ static int i7core_create_sysfs_devices(s
 
 		rc = device_add(pvt->chancounts_dev);
 		if (rc < 0)
-			return rc;
+			goto err_put_chancounts;
 	}
 	return 0;
+
+err_put_chancounts:
+	put_device(pvt->chancounts_dev);
+err_del_addrmatch:
+	device_del(pvt->addrmatch_dev);
+err_put_addrmatch:
+	put_device(pvt->addrmatch_dev);
+
+	return rc;
 }
 
 static void i7core_delete_sysfs_devices(struct mem_ctl_info *mci)
@@ -1229,11 +1237,11 @@ static void i7core_delete_sysfs_devices(
 	device_remove_file(&mci->dev, &dev_attr_inject_enable);
 
 	if (!pvt->is_registered) {
-		put_device(pvt->chancounts_dev);
 		device_del(pvt->chancounts_dev);
+		put_device(pvt->chancounts_dev);
 	}
-	put_device(pvt->addrmatch_dev);
 	device_del(pvt->addrmatch_dev);
+	put_device(pvt->addrmatch_dev);
 }
 
 /****************************************************************************
#4 lore raw

PATCH 4/328 audit: Fix extended comparison of GID/EGID

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Ondrej Mosnáček <[email protected]>

commit af85d1772e31fed34165a1b3decef340cf4080c0 upstream.

The audit_filter_rules() function in auditsc.c used the in_[e]group_p() functions to check GID/EGID match, but these functions use the current task's credentials, while the comparison should use the credentials of the task given to audit_filter_rules() as a parameter (tsk).

Note that we can use group_search(cred->group_info, ...) as a replacement for both in_group_p and in_egroup_p as these functions only compare the parameter to cred->fsgid/egid and then call group_search.

In fact, the usage of in_group_p was even more incorrect: it compares to cred->fsgid (which is usually equal to cred->egid) and not cred->gid.

GitHub issue:
https://github.com/linux-audit/audit-kernel/issues/82

Fixes 37eebe39c973 ("audit: improve GID/EGID comparation logic")
---
 kernel/auditsc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/auditsc.c +4 -4
@@ -489,20 +489,20 @@ static int audit_filter_rules(struct tas
 			result = audit_gid_comparator(cred->gid, f->op, f->gid);
 			if (f->op == Audit_equal) {
 				if (!result)
-					result = in_group_p(f->gid);
+					result = groups_search(cred->group_info, f->gid);
 			} else if (f->op == Audit_not_equal) {
 				if (result)
-					result = !in_group_p(f->gid);
+					result = !groups_search(cred->group_info, f->gid);
 			}
 			break;
 		case AUDIT_EGID:
 			result = audit_gid_comparator(cred->egid, f->op, f->gid);
 			if (f->op == Audit_equal) {
 				if (!result)
-					result = in_egroup_p(f->gid);
+					result = groups_search(cred->group_info, f->gid);
 			} else if (f->op == Audit_not_equal) {
 				if (result)
-					result = !in_egroup_p(f->gid);
+					result = !groups_search(cred->group_info, f->gid);
 			}
 			break;
 		case AUDIT_SGID:
#5 lore raw

PATCH 5/328 kprobes: Make list and blacklist root user read only

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Masami Hiramatsu <[email protected]>

commit f2a3ab36077222437b4826fc76111caa14562b7c upstream.

Since the blacklist and list files on debugfs indicates a sensitive address information to reader, it should be restricted to the root user.

---
 kernel/kprobes.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kprobes.c +2 -2
@@ -2414,7 +2414,7 @@ static int __init debugfs_kprobe_init(vo
 	if (!dir)
 		return -ENOMEM;
 
-	file = debugfs_create_file("list", 0444, dir, NULL,
+	file = debugfs_create_file("list", 0400, dir, NULL,
 				&debugfs_kprobes_operations);
 	if (!file)
 		goto error;
@@ -2424,7 +2424,7 @@ static int __init debugfs_kprobe_init(vo
 	if (!file)
 		goto error;
 
-	file = debugfs_create_file("blacklist", 0444, dir, NULL,
+	file = debugfs_create_file("blacklist", 0400, dir, NULL,
 				&debugfs_kprobe_blacklist_ops);
 	if (!file)
 		goto error;
#6 lore raw

PATCH 6/328 s390/qdio: reset old sbal_state flags

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Julian Wiedmann <[email protected]>

commit 64e03ff72623b8c2ea89ca3cb660094e019ed4ae upstream.

When allocating a new AOB fails, handle_outbound() is still capable of transmitting the selected buffer (just without async completion).

But if a previous transfer on this queue slot used async completion, its sbal_state flags field is still set to QDIO_OUTBUF_STATE_FLAG_PENDING. So when the upper layer driver sees this stale flag, it expects an async completion that never happens.

Fix this by unconditionally clearing the flags field.

Fixes 104ea556ee7f ("qdio: support asynchronous delivery of storage blocks")
---
 arch/s390/include/asm/qdio.h | 1 -
 drivers/s390/cio/qdio_main.c | 5 ++---
 2 files changed, 2 insertions(+), 4 deletions(-)
arch/s390/include/asm/qdio.h +0 -1
@@ -271,7 +271,6 @@ struct qdio_outbuf_state {
 	void *user;
 };
 
-#define QDIO_OUTBUF_STATE_FLAG_NONE	0x00
 #define QDIO_OUTBUF_STATE_FLAG_PENDING	0x01
 
 #define CHSC_AC1_INITIATE_INPUTQ	0x80
drivers/s390/cio/qdio_main.c +2 -3
@@ -640,21 +640,20 @@ static inline unsigned long qdio_aob_for
 	unsigned long phys_aob = 0;
 
 	if (!q->use_cq)
-		goto out;
+		return 0;
 
 	if (!q->aobs[bufnr]) {
 		struct qaob *aob = qdio_allocate_aob();
 		q->aobs[bufnr] = aob;
 	}
 	if (q->aobs[bufnr]) {
-		q->sbal_state[bufnr].flags = QDIO_OUTBUF_STATE_FLAG_NONE;
 		q->sbal_state[bufnr].aob = q->aobs[bufnr];
 		q->aobs[bufnr]->user1 = (u64) q->sbal_state[bufnr].user;
 		phys_aob = virt_to_phys(q->aobs[bufnr]);
 		WARN_ON_ONCE(phys_aob & 0xFF);
 	}
 
-out:
+	q->sbal_state[bufnr].flags = 0;
 	return phys_aob;
 }
 
#7 lore raw

PATCH 7/328 USB: serial: sierra: fix potential deadlock at close

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: John Ogness <[email protected]>

commit e60870012e5a35b1506d7b376fddfb30e9da0b27 upstream.

The portdata spinlock can be taken in interrupt context (via sierra_outdat_callback()).
Disable interrupts when taking the portdata spinlock when discarding deferred URBs during close to prevent a possible deadlock.

Fixes 014333f77c0b ("USB: sierra: fix urb and memory leak on disconnect")
[ johan: amend commit message and add fixes and stable tags ]
---
 drivers/usb/serial/sierra.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/serial/sierra.c +2 -2
@@ -772,9 +772,9 @@ static void sierra_close(struct usb_seri
 		kfree(urb->transfer_buffer);
 		usb_free_urb(urb);
 		usb_autopm_put_interface_async(serial->interface);
-		spin_lock(&portdata->lock);
+		spin_lock_irq(&portdata->lock);
 		portdata->outstanding_urbs--;
-		spin_unlock(&portdata->lock);
+		spin_unlock_irq(&portdata->lock);
 	}
 
 	sierra_stop_rx_urbs(port);
#8 lore raw

PATCH 8/328 platform/x86: ideapad-laptop: Add Y520-15IKBN to no_hw_rfkill

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Olle Liljenzin <[email protected]>

commit 5d9f40b56630a8702b5f7a61a770f9b73aa07464 upstream.

Lenovo Legion Y520-15IKBN is yet another Lenovo model that does not have an hw rfkill switch, resulting in wifi always reported as hard blocked.

Add the model to the list of models without rfkill switch.

---
 drivers/platform/x86/ideapad-laptop.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/platform/x86/ideapad-laptop.c +7 -0
@@ -860,6 +860,13 @@ static struct dmi_system_id no_hw_rfkill
 		},
 	},
 	{
+		.ident = "Lenovo Legion Y520-15IKBN",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+			DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Y520-15IKBN"),
+		},
+	},
+	{
 		.ident = "Lenovo Yoga 2 11 / 13 / Pro",
 		.matches = {
 			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
#9 lore raw

PATCH 9/328 platform/x86: ideapad-laptop: Apply no_hw_rfkill to Y20-15IKBM, too

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <[email protected]>

commit 58e73aa177850babb947555257fd4f79e5275cf1 upstream.

The commit 5d9f40b56630 ("platform/x86: ideapad-laptop: Add Y520-15IKBN to no_hw_rfkill") added the entry for Y20-15IKBN, and it turned out that another variant, Y20-15IKBM, also requires the no_hw_rfkill.

Trim the last letter from the string so that it matches to both Y20-15IKBN and Y20-15IKBM models.

Bugzilla: https://bugzilla.opensuse.org/show_bug.cgi?id=1098626

---
 drivers/platform/x86/ideapad-laptop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/ideapad-laptop.c +2 -2
@@ -860,10 +860,10 @@ static struct dmi_system_id no_hw_rfkill
 		},
 	},
 	{
-		.ident = "Lenovo Legion Y520-15IKBN",
+		.ident = "Lenovo Legion Y520-15IKB",
 		.matches = {
 			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
-			DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Y520-15IKBN"),
+			DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Y520-15IKB"),
 		},
 	},
 	{
#10 lore raw

PATCH 10/328 rndis_wlan: potential buffer overflow in rndis_wlan_auth_indication()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dan Carpenter <[email protected]>

commit ae636fb1554833ee5133ca47bf4b2791b6739c52 upstream.

This is a static checker fix, not something I have tested. The issue is that on the second iteration through the loop, we jump forward by le32_to_cpu(auth_req->length) bytes. The problem is that if the length is more than "buflen" then we end up with a negative "buflen". A negative buflen is type promoted to a high positive value and the loop continues but it's accessing beyond the end of the buffer.

I believe the "auth_req->length" comes from the firmware and if the firmware is malicious or buggy, you're already toasted so the impact of this bug is probably not very severe.

Fixes 030645aceb3d ("rndis_wlan: handle 802.11 indications from device")
---
 drivers/net/wireless/rndis_wlan.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/wireless/rndis_wlan.c +2 -0
@@ -2917,6 +2917,8 @@ static void rndis_wlan_auth_indication(s
 
 	while (buflen >= sizeof(*auth_req)) {
 		auth_req = (void *)buf;
+		if (buflen < le32_to_cpu(auth_req->length))
+			return;
 		type = "unknown";
 		flags = le32_to_cpu(auth_req->flags);
 		pairwise_error = false;
#11 lore raw

PATCH 11/328 serial: pxa: Fix an error handling path in 'serial_pxa_probe()'

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Christophe JAILLET <[email protected]>

commit 95a0e656580fab3128c7bee5f660c50784f53651 upstream.

If port.line is out of range, we still need to release some resources, or we will leak them.

Fixes afc7851fab83 ("serial: pxa: Fix out-of-bounds access through serial port index")
---
 drivers/tty/serial/pxa.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/serial/pxa.c +2 -1
@@ -890,7 +890,8 @@ static int serial_pxa_probe(struct platf
 		goto err_clk;
 	if (sport->port.line >= ARRAY_SIZE(serial_pxa_ports)) {
 		dev_err(&dev->dev, "serial%d out of range\n", sport->port.line);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_clk;
 	}
 	snprintf(sport->name, PXA_NAME_LEN - 1, "UART%d", sport->port.line + 1);
 
#12 lore raw

PATCH 12/328 media: omap3isp: zero-initialize the isp cam_xclk{a,b} initial data

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Javier Martinez Canillas <[email protected]>

commit 2ec7debd44b49927a6e2861521994cc075a389ed upstream.

The struct clk_init_data init variable is declared in the isp_xclk_init() function so is an automatic variable allocated in the stack. But it's not explicitly zero-initialized, so some init fields are left uninitialized.

This causes the data structure to have undefined values that may confuse the common clock framework when the clock is registered.

For example, the uninitialized .flags field could have the CLK_IS_CRITICAL bit set, causing the framework to wrongly prepare the clk on registration. This leads to the isp_xclk_prepare() callback being called, which in turn calls to the omap3isp_get() function that increments the isp dev refcount.

Since this omap3isp_get() call is unexpected, this leads to an unbalanced omap3isp_get() call that prevents the requested IRQ to be later enabled, due the refcount not being 0 when the correct omap3isp_get() call happens.

Fixes 9b28ee3c9122 ("[media] omap3isp: Use the common clock framework")
---
 drivers/media/platform/omap3isp/isp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/omap3isp/isp.c +1 -1
@@ -282,7 +282,7 @@ static const char *isp_xclk_parent_name
 static int isp_xclk_init(struct isp_device *isp)
 {
 	struct isp_platform_data *pdata = isp->pdata;
-	struct clk_init_data init;
+	struct clk_init_data init = { 0 };
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(isp->xclks); ++i)
#13 lore raw

PATCH 13/328 ALSA: snd-aoa: add of_node_put() in error path

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Nicholas Mc Guire <[email protected]>

commit 222bce5eb88d1af656419db04bcd84b2419fb900 upstream.

Both calls to of_find_node_by_name() and of_get_next_child() return a
node pointer with refcount incremented thus it must be explicidly decremented here after the last usage. As we are assured to have a refcounted np either from the initial of_find_node_by_name(NULL, name); or from the of_get_next_child(gpio, np) in the while loop if we reached the error code path below, an x of_node_put(np) is needed.

Fixes commit f3d9478b2ce4 ("[ALSA] snd-aoa: add snd-aoa")
---
 sound/aoa/core/gpio-feature.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
sound/aoa/core/gpio-feature.c +3 -1
@@ -88,8 +88,10 @@ static struct device_node *get_gpio(char
 	}
 
 	reg = of_get_property(np, "reg", NULL);
-	if (!reg)
+	if (!reg) {
+		of_node_put(np);
 		return NULL;
+	}
 
 	*gpioptr = *reg;
 
#14 lore raw

PATCH 14/328 IB/srpt: Support HCAs with more than two ports

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Bart Van Assche <[email protected]>

commit e620ebfc228dcbef7519e3d16f43c6c6f1a1d0cb upstream.

Since there are adapters that have four ports, increase the size of the srpt_device.port[] array. This patch avoids that the following warning is hit with quad port Chelsio adapters:

    WARN_ON(sdev->device->phys_port_cnt > ARRAY_SIZE(sdev->port));

[bwh: Backported to 3.16:
- Use inline calculation instead of struct_size; the number of ports is not user-controlled so no overflow check is needed
- Adjust context]

---

drivers/infiniband/ulp/srpt/ib_srpt.c +3 -3
@@ -3147,7 +3147,9 @@ static void srpt_add_one(struct ib_devic
 	pr_debug("device = %p, device->dma_ops = %p\n", device,
 		 device->dma_ops);
 
-	sdev = kzalloc(sizeof *sdev, GFP_KERNEL);
+	sdev = kzalloc(sizeof(*sdev) +
+		       device->phys_port_cnt * sizeof(*sdev->port),
+		       GFP_KERNEL);
 	if (!sdev)
 		goto err;
 
@@ -3220,8 +3222,6 @@ static void srpt_add_one(struct ib_devic
 	for (i = 0; i < sdev->srq_size; ++i)
 		srpt_post_recv(sdev, sdev->ioctx_ring[i]);
 
-	WARN_ON(sdev->device->phys_port_cnt > ARRAY_SIZE(sdev->port));
-
 	for (i = 1; i <= sdev->device->phys_port_cnt; i++) {
 		sport = &sdev->port[i - 1];
 		sport->sdev = sdev;
drivers/infiniband/ulp/srpt/ib_srpt.h +2 -2
@@ -387,9 +387,9 @@ struct srpt_port {
  * @rch_list:      Per-device channel list -- see also srpt_rdma_ch.list.
  * @ch_releaseQ:   Enables waiting for removal from rch_list.
  * @spinlock:      Protects rch_list and tpg.
- * @port:          Information about the ports owned by this HCA.
  * @event_handler: Per-HCA asynchronous IB event handler.
  * @list:          Node in srpt_dev_list.
+ * @port:          Information about the ports owned by this HCA.
  */
 struct srpt_device {
 	struct ib_device	*device;
@@ -403,9 +403,9 @@ struct srpt_device {
 	struct list_head	rch_list;
 	wait_queue_head_t	ch_releaseQ;
 	spinlock_t		spinlock;
-	struct srpt_port	port[2];
 	struct ib_event_handler	event_handler;
 	struct list_head	list;
+	struct srpt_port        port[];
 };
 
 /**
#15 lore raw

PATCH 15/328 crypto: vmac - require a block cipher with 128-bit block size

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Eric Biggers <[email protected]>

commit 73bf20ef3df262026c3470241ae4ac8196943ffa upstream.

The VMAC template assumes the block cipher has a 128-bit block size, but it failed to check for that. Thus it was possible to instantiate it using a 64-bit block size cipher, e.g. "vmac(cast5)", causing uninitialized memory to be used.

Add the needed check when instantiating the template.

Fixes f1939f7c5645 ("crypto: vmac - New hash algorithm for intel_txt support")
---
 crypto/vmac.c | 4 ++++
 1 file changed, 4 insertions(+)
crypto/vmac.c +4 -0
@@ -655,6 +655,10 @@ static int vmac_create(struct crypto_tem
 	if (IS_ERR(alg))
 		return PTR_ERR(alg);
 
+	err = -EINVAL;
+	if (alg->cra_blocksize != 16)
+		goto out_put_alg;
+
 	inst = shash_alloc_instance("vmac", alg);
 	err = PTR_ERR(inst);
 	if (IS_ERR(inst))
#16 lore raw

PATCH 16/328 crypto: memzero_explicit - make sure to clear out sensitive data

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Daniel Borkmann <[email protected]>

commit 7185ad2672a7d50bc384de0e38d90b75d99f3d82 upstream.

Recently, in commit 13aa93c70e71 ("random: add and use memzero_explicit() for clearing data"), we have found that GCC may optimize some memset() cases away when it detects a stack variable is not being used anymore and going out of scope. This can happen, for example, in cases when we are clearing out sensitive information such as keying material or any e.g. intermediate results from crypto computations, etc.

With the help of Coccinelle, we can figure out and fix such occurences in the crypto subsytem as well. Julia Lawall provided the following Coccinelle program:

@@
type T;
identifier x;
@@

T x;
... when exists
when any
-memset
+memzero_explicit

     (&x,
  -0,
     ...)

... when != x
when strict

@@
type T;
identifier x;
@@

  T x[...];
  ... when exists
      when any
  -memset
  +memzero_explicit
     (x,
  -0,
     ...)
  ... when != x
      when strict

Therefore, make use of the drop-in replacement memzero_explicit() for exactly such cases instead of using memset().

---
 crypto/cts.c            | 3 ++-
 crypto/sha1_generic.c   | 2 +-
 crypto/sha256_generic.c | 5 ++---
 crypto/sha512_generic.c | 2 +-
 crypto/tgr192.c         | 4 ++--
 crypto/vmac.c           | 2 +-
 crypto/wp512.c          | 8 ++++----
 7 files changed, 13 insertions(+), 13 deletions(-)
crypto/cts.c +2 -1
@@ -202,7 +202,8 @@ static int cts_cbc_decrypt(struct crypto
 	/* 5. Append the tail (BB - Ln) bytes of Xn (tmp) to Cn to create En */
 	memcpy(s + bsize + lastn, tmp + lastn, bsize - lastn);
 	/* 6. Decrypt En to create Pn-1 */
-	memset(iv, 0, sizeof(iv));
+	memzero_explicit(iv, sizeof(iv));
+
 	sg_set_buf(&sgsrc[0], s + bsize, bsize);
 	sg_set_buf(&sgdst[0], d, bsize);
 	err = crypto_blkcipher_decrypt_iv(&lcldesc, sgdst, sgsrc, bsize);
crypto/sha1_generic.c +1 -1
@@ -64,7 +64,7 @@ int crypto_sha1_update(struct shash_desc
 			src = data + done;
 		} while (done + SHA1_BLOCK_SIZE <= len);
 
-		memset(temp, 0, sizeof(temp));
+		memzero_explicit(temp, sizeof(temp));
 		partial = 0;
 	}
 	memcpy(sctx->buffer + partial, src, len - done);
crypto/sha256_generic.c +2 -3
@@ -210,10 +210,9 @@ static void sha256_transform(u32 *state,
 
 	/* clear any sensitive info... */
 	a = b = c = d = e = f = g = h = t1 = t2 = 0;
-	memset(W, 0, 64 * sizeof(u32));
+	memzero_explicit(W, 64 * sizeof(u32));
 }
 
-
 static int sha224_init(struct shash_desc *desc)
 {
 	struct sha256_state *sctx = shash_desc_ctx(desc);
@@ -316,7 +315,7 @@ static int sha224_final(struct shash_des
 	sha256_final(desc, D);
 
 	memcpy(hash, D, SHA224_DIGEST_SIZE);
-	memset(D, 0, SHA256_DIGEST_SIZE);
+	memzero_explicit(D, SHA256_DIGEST_SIZE);
 
 	return 0;
 }
crypto/sha512_generic.c +1 -1
@@ -238,7 +238,7 @@ static int sha384_final(struct shash_des
 	sha512_final(desc, D);
 
 	memcpy(hash, D, 48);
-	memset(D, 0, 64);
+	memzero_explicit(D, 64);
 
 	return 0;
 }
crypto/tgr192.c +2 -2
@@ -612,7 +612,7 @@ static int tgr160_final(struct shash_des
 
 	tgr192_final(desc, D);
 	memcpy(out, D, TGR160_DIGEST_SIZE);
-	memset(D, 0, TGR192_DIGEST_SIZE);
+	memzero_explicit(D, TGR192_DIGEST_SIZE);
 
 	return 0;
 }
@@ -623,7 +623,7 @@ static int tgr128_final(struct shash_des
 
 	tgr192_final(desc, D);
 	memcpy(out, D, TGR128_DIGEST_SIZE);
-	memset(D, 0, TGR192_DIGEST_SIZE);
+	memzero_explicit(D, TGR192_DIGEST_SIZE);
 
 	return 0;
 }
crypto/vmac.c +1 -1
@@ -613,7 +613,7 @@ static int vmac_final(struct shash_desc
 	}
 	mac = vmac(ctx->partial, ctx->partial_size, nonce, NULL, ctx);
 	memcpy(out, &mac, sizeof(vmac_t));
-	memset(&mac, 0, sizeof(vmac_t));
+	memzero_explicit(&mac, sizeof(vmac_t));
 	memset(&ctx->__vmac_ctx, 0, sizeof(struct vmac_ctx));
 	ctx->partial_size = 0;
 	return 0;
crypto/wp512.c +4 -4
@@ -1102,8 +1102,8 @@ static int wp384_final(struct shash_desc
 	u8 D[64];
 
 	wp512_final(desc, D);
-	memcpy (out, D, WP384_DIGEST_SIZE);
-	memset (D, 0, WP512_DIGEST_SIZE);
+	memcpy(out, D, WP384_DIGEST_SIZE);
+	memzero_explicit(D, WP512_DIGEST_SIZE);
 
 	return 0;
 }
@@ -1113,8 +1113,8 @@ static int wp256_final(struct shash_desc
 	u8 D[64];
 
 	wp512_final(desc, D);
-	memcpy (out, D, WP256_DIGEST_SIZE);
-	memset (D, 0, WP512_DIGEST_SIZE);
+	memcpy(out, D, WP256_DIGEST_SIZE);
+	memzero_explicit(D, WP512_DIGEST_SIZE);
 
 	return 0;
 }
#17 lore raw

PATCH 17/328 crypto: vmac - separate tfm and request context

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Eric Biggers <[email protected]>

commit bb29648102335586e9a66289a1d98a0cb392b6e5 upstream.

syzbot reported a crash in vmac_final() when multiple threads concurrently use the same "vmac(aes)" transform through AF_ALG. The bug is pretty fundamental: the VMAC template doesn't separate per-request state from per-tfm (per-key) state like the other hash algorithms do, but rather stores it all in the tfm context. That's wrong.

Also, vmac_final() incorrectly zeroes most of the state including the derived keys and cached pseudorandom pad. Therefore, only the first VMAC invocation with a given key calculates the correct digest.

Fix these bugs by splitting the per-tfm state from the per-request state and using the proper init/update/final sequencing for requests.

Reproducer for the crash:

    #include <linux/if_alg.h>
    #include <sys/socket.h>
    #include <unistd.h>

    int main()
    {
            int fd;
            struct sockaddr_alg addr = {
                    .salg_type = "hash",
                    .salg_name = "vmac(aes)",
            };
            char buf[256] = { 0 };

            fd = socket(AF_ALG, SOCK_SEQPACKET, 0);
            bind(fd, (void *)&addr, sizeof(addr));
            setsockopt(fd, SOL_ALG, ALG_SET_KEY, buf, 16);
            fork();
            fd = accept(fd, NULL, NULL);
            for (;;)
                    write(fd, buf, 256);
    }

The immediate cause of the crash is that vmac_ctx_t.partial_size exceeds VMAC_NHBYTES, causing vmac_final() to memset() a negative length.

Reported-by [email protected]
Fixes f1939f7c5645 ("crypto: vmac - New hash algorithm for intel_txt support")
---
 crypto/vmac.c         | 408 +++++++++++++++++++-----------------------
 include/crypto/vmac.h |  63 -------
 2 files changed, 181 insertions(+), 290 deletions(-)
 delete mode 100644 include/crypto/vmac.h
crypto/vmac.c +184 -230
@@ -1,6 +1,10 @@
 /*
- * Modified to interface to the Linux kernel
+ * VMAC: Message Authentication Code using Universal Hashing
+ *
+ * Reference: https://tools.ietf.org/html/draft-krovetz-vmac-01
+ *
  * Copyright (c) 2009, Intel Corporation.
+ * Copyright (c) 2018, Google Inc.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -16,14 +20,15 @@
  * Place - Suite 330, Boston, MA 02111-1307 USA.
  */
 
-/* --------------------------------------------------------------------------
- * VMAC and VHASH Implementation by Ted Krovetz ([email protected]) and Wei Dai.
- * This implementation is herby placed in the public domain.
- * The authors offers no warranty. Use at your own risk.
- * Please send bug reports to the authors.
- * Last modified: 17 APR 08, 1700 PDT
- * ----------------------------------------------------------------------- */
+/*
+ * Derived from:
+ *	VMAC and VHASH Implementation by Ted Krovetz ([email protected]) and Wei Dai.
+ *	This implementation is herby placed in the public domain.
+ *	The authors offers no warranty. Use at your own risk.
+ *	Last modified: 17 APR 08, 1700 PDT
+ */
 
+#include <asm/unaligned.h>
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/crypto.h>
@@ -31,10 +36,36 @@
 #include <linux/scatterlist.h>
 #include <asm/byteorder.h>
 #include <crypto/scatterwalk.h>
-#include <crypto/vmac.h>
 #include <crypto/internal/hash.h>
 
 /*
+ * User definable settings.
+ */
+#define VMAC_TAG_LEN	64
+#define VMAC_KEY_SIZE	128/* Must be 128, 192 or 256			*/
+#define VMAC_KEY_LEN	(VMAC_KEY_SIZE/8)
+#define VMAC_NHBYTES	128/* Must 2^i for any 3 < i < 13 Standard = 128*/
+
+/* per-transform (per-key) context */
+struct vmac_tfm_ctx {
+	struct crypto_cipher *cipher;
+	u64 nhkey[(VMAC_NHBYTES/8)+2*(VMAC_TAG_LEN/64-1)];
+	u64 polykey[2*VMAC_TAG_LEN/64];
+	u64 l3key[2*VMAC_TAG_LEN/64];
+};
+
+/* per-request context */
+struct vmac_desc_ctx {
+	union {
+		u8 partial[VMAC_NHBYTES];	/* partial block */
+		__le64 partial_words[VMAC_NHBYTES / 8];
+	};
+	unsigned int partial_size;	/* size of the partial block */
+	bool first_block_processed;
+	u64 polytmp[2*VMAC_TAG_LEN/64];	/* running total of L2-hash */
+};
+
+/*
  * Constants and masks
  */
 #define UINT64_C(x) x##ULL
@@ -318,13 +349,6 @@ static void poly_step_func(u64 *ahi, u64
 	} while (0)
 #endif
 
-static void vhash_abort(struct vmac_ctx *ctx)
-{
-	ctx->polytmp[0] = ctx->polykey[0] ;
-	ctx->polytmp[1] = ctx->polykey[1] ;
-	ctx->first_block_processed = 0;
-}
-
 static u64 l3hash(u64 p1, u64 p2, u64 k1, u64 k2, u64 len)
 {
 	u64 rh, rl, t, z = 0;
@@ -364,280 +388,209 @@ static u64 l3hash(u64 p1, u64 p2, u64 k1
 	return rl;
 }
 
-static void vhash_update(const unsigned char *m,
-			unsigned int mbytes, /* Pos multiple of VMAC_NHBYTES */
-			struct vmac_ctx *ctx)
-{
-	u64 rh, rl, *mptr;
-	const u64 *kptr = (u64 *)ctx->nhkey;
-	int i;
-	u64 ch, cl;
-	u64 pkh = ctx->polykey[0];
-	u64 pkl = ctx->polykey[1];
-
-	if (!mbytes)
-		return;
-
-	BUG_ON(mbytes % VMAC_NHBYTES);
+/* L1 and L2-hash one or more VMAC_NHBYTES-byte blocks */
+static void vhash_blocks(const struct vmac_tfm_ctx *tctx,
+			 struct vmac_desc_ctx *dctx,
+			 const __le64 *mptr, unsigned int blocks)
+{
+	const u64 *kptr = tctx->nhkey;
+	const u64 pkh = tctx->polykey[0];
+	const u64 pkl = tctx->polykey[1];
+	u64 ch = dctx->polytmp[0];
+	u64 cl = dctx->polytmp[1];
+	u64 rh, rl;
 
-	mptr = (u64 *)m;
-	i = mbytes / VMAC_NHBYTES;  /* Must be non-zero */
-
-	ch = ctx->polytmp[0];
-	cl = ctx->polytmp[1];
-
-	if (!ctx->first_block_processed) {
-		ctx->first_block_processed = 1;
+	if (!dctx->first_block_processed) {
+		dctx->first_block_processed = true;
 		nh_vmac_nhbytes(mptr, kptr, VMAC_NHBYTES/8, rh, rl);
 		rh &= m62;
 		ADD128(ch, cl, rh, rl);
 		mptr += (VMAC_NHBYTES/sizeof(u64));
-		i--;
+		blocks--;
 	}
 
-	while (i--) {
+	while (blocks--) {
 		nh_vmac_nhbytes(mptr, kptr, VMAC_NHBYTES/8, rh, rl);
 		rh &= m62;
 		poly_step(ch, cl, pkh, pkl, rh, rl);
 		mptr += (VMAC_NHBYTES/sizeof(u64));
 	}
 
-	ctx->polytmp[0] = ch;
-	ctx->polytmp[1] = cl;
+	dctx->polytmp[0] = ch;
+	dctx->polytmp[1] = cl;
 }
 
-static u64 vhash(unsigned char m[], unsigned int mbytes,
-			u64 *tagl, struct vmac_ctx *ctx)
+static int vmac_setkey(struct crypto_shash *tfm,
+		       const u8 *key, unsigned int keylen)
 {
-	u64 rh, rl, *mptr;
-	const u64 *kptr = (u64 *)ctx->nhkey;
-	int i, remaining;
-	u64 ch, cl;
-	u64 pkh = ctx->polykey[0];
-	u64 pkl = ctx->polykey[1];
-
-	mptr = (u64 *)m;
-	i = mbytes / VMAC_NHBYTES;
-	remaining = mbytes % VMAC_NHBYTES;
-
-	if (ctx->first_block_processed) {
-		ch = ctx->polytmp[0];
-		cl = ctx->polytmp[1];
-	} else if (i) {
-		nh_vmac_nhbytes(mptr, kptr, VMAC_NHBYTES/8, ch, cl);
-		ch &= m62;
-		ADD128(ch, cl, pkh, pkl);
-		mptr += (VMAC_NHBYTES/sizeof(u64));
-		i--;
-	} else if (remaining) {
-		nh_16(mptr, kptr, 2*((remaining+15)/16), ch, cl);
-		ch &= m62;
-		ADD128(ch, cl, pkh, pkl);
-		mptr += (VMAC_NHBYTES/sizeof(u64));
-		goto do_l3;
-	} else {/* Empty String */
-		ch = pkh; cl = pkl;
-		goto do_l3;
-	}
-
-	while (i--) {
-		nh_vmac_nhbytes(mptr, kptr, VMAC_NHBYTES/8, rh, rl);
-		rh &= m62;
-		poly_step(ch, cl, pkh, pkl, rh, rl);
-		mptr += (VMAC_NHBYTES/sizeof(u64));
-	}
-	if (remaining) {
-		nh_16(mptr, kptr, 2*((remaining+15)/16), rh, rl);
-		rh &= m62;
-		poly_step(ch, cl, pkh, pkl, rh, rl);
-	}
-
-do_l3:
-	vhash_abort(ctx);
-	remaining *= 8;
-	return l3hash(ch, cl, ctx->l3key[0], ctx->l3key[1], remaining);
-}
-
-static u64 vmac(unsigned char m[], unsigned int mbytes,
-			const unsigned char n[16], u64 *tagl,
-			struct vmac_ctx_t *ctx)
-{
-	u64 *in_n, *out_p;
-	u64 p, h;
-	int i;
-
-	in_n = ctx->__vmac_ctx.cached_nonce;
-	out_p = ctx->__vmac_ctx.cached_aes;
-
-	i = n[15] & 1;
-	if ((*(u64 *)(n+8) != in_n[1]) || (*(u64 *)(n) != in_n[0])) {
-		in_n[0] = *(u64 *)(n);
-		in_n[1] = *(u64 *)(n+8);
-		((unsigned char *)in_n)[15] &= 0xFE;
-		crypto_cipher_encrypt_one(ctx->child,
-			(unsigned char *)out_p, (unsigned char *)in_n);
+	struct vmac_tfm_ctx *tctx = crypto_shash_ctx(tfm);
+	__be64 out[2];
+	u8 in[16] = { 0 };
+	unsigned int i;
+	int err;
 
-		((unsigned char *)in_n)[15] |= (unsigned char)(1-i);
+	if (keylen != VMAC_KEY_LEN) {
+		crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
+		return -EINVAL;
 	}
-	p = be64_to_cpup(out_p + i);
-	h = vhash(m, mbytes, (u64 *)0, &ctx->__vmac_ctx);
-	return le64_to_cpu(p + h);
-}
-
-static int vmac_set_key(unsigned char user_key[], struct vmac_ctx_t *ctx)
-{
-	u64 in[2] = {0}, out[2];
-	unsigned i;
-	int err = 0;
 
-	err = crypto_cipher_setkey(ctx->child, user_key, VMAC_KEY_LEN);
+	err = crypto_cipher_setkey(tctx->cipher, key, keylen);
 	if (err)
 		return err;
 
 	/* Fill nh key */
-	((unsigned char *)in)[0] = 0x80;
-	for (i = 0; i < sizeof(ctx->__vmac_ctx.nhkey)/8; i += 2) {
-		crypto_cipher_encrypt_one(ctx->child,
-			(unsigned char *)out, (unsigned char *)in);
-		ctx->__vmac_ctx.nhkey[i] = be64_to_cpup(out);
-		ctx->__vmac_ctx.nhkey[i+1] = be64_to_cpup(out+1);
-		((unsigned char *)in)[15] += 1;
+	in[0] = 0x80;
+	for (i = 0; i < ARRAY_SIZE(tctx->nhkey); i += 2) {
+		crypto_cipher_encrypt_one(tctx->cipher, (u8 *)out, in);
+		tctx->nhkey[i] = be64_to_cpu(out[0]);
+		tctx->nhkey[i+1] = be64_to_cpu(out[1]);
+		in[15]++;
 	}
 
 	/* Fill poly key */
-	((unsigned char *)in)[0] = 0xC0;
-	in[1] = 0;
-	for (i = 0; i < sizeof(ctx->__vmac_ctx.polykey)/8; i += 2) {
-		crypto_cipher_encrypt_one(ctx->child,
-			(unsigned char *)out, (unsigned char *)in);
-		ctx->__vmac_ctx.polytmp[i] =
-			ctx->__vmac_ctx.polykey[i] =
-				be64_to_cpup(out) & mpoly;
-		ctx->__vmac_ctx.polytmp[i+1] =
-			ctx->__vmac_ctx.polykey[i+1] =
-				be64_to_cpup(out+1) & mpoly;
-		((unsigned char *)in)[15] += 1;
+	in[0] = 0xC0;
+	in[15] = 0;
+	for (i = 0; i < ARRAY_SIZE(tctx->polykey); i += 2) {
+		crypto_cipher_encrypt_one(tctx->cipher, (u8 *)out, in);
+		tctx->polykey[i] = be64_to_cpu(out[0]) & mpoly;
+		tctx->polykey[i+1] = be64_to_cpu(out[1]) & mpoly;
+		in[15]++;
 	}
 
 	/* Fill ip key */
-	((unsigned char *)in)[0] = 0xE0;
-	in[1] = 0;
-	for (i = 0; i < sizeof(ctx->__vmac_ctx.l3key)/8; i += 2) {
+	in[0] = 0xE0;
+	in[15] = 0;
+	for (i = 0; i < ARRAY_SIZE(tctx->l3key); i += 2) {
 		do {
-			crypto_cipher_encrypt_one(ctx->child,
-				(unsigned char *)out, (unsigned char *)in);
-			ctx->__vmac_ctx.l3key[i] = be64_to_cpup(out);
-			ctx->__vmac_ctx.l3key[i+1] = be64_to_cpup(out+1);
-			((unsigned char *)in)[15] += 1;
-		} while (ctx->__vmac_ctx.l3key[i] >= p64
-			|| ctx->__vmac_ctx.l3key[i+1] >= p64);
+			crypto_cipher_encrypt_one(tctx->cipher, (u8 *)out, in);
+			tctx->l3key[i] = be64_to_cpu(out[0]);
+			tctx->l3key[i+1] = be64_to_cpu(out[1]);
+			in[15]++;
+		} while (tctx->l3key[i] >= p64 || tctx->l3key[i+1] >= p64);
 	}
 
-	/* Invalidate nonce/aes cache and reset other elements */
-	ctx->__vmac_ctx.cached_nonce[0] = (u64)-1; /* Ensure illegal nonce */
-	ctx->__vmac_ctx.cached_nonce[1] = (u64)0;  /* Ensure illegal nonce */
-	ctx->__vmac_ctx.first_block_processed = 0;
-
-	return err;
+	return 0;
 }
 
-static int vmac_setkey(struct crypto_shash *parent,
-		const u8 *key, unsigned int keylen)
+static int vmac_init(struct shash_desc *desc)
 {
-	struct vmac_ctx_t *ctx = crypto_shash_ctx(parent);
+	const struct vmac_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm);
+	struct vmac_desc_ctx *dctx = shash_desc_ctx(desc);
 
-	if (keylen != VMAC_KEY_LEN) {
-		crypto_shash_set_flags(parent, CRYPTO_TFM_RES_BAD_KEY_LEN);
-		return -EINVAL;
-	}
-
-	return vmac_set_key((u8 *)key, ctx);
-}
-
-static int vmac_init(struct shash_desc *pdesc)
-{
+	dctx->partial_size = 0;
+	dctx->first_block_processed = false;
+	memcpy(dctx->polytmp, tctx->polykey, sizeof(dctx->polytmp));
 	return 0;
 }
 
-static int vmac_update(struct shash_desc *pdesc, const u8 *p,
-		unsigned int len)
+static int vmac_update(struct shash_desc *desc, const u8 *p, unsigned int len)
 {
-	struct crypto_shash *parent = pdesc->tfm;
-	struct vmac_ctx_t *ctx = crypto_shash_ctx(parent);
-	int expand;
-	int min;
-
-	expand = VMAC_NHBYTES - ctx->partial_size > 0 ?
-			VMAC_NHBYTES - ctx->partial_size : 0;
-
-	min = len < expand ? len : expand;
-
-	memcpy(ctx->partial + ctx->partial_size, p, min);
-	ctx->partial_size += min;
-
-	if (len < expand)
-		return 0;
-
-	vhash_update(ctx->partial, VMAC_NHBYTES, &ctx->__vmac_ctx);
-	ctx->partial_size = 0;
-
-	len -= expand;
-	p += expand;
-
-	if (len % VMAC_NHBYTES) {
-		memcpy(ctx->partial, p + len - (len % VMAC_NHBYTES),
-			len % VMAC_NHBYTES);
-		ctx->partial_size = len % VMAC_NHBYTES;
+	const struct vmac_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm);
+	struct vmac_desc_ctx *dctx = shash_desc_ctx(desc);
+	unsigned int n;
+
+	if (dctx->partial_size) {
+		n = min(len, VMAC_NHBYTES - dctx->partial_size);
+		memcpy(&dctx->partial[dctx->partial_size], p, n);
+		dctx->partial_size += n;
+		p += n;
+		len -= n;
+		if (dctx->partial_size == VMAC_NHBYTES) {
+			vhash_blocks(tctx, dctx, dctx->partial_words, 1);
+			dctx->partial_size = 0;
+		}
+	}
+
+	if (len >= VMAC_NHBYTES) {
+		n = round_down(len, VMAC_NHBYTES);
+		/* TODO: 'p' may be misaligned here */
+		vhash_blocks(tctx, dctx, (const __le64 *)p, n / VMAC_NHBYTES);
+		p += n;
+		len -= n;
+	}
+
+	if (len) {
+		memcpy(dctx->partial, p, len);
+		dctx->partial_size = len;
 	}
 
-	vhash_update(p, len - len % VMAC_NHBYTES, &ctx->__vmac_ctx);
-
 	return 0;
 }
 
-static int vmac_final(struct shash_desc *pdesc, u8 *out)
+static u64 vhash_final(const struct vmac_tfm_ctx *tctx,
+		       struct vmac_desc_ctx *dctx)
 {
-	struct crypto_shash *parent = pdesc->tfm;
-	struct vmac_ctx_t *ctx = crypto_shash_ctx(parent);
-	vmac_t mac;
-	u8 nonce[16] = {};
-
-	/* vmac() ends up accessing outside the array bounds that
-	 * we specify.  In appears to access up to the next 2-word
-	 * boundary.  We'll just be uber cautious and zero the
-	 * unwritten bytes in the buffer.
-	 */
-	if (ctx->partial_size) {
-		memset(ctx->partial + ctx->partial_size, 0,
-			VMAC_NHBYTES - ctx->partial_size);
-	}
-	mac = vmac(ctx->partial, ctx->partial_size, nonce, NULL, ctx);
-	memcpy(out, &mac, sizeof(vmac_t));
-	memzero_explicit(&mac, sizeof(vmac_t));
-	memset(&ctx->__vmac_ctx, 0, sizeof(struct vmac_ctx));
-	ctx->partial_size = 0;
+	unsigned int partial = dctx->partial_size;
+	u64 ch = dctx->polytmp[0];
+	u64 cl = dctx->polytmp[1];
+
+	/* L1 and L2-hash the final block if needed */
+	if (partial) {
+		/* Zero-pad to next 128-bit boundary */
+		unsigned int n = round_up(partial, 16);
+		u64 rh, rl;
+
+		memset(&dctx->partial[partial], 0, n - partial);
+		nh_16(dctx->partial_words, tctx->nhkey, n / 8, rh, rl);
+		rh &= m62;
+		if (dctx->first_block_processed)
+			poly_step(ch, cl, tctx->polykey[0], tctx->polykey[1],
+				  rh, rl);
+		else
+			ADD128(ch, cl, rh, rl);
+	}
+
+	/* L3-hash the 128-bit output of L2-hash */
+	return l3hash(ch, cl, tctx->l3key[0], tctx->l3key[1], partial * 8);
+}
+
+static int vmac_final(struct shash_desc *desc, u8 *out)
+{
+	const struct vmac_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm);
+	struct vmac_desc_ctx *dctx = shash_desc_ctx(desc);
+	static const u8 nonce[16] = {}; /* TODO: this is insecure */
+	union {
+		u8 bytes[16];
+		__be64 pads[2];
+	} block;
+	int index;
+	u64 hash, pad;
+
+	/* Finish calculating the VHASH of the message */
+	hash = vhash_final(tctx, dctx);
+
+	/* Generate pseudorandom pad by encrypting the nonce */
+	memcpy(&block, nonce, 16);
+	index = block.bytes[15] & 1;
+	block.bytes[15] &= ~1;
+	crypto_cipher_encrypt_one(tctx->cipher, block.bytes, block.bytes);
+	pad = be64_to_cpu(block.pads[index]);
+
+	/* The VMAC is the sum of VHASH and the pseudorandom pad */
+	put_unaligned_le64(hash + pad, out);
 	return 0;
 }
 
 static int vmac_init_tfm(struct crypto_tfm *tfm)
 {
-	struct crypto_cipher *cipher;
-	struct crypto_instance *inst = (void *)tfm->__crt_alg;
+	struct crypto_instance *inst = crypto_tfm_alg_instance(tfm);
 	struct crypto_spawn *spawn = crypto_instance_ctx(inst);
-	struct vmac_ctx_t *ctx = crypto_tfm_ctx(tfm);
+	struct vmac_tfm_ctx *tctx = crypto_tfm_ctx(tfm);
+	struct crypto_cipher *cipher;
 
 	cipher = crypto_spawn_cipher(spawn);
 	if (IS_ERR(cipher))
 		return PTR_ERR(cipher);
 
-	ctx->child = cipher;
+	tctx->cipher = cipher;
 	return 0;
 }
 
 static void vmac_exit_tfm(struct crypto_tfm *tfm)
 {
-	struct vmac_ctx_t *ctx = crypto_tfm_ctx(tfm);
-	crypto_free_cipher(ctx->child);
+	struct vmac_tfm_ctx *tctx = crypto_tfm_ctx(tfm);
+
+	crypto_free_cipher(tctx->cipher);
 }
 
 static int vmac_create(struct crypto_template *tmpl, struct rtattr **tb)
@@ -674,11 +627,12 @@ static int vmac_create(struct crypto_tem
 	inst->alg.base.cra_blocksize = alg->cra_blocksize;
 	inst->alg.base.cra_alignmask = alg->cra_alignmask;
 
-	inst->alg.digestsize = sizeof(vmac_t);
-	inst->alg.base.cra_ctxsize = sizeof(struct vmac_ctx_t);
+	inst->alg.base.cra_ctxsize = sizeof(struct vmac_tfm_ctx);
 	inst->alg.base.cra_init = vmac_init_tfm;
 	inst->alg.base.cra_exit = vmac_exit_tfm;
 
+	inst->alg.descsize = sizeof(struct vmac_desc_ctx);
+	inst->alg.digestsize = VMAC_TAG_LEN / 8;
 	inst->alg.init = vmac_init;
 	inst->alg.update = vmac_update;
 	inst->alg.final = vmac_final;
include/crypto/vmac.h deleted +0 -63

63 lines not on this page · raw message

#18 lore raw

PATCH 18/328 alarmtimer: Prevent overflow for relative nanosleep

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Thomas Gleixner <[email protected]>

commit 5f936e19cc0ef97dbe3a56e9498922ad5ba1edef upstream.

Air Icy reported:

  UBSAN: Undefined behaviour in kernel/time/alarmtimer.c:811:7
  signed integer overflow:
  1529859276030040771 + 9223372036854775807 cannot be represented in type 'long long int'
  Call Trace:
   alarm_timer_nsleep+0x44c/0x510 kernel/time/alarmtimer.c:811
   __do_sys_clock_nanosleep kernel/time/posix-timers.c:1235 [inline]
   __se_sys_clock_nanosleep kernel/time/posix-timers.c:1213 [inline]
   __x64_sys_clock_nanosleep+0x326/0x4e0 kernel/time/posix-timers.c:1213
   do_syscall_64+0xb8/0x3a0 arch/x86/entry/common.c:290

alarm_timer_nsleep() uses ktime_add() to add the current time and the relative expiry value. ktime_add() has no sanity checks so the addition can overflow when the relative timeout is large enough.

Use ktime_add_safe() which has the necessary sanity checks in place and limits the result to the valid range.

Fixes 9a7adcf5c6de ("timers: Posix interface for alarm-timers")
Cc John Stultz <[email protected]>
---
 kernel/time/alarmtimer.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/alarmtimer.c +2 -1
@@ -775,7 +775,8 @@ static int alarm_timer_nsleep(const cloc
 	/* Convert (if necessary) to absolute time */
 	if (flags != TIMER_ABSTIME) {
 		ktime_t now = alarm_bases[type].gettime();
-		exp = ktime_add(now, exp);
+
+		exp = ktime_add_safe(now, exp);
 	}
 
 	if (alarmtimer_do_nsleep(&alarm, exp))
#19 lore raw

PATCH 19/328 scsi: target/iscsi: Make iscsit_ta_authentication() respect the output buffer size

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Bart Van Assche <[email protected]>

commit 35bea5c84fd13c643cce63f0b5cd4b148f8c901d upstream.

Fixes e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")
Cc Mike Christie <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
---
 drivers/target/iscsi/iscsi_target_tpg.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/target/iscsi/iscsi_target_tpg.c +1 -2
@@ -652,8 +652,7 @@ int iscsit_ta_authentication(struct iscs
 		none = strstr(buf1, NONE);
 		if (none)
 			goto out;
-		strncat(buf1, ",", strlen(","));
-		strncat(buf1, NONE, strlen(NONE));
+		strlcat(buf1, "," NONE, sizeof(buf1));
 		if (iscsi_update_param_value(param, buf1) < 0)
 			return -EINVAL;
 	}
#20 lore raw

PATCH 20/328 leds: max8997: use mode when calling max8997_led_set_mode

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Colin Ian King <[email protected]>

commit 7a5de56db902ea632a0ff0c2b47481d278db645f upstream.

Variable mode is assigned to pdata->led_pdata->mode[led->id] and yet is not being used when calling function max8997_led_set_mode. Fix this by using mode when calling max8997_led_set_mode.

Cleans up clang warning:
warning: variable 'mode' set but not used [-Wunused-but-set-variable]

Fixes 8584cb82f151 ("leds: Add suuport for MAX8997-LED driver")
---
 drivers/leds/leds-max8997.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/leds/leds-max8997.c +1 -1
@@ -262,7 +262,7 @@ static int max8997_led_probe(struct plat
 		mode = pdata->led_pdata->mode[led->id];
 		brightness = pdata->led_pdata->brightness[led->id];
 
-		max8997_led_set_mode(led, pdata->led_pdata->mode[led->id]);
+		max8997_led_set_mode(led, mode);
 
 		if (brightness > led->cdev.max_brightness)
 			brightness = led->cdev.max_brightness;
#21 lore raw

PATCH 21/328 libertas: fix suspend and resume for SDIO connected cards

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Daniel Mack <[email protected]>

commit 7444a8092906ed44c09459780c56ba57043e39b1 upstream.

Prior to commit 573185cc7e64 ("mmc: core: Invoke sdio func driver's PM callbacks from the sdio bus"), the MMC core used to call into the power management functions of SDIO clients itself and removed the card if the return code was non-zero. IOW, the mmc handled errors gracefully and didn't upchain them to the pm core.

Since this change, the mmc core relies on generic power management functions which treat all errors as a reason to cancel the suspend immediately. This causes suspend attempts to fail when the libertas driver is loaded.

To fix this, power down the card explicitly in if_sdio_suspend() when we know we're about to lose power and return success. Also set a flag in these cases, and power up the card again in if_sdio_resume().

Fixes 573185cc7e64 ("mmc: core: Invoke sdio func driver's PM callbacks from the sdio bus")
[bwh: Backported to 3.16: adjust filenames]
---
 drivers/net/wireless/libertas/dev.h     |  1 +
 drivers/net/wireless/libertas/if_sdio.c | 30 +++++++++++++++----
 2 files changed, 25 insertions(+), 6 deletions(-)
drivers/net/wireless/libertas/dev.h +1 -0
@@ -102,6 +102,7 @@ struct lbs_private {
 	u8 fw_ready;
 	u8 surpriseremoved;
 	u8 setup_fw_on_resume;
+	u8 power_up_on_resume;
 	int (*hw_host_to_card) (struct lbs_private *priv, u8 type, u8 *payload, u16 nb);
 	void (*reset_card) (struct lbs_private *priv);
 	int (*power_save) (struct lbs_private *priv);
drivers/net/wireless/libertas/if_sdio.c +24 -6
@@ -1342,15 +1342,23 @@ static void if_sdio_remove(struct sdio_f
 static int if_sdio_suspend(struct device *dev)
 {
 	struct sdio_func *func = dev_to_sdio_func(dev);
-	int ret;
 	struct if_sdio_card *card = sdio_get_drvdata(func);
+	struct lbs_private *priv = card->priv;
+	int ret;
 
 	mmc_pm_flag_t flags = sdio_get_host_pm_caps(func);
+	priv->power_up_on_resume = false;
 
 	/* If we're powered off anyway, just let the mmc layer remove the
 	 * card. */
-	if (!lbs_iface_active(card->priv))
-		return -ENOSYS;
+	if (!lbs_iface_active(priv)) {
+		if (priv->fw_ready) {
+			priv->power_up_on_resume = true;
+			if_sdio_power_off(card);
+		}
+
+		return 0;
+	}
 
 	dev_info(dev, "%s: suspend: PM flags = 0x%x\n",
 		 sdio_func_id(func), flags);
@@ -1358,9 +1366,14 @@ static int if_sdio_suspend(struct device
 	/* If we aren't being asked to wake on anything, we should bail out
 	 * and let the SD stack power down the card.
 	 */
-	if (card->priv->wol_criteria == EHS_REMOVE_WAKEUP) {
+	if (priv->wol_criteria == EHS_REMOVE_WAKEUP) {
 		dev_info(dev, "Suspend without wake params -- powering down card\n");
-		return -ENOSYS;
+		if (priv->fw_ready) {
+			priv->power_up_on_resume = true;
+			if_sdio_power_off(card);
+		}
+
+		return 0;
 	}
 
 	if (!(flags & MMC_PM_KEEP_POWER)) {
@@ -1373,7 +1386,7 @@ static int if_sdio_suspend(struct device
 	if (ret)
 		return ret;
 
-	ret = lbs_suspend(card->priv);
+	ret = lbs_suspend(priv);
 	if (ret)
 		return ret;
 
@@ -1388,6 +1401,11 @@ static int if_sdio_resume(struct device
 
 	dev_info(dev, "%s: resume: we're back\n", sdio_func_id(func));
 
+	if (card->priv->power_up_on_resume) {
+		if_sdio_power_on(card);
+		wait_event(card->pwron_waitq, card->priv->fw_ready);
+	}
+
 	ret = lbs_resume(card->priv);
 
 	return ret;
#22 lore raw

PATCH 22/328 media: exynos4-is: Prevent NULL pointer dereference in __isp_video_try_fmt()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Sylwester Nawrocki <[email protected]>

commit 7c1b9a5aeed91bef98988ac0fcf38c8c1f4f9a3a upstream.

This patch fixes potential NULL pointer dereference as indicated by the following static checker warning:

drivers/media/platform/exynos4-is/fimc-isp-video.c:408 isp_video_try_fmt_mplane()
error: NULL dereference inside function '__isp_video_try_fmt(isp, &f->fmt.pix_mp, (0))()'.

Fixes 34947b8aebe3: ("[media] exynos4-is: Add the FIMC-IS ISP capture DMA driver")
---
 drivers/media/platform/exynos4-is/fimc-isp-video.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/media/platform/exynos4-is/fimc-isp-video.c +8 -3
@@ -390,12 +390,17 @@ static void __isp_video_try_fmt(struct f
 				struct v4l2_pix_format_mplane *pixm,
 				const struct fimc_fmt **fmt)
 {
-	*fmt = fimc_isp_find_format(&pixm->pixelformat, NULL, 2);
+	const struct fimc_fmt *__fmt;
+
+	__fmt = fimc_isp_find_format(&pixm->pixelformat, NULL, 2);
+
+	if (fmt)
+		*fmt = __fmt;
 
 	pixm->colorspace = V4L2_COLORSPACE_SRGB;
 	pixm->field = V4L2_FIELD_NONE;
-	pixm->num_planes = (*fmt)->memplanes;
-	pixm->pixelformat = (*fmt)->fourcc;
+	pixm->num_planes = __fmt->memplanes;
+	pixm->pixelformat = __fmt->fourcc;
 	/*
 	 * TODO: double check with the docmentation these width/height
 	 * constraints are correct.
#23 lore raw

PATCH 23/328 USB: serial: kobil_sct: fix modem-status error handling

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Johan Hovold <[email protected]>

commit a420b5d939ee58f1d950f0ea782834056520aeaa upstream.

Make sure to return -EIO in case of a short modem-status read request.

While at it, split the debug message to not include the (zeroed) transfer-buffer content in case of errors.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/usb/serial/kobil_sct.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/usb/serial/kobil_sct.c +10 -2
@@ -408,12 +408,20 @@ static int kobil_tiocmget(struct tty_str
 			  transfer_buffer_length,
 			  KOBIL_TIMEOUT);
 
-	dev_dbg(&port->dev, "%s - Send get_status_line_state URB returns: %i. Statusline: %02x\n",
-		__func__, result, transfer_buffer[0]);
+	dev_dbg(&port->dev, "Send get_status_line_state URB returns: %i\n",
+			result);
+	if (result < 1) {
+		if (result >= 0)
+			result = -EIO;
+		goto out_free;
+	}
+
+	dev_dbg(&port->dev, "Statusline: %02x\n", transfer_buffer[0]);
 
 	result = 0;
 	if ((transfer_buffer[0] & SUSBCR_GSL_DSR) != 0)
 		result = TIOCM_DSR;
+out_free:
 	kfree(transfer_buffer);
 	return result;
 }
#24 lore raw

PATCH 24/328 staging: rts5208: fix missing error check on call to rtsx_write_register

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Colin Ian King <[email protected]>

commit c5fae4f4fd28189b1062fb8ef7b21fec37cb8b17 upstream.

Currently the check on error return from the call to rtsx_write_register is checking the error status from the previous call. Fix this by adding in the missing assignment of retval.

Detected by CoverityScan, CID#709877

Fixes fa590c222fba ("staging: rts5208: add support for rts5208 and rts5288")
[bwh: Backported to 3.16: adjust context]
---
 drivers/staging/rts5208/sd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rts5208/sd.c +1 -1
@@ -4276,7 +4276,7 @@ int sd_execute_write_data(struct scsi_cm
 		if (retval != STATUS_SUCCESS)
 			TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
 
-		rtsx_write_register(chip, SD_BYTE_CNT_L, 0xFF, 0x00);
+		retval = rtsx_write_register(chip, SD_BYTE_CNT_L, 0xFF, 0x00);
 		if (retval != STATUS_SUCCESS)
 			TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
 	}
#25 lore raw

PATCH 25/328 power: generic-adc-battery: fix out-of-bounds write when copying channel properties

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: "H. Nikolaus Schaller" <[email protected]>

commit 932d47448c3caa0fa99e84d7f5bc302aa286efd8 upstream.

We did have sporadic problems in the pinctrl framework during boot where a pin group name unexpectedly became NULL leading to a NULL dereference in strcmp.

Detailled analysis of the failing cases did reveal that there were two devm allocated objects close to each other. The second one was the affected group_desc in pinmux and the first one was the psy_desc->properties buffer of the gab driver.

Review of the gab code showed that the address calculation for one memcpy() is wrong. It does

properties + sizeof(type) * index

but C is defined to do the index multiplication already for pointer + integer additions. Hence the factor was applied twice and the memcpy() does write outside of the properties buffer. Sometimes it happened to be the pinctrl and triggered the strcmp(NULL).

Anyways, it is overkill to use a memcpy() here instead of a simple assignment, which is easier to read and has less risk for wrong address calculations. So we change code to a simple assignment.

If we initialize the index to the first free location, we can even remove the local variable 'properties'.

This bug seems to exist right from the beginning in 3.7-rc1 in

commit e60fea794e6e ("power: battery: Generic battery driver using IIO")

Fixes e60fea794e6e ("power: battery: Generic battery driver using IIO")

[bwh: Backported to 3.16:
- s/psy_desc/psy/g
- Adjust filename]

---
 drivers/power/generic-adc-battery.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/power/generic-adc-battery.c +4 -10
@@ -241,10 +241,9 @@ static int gab_probe(struct platform_dev
 	struct gab *adc_bat;
 	struct power_supply *psy;
 	struct gab_platform_data *pdata = pdev->dev.platform_data;
-	enum power_supply_property *properties;
 	int ret = 0;
 	int chan;
-	int index = 0;
+	int index = ARRAY_SIZE(gab_props);
 
 	adc_bat = devm_kzalloc(&pdev->dev, sizeof(*adc_bat), GFP_KERNEL);
 	if (!adc_bat) {
@@ -276,8 +275,6 @@ static int gab_probe(struct platform_dev
 	}
 
 	memcpy(psy->properties, gab_props, sizeof(gab_props));
-	properties = (enum power_supply_property *)
-				((char *)psy->properties + sizeof(gab_props));
 
 	/*
 	 * getting channel from iio and copying the battery properties
@@ -291,15 +288,12 @@ static int gab_probe(struct platform_dev
 			adc_bat->channel[chan] = NULL;
 		} else {
 			/* copying properties for supported channels only */
-			memcpy(properties + sizeof(*(psy->properties)) * index,
-					&gab_dyn_props[chan],
-					sizeof(gab_dyn_props[chan]));
-			index++;
+			psy->properties[index++] = gab_dyn_props[chan];
 		}
 	}
 
 	/* none of the channels are supported so let's bail out */
-	if (index == 0) {
+	if (index == ARRAY_SIZE(gab_props)) {
 		ret = -ENODEV;
 		goto second_mem_fail;
 	}
@@ -310,7 +304,7 @@ static int gab_probe(struct platform_dev
 	 * as come channels may be not be supported by the device.So
 	 * we need to take care of that.
 	 */
-	psy->num_properties = ARRAY_SIZE(gab_props) + index;
+	psy->num_properties = index;
 
 	ret = power_supply_register(&pdev->dev, psy);
 	if (ret)
#26 lore raw

PATCH 26/328 power: generic-adc-battery: check for duplicate properties copied from iio channels

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: "H. Nikolaus Schaller" <[email protected]>

commit a427503edaaed9b75ed9746a654cece7e93e60a8 upstream.

If an iio channel defines a basic property, there are duplicate entries in /sys/class/power/*/uevent.

So add a check to avoid duplicates. Since all channels may be duplicates, we have to modify the related error check.

Fixes e60fea794e6e ("power: battery: Generic battery driver using IIO")

[bwh: Backported to 3.16:
- s/psy_desc/psy/
- Adjust filename]

---
 drivers/power/generic-adc-battery.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/power/generic-adc-battery.c +13 -2
@@ -244,6 +244,7 @@ static int gab_probe(struct platform_dev
 	int ret = 0;
 	int chan;
 	int index = ARRAY_SIZE(gab_props);
+	bool any = false;
 
 	adc_bat = devm_kzalloc(&pdev->dev, sizeof(*adc_bat), GFP_KERNEL);
 	if (!adc_bat) {
@@ -288,12 +289,22 @@ static int gab_probe(struct platform_dev
 			adc_bat->channel[chan] = NULL;
 		} else {
 			/* copying properties for supported channels only */
-			psy->properties[index++] = gab_dyn_props[chan];
+			int index2;
+
+			for (index2 = 0; index2 < index; index2++) {
+				if (psy->properties[index2] ==
+				    gab_dyn_props[chan])
+					break;	/* already known */
+			}
+			if (index2 == index)	/* really new */
+				psy->properties[index++] =
+					gab_dyn_props[chan];
+			any = true;
 		}
 	}
 
 	/* none of the channels are supported so let's bail out */
-	if (index == ARRAY_SIZE(gab_props)) {
+	if (!any) {
 		ret = -ENODEV;
 		goto second_mem_fail;
 	}
#27 lore raw

PATCH 27/328 vxlan: fix a potential issue when create a new vxlan fdb entry.

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Haishuang Yan <[email protected]>

commit 17b463654f41f0aa334efd5a6efeab8a6e9496f7 upstream.

vxlan_fdb_append may return error, so add the proper check, otherwise it will cause memory leak.

Changes in v2:
- Unnecessary to initialize rc to zero.

---
 drivers/net/vxlan.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/vxlan.c +7 -3
@@ -695,6 +695,7 @@ static int vxlan_fdb_create(struct vxlan
 	struct vxlan_rdst *rd = NULL;
 	struct vxlan_fdb *f;
 	int notify = 0;
+	int rc;
 
 	f = __vxlan_find_mac(vxlan, mac);
 	if (f) {
@@ -729,8 +730,7 @@ static int vxlan_fdb_create(struct vxlan
 		if ((flags & NLM_F_APPEND) &&
 		    (is_multicast_ether_addr(f->eth_addr) ||
 		     is_zero_ether_addr(f->eth_addr))) {
-			int rc = vxlan_fdb_append(f, ip, port, vni, ifindex,
-						  &rd);
+			rc = vxlan_fdb_append(f, ip, port, vni, ifindex, &rd);
 
 			if (rc < 0)
 				return rc;
@@ -760,7 +760,11 @@ static int vxlan_fdb_create(struct vxlan
 		INIT_LIST_HEAD(&f->remotes);
 		memcpy(f->eth_addr, mac, ETH_ALEN);
 
-		vxlan_fdb_append(f, ip, port, vni, ifindex, &rd);
+		rc = vxlan_fdb_append(f, ip, port, vni, ifindex, &rd);
+		if (rc < 0) {
+			kfree(f);
+			return rc;
+		}
 
 		++vxlan->addrcnt;
 		hlist_add_head_rcu(&f->hlist,
#28 lore raw

PATCH 28/328 vxlan: add new fdb alloc and create helpers

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Roopa Prabhu <[email protected]>

commit 25e20e730d56471cffa25419bf2a66078bd55330 upstream.

- Add new vxlan_fdb_alloc helper
- rename existing vxlan_fdb_create into vxlan_fdb_update:
because it really creates or updates an existing fdb entry
- move new fdb creation into a separate vxlan_fdb_create

Main motivation for this change is to introduce the ability to decouple vxlan fdb creation and notify, used in a later patch.

[bwh: Backported to 3.16:
- s/vxlan->cfg\.addrmax/vxlan->addrmax/g
- Drop src_vni parameters and initialisation of vxlan_fdb::vni
- Drop last argument to vxlan_fdb_head()
- Drop change to vxlan_changelink()]

---
 drivers/net/vxlan.c | 91 ++++++++++++++++++++++++++++++---------------
 1 file changed, 62 insertions(+), 29 deletions(-)
drivers/net/vxlan.c +59 -26
@@ -685,9 +685,60 @@ static void vxlan_notify_del_rx_port(str
 		udp_del_offload(&vs->udp_offloads);
 }
 
-/* Add new entry to forwarding table -- assumes lock held */
+static struct vxlan_fdb *vxlan_fdb_alloc(struct vxlan_dev *vxlan,
+					 const u8 *mac, __u16 state,
+					 __u8 ndm_flags)
+{
+	struct vxlan_fdb *f;
+
+	f = kmalloc(sizeof(*f), GFP_ATOMIC);
+	if (!f)
+		return NULL;
+	f->state = state;
+	f->flags = ndm_flags;
+	f->updated = f->used = jiffies;
+	INIT_LIST_HEAD(&f->remotes);
+	memcpy(f->eth_addr, mac, ETH_ALEN);
+
+	return f;
+}
+
 static int vxlan_fdb_create(struct vxlan_dev *vxlan,
 			    const u8 *mac, union vxlan_addr *ip,
+			    __u16 state, __be16 port,
+			    __be32 vni, __u32 ifindex, __u8 ndm_flags,
+			    struct vxlan_fdb **fdb)
+{
+	struct vxlan_rdst *rd = NULL;
+	struct vxlan_fdb *f;
+	int rc;
+
+	if (vxlan->addrmax && vxlan->addrcnt >= vxlan->addrmax)
+		return -ENOSPC;
+
+	netdev_dbg(vxlan->dev, "add %pM -> %pIS\n", mac, ip);
+	f = vxlan_fdb_alloc(vxlan, mac, state, ndm_flags);
+	if (!f)
+		return -ENOMEM;
+
+	rc = vxlan_fdb_append(f, ip, port, vni, ifindex, &rd);
+	if (rc < 0) {
+		kfree(f);
+		return rc;
+	}
+
+	++vxlan->addrcnt;
+	hlist_add_head_rcu(&f->hlist,
+			   vxlan_fdb_head(vxlan, mac));
+
+	*fdb = f;
+
+	return 0;
+}
+
+/* Add new entry to forwarding table -- assumes lock held */
+static int vxlan_fdb_update(struct vxlan_dev *vxlan,
+			    const u8 *mac, union vxlan_addr *ip,
 			    __u16 state, __u16 flags,
 			    __be16 port, __u32 vni, __u32 ifindex,
 			    __u8 ndm_flags)
@@ -740,35 +791,17 @@ static int vxlan_fdb_create(struct vxlan
 		if (!(flags & NLM_F_CREATE))
 			return -ENOENT;
 
-		if (vxlan->addrmax && vxlan->addrcnt >= vxlan->addrmax)
-			return -ENOSPC;
-
 		/* Disallow replace to add a multicast entry */
 		if ((flags & NLM_F_REPLACE) &&
 		    (is_multicast_ether_addr(mac) || is_zero_ether_addr(mac)))
 			return -EOPNOTSUPP;
 
 		netdev_dbg(vxlan->dev, "add %pM -> %pIS\n", mac, ip);
-		f = kmalloc(sizeof(*f), GFP_ATOMIC);
-		if (!f)
-			return -ENOMEM;
-
-		notify = 1;
-		f->state = state;
-		f->flags = ndm_flags;
-		f->updated = f->used = jiffies;
-		INIT_LIST_HEAD(&f->remotes);
-		memcpy(f->eth_addr, mac, ETH_ALEN);
-
-		rc = vxlan_fdb_append(f, ip, port, vni, ifindex, &rd);
-		if (rc < 0) {
-			kfree(f);
+		rc = vxlan_fdb_create(vxlan, mac, ip, state, port,
+				      vni, ifindex, ndm_flags, &f);
+		if (rc < 0)
 			return rc;
-		}
-
-		++vxlan->addrcnt;
-		hlist_add_head_rcu(&f->hlist,
-				   vxlan_fdb_head(vxlan, mac));
+		notify = 1;
 	}
 
 	if (notify) {
@@ -886,7 +919,7 @@ static int vxlan_fdb_add(struct ndmsg *n
 		return -EAFNOSUPPORT;
 
 	spin_lock_bh(&vxlan->hash_lock);
-	err = vxlan_fdb_create(vxlan, addr, &ip, ndm->ndm_state, flags,
+	err = vxlan_fdb_update(vxlan, addr, &ip, ndm->ndm_state, flags,
 			       port, vni, ifindex, ndm->ndm_flags);
 	spin_unlock_bh(&vxlan->hash_lock);
 
@@ -1012,7 +1045,7 @@ static bool vxlan_snoop(struct net_devic
 
 		/* close off race between vxlan_flush and incoming packets */
 		if (netif_running(dev))
-			vxlan_fdb_create(vxlan, src_mac, src_ip,
+			vxlan_fdb_update(vxlan, src_mac, src_ip,
 					 NUD_REACHABLE,
 					 NLM_F_EXCL|NLM_F_CREATE,
 					 vxlan->dst_port,
@@ -2718,7 +2751,7 @@ static int vxlan_newlink(struct net *net
 
 	/* create an fdb entry for a valid default destination */
 	if (!vxlan_addr_any(&vxlan->default_dst.remote_ip)) {
-		err = vxlan_fdb_create(vxlan, all_zeros_mac,
+		err = vxlan_fdb_update(vxlan, all_zeros_mac,
 				       &vxlan->default_dst.remote_ip,
 				       NUD_REACHABLE|NUD_PERMANENT,
 				       NLM_F_EXCL|NLM_F_CREATE,
#29 lore raw

PATCH 29/328 vxlan: fix default fdb entry netlink notify ordering during netdev create

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Roopa Prabhu <[email protected]>

commit 0241b836732f5f43c3f0fd9e9073c1fb24ea6757 upstream.

Problem:
In vxlan_newlink, a default fdb entry is added before register_netdev. The default fdb creation function also notifies user-space of the fdb entry on the vxlan device which user-space does not know about yet. (RTM_NEWNEIGH goes before RTM_NEWLINK for the same ifindex).

This patch fixes the user-space netlink notification ordering issue with the following changes:
- decouple fdb notify from fdb create.
- Move fdb notify after register_netdev.
- Call rtnl_configure_link in vxlan newlink handler to notify userspace about the newlink before fdb notify and
hence avoiding the user-space race.

Fixes afbd8bae9c79 ("vxlan: add implicit fdb entry for default destination")

[bwh: Backported to 3.16:
- Drop changes to vxlan_changelink()
- Drop last argument to vxlan_fdb_destroy()
- Adjust context]

---

drivers/net/vxlan.c +17 -5
@@ -2614,6 +2614,7 @@ static int vxlan_newlink(struct net *net
 	struct vxlan_net *vn = net_generic(net, vxlan_net_id);
 	struct vxlan_dev *vxlan = netdev_priv(dev), *tmp;
 	struct vxlan_rdst *dst = &vxlan->default_dst;
+	struct vxlan_fdb *f = NULL;
 	__u32 vni;
 	int err;
 	bool use_ipv6 = false;
@@ -2751,27 +2752,38 @@ static int vxlan_newlink(struct net *net
 
 	/* create an fdb entry for a valid default destination */
 	if (!vxlan_addr_any(&vxlan->default_dst.remote_ip)) {
-		err = vxlan_fdb_update(vxlan, all_zeros_mac,
+		err = vxlan_fdb_create(vxlan, all_zeros_mac,
 				       &vxlan->default_dst.remote_ip,
 				       NUD_REACHABLE|NUD_PERMANENT,
-				       NLM_F_EXCL|NLM_F_CREATE,
 				       vxlan->dst_port,
 				       vxlan->default_dst.remote_vni,
 				       vxlan->default_dst.remote_ifindex,
-				       NTF_SELF);
+				       NTF_SELF, &f);
 		if (err)
 			return err;
 	}
 
 	err = register_netdevice(dev);
+	if (err)
+		goto errout;
+
+	err = rtnl_configure_link(dev, NULL);
 	if (err) {
-		vxlan_fdb_delete_default(vxlan);
-		return err;
+		unregister_netdevice(dev);
+		goto errout;
 	}
 
+	/* notify default fdb entry */
+	if (f)
+		vxlan_fdb_notify(vxlan, f, first_remote_rtnl(f), RTM_NEWNEIGH);
+
 	list_add(&vxlan->next, &vn->vxlan_list);
 
 	return 0;
+errout:
+	if (f)
+		vxlan_fdb_destroy(vxlan, f);
+	return err;
 }
 
 static void vxlan_dellink(struct net_device *dev, struct list_head *head)
#30 lore raw

PATCH 30/328 vmci: type promotion bug in qp_host_get_user_memory()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dan Carpenter <[email protected]>

commit 7fb2fd4e25fc1fb10dcb30b5519de257cfeae84c upstream.

The problem is that if get_user_pages_fast() fails and returns a negative error code, it gets type promoted to a high positive value and treated as a success.

Fixes 06164d2b72aa ("VMCI: queue pairs implementation.")
[bwh: Backported to 3.16: adjust context]
---
 drivers/misc/vmw_vmci/vmci_queue_pair.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/vmw_vmci/vmci_queue_pair.c +2 -2
@@ -735,7 +735,7 @@ static int qp_host_get_user_memory(u64 p
 	retval = get_user_pages_fast((uintptr_t) produce_uva,
 				     produce_q->kernel_if->num_pages, 1,
 				     produce_q->kernel_if->u.h.header_page);
-	if (retval < produce_q->kernel_if->num_pages) {
+	if (retval < (int)produce_q->kernel_if->num_pages) {
 		pr_warn("get_user_pages(produce) failed (retval=%d)", retval);
 		qp_release_pages(produce_q->kernel_if->u.h.header_page,
 				 retval, false);
@@ -746,7 +746,7 @@ static int qp_host_get_user_memory(u64 p
 	retval = get_user_pages_fast((uintptr_t) consume_uva,
 				     consume_q->kernel_if->num_pages, 1,
 				     consume_q->kernel_if->u.h.header_page);
-	if (retval < consume_q->kernel_if->num_pages) {
+	if (retval < (int)consume_q->kernel_if->num_pages) {
 		pr_warn("get_user_pages(consume) failed (retval=%d)", retval);
 		qp_release_pages(consume_q->kernel_if->u.h.header_page,
 				 retval, false);
#31 lore raw

PATCH 31/328 pinctrl: msm: Fix msm_config_group_get() to be compliant

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Douglas Anderson <[email protected]>

commit 05e0c828955c1cab58dd71a04539442e5375d917 upstream.

If you do this on an sdm845 board:
cat /sys/kernel/debug/pinctrl/3400000.pinctrl/pinconf-groups

...it looks like nonsense. For every pin you see listed:
input bias bus hold, input bias disabled, input bias pull down, input bias pull up

That's because msm_config_group_get() isn't complying with the rules that pinconf_generic_dump_one() expects. Specifically for boolean parameters (anything with a "struct pin_config_item" where has_arg is false) the function expects that the function should return its value not through the "config" parameter but should return "0" if the value is set and "-EINVAL" if the value isn't set.

Let's fix this.

=46roma quick sample of other pinctrl drivers, it appears to be tradition to also return 1 through the config parameter for these boolean parameters when they exist. I'm not one to knock tradition, so I'll follow tradition and return 1 in these cases. While I'm at it, I'll also continue searching for four leaf clovers, kocking on wood three times, and trying not to break mirrors.

Fixes f365be092572 ("pinctrl: Add Qualcomm TLMM driver")

[bwh: Backported to 3.16:
- Drop change to case PIN_CONFIG_BIAS_BUS_HOLD
- Adjust filename, context]

---
 drivers/pinctrl/pinctrl-msm.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/pinctrl/pinctrl-msm.c +8 -2
@@ -275,13 +275,19 @@ static int msm_config_group_get(struct p
 	/* Convert register value to pinconf value */
 	switch (param) {
 	case PIN_CONFIG_BIAS_DISABLE:
-		arg = arg == MSM_NO_PULL;
+		if (arg != MSM_NO_PULL)
+			return -EINVAL;
+		arg = 1;
 		break;
 	case PIN_CONFIG_BIAS_PULL_DOWN:
-		arg = arg == MSM_PULL_DOWN;
+		if (arg != MSM_PULL_DOWN)
+			return -EINVAL;
+		arg = 1;
 		break;
 	case PIN_CONFIG_BIAS_PULL_UP:
 		arg = arg == MSM_PULL_UP;
+		if (!arg)
+			return -EINVAL;
 		break;
 	case PIN_CONFIG_DRIVE_STRENGTH:
 		arg = msm_regval_to_drive(arg);
#32 lore raw

PATCH 32/328 ARM: tegra: Fix Tegra30 Cardhu PCA954x reset

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Jon Hunter <[email protected]>

commit 6e1811900b6fe6f2b4665dba6bd6ed32c6b98575 upstream.

On all versions of Tegra30 Cardhu, the reset signal to the NXP PCA9546 I2C mux is connected to the Tegra GPIO BB0. Currently, this pin on the Tegra is not configured as a GPIO but as a special-function IO (SFIO) that is multiplexing the pin to an I2S controller. On exiting system suspend, I2C commands sent to the PCA9546 are failing because there is no ACK. Although it is not possible to see exactly what is happening to the reset during suspend, by ensuring it is configured as a GPIO and driven high, to de-assert the reset, the failures are no longer seen.

Please note that this GPIO is also used to drive the reset signal going to the camera connector on the board. However, given that there is no camera support currently for Cardhu, this should not have any impact.

Fixes 40431d16ff11 ("ARM: tegra: enable PCA9546 on Cardhu")
---
 arch/arm/boot/dts/tegra30-cardhu.dtsi | 1 +
 1 file changed, 1 insertion(+)
arch/arm/boot/dts/tegra30-cardhu.dtsi +1 -0
@@ -193,6 +193,7 @@
 			#address-cells = <1>;
 			#size-cells = <0>;
 			reg = <0x70>;
+			reset-gpio = <&gpio TEGRA_GPIO(BB, 0) GPIO_ACTIVE_LOW>;
 		};
 	};
 
#33 lore raw

PATCH 33/328 pwm: tiehrpwm: Don't use emulation mode bits to control PWM output

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Vignesh R <[email protected]>

commit aa49d628f6e016bcec8c6f8e704b9b18ee697329 upstream.

As per AM335x TRM SPRUH73P "15.2.2.11 ePWM Behavior During Emulation", TBCTL[15:14] only have effect during emulation suspend events (IOW, to stop PWM when debugging using a debugger). These bits have no effect on PWM output during normal running of system. Hence, remove code accessing these bits as they have no role in enabling/disabling PWMs.

Fixes 19891b20e7c2 ("pwm: pwm-tiehrpwm: PWM driver support for EHRPWM")
[bwh: Backported to 3.16: adjust context]

---

drivers/pwm/pwm-tiehrpwm.c +1 -10
@@ -35,10 +35,6 @@
 #define TBCTL			0x00
 #define TBPRD			0x0A
 
-#define TBCTL_RUN_MASK		(BIT(15) | BIT(14))
-#define TBCTL_STOP_NEXT		0
-#define TBCTL_STOP_ON_CYCLE	BIT(14)
-#define TBCTL_FREE_RUN		(BIT(15) | BIT(14))
 #define TBCTL_PRDLD_MASK	BIT(3)
 #define TBCTL_PRDLD_SHDW	0
 #define TBCTL_PRDLD_IMDT	BIT(3)
@@ -357,7 +353,7 @@ static int ehrpwm_pwm_enable(struct pwm_
 	/* Channels polarity can be configured from action qualifier module */
 	configure_polarity(pc, pwm->hwpwm);
 
-	/* Enable TBCLK before enabling PWM device */
+	/* Enable TBCLK */
 	ret = clk_enable(pc->tbclk);
 	if (ret) {
 		dev_err(chip->dev, "Failed to enable TBCLK for %s\n",
@@ -365,8 +361,6 @@ static int ehrpwm_pwm_enable(struct pwm_
 		return ret;
 	}
 
-	/* Enable time counter for free_run */
-	ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_RUN_MASK, TBCTL_FREE_RUN);
 	return 0;
 }
 
@@ -396,9 +390,6 @@ static void ehrpwm_pwm_disable(struct pw
 	/* Disabling TBCLK on PWM disable */
 	clk_disable(pc->tbclk);
 
-	/* Stop Time base counter */
-	ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_RUN_MASK, TBCTL_STOP_NEXT);
-
 	/* Disable clock on PWM disable */
 	pm_runtime_put_sync(chip->dev);
 }
#34 lore raw

PATCH 34/328 pwm: tiehrpwm: Fix disabling of output of PWMs

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Vignesh R <[email protected]>

commit 38dabd91ff0bde33352ca3cc65ef515599b77a05 upstream.

pwm-tiehrpwm driver disables PWM output by putting it in low output state via active AQCSFRC register in ehrpwm_pwm_disable(). But, the AQCSFRC shadow register is not updated. Therefore, when shadow AQCSFRC register is re-enabled in ehrpwm_pwm_enable() (say to enable second PWM output), previous settings are lost as shadow register value is loaded into active register. This results in things like PWMA getting enabled automatically, when PWMB is enabled and vice versa. Fix this by updating AQCSFRC shadow register as well during ehrpwm_pwm_disable().

Fixes 19891b20e7c2 ("pwm: pwm-tiehrpwm: PWM driver support for EHRPWM")
---
 drivers/pwm/pwm-tiehrpwm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pwm/pwm-tiehrpwm.c +2 -0
@@ -378,6 +378,8 @@ static void ehrpwm_pwm_disable(struct pw
 		aqcsfrc_mask = AQCSFRC_CSFA_MASK;
 	}
 
+	/* Update shadow register first before modifying active register */
+	ehrpwm_modify(pc->mmio_base, AQCSFRC, aqcsfrc_mask, aqcsfrc_val);
 	/*
 	 * Changes to immediate action on Action Qualifier. This puts
 	 * Action Qualifier control on PWM output from next TBCLK
#35 lore raw

PATCH 35/328 drm/panel: type promotion bug in s6e8aa0_read_mtp_id()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dan Carpenter <[email protected]>

commit cd0e0ca69109d025b1a1b6609f70682db62138b0 upstream.

The ARRAY_SIZE() macro is type size_t. If s6e8aa0_dcs_read() returns a negative error code, then "ret < ARRAY_SIZE(id)" is false because the negative error code is type promoted to a high positive value.

Fixes 02051ca06371 ("drm/panel: add S6E8AA0 driver")
[bwh: Backported to 3.16: adjust filename]
---
 drivers/gpu/drm/panel/panel-s6e8aa0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panel/panel-s6e8aa0.c +1 -1
@@ -832,7 +832,7 @@ static void s6e8aa0_read_mtp_id(struct s
 	int ret, i;
 
 	ret = s6e8aa0_dcs_read(ctx, 0xd1, id, ARRAY_SIZE(id));
-	if (ret < ARRAY_SIZE(id) || id[0] == 0x00) {
+	if (ret < 0 || ret < ARRAY_SIZE(id) || id[0] == 0x00) {
 		dev_err(ctx->dev, "read id failed\n");
 		ctx->error = -EIO;
 		return;
#36 lore raw

PATCH 36/328 mei: bus: type promotion bug in mei_nfc_if_version()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dan Carpenter <[email protected]>

commit b40b3e9358fbafff6a4ba0f4b9658f6617146f9c upstream.

We accidentally removed the check for negative returns without considering the issue of type promotion.
The "if_version_length" variable is type size_t so if __mei_cl_recv() returns a negative then "bytes_recv" is type promoted
to a high positive value and treated as success.

Fixes 582ab27a063a ("mei: bus: fix received data size check in NFC fixup")
[bwh: Backported to 3.16: adjust filename, context]
---
 drivers/misc/mei/nfc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/mei/nfc.c +1 -1
@@ -292,7 +292,7 @@ static int mei_nfc_if_version(struct mei
 		return -ENOMEM;
 
 	bytes_recv = __mei_cl_recv(cl, (u8 *)reply, if_version_length);
-	if (bytes_recv < if_version_length) {
+	if (bytes_recv < 0 || bytes_recv < if_version_length) {
 		dev_err(&dev->pdev->dev, "Could not read IF version\n");
 		ret = -EIO;
 		goto err;
#37 lore raw

PATCH 37/328 uart: fix race between uart_put_char() and uart_shutdown()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Tycho Andersen <[email protected]>

commit a5ba1d95e46ecaea638ddd7cd144107c783acb5d upstream.

We have reports of the following crash:

    PID: 7 TASK: ffff88085c6d61c0 CPU: 1 COMMAND: "kworker/u25:0"
    #0 [ffff88085c6db710] machine_kexec at ffffffff81046239
    #1 [ffff88085c6db760] crash_kexec at ffffffff810fc248
    #2 [ffff88085c6db830] oops_end at ffffffff81008ae7
    #3 [ffff88085c6db860] no_context at ffffffff81050b8f
    #4 [ffff88085c6db8b0] __bad_area_nosemaphore at ffffffff81050d75
    #5 [ffff88085c6db900] bad_area_nosemaphore at ffffffff81050e83
    #6 [ffff88085c6db910] __do_page_fault at ffffffff8105132e
    #7 [ffff88085c6db9b0] do_page_fault at ffffffff8105152c
    #8 [ffff88085c6db9c0] page_fault at ffffffff81a3f122
    [exception RIP: uart_put_char+149]
    RIP: ffffffff814b67b5 RSP: ffff88085c6dba78 RFLAGS: 00010006
    RAX: 0000000000000292 RBX: ffffffff827c5120 RCX: 0000000000000081
    RDX: 0000000000000000 RSI: 000000000000005f RDI: ffffffff827c5120
    RBP: ffff88085c6dba98 R8: 000000000000012c R9: ffffffff822ea320
    R10: ffff88085fe4db04 R11: 0000000000000001 R12: ffff881059f9c000
    R13: 0000000000000001 R14: 000000000000005f R15: 0000000000000fba
    ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018
    #9 [ffff88085c6dbaa0] tty_put_char at ffffffff81497544
    #10 [ffff88085c6dbac0] do_output_char at ffffffff8149c91c
    #11 [ffff88085c6dbae0] __process_echoes at ffffffff8149cb8b
    #12 [ffff88085c6dbb30] commit_echoes at ffffffff8149cdc2
    #13 [ffff88085c6dbb60] n_tty_receive_buf_fast at ffffffff8149e49b
    #14 [ffff88085c6dbbc0] __receive_buf at ffffffff8149ef5a
    #15 [ffff88085c6dbc20] n_tty_receive_buf_common at ffffffff8149f016
    #16 [ffff88085c6dbca0] n_tty_receive_buf2 at ffffffff8149f194
    #17 [ffff88085c6dbcb0] flush_to_ldisc at ffffffff814a238a
    #18 [ffff88085c6dbd50] process_one_work at ffffffff81090be2
    #19 [ffff88085c6dbe20] worker_thread at ffffffff81091b4d
    #20 [ffff88085c6dbeb0] kthread at ffffffff81096384
    #21 [ffff88085c6dbf50] ret_from_fork at ffffffff81a3d69f​

after slogging through some dissasembly:

ffffffff814b6720 <uart_put_char>:

ffffffff814b6720:	55                   	push   %rbp
ffffffff814b6721:	48 89 e5             	mov    %rsp,%rbp
ffffffff814b6724:	48 83 ec 20          	sub    $0x20,%rsp
ffffffff814b6728:	48 89 1c 24          	mov    %rbx,(%rsp)
ffffffff814b672c:	4c 89 64 24 08       	mov    %r12,0x8(%rsp)
ffffffff814b6731:	4c 89 6c 24 10       	mov    %r13,0x10(%rsp)
ffffffff814b6736:	4c 89 74 24 18       	mov    %r14,0x18(%rsp)
ffffffff814b673b:	e8 b0 8e 58 00       	callq  ffffffff81a3f5f0 <mcount>
ffffffff814b6740:	4c 8b a7 88 02 00 00 	mov    0x288(%rdi),%r12
ffffffff814b6747:	45 31 ed             	xor    %r13d,%r13d
ffffffff814b674a:	41 89 f6             	mov    %esi,%r14d
ffffffff814b674d:	49 83 bc 24 70 01 00 	cmpq   $0x0,0x170(%r12)
ffffffff814b6754:	00 00
ffffffff814b6756:	49 8b 9c 24 80 01 00 	mov    0x180(%r12),%rbx
ffffffff814b675d:	00
ffffffff814b675e:	74 2f                	je     ffffffff814b678f <uart_put_char+0x6f>
ffffffff814b6760:	48 89 df             	mov    %rbx,%rdi
ffffffff814b6763:	e8 a8 67 58 00       	callq  ffffffff81a3cf10 <_raw_spin_lock_irqsave>
ffffffff814b6768:	41 8b 8c 24 78 01 00 	mov    0x178(%r12),%ecx
ffffffff814b676f:	00
ffffffff814b6770:	89 ca                	mov    %ecx,%edx
ffffffff814b6772:	f7 d2                	not    %edx
ffffffff814b6774:	41 03 94 24 7c 01 00 	add    0x17c(%r12),%edx
ffffffff814b677b:	00
ffffffff814b677c:	81 e2 ff 0f 00 00    	and    $0xfff,%edx
ffffffff814b6782:	75 23                	jne    ffffffff814b67a7 <uart_put_char+0x87>
ffffffff814b6784:	48 89 c6             	mov    %rax,%rsi
ffffffff814b6787:	48 89 df             	mov    %rbx,%rdi
ffffffff814b678a:	e8 e1 64 58 00       	callq  ffffffff81a3cc70 <_raw_spin_unlock_irqrestore>
ffffffff814b678f:	44 89 e8             	mov    %r13d,%eax
ffffffff814b6792:	48 8b 1c 24          	mov    (%rsp),%rbx
ffffffff814b6796:	4c 8b 64 24 08       	mov    0x8(%rsp),%r12
ffffffff814b679b:	4c 8b 6c 24 10       	mov    0x10(%rsp),%r13
ffffffff814b67a0:	4c 8b 74 24 18       	mov    0x18(%rsp),%r14
ffffffff814b67a5:	c9                   	leaveq
ffffffff814b67a6:	c3                   	retq
ffffffff814b67a7:	49 8b 94 24 70 01 00 	mov    0x170(%r12),%rdx
ffffffff814b67ae:	00
ffffffff814b67af:	48 63 c9             	movslq %ecx,%rcx
ffffffff814b67b2:	41 b5 01             	mov    $0x1,%r13b
ffffffff814b67b5:	44 88 34 0a          	mov    %r14b,(%rdx,%rcx,1)
ffffffff814b67b9:	41 8b 94 24 78 01 00 	mov    0x178(%r12),%edx
ffffffff814b67c0:	00
ffffffff814b67c1:	83 c2 01             	add    $0x1,%edx
ffffffff814b67c4:	81 e2 ff 0f 00 00    	and    $0xfff,%edx
ffffffff814b67ca:	41 89 94 24 78 01 00 	mov    %edx,0x178(%r12)

ffffffff814b67d1: 00
ffffffff814b67d2: eb b0 jmp ffffffff814b6784 <uart_put_char+0x64>
ffffffff814b67d4: 66 66 66 2e 0f 1f 84 data32 data32 nopw %cs:0x0(%rax,%rax,1)
ffffffff814b67db: 00 00 00 00 00

for our build, this is crashing at:

    circ->buf[circ->head] = c;

Looking in uart_port_startup(), it seems that circ->buf (state->xmit.buf) protected by the "per-port mutex", which based on uart_port_check() is state->port.mutex. Indeed, the lock acquired in uart_put_char() is uport->lock, i.e. not the same lock.

Anyway, since the lock is not acquired, if uart_shutdown() is called, the last chunk of that function may release state->xmit.buf before its assigned to null, and cause the race above.

To fix it, let's lock uport->lock when allocating/deallocating state->xmit.buf in addition to the per-port mutex.

v2: switch to locking uport->lock on allocation/deallocation instead of
locking the per-port mutex in uart_put_char. Note that since uport->lock is a spin lock, we have to switch the allocation to GFP_ATOMIC.
v3: move the allocation outside the lock, so we can switch back to
GFP_KERNEL

[bwh: Backported to 3.16: Use uport->lock directly rather than through
uart_port_{,un}lock()]

---
 drivers/tty/serial/serial_core.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/tty/serial/serial_core.c +12 -5
@@ -131,6 +131,7 @@ static int uart_port_startup(struct tty_
 	struct uart_port *uport = state->uart_port;
 	struct tty_port *port = &state->port;
 	unsigned long page;
+	unsigned long flags = 0;
 	int retval = 0;
 
 	if (uport->type == PORT_UNKNOWN)
@@ -145,15 +146,18 @@ static int uart_port_startup(struct tty_
 	 * Initialise and allocate the transmit and temporary
 	 * buffer.
 	 */
-	if (!state->xmit.buf) {
-		/* This is protected by the per port mutex */
-		page = get_zeroed_page(GFP_KERNEL);
-		if (!page)
-			return -ENOMEM;
+	page = get_zeroed_page(GFP_KERNEL);
+	if (!page)
+		return -ENOMEM;
 
+	spin_lock_irqsave(&uport->lock, flags);
+	if (!state->xmit.buf) {
 		state->xmit.buf = (unsigned char *) page;
 		uart_circ_clear(&state->xmit);
+	} else {
+		free_page(page);
 	}
+	spin_unlock_irqrestore(&uport->lock, flags);
 
 	retval = uport->ops->startup(uport);
 	if (retval == 0) {
@@ -232,6 +236,7 @@ static void uart_shutdown(struct tty_str
 {
 	struct uart_port *uport = state->uart_port;
 	struct tty_port *port = &state->port;
+	unsigned long flags = 0;
 
 	/*
 	 * Set the TTY IO error marker
@@ -262,10 +267,12 @@ static void uart_shutdown(struct tty_str
 	/*
 	 * Free the transmit buffer page.
 	 */
+	spin_lock_irqsave(&uport->lock, flags);
 	if (state->xmit.buf) {
 		free_page((unsigned long)state->xmit.buf);
 		state->xmit.buf = NULL;
 	}
+	spin_unlock_irqrestore(&uport->lock, flags);
 }
 
 /**
#38 lore raw

PATCH 38/328 tty: fix typo in comment of tty_termios_encode_baud_rate

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Matthias Brugger <[email protected]>

commit a1d51aa2214cea3f91611893610a2f769cada0e7 upstream.

---
 drivers/tty/tty_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/tty_ioctl.c +1 -1
@@ -408,7 +408,7 @@ void tty_termios_encode_baud_rate(struct
 
 #ifdef BOTHER
 	/* If the user asked for a precise weird speed give a precise weird
-	   answer. If they asked for a Bfoo speed they many have problems
+	   answer. If they asked for a Bfoo speed they may have problems
 	   digesting non-exact replies so fuzz a bit */
 
 	if ((termios->c_cflag & CBAUD) == BOTHER)
#39 lore raw

Re: [PATCH 3.16 038/328] tty: fix typo in comment of tty_termios_encode_baud_rate

Quoted 18 lines · Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Matthias Brugger <[email protected]>

commit a1d51aa2214cea3f91611893610a2f769cada0e7 upstream.

---
 drivers/tty/tty_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

drivers/tty/tty_ioctl.c void tty_termios_encode_baud_rate(struct · line 411

Quoted 5 lines
drivers/tty/tty_ioctl.c +1 -1
@@ -408,7 +408,7 @@ void tty_termios_encode_baud_rate(struct
 
 #ifdef BOTHER
 	/* If the user asked for a precise weird speed give a precise weird
-	   answer. If they asked for a Bfoo speed they many have problems
+	   answer. If they asked for a Bfoo speed they may have problems

I don't think fixes of comments are good candidates for stable.

Regards,
Matthias

Quoted 4 lines
drivers/tty/tty_ioctl.c +0 -0
 	   digesting non-exact replies so fuzz a bit */
 
 	if ((termios->c_cflag & CBAUD) == BOTHER)
#40 lore raw

Re: [PATCH 3.16 038/328] tty: fix typo in comment of tty_termios_encode_baud_rate

Quoted 21 lines · Matthias Brugger
Quoted 19 lines · Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Matthias Brugger <[email protected]>

commit a1d51aa2214cea3f91611893610a2f769cada0e7 upstream.

---
 drivers/tty/tty_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/tty_ioctl.c +0 -0
@@ -408,7 +408,7 @@ void tty_termios_encode_baud_rate(struct
 
Quoted 6 lines

drivers/tty/tty_ioctl.c void tty_termios_encode_baud_rate(struct · line 411

Quoted 4 lines
drivers/tty/tty_ioctl.c +1 -1
 #ifdef BOTHER
 	/* If the user asked for a precise weird speed give a precise weird
-	   answer. If they asked for a Bfoo speed they many have problems
+	   answer. If they asked for a Bfoo speed they may have problems

I don't think fixes of comments are good candidates for stable.

I agree in general, but this allows commit 1cee38f0363a "tty: fix termios input-speed encoding when using BOTHER" to apply more cleanly.

Ben.

Quoted 7 lines

Regards,
Matthias

Quoted 4 lines
drivers/tty/tty_ioctl.c +0 -0
 	   digesting non-exact replies so fuzz a bit */
 
 	if ((termios->c_cflag & CBAUD) == BOTHER)
Signature · 2 lines
Ben Hutchings
If more than one person is responsible for a bug, no one is at fault.
#41 lore raw

PATCH 39/328 tty: fix termios input-speed encoding

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Johan Hovold <[email protected]>

commit fada18c48d774b9e837928ecdce6a5d5fdd11ee7 upstream.

Make sure to clear the CIBAUD bits before OR-ing the new mask when encoding the termios input baud rate.

This could otherwise lead to an incorrect input rate being reported back and incidentally set on subsequent termios updates.

Fixes edc6afc54968 ("[PATCH] tty: switch to ktermios and new framework")
[bwh: Backported to 3.16: adjust filename]
---
 drivers/tty/tty_ioctl.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/tty/tty_ioctl.c +3 -0
@@ -419,6 +419,9 @@ void tty_termios_encode_baud_rate(struct
 		ibinput = 1;	/* An input speed was specified */
 #endif
 	termios->c_cflag &= ~CBAUD;
+#ifdef IBSHIFT
+	termios->c_cflag &= ~(CBAUD << IBSHIFT);
+#endif
 
 	/*
 	 *	Our goal is to find a close match to the standard baud rate
#42 lore raw

PATCH 40/328 tty: fix termios input-speed encoding when using BOTHER

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Johan Hovold <[email protected]>

commit 1cee38f0363a88db374e50b232ca17b9a4c12fa0 upstream.

When the termios CIBAUD bits are left unset (i.e. B0), we use the same output and input speed and should leave CIBAUD unchanged.

When the user requests a rate using BOTHER and c_ospeed which the driver cannot set exactly, the driver can report back the actual baud rate using tty_termios_encode_baud_rate(). If this rate is close enough to a standard rate however, we could end up setting CIBAUD to a Bfoo value despite the user having left it unset.

This in turn could lead to an unexpected input rate being set on subsequent termios updates.

Fix this by using a zero tolerance value also for the input rate when CIBAUD is clear so that the matching logic works as expected.

Fixes 78137e3b34e1 ("[PATCH] tty: improve encode_baud_rate logic")
[bwh: Backported to 3.16: adjust filename]
---
 drivers/tty/tty_ioctl.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/tty/tty_ioctl.c +7 -3
@@ -407,16 +407,20 @@ void tty_termios_encode_baud_rate(struct
 	termios->c_ospeed = obaud;
 
 #ifdef BOTHER
+	if ((termios->c_cflag >> IBSHIFT) & CBAUD)
+		ibinput = 1;	/* An input speed was specified */
+
 	/* If the user asked for a precise weird speed give a precise weird
 	   answer. If they asked for a Bfoo speed they may have problems
 	   digesting non-exact replies so fuzz a bit */
 
-	if ((termios->c_cflag & CBAUD) == BOTHER)
+	if ((termios->c_cflag & CBAUD) == BOTHER) {
 		oclose = 0;
+		if (!ibinput)
+			iclose = 0;
+	}
 	if (((termios->c_cflag >> IBSHIFT) & CBAUD) == BOTHER)
 		iclose = 0;
-	if ((termios->c_cflag >> IBSHIFT) & CBAUD)
-		ibinput = 1;	/* An input speed was specified */
 #endif
 	termios->c_cflag &= ~CBAUD;
 #ifdef IBSHIFT
#43 lore raw

PATCH 41/328 s390/kvm: fix deadlock when killed by oom

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Claudio Imbrenda <[email protected]>

commit 306d6c49ac9ded11114cb53b0925da52f2c2ada1 upstream.

When the oom killer kills a userspace process in the page fault handler while in guest context, the fault handler fails to release the mm_sem if the FAULT_FLAG_RETRY_NOWAIT option is set. This leads to a deadlock when tearing down the mm when the process terminates. This bug can only happen when pfault is enabled, so only KVM clients are affected.

The problem arises in the rare cases in which handle_mm_fault does not release the mm_sem. This patch fixes the issue by manually releasing the mm_sem when needed.

Fixes 24eb3a824c4f3 ("KVM: s390: Add FAULT_FLAG_RETRY_NOWAIT for guest fault")
---
 arch/s390/mm/fault.c | 2 ++
 1 file changed, 2 insertions(+)
arch/s390/mm/fault.c +2 -0
@@ -497,6 +497,8 @@ retry:
 	/* No reason to continue if interrupted by SIGKILL. */
 	if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) {
 		fault = VM_FAULT_SIGNAL;
+		if (flags & FAULT_FLAG_RETRY_NOWAIT)
+			goto out_up;
 		goto out;
 	}
 	if (unlikely(fault & VM_FAULT_ERROR))
#44 lore raw

PATCH 42/328 ARM: hisi: handle of_iomap and fix missing of_node_put

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Nicholas Mc Guire <[email protected]>

commit d396cb185c0337aae5664b250cdd9a73f6eb1503 upstream.

Relying on an unchecked of_iomap() which can return NULL is problematic here, an explicit check seems mandatory. Also the call to of_find_compatible_node() returns a device node with refcount incremented therefor an explicit of_node_put() is needed here.

Fixes commit 22bae4290457 ("ARM: hi3xxx: add hotplug support")
---
 arch/arm/mach-hisi/hotplug.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
arch/arm/mach-hisi/hotplug.c +13 -6
@@ -137,13 +137,20 @@ static int hi3xxx_hotplug_init(void)
 	struct device_node *node;
 
 	node = of_find_compatible_node(NULL, NULL, "hisilicon,sysctrl");
-	if (node) {
-		ctrl_base = of_iomap(node, 0);
-		id = HI3620_CTRL;
-		return 0;
+	if (!node) {
+		id = ERROR_CTRL;
+		return -ENOENT;
 	}
-	id = ERROR_CTRL;
-	return -ENOENT;
+
+	ctrl_base = of_iomap(node, 0);
+	of_node_put(node);
+	if (!ctrl_base) {
+		id = ERROR_CTRL;
+		return -ENOMEM;
+	}
+
+	id = HI3620_CTRL;
+	return 0;
 }
 
 void hi3xxx_set_cpu(int cpu, bool enable)
#45 lore raw

PATCH 43/328 mtd: rawnand: mxc: remove __init qualifier from mxcnd_probe_dt

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Martin Kaiser <[email protected]>

commit 24f0ae995deb728076e3ea93fea1949a9775debf upstream.

Using the sysfs unbind, bind nodes, mxcnd_probe and mxcnd_probe_dt can potentially be called at any time. After the __init functions are cleaned, mxcnd_probe_dt is no longer available. Calling it anyway causes a crash.

mxcnd_probe used to be marked as __init, this was removed years ago. Remove the __init qualifier from from mxcnd_probe_dt as well.

Fixes 06f255106923 ("mtd: remove use of __devinit")
[bwh: Backported to 3.16: adjust filename]
---
 drivers/mtd/nand/mxc_nand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/mxc_nand.c +2 -2
@@ -1360,7 +1360,7 @@ static const struct of_device_id mxcnd_d
 	{ /* sentinel */ }
 };
 
-static int __init mxcnd_probe_dt(struct mxc_nand_host *host)
+static int mxcnd_probe_dt(struct mxc_nand_host *host)
 {
 	struct device_node *np = host->dev->of_node;
 	struct mxc_nand_platform_data *pdata = &host->pdata;
@@ -1387,7 +1387,7 @@ static int __init mxcnd_probe_dt(struct
 	return 0;
 }
 #else
-static int __init mxcnd_probe_dt(struct mxc_nand_host *host)
+static int mxcnd_probe_dt(struct mxc_nand_host *host)
 {
 	return 1;
 }
#46 lore raw

PATCH 44/328 mtdchar: fix overflows in adjustment of `count`

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Jann Horn <[email protected]>

commit 6c6bc9ea84d0008024606bf5ba10519e20d851bf upstream.

The first checks in mtdchar_read() and mtdchar_write() attempt to limit count such that *ppos + count <= mtd->size. However, they ignore the possibility of *ppos > mtd->size, allowing the calculation of count to wrap around. mtdchar_lseek() prevents seeking beyond mtd->size, but the pread/pwrite syscalls bypass this.

I haven't found any codepath on which this actually causes dangerous behavior, but it seems like a sensible change anyway.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/mtd/mtdchar.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/mtd/mtdchar.c +7 -3
@@ -190,8 +190,12 @@ static ssize_t mtdchar_read(struct file
 
 	pr_debug("MTD_read\n");
 
-	if (*ppos + count > mtd->size)
-		count = mtd->size - *ppos;
+	if (*ppos + count > mtd->size) {
+		if (*ppos < mtd->size)
+			count = mtd->size - *ppos;
+		else
+			count = 0;
+	}
 
 	if (!count)
 		return 0;
@@ -276,7 +280,7 @@ static ssize_t mtdchar_write(struct file
 
 	pr_debug("MTD_write\n");
 
-	if (*ppos == mtd->size)
+	if (*ppos >= mtd->size)
 		return -ENOSPC;
 
 	if (*ppos + count > mtd->size)
#47 lore raw

PATCH 45/328 binfmt_elf: Respect error return from `regset->active'

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: "Maciej W. Rozycki" <[email protected]>

commit 2f819db565e82e5f73cd42b39925098986693378 upstream.

The regset API documented in <linux/regset.h> defines -ENODEV as the result of the ->active' handler to be used where the feature requested is not available on the hardware found. However code handling core file note generation in fill_thread_core_info' interpretes any non-zero result from the `->active' handler as the regset requested being active. Consequently processing continues (and hopefully gracefully fails later on) rather than being abandoned right away for the regset requested.

Fix the problem then by making the code proceed only if a positive result is returned from the `->active' handler.

Fixes 4206d3aa1978 ("elf core dump: notes user_regset")

Patchwork: https://patchwork.linux-mips.org/patch/19332/

---
 fs/binfmt_elf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/binfmt_elf.c +1 -1
@@ -1571,7 +1571,7 @@ static int fill_thread_core_info(struct
 		const struct user_regset *regset = &view->regsets[i];
 		do_thread_regset_writeback(t->task, regset);
 		if (regset->core_note_type && regset->get &&
-		    (!regset->active || regset->active(t->task, regset))) {
+		    (!regset->active || regset->active(t->task, regset) > 0)) {
 			int ret;
 			size_t size = regset->n * regset->size;
 			void *data = kmalloc(size, GFP_KERNEL);
#48 lore raw

PATCH 46/328 MIPS: Correct the 64-bit DSP accumulator register size

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: "Maciej W. Rozycki" <[email protected]>

commit f5958b4cf4fc38ed4583ab83fb7c4cd1ab05f47b upstream.

Use the unsigned long' rather than __u32' type for DSP accumulator registers, like with the regular MIPS multiply/divide accumulator and general-purpose registers, as all are 64-bit in 64-bit implementations and using a 32-bit data type leads to contents truncation on context saving.

Update arch_ptrace' and compat_arch_ptrace' accordingly, removing casts that are similarly not used with multiply/divide accumulator or general-purpose register accesses.

Fixes e50c0a8fa60d ("Support the MIPS32 / MIPS64 DSP ASE.")

Patchwork: https://patchwork.linux-mips.org/patch/19329/

---
 arch/mips/include/asm/processor.h | 2 +-
 arch/mips/kernel/ptrace.c         | 2 +-
 arch/mips/kernel/ptrace32.c       | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
arch/mips/include/asm/processor.h +1 -1
@@ -143,7 +143,7 @@ struct mips_fpu_struct {
 
 #define NUM_DSP_REGS   6
 
-typedef __u32 dspreg_t;
+typedef unsigned long dspreg_t;
 
 struct mips_dsp_state {
 	dspreg_t	dspr[NUM_DSP_REGS];
arch/mips/kernel/ptrace.c +1 -1
@@ -790,7 +790,7 @@ long arch_ptrace(struct task_struct *chi
 				goto out;
 			}
 			dregs = __get_dsp_regs(child);
-			tmp = (unsigned long) (dregs[addr - DSP_BASE]);
+			tmp = dregs[addr - DSP_BASE];
 			break;
 		}
 		case DSP_CONTROL:
arch/mips/kernel/ptrace32.c +1 -1
@@ -140,7 +140,7 @@ long compat_arch_ptrace(struct task_stru
 				goto out;
 			}
 			dregs = __get_dsp_regs(child);
-			tmp = (unsigned long) (dregs[addr - DSP_BASE]);
+			tmp = dregs[addr - DSP_BASE];
 			break;
 		}
 		case DSP_CONTROL:
#49 lore raw

PATCH 47/328 xen-netfront: fix queue name setting

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Vitaly Kuznetsov <[email protected]>

commit 2d408c0d4574b01b9ed45e02516888bf925e11a9 upstream.

Commit f599c64fdf7d ("xen-netfront: Fix race between device setup and open") changed the initialization order: xennet_create_queues() now happens before we do register_netdev() so using netdev->name in xennet_init_queue() is incorrect, we end up with the following in /proc/interrupts:

 60:        139          0   xen-dyn    -event     eth%d-q0-tx
 61:        265          0   xen-dyn    -event     eth%d-q0-rx
 62:        234          0   xen-dyn    -event     eth%d-q1-tx
 63:          1          0   xen-dyn    -event     eth%d-q1-rx

and this looks ugly. Actually, using early netdev name (even when it's already set) is also not ideal: nowadays we tend to rename eth devices and queue name may end up not corresponding to the netdev name.

Use nodename from xenbus device for queue naming: this can't change in VM's lifetime. Now /proc/interrupts looks like

 62:        202          0   xen-dyn    -event     device/vif/0-q0-tx
 63:        317          0   xen-dyn    -event     device/vif/0-q0-rx
 64:        262          0   xen-dyn    -event     device/vif/0-q1-tx
 65:         17          0   xen-dyn    -event     device/vif/0-q1-rx
Fixes f599c64fdf7d ("xen-netfront: Fix race between device setup and open")
---
 drivers/net/xen-netfront.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/xen-netfront.c +1 -1
@@ -1646,7 +1646,7 @@ static int xennet_init_queue(struct netf
 	queue->rx_refill_timer.function = rx_refill_timeout;
 
 	snprintf(queue->name, sizeof(queue->name), "%s-q%u",
-		 queue->info->netdev->name, queue->id);
+		 queue->info->xbdev->nodename, queue->id);
 
 	/* Initialise tx_skbs as a free chain containing every entry. */
 	queue->tx_skb_freelist = 0;
#50 lore raw

Re: [PATCH 3.16 047/328] xen-netfront: fix queue name setting

Quoted 44 lines · Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Vitaly Kuznetsov <[email protected]>

commit 2d408c0d4574b01b9ed45e02516888bf925e11a9 upstream.

Commit f599c64fdf7d ("xen-netfront: Fix race between device setup and open") changed the initialization order: xennet_create_queues() now happens before we do register_netdev() so using netdev->name in xennet_init_queue() is incorrect, we end up with the following in /proc/interrupts:

 60:        139          0   xen-dyn    -event     eth%d-q0-tx
 61:        265          0   xen-dyn    -event     eth%d-q0-rx
 62:        234          0   xen-dyn    -event     eth%d-q1-tx
 63:          1          0   xen-dyn    -event     eth%d-q1-rx

and this looks ugly. Actually, using early netdev name (even when it's already set) is also not ideal: nowadays we tend to rename eth devices and queue name may end up not corresponding to the netdev name.

Use nodename from xenbus device for queue naming: this can't change in VM's lifetime. Now /proc/interrupts looks like

 62:        202          0   xen-dyn    -event     device/vif/0-q0-tx
 63:        317          0   xen-dyn    -event     device/vif/0-q0-rx
 64:        262          0   xen-dyn    -event     device/vif/0-q1-tx
 65:         17          0   xen-dyn    -event     device/vif/0-q1-rx
Fixes f599c64fdf7d ("xen-netfront: Fix race between device setup and open")
---
 drivers/net/xen-netfront.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

drivers/net/xen-netfront.c static int xennet_init_queue(struct netf · line 1652

Quoted 8 lines
drivers/net/xen-netfront.c +1 -1
@@ -1646,7 +1646,7 @@ static int xennet_init_queue(struct netf
 	queue->rx_refill_timer.function = rx_refill_timeout;
 
 	snprintf(queue->name, sizeof(queue->name), "%s-q%u",
-		 queue->info->netdev->name, queue->id);
+		 queue->info->xbdev->nodename, queue->id);
 
 	/* Initialise tx_skbs as a free chain containing every entry. */
 	queue->tx_skb_freelist = 0;

We should also take

commit 21f2706b20100bb3db378461ab9b8e2035309b5b

Author: Xiao Liang <[email protected]>
Date:   Tue Aug 14 23:21:28 2018 +0800

xen-netfront: fix warn message as irq device name has '/'

as it fixes an issue introduced by the commit in question. Sorry if this is already in your series but I wasn't CCed on it.

Signature · 1 line
Vitaly
#51 lore raw

Re: [PATCH 3.16 047/328] xen-netfront: fix queue name setting

Quoted 9 lines · Vitaly Kuznetsov
Quoted 7 lines · Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Vitaly Kuznetsov <[email protected]>

commit 2d408c0d4574b01b9ed45e02516888bf925e11a9 upstream.

[...]

Quoted 10 lines

We should also take

commit 21f2706b20100bb3db378461ab9b8e2035309b5b

Author: Xiao Liang <[email protected]>
Date:   Tue Aug 14 23:21:28 2018 +0800

xen-netfront: fix warn message as irq device name has '/'

as it fixes an issue introduced by the commit in question. Sorry if this is already in your series but I wasn't CCed on it.

Thanks, I've added that.

Ben.

Signature · 2 lines
Ben Hutchings
If you seem to know what you are doing, you'll be given more to do.
#52 lore raw

PATCH 48/328 ALSA: memalloc: Don't exceed over the requested size

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <[email protected]>

commit dfef01e150824b0e6da750cacda8958188d29aea upstream.

snd_dma_alloc_pages_fallback() tries to allocate pages again when the allocation fails with reduced size. But the first try actually *increases* the size to power-of-two, which may give back a larger chunk than the requested size. This confuses the callers, e.g. sgbuf assumes that the size is equal or less, and it may result in a bad loop due to the underflow and eventually lead to Oops.

The code of this function seems incorrectly assuming the usage of get_order(). We need to decrease at first, then align to power-of-two.

---
 sound/core/memalloc.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
sound/core/memalloc.c +2 -6
@@ -239,16 +239,12 @@ int snd_dma_alloc_pages_fallback(int typ
 	int err;
 
 	while ((err = snd_dma_alloc_pages(type, device, size, dmab)) < 0) {
-		size_t aligned_size;
 		if (err != -ENOMEM)
 			return err;
 		if (size <= PAGE_SIZE)
 			return -ENOMEM;
-		aligned_size = PAGE_SIZE << get_order(size);
-		if (size != aligned_size)
-			size = aligned_size;
-		else
-			size >>= 1;
+		size >>= 1;
+		size = PAGE_SIZE << get_order(size);
 	}
 	if (! dmab->area)
 		return -ENOMEM;
#53 lore raw

PATCH 49/328 MIPS: Change definition of cpu_relax() for Loongson-3

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Huacai Chen <[email protected]>

commit a30718868915fbb991a9ae9e45594b059f28e9ae upstream.

Linux expects that if a CPU modifies a memory location, then that modification will eventually become visible to other CPUs in the system.

Loongson 3 CPUs include a Store Fill Buffer (SFB) which sits between a core & its L1 data cache, queueing memory accesses & allowing for faster forwarding of data from pending stores to younger loads from the core. Unfortunately the SFB prioritizes loads such that a continuous stream of loads may cause a pending write to be buffered indefinitely. This is problematic if we end up with 2 CPUs which each perform a store that the other polls for - one or both CPUs may end up with their stores buffered in the SFB, never reaching cache due to the continuous reads from the poll loop. Such a deadlock condition has been observed whilst running qspinlock code.

This patch changes the definition of cpu_relax() to smp_mb() for Loongson-3, forcing a flush of the SFB on SMP systems which will cause any pending writes to make it as far as the L1 caches where they will become visible to other CPUs. If the kernel is not compiled for SMP support, this will expand to a barrier() as before.

This workaround matches that currently implemented for ARM when CONFIG_ARM_ERRATA_754327=y, which was introduced by commit 534be1d5a2da ("ARM: 6194/1: change definition of cpu_relax() for ARM11MPCore").

Although the workaround is only required when the Loongson 3 SFB functionality is enabled, and we only began explicitly enabling that functionality in v4.7 with commit 1e820da3c9af ("MIPS: Loongson-3:
Introduce CONFIG_LOONGSON3_ENHANCEMENT"), existing or future firmware may enable the SFB which means we may need the workaround backported to earlier kernels too.

[[email protected]:
- Reword commit message & comment.
- Limit stable backport to v3.15+ where we support Loongson 3 CPUs.]

References: 534be1d5a2da ("ARM: 6194/1: change definition of cpu_relax() for ARM11MPCore")
References: 1e820da3c9af ("MIPS: Loongson-3: Introduce CONFIG_LOONGSON3_ENHANCEMENT")
Patchwork: https://patchwork.linux-mips.org/patch/19830/

Cc Ralf Baechle <[email protected]>
Cc James Hogan <[email protected]>
Cc Fuxin Zhang <[email protected]>
Cc Zhangjin Wu <[email protected]>
Cc Huacai Chen <[email protected]>
---
 arch/mips/include/asm/processor.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
arch/mips/include/asm/processor.h +13 -0
@@ -366,7 +366,20 @@ unsigned long get_wchan(struct task_stru
 #define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[29])
 #define KSTK_STATUS(tsk) (task_pt_regs(tsk)->cp0_status)
 
+#ifdef CONFIG_CPU_LOONGSON3
+/*
+ * Loongson-3's SFB (Store-Fill-Buffer) may buffer writes indefinitely when a
+ * tight read loop is executed, because reads take priority over writes & the
+ * hardware (incorrectly) doesn't ensure that writes will eventually occur.
+ *
+ * Since spin loops of any kind should have a cpu_relax() in them, force an SFB
+ * flush from cpu_relax() such that any pending writes will become visible as
+ * expected.
+ */
+#define cpu_relax()	smp_mb()
+#else
 #define cpu_relax()	barrier()
+#endif
 
 /*
  * Return_address is a replacement for __builtin_return_address(count)
#54 lore raw

PATCH 50/328 PCI: hotplug: Don't leak pci_slot on registration failure

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Lukas Wunner <[email protected]>

commit 4ce6435820d1f1cc2c2788e232735eb244bcc8a3 upstream.

If addition of sysfs files fails on registration of a hotplug slot, the struct pci_slot as well as the entry in the slot_list is leaked. The issue has been present since the hotplug core was introduced in 2002:
https://git.kernel.org/tglx/history/c/a8a2069f432c

Perhaps the idea was that even though sysfs addition fails, the slot should still be usable. But that's not how drivers use the interface, they abort probe if a non-zero value is returned.

---
 drivers/pci/hotplug/pci_hotplug_core.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/pci/hotplug/pci_hotplug_core.c +9 -0
@@ -457,8 +457,17 @@ int __pci_hp_register(struct hotplug_slo
 	list_add(&slot->slot_list, &pci_hotplug_slot_list);
 
 	result = fs_add_slot(pci_slot);
+	if (result)
+		goto err_list_del;
+
 	kobject_uevent(&pci_slot->kobj, KOBJ_ADD);
 	dbg("Added slot %s to the list\n", name);
+	goto out;
+
+err_list_del:
+	list_del(&slot->slot_list);
+	pci_slot->hotplug = NULL;
+	pci_destroy_slot(pci_slot);
 out:
 	mutex_unlock(&pci_hp_mutex);
 	return result;
#55 lore raw

PATCH 51/328 PCI: pciehp: Fix use-after-free on unplug

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Lukas Wunner <[email protected]>

commit 281e878eab191cce4259abbbf1a0322e3adae02c upstream.

When pciehp is unbound (e.g. on unplug of a Thunderbolt device), the hotplug_slot struct is deregistered and thus freed before freeing the IRQ. The IRQ handler and the work items it schedules print the slot name referenced from the freed structure in various informational and debug log messages, each time resulting in a quadruple dereference of freed pointers (hotplug_slot -> pci_slot -> kobject -> name).

At best the slot name is logged as "(null)", at worst kernel memory is exposed in logs or the driver crashes:

pciehp 0000:10:00.0:pcie204: Slot((null)): Card not present

An attacker may provoke the bug by unplugging multiple devices on a Thunderbolt daisy chain at once. Unplugging can also be simulated by powering down slots via sysfs. The bug is particularly easy to trigger in poll mode.

It has been present since the driver's introduction in 2004:
https://git.kernel.org/tglx/history/c/c16b4b14d980

Fix by rearranging teardown such that the IRQ is freed first. Run the work items queued by the IRQ handler to completion before freeing the hotplug_slot struct by draining the work queue from the ->release_slot callback which is invoked by pci_hp_deregister().

[bwh: Backported to 3.16: adjust context]

---

drivers/pci/hotplug/pciehp.h +1 -0
@@ -141,6 +141,7 @@ int pciehp_unconfigure_device(struct slo
 void pciehp_queue_pushbutton_work(struct work_struct *work);
 struct controller *pcie_init(struct pcie_device *dev);
 int pcie_init_notification(struct controller *ctrl);
+void pcie_shutdown_notification(struct controller *ctrl);
 int pciehp_enable_slot(struct slot *p_slot);
 int pciehp_disable_slot(struct slot *p_slot);
 void pcie_reenable_notification(struct controller *ctrl);
drivers/pci/hotplug/pciehp_core.c +5 -0
@@ -82,6 +82,10 @@ static void release_slot(struct hotplug_
 	ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
 		 __func__, hotplug_slot_name(hotplug_slot));
 
+	/* queued work needs hotplug_slot name */
+	cancel_delayed_work(&slot->work);
+	drain_workqueue(slot->wq);
+
 	kfree(hotplug_slot->ops);
 	kfree(hotplug_slot->info);
 	kfree(hotplug_slot);
@@ -313,6 +317,7 @@ static void pciehp_remove(struct pcie_de
 {
 	struct controller *ctrl = get_service_data(dev);
 
+	pcie_shutdown_notification(ctrl);
 	cleanup_slot(ctrl);
 	pciehp_release_ctrl(ctrl);
 }
drivers/pci/hotplug/pciehp_hpc.c +2 -3
@@ -687,7 +687,7 @@ int pcie_init_notification(struct contro
 	return 0;
 }
 
-static void pcie_shutdown_notification(struct controller *ctrl)
+void pcie_shutdown_notification(struct controller *ctrl)
 {
 	if (ctrl->notification_enabled) {
 		pcie_disable_notification(ctrl);
@@ -722,7 +722,7 @@ abort:
 static void pcie_cleanup_slot(struct controller *ctrl)
 {
 	struct slot *slot = ctrl->slot;
-	cancel_delayed_work(&slot->work);
+
 	destroy_workqueue(slot->wq);
 	kfree(slot);
 }
@@ -846,7 +846,6 @@ abort:
 
 void pciehp_release_ctrl(struct controller *ctrl)
 {
-	pcie_shutdown_notification(ctrl);
 	pcie_cleanup_slot(ctrl);
 	kfree(ctrl);
 }
#56 lore raw

PATCH 52/328 PCI: pciehp: Fix unprotected list iteration in IRQ handler

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Lukas Wunner <[email protected]>

commit 1204e35bedf4e5015cda559ed8c84789a6dae24e upstream.

Commit b440bde74f04 ("PCI: Add pci_ignore_hotplug() to ignore hotplug events for a device") iterates over the devices on a hotplug port's subordinate bus in pciehp's IRQ handler without acquiring pci_bus_sem. It is thus possible for a user to cause a crash by concurrently manipulating the device list, e.g. by disabling slot power via sysfs on a different CPU or by initiating a remove/rescan via sysfs.

This can't be fixed by acquiring pci_bus_sem because it may sleep. The simplest fix is to avoid the list iteration altogether and just check the ignore_hotplug flag on the port itself. This works because pci_ignore_hotplug() sets the flag both on the device as well as on its parent bridge.

We do lose the ability to print the name of the device blocking hotplug in the debug message, but that's probably bearable.

Fixes b440bde74f04 ("PCI: Add pci_ignore_hotplug() to ignore hotplug events for a device")
[bwh: Backported to 3.16: s/events/intr_loc/]
---
 drivers/pci/hotplug/pciehp_hpc.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/pci/hotplug/pciehp_hpc.c +3 -10
@@ -508,8 +508,6 @@ static irqreturn_t pcie_isr(int irq, voi
 {
 	struct controller *ctrl = (struct controller *)dev_id;
 	struct pci_dev *pdev = ctrl_dev(ctrl);
-	struct pci_bus *subordinate = pdev->subordinate;
-	struct pci_dev *dev;
 	struct slot *slot = ctrl->slot;
 	u16 detected, intr_loc;
 
@@ -543,14 +541,9 @@ static irqreturn_t pcie_isr(int irq, voi
 		wake_up(&ctrl->queue);
 	}
 
-	if (subordinate) {
-		list_for_each_entry(dev, &subordinate->devices, bus_list) {
-			if (dev->ignore_hotplug) {
-				ctrl_dbg(ctrl, "ignoring hotplug event %#06x (%s requested no hotplug)\n",
-					 intr_loc, pci_name(dev));
-				return IRQ_HANDLED;
-			}
-		}
+	if (pdev->ignore_hotplug) {
+		ctrl_dbg(ctrl, "ignoring hotplug event %#06x\n", intr_loc);
+		return IRQ_HANDLED;
 	}
 
 	if (!(intr_loc & ~PCI_EXP_SLTSTA_CC))
#57 lore raw

PATCH 53/328 fbdev: omapfb: off by one in omapfb_register_client()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dan Carpenter <[email protected]>

commit 5ec1ec35b2979b59d0b33381e7c9aac17e159d16 upstream.

The omapfb_register_client[] array has OMAPFB_PLANE_NUM elements so the

Quoted 1 line

should be >= or we are one element beyond the end of the array.

Fixes 8b08cf2b64f5 ("OMAP: add TI OMAP framebuffer driver")
Cc Imre Deak <[email protected]>
---
 drivers/video/fbdev/omap/omapfb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/fbdev/omap/omapfb_main.c +1 -1
@@ -982,7 +982,7 @@ int omapfb_register_client(struct omapfb
 {
 	int r;
 
-	if ((unsigned)omapfb_nb->plane_idx > OMAPFB_PLANE_NUM)
+	if ((unsigned)omapfb_nb->plane_idx >= OMAPFB_PLANE_NUM)
 		return -EINVAL;
 
 	if (!notifier_inited) {
#58 lore raw

PATCH 54/328 iio: ad9523: Fix displayed phase

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Lars-Peter Clausen <[email protected]>

commit 5a4e33c1c53ae7d4425f7d94e60e4458a37b349e upstream.

Fix the displayed phase for the ad9523 driver. Currently the most significant decimal place is dropped and all other digits are shifted one to the left. This is due to a multiplication by 10, which is not necessary, so remove it.

Fixes cd1678f9632 ("iio: frequency: New driver for AD9523 SPI Low Jitter Clock Generator")
---
 drivers/iio/frequency/ad9523.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/frequency/ad9523.c +1 -1
@@ -641,7 +641,7 @@ static int ad9523_read_raw(struct iio_de
 		code = (AD9523_CLK_DIST_DIV_PHASE_REV(ret) * 3141592) /
 			AD9523_CLK_DIST_DIV_REV(ret);
 		*val = code / 1000000;
-		*val2 = (code % 1000000) * 10;
+		*val2 = code % 1000000;
 		return IIO_VAL_INT_PLUS_MICRO;
 	default:
 		return -EINVAL;
#59 lore raw

PATCH 55/328 fb: fix lost console when the user unplugs a USB adapter

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mikulas Patocka <[email protected]>

commit 8c5b044299951acd91e830a688dd920477ea1eda upstream.

I have a USB display adapter using the udlfb driver and I use it on an ARM board that doesn't have any graphics card. When I plug the adapter in, the console is properly displayed, however when I unplug and re-plug the adapter, the console is not displayed and I can't access it until I reboot the board.

The reason is this:
When the adapter is unplugged, dlfb_usb_disconnect calls unlink_framebuffer, then it waits until the reference count drops to zero and then it deallocates the framebuffer. However, the console that is attached to the framebuffer device keeps the reference count non-zero, so the framebuffer device is never destroyed. When the USB adapter is plugged again, it creates a new device /dev/fb1 and the console is not attached to it.

This patch fixes the bug by unbinding the console from unlink_framebuffer. The code to unbind the console is moved from do_unregister_framebuffer to a function unbind_console. When the console is unbound, the reference count drops to zero and the udlfb driver frees the framebuffer. When the adapter is plugged back, a new framebuffer is created and the console is attached to it.

Cc Dave Airlie <[email protected]>
Cc Bernie Thompson <[email protected]>
Cc Ladislav Michl <[email protected]>
[b.zolnierkie: preserve old behavior for do_unregister_framebuffer()]
---
 drivers/video/fbdev/core/fbmem.c | 38 +++++++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 6 deletions(-)
drivers/video/fbdev/core/fbmem.c +32 -6
@@ -1687,12 +1687,12 @@ static int do_register_framebuffer(struc
 	return 0;
 }
 
-static int do_unregister_framebuffer(struct fb_info *fb_info)
+static int unbind_console(struct fb_info *fb_info)
 {
 	struct fb_event event;
-	int i, ret = 0;
+	int ret;
+	int i = fb_info->node;
 
-	i = fb_info->node;
 	if (i < 0 || i >= FB_MAX || registered_fb[i] != fb_info)
 		return -EINVAL;
 
@@ -1707,17 +1707,29 @@ static int do_unregister_framebuffer(str
 	unlock_fb_info(fb_info);
 	console_unlock();
 
+	return ret;
+}
+
+static int __unlink_framebuffer(struct fb_info *fb_info);
+
+static int do_unregister_framebuffer(struct fb_info *fb_info)
+{
+	struct fb_event event;
+	int ret;
+
+	ret = unbind_console(fb_info);
+
 	if (ret)
 		return -EINVAL;
 
 	pm_vt_switch_unregister(fb_info->dev);
 
-	unlink_framebuffer(fb_info);
+	__unlink_framebuffer(fb_info);
 	if (fb_info->pixmap.addr &&
 	    (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT))
 		kfree(fb_info->pixmap.addr);
 	fb_destroy_modelist(&fb_info->modelist);
-	registered_fb[i] = NULL;
+	registered_fb[fb_info->node] = NULL;
 	num_registered_fb--;
 	fb_cleanup_device(fb_info);
 	event.info = fb_info;
@@ -1730,7 +1742,7 @@ static int do_unregister_framebuffer(str
 	return 0;
 }
 
-int unlink_framebuffer(struct fb_info *fb_info)
+static int __unlink_framebuffer(struct fb_info *fb_info)
 {
 	int i;
 
@@ -1742,6 +1754,20 @@ int unlink_framebuffer(struct fb_info *f
 		device_destroy(fb_class, MKDEV(FB_MAJOR, i));
 		fb_info->dev = NULL;
 	}
+
+	return 0;
+}
+
+int unlink_framebuffer(struct fb_info *fb_info)
+{
+	int ret;
+
+	ret = __unlink_framebuffer(fb_info);
+	if (ret)
+		return ret;
+
+	unbind_console(fb_info);
+
 	return 0;
 }
 EXPORT_SYMBOL(unlink_framebuffer);
#60 lore raw

PATCH 56/328 video: udlfb: Remove noisy warnings

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Ladislav Michl <[email protected]>

commit de4b74bda8e87a4ed45ebc2c26cc3e2eaae38429 upstream.

These warnings comes from times of driver development and do not carry any usefull debugging information.

Cc Bernie Thompson <[email protected]>
[bwh: Backported to 3.16: adjust context]
---
 drivers/video/fbdev/udlfb.c | 20 --------------------
 1 file changed, 20 deletions(-)
drivers/video/fbdev/udlfb.c +0 -20
@@ -924,11 +924,7 @@ static void dlfb_free(struct kref *kref)
 
 	if (dev->backing_buffer)
 		vfree(dev->backing_buffer);
-
 	kfree(dev->edid);
-
-	pr_warn("freeing dlfb_data %p\n", dev);
-
 	kfree(dev);
 }
 
@@ -945,8 +941,6 @@ static void dlfb_free_framebuffer(struct
 	struct fb_info *info = dev->info;
 
 	if (info) {
-		int node = info->node;
-
 		unregister_framebuffer(info);
 
 		if (info->cmap.len != 0)
@@ -962,8 +956,6 @@ static void dlfb_free_framebuffer(struct
 
 		/* Assume info structure is freed after this point */
 		framebuffer_release(info);
-
-		pr_warn("fb_info for /dev/fb%d has been freed\n", node);
 	}
 
 	/* ref taken in probe() as part of registering framebfufer */
@@ -1064,8 +1056,6 @@ static int dlfb_ops_set_par(struct fb_in
 	u16 *pix_framebuffer;
 	int i;
 
-	pr_notice("set_par mode %dx%d\n", info->var.xres, info->var.yres);
-
 	result = dlfb_set_video_mode(dev, &info->var);
 
 	if ((result == 0) && (dev->fb_count == 0)) {
@@ -1168,8 +1158,6 @@ static int dlfb_realloc_framebuffer(stru
 	unsigned char *new_fb;
 	unsigned char *new_back = NULL;
 
-	pr_warn("Reallocating framebuffer. Addresses will change!\n");
-
 	new_len = info->fix.line_length * info->var.yres;
 
 	if (PAGE_ALIGN(new_len) > old_len) {
@@ -1420,9 +1408,6 @@ static ssize_t edid_show(
 	if (off + count > dev->edid_size)
 		count = dev->edid_size - off;
 
-	pr_info("sysfs edid copy %p to %p, %d bytes\n",
-		dev->edid, buf, (int) count);
-
 	memcpy(buf, dev->edid, count);
 
 	return count;
@@ -1448,7 +1433,6 @@ static ssize_t edid_store(
 	if (!dev->edid || memcmp(src, dev->edid, src_size))
 		return -EINVAL;
 
-	pr_info("sysfs written EDID is new default\n");
 	dlfb_ops_set_par(fb_info);
 	return src_size;
 }
@@ -1831,8 +1815,6 @@ static void dlfb_free_urb_list(struct dl
 	int ret;
 	unsigned long flags;
 
-	pr_notice("Freeing all render urbs\n");
-
 	/* keep waiting and freeing, until we've got 'em all */
 	while (count--) {
 
@@ -1911,8 +1893,6 @@ static int dlfb_alloc_urb_list(struct dl
 	dev->urbs.count = i;
 	dev->urbs.available = i;
 
-	pr_notice("allocated %d %d byte urbs\n", i, (int) size);
-
 	return i;
 }
 
#61 lore raw

PATCH 57/328 video: udlfb: Fix unaligned access

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Ladislav Michl <[email protected]>

commit 115e77597efcc94cb1f6cbb7df5cf7ce8feb8632 upstream.

Driver generates lots of alignment trap exceptions on ARM. Fix that by replacing typecasting of odd addresses with byte shifting and remove uneccessary typecasting.

Cc Bernie Thompson <[email protected]>
[bwh: Backported to 3.16: adjust context]
---
 drivers/video/fbdev/udlfb.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
drivers/video/fbdev/udlfb.c +12 -11
@@ -443,9 +443,9 @@ static void dlfb_compress_hline(
 
 		*cmd++ = 0xAF;
 		*cmd++ = 0x6B;
-		*cmd++ = (uint8_t) ((dev_addr >> 16) & 0xFF);
-		*cmd++ = (uint8_t) ((dev_addr >> 8) & 0xFF);
-		*cmd++ = (uint8_t) ((dev_addr) & 0xFF);
+		*cmd++ = dev_addr >> 16;
+		*cmd++ = dev_addr >> 8;
+		*cmd++ = dev_addr;
 
 		cmd_pixels_count_byte = cmd++; /*  we'll know this later */
 		cmd_pixel_start = pixel;
@@ -462,8 +462,8 @@ static void dlfb_compress_hline(
 		while (pixel < cmd_pixel_end) {
 			const uint16_t * const repeating_pixel = pixel;
 
-			*(uint16_t *)cmd = cpu_to_be16p(pixel);
-			cmd += 2;
+			*cmd++ = *pixel >> 8;
+			*cmd++ = *pixel;
 			pixel++;
 
 			if (unlikely((pixel < cmd_pixel_end) &&
@@ -1532,15 +1532,16 @@ static int dlfb_parse_vendor_descriptor(
 			u8 length;
 			u16 key;
 
-			key = le16_to_cpu(*((u16 *) desc));
-			desc += sizeof(u16);
-			length = *desc;
-			desc++;
+			key = *desc++;
+			key |= (u16)*desc++ << 8;
+			length = *desc++;
 
 			switch (key) {
 			case 0x0200: { /* max_area */
-				u32 max_area;
-				max_area = le32_to_cpu(*((u32 *)desc));
+				u32 max_area = *desc++;
+				max_area |= (u32)*desc++ << 8;
+				max_area |= (u32)*desc++ << 16;
+				max_area |= (u32)*desc++ << 24;
 				pr_warn("DL chip limited to %d pixel modes\n",
 					max_area);
 				dev->sku_pixel_limit = max_area;
#62 lore raw

PATCH 58/328 udlfb: fix semaphore value leak

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mikulas Patocka <[email protected]>

commit 9d0aa601e4cd9c0892f90d36e8488d79b72f4073 upstream.

I observed that the performance of the udl fb driver degrades over time. On a freshly booted machine, it takes 6 seconds to do "ls -la /usr/bin"; after some time of use, the same operation takes 14 seconds.

The reason is that the value of "limit_sem" decays over time.

The udl driver uses a semaphore "limit_set" to specify how many free urbs are there on dlfb->urbs.list. If the count is zero, the "down" operation will sleep until some urbs are added to the freelist.

In order to avoid some hypothetical deadlock, the driver will not call "up" immediately, but it will offload it to a workqueue. The problem is that if we call "schedule_delayed_work" on the same work item multiple times, the work item may only be executed once.

This is happening:
* some urb completes
* dlfb_urb_completion adds it to the free list
* dlfb_urb_completion calls schedule_delayed_work to schedule the function dlfb_release_urb_work to increase the semaphore count
* as the urb is on the free list, some other task grabs it and submits it
* the submitted urb completes, dlfb_urb_completion is called again
* dlfb_urb_completion calls schedule_delayed_work, but the work is already scheduled, so it does nothing
* finally, dlfb_release_urb_work is called, it increases the semaphore count by 1, although it should increase it by 2

So, the semaphore count is decreasing over time, and this causes gradual performance degradation.

Note that in the current kernel, the "up" function may be called from interrupt and it may race with the "down" function called by another thread, so we don't have to offload the call of "up" to a workqueue at all. This patch removes the workqueue code. The patch also changes "down_interruptible" to "down" in dlfb_free_urb_list, so that we will clean up the driver properly even if a signal arrives.

With this patch, the performance of udlfb no longer degrades.

[b.zolnierkie: fix immediatelly -> immediately typo]

[bwh: Backported to 3.16: Pointers to struct dlfb_data are named "dev" rather
than "dlfb"]

---
 drivers/video/fbdev/udlfb.c | 27 ++-------------------------
 include/video/udlfb.h       |  1 -
 2 files changed, 2 insertions(+), 26 deletions(-)
drivers/video/fbdev/udlfb.c +2 -25
@@ -928,14 +928,6 @@ static void dlfb_free(struct kref *kref)
 	kfree(dev);
 }
 
-static void dlfb_release_urb_work(struct work_struct *work)
-{
-	struct urb_node *unode = container_of(work, struct urb_node,
-					      release_urb_work.work);
-
-	up(&unode->dev->urbs.limit_sem);
-}
-
 static void dlfb_free_framebuffer(struct dlfb_data *dev)
 {
 	struct fb_info *info = dev->info;
@@ -1797,14 +1789,7 @@ static void dlfb_urb_completion(struct u
 	dev->urbs.available++;
 	spin_unlock_irqrestore(&dev->urbs.lock, flags);
 
-	/*
-	 * When using fb_defio, we deadlock if up() is called
-	 * while another is waiting. So queue to another process.
-	 */
-	if (fb_defio)
-		schedule_delayed_work(&unode->release_urb_work, 0);
-	else
-		up(&dev->urbs.limit_sem);
+	up(&dev->urbs.limit_sem);
 }
 
 static void dlfb_free_urb_list(struct dlfb_data *dev)
@@ -1813,16 +1798,11 @@ static void dlfb_free_urb_list(struct dl
 	struct list_head *node;
 	struct urb_node *unode;
 	struct urb *urb;
-	int ret;
 	unsigned long flags;
 
 	/* keep waiting and freeing, until we've got 'em all */
 	while (count--) {
-
-		/* Getting interrupted means a leak, but ok at disconnect */
-		ret = down_interruptible(&dev->urbs.limit_sem);
-		if (ret)
-			break;
+		down(&dev->urbs.limit_sem);
 
 		spin_lock_irqsave(&dev->urbs.lock, flags);
 
@@ -1862,9 +1842,6 @@ static int dlfb_alloc_urb_list(struct dl
 			break;
 		unode->dev = dev;
 
-		INIT_DELAYED_WORK(&unode->release_urb_work,
-			  dlfb_release_urb_work);
-
 		urb = usb_alloc_urb(0, GFP_KERNEL);
 		if (!urb) {
 			kfree(unode);
include/video/udlfb.h +0 -1
@@ -19,7 +19,6 @@ struct dloarea {
 struct urb_node {
 	struct list_head entry;
 	struct dlfb_data *dev;
-	struct delayed_work release_urb_work;
 	struct urb *urb;
 };
 
#63 lore raw

PATCH 59/328 udlfb: fix display corruption of the last line

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mikulas Patocka <[email protected]>

commit 4e705e17ce3409a1f492cfd5dadcf6a4f6075842 upstream.

The displaylink hardware has such a peculiarity that it doesn't render a command until next command is received. This produces occasional corruption, such as when setting 22x11 font on the console, only the first line of the cursor will be blinking if the cursor is located at some specific columns.

When we end up with a repeating pixel, the driver has a bug that it leaves one uninitialized byte after the command (and this byte is enough to flush the command and render it - thus it fixes the screen corruption), however whe we end up with a non-repeating pixel, there is no byte appended and this results in temporary screen corruption.

This patch fixes the screen corruption by always appending a byte 0xAF at the end of URB. It also removes the uninitialized byte.

[bwh: Backported to 3.16:
- Pointers to struct dlfb_data are named "dev" rather than "dlfb"
- s/BPP/bpp/

---
 drivers/video/fbdev/udlfb.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
drivers/video/fbdev/udlfb.c +20 -10
@@ -29,6 +29,7 @@
 #include <linux/slab.h>
 #include <linux/prefetch.h>
 #include <linux/delay.h>
+#include <asm/unaligned.h>
 #include <video/udlfb.h>
 #include "edid.h"
 
@@ -453,17 +454,17 @@ static void dlfb_compress_hline(
 		raw_pixels_count_byte = cmd++; /*  we'll know this later */
 		raw_pixel_start = pixel;
 
-		cmd_pixel_end = pixel + min(MAX_CMD_PIXELS + 1,
-			min((int)(pixel_end - pixel),
-			    (int)(cmd_buffer_end - cmd) / bpp));
+		cmd_pixel_end = pixel + min3(MAX_CMD_PIXELS + 1UL,
+					(unsigned long)(pixel_end - pixel),
+					(unsigned long)(cmd_buffer_end - 1 - cmd) / bpp);
 
-		prefetch_range((void *) pixel, (cmd_pixel_end - pixel) * bpp);
+		prefetch_range((void *) pixel, (u8 *)cmd_pixel_end - (u8 *)pixel);
 
 		while (pixel < cmd_pixel_end) {
 			const uint16_t * const repeating_pixel = pixel;
 
-			*cmd++ = *pixel >> 8;
-			*cmd++ = *pixel;
+			put_unaligned_be16(*pixel, cmd);
+			cmd += 2;
 			pixel++;
 
 			if (unlikely((pixel < cmd_pixel_end) &&
@@ -489,13 +490,16 @@ static void dlfb_compress_hline(
 		if (pixel > raw_pixel_start) {
 			/* finalize last RAW span */
 			*raw_pixels_count_byte = (pixel-raw_pixel_start) & 0xFF;
+		} else {
+			/* undo unused byte */
+			cmd--;
 		}
 
 		*cmd_pixels_count_byte = (pixel - cmd_pixel_start) & 0xFF;
-		dev_addr += (pixel - cmd_pixel_start) * bpp;
+		dev_addr += (u8 *)pixel - (u8 *)cmd_pixel_start;
 	}
 
-	if (cmd_buffer_end <= MIN_RLX_CMD_BYTES + cmd) {
+	if (cmd_buffer_end - MIN_RLX_CMD_BYTES <= cmd) {
 		/* Fill leftover bytes with no-ops */
 		if (cmd_buffer_end > cmd)
 			memset(cmd, 0xAF, cmd_buffer_end - cmd);
@@ -615,8 +619,11 @@ static int dlfb_handle_damage(struct dlf
 	}
 
 	if (cmd > (char *) urb->transfer_buffer) {
+		int len;
+		if (cmd < (char *) urb->transfer_buffer + urb->transfer_buffer_length)
+			*cmd++ = 0xAF;
 		/* Send partial buffer remaining before exiting */
-		int len = cmd - (char *) urb->transfer_buffer;
+		len = cmd - (char *) urb->transfer_buffer;
 		ret = dlfb_submit_urb(dev, urb, len);
 		bytes_sent += len;
 	} else
@@ -740,8 +747,11 @@ static void dlfb_dpy_deferred_io(struct
 	}
 
 	if (cmd > (char *) urb->transfer_buffer) {
+		int len;
+		if (cmd < (char *) urb->transfer_buffer + urb->transfer_buffer_length)
+			*cmd++ = 0xAF;
 		/* Send partial buffer remaining before exiting */
-		int len = cmd - (char *) urb->transfer_buffer;
+		len = cmd - (char *) urb->transfer_buffer;
 		dlfb_submit_urb(dev, urb, len);
 		bytes_sent += len;
 	} else
#64 lore raw

PATCH 60/328 udlfb: don't switch if we are switching to the same videomode

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mikulas Patocka <[email protected]>

commit 564f1807379298dfdb12ed0d5b25fcb89c238527 upstream.

The udlfb driver reprograms the hardware everytime the user switches the console, that makes quite unusable when working on the console.

This patch makes the driver remember the videomode we are in and avoid reprogramming the hardware if we switch to the same videomode.

We mask the "activate" field and the "FB_VMODE_SMOOTH_XPAN" flag when comparing the videomode, because they cause spurious switches when switching to and from the Xserver.

[bwh: Backported to 3.16: Pointer to struct dlfb_data is named "dev" rather
than "dlfb"]

---
 drivers/video/fbdev/udlfb.c | 18 ++++++++++++++++--
 include/video/udlfb.h       |  1 +
 2 files changed, 17 insertions(+), 2 deletions(-)
drivers/video/fbdev/udlfb.c +16 -2
@@ -1057,10 +1057,24 @@ static int dlfb_ops_set_par(struct fb_in
 	int result;
 	u16 *pix_framebuffer;
 	int i;
+	struct fb_var_screeninfo fvs;
+
+	/* clear the activate field because it causes spurious miscompares */
+	fvs = info->var;
+	fvs.activate = 0;
+	fvs.vmode &= ~FB_VMODE_SMOOTH_XPAN;
+
+	if (!memcmp(&dev->current_mode, &fvs, sizeof(struct fb_var_screeninfo)))
+		return 0;
 
 	result = dlfb_set_video_mode(dev, &info->var);
 
-	if ((result == 0) && (dev->fb_count == 0)) {
+	if (result)
+		return result;
+
+	dev->current_mode = fvs;
+
+	if (dev->fb_count == 0) {
 
 		/* paint greenscreen */
 
@@ -1072,7 +1086,7 @@ static int dlfb_ops_set_par(struct fb_in
 				   info->screen_base);
 	}
 
-	return result;
+	return 0;
 }
 
 /* To fonzi the jukebox (e.g. make blanking changes take effect) */
include/video/udlfb.h +1 -0
@@ -56,6 +56,7 @@ struct dlfb_data {
 	atomic_t bytes_identical; /* saved effort with backbuffer comparison */
 	atomic_t bytes_sent; /* to usb, after compression including overhead */
 	atomic_t cpu_kcycles_used; /* transpired during pixel processing */
+	struct fb_var_screeninfo current_mode;
 };
 
 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
#65 lore raw

PATCH 61/328 udlfb: make a local copy of fb_ops

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mikulas Patocka <[email protected]>

commit 2c29cfc3eaf11779176bf41475cfca49bccba11c upstream.

The defio subsystem overwrites the method fb_osp->mmap. That method is stored in module's static data - and that means that if we have multiple diplaylink adapters, they will over write each other's method.

In order to avoid interference between multiple adapters, we copy the fb_ops structure to a device-local memory.

[bwh: Backported to 3.16: Pointer to struct dlfb_data is named "dev" rather
than "dlfb"]

---
 drivers/video/fbdev/udlfb.c | 3 ++-
 include/video/udlfb.h       | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/video/fbdev/udlfb.c +2 -1
@@ -1680,7 +1680,8 @@ static void dlfb_init_framebuffer_work(s
 	dev->info = info;
 	info->par = dev;
 	info->pseudo_palette = dev->pseudo_palette;
-	info->fbops = &dlfb_ops;
+	dev->ops = dlfb_ops;
+	info->fbops = &dev->ops;
 
 	retval = fb_alloc_cmap(&info->cmap, 256, 0);
 	if (retval < 0) {
include/video/udlfb.h +1 -0
@@ -51,6 +51,7 @@ struct dlfb_data {
 	int base8;
 	u32 pseudo_palette[256];
 	int blank_mode; /*one of FB_BLANK_ */
+	struct fb_ops ops;
 	/* blit-only rendering path metrics, exposed through sysfs */
 	atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
 	atomic_t bytes_identical; /* saved effort with backbuffer comparison */
#66 lore raw

PATCH 62/328 udlfb: set optimal write delay

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mikulas Patocka <[email protected]>

commit bb24153a3f13dd0dbc1f8055ad97fe346d598f66 upstream.

The default delay 5 jiffies is too much when the kernel is compiled with HZ=100 - it results in jumpy cursor in Xwindow.

In order to find out the optimal delay, I benchmarked the driver on 1280x720x30fps video. I found out that with HZ=1000, 10ms is acceptable, but with HZ=250 or HZ=300, we need 4ms, so that the video is played without any frame skips.

This patch changes the delay to this value.

---
 include/video/udlfb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/video/udlfb.h +1 -1
@@ -88,7 +88,7 @@ struct dlfb_data {
 #define MIN_RAW_PIX_BYTES	2
 #define MIN_RAW_CMD_BYTES	(RAW_HEADER_BYTES + MIN_RAW_PIX_BYTES)
 
-#define DL_DEFIO_WRITE_DELAY    5 /* fb_deferred_io.delay in jiffies */
+#define DL_DEFIO_WRITE_DELAY    msecs_to_jiffies(HZ <= 300 ? 4 : 10) /* optimal value for 720p video */
 #define DL_DEFIO_WRITE_DISABLE  (HZ*60) /* "disable" with long delay */
 
 /* remove these once align.h patch is taken into kernel */
#67 lore raw

PATCH 63/328 udlfb: handle allocation failure

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mikulas Patocka <[email protected]>

commit 080fb5240bdcabed7387b814139c3ea172d59fc5 upstream.

Allocations larger than PAGE_ALLOC_COSTLY_ORDER are unreliable and they may fail anytime. This patch fixes the udlfb driver so that when a large alloactions fails, it tries to do multiple smaller allocations.

[bwh: Backported to 3.16:
- Pointers to struct dlfb_data are named "dev" rather than "dlfb"
- Adjust context]

---
 drivers/video/fbdev/udlfb.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
drivers/video/fbdev/udlfb.c +17 -9
@@ -1851,17 +1851,22 @@ static void dlfb_free_urb_list(struct dl
 
 static int dlfb_alloc_urb_list(struct dlfb_data *dev, int count, size_t size)
 {
-	int i = 0;
 	struct urb *urb;
 	struct urb_node *unode;
 	char *buf;
+	size_t wanted_size = count * size;
 
 	spin_lock_init(&dev->urbs.lock);
 
+retry:
 	dev->urbs.size = size;
 	INIT_LIST_HEAD(&dev->urbs.list);
 
-	while (i < count) {
+	sema_init(&dev->urbs.limit_sem, 0);
+	dev->urbs.count = 0;
+	dev->urbs.available = 0;
+
+	while (dev->urbs.count * size < wanted_size) {
 		unode = kzalloc(sizeof(struct urb_node), GFP_KERNEL);
 		if (!unode)
 			break;
@@ -1874,11 +1879,16 @@ static int dlfb_alloc_urb_list(struct dl
 		}
 		unode->urb = urb;
 
-		buf = usb_alloc_coherent(dev->udev, MAX_TRANSFER, GFP_KERNEL,
+		buf = usb_alloc_coherent(dev->udev, size, GFP_KERNEL,
 					 &urb->transfer_dma);
 		if (!buf) {
 			kfree(unode);
 			usb_free_urb(urb);
+			if (size > PAGE_SIZE) {
+				size /= 2;
+				dlfb_free_urb_list(dev);
+				goto retry;
+			}
 			break;
 		}
 
@@ -1889,14 +1899,12 @@ static int dlfb_alloc_urb_list(struct dl
 
 		list_add_tail(&unode->entry, &dev->urbs.list);
 
-		i++;
+		up(&dev->urbs.limit_sem);
+		dev->urbs.count++;
+		dev->urbs.available++;
 	}
 
-	sema_init(&dev->urbs.limit_sem, i);
-	dev->urbs.count = i;
-	dev->urbs.available = i;
-
-	return i;
+	return dev->urbs.count;
 }
 
 static struct urb *dlfb_get_urb(struct dlfb_data *dev)
#68 lore raw

PATCH 64/328 udlfb: set line_length in dlfb_ops_set_par

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mikulas Patocka <[email protected]>

commit 0ac319b7af1bb24a33365d0ec82a2f56a59b2a78 upstream.

Set the variable "line_length" in the function dlfb_ops_set_par. Without this, we get garbage if we select different videomode with fbset.

[bwh: Backported to 3.16: adjust context]
---
 drivers/video/fbdev/udlfb.c | 1 +
 1 file changed, 1 insertion(+)
drivers/video/fbdev/udlfb.c +1 -0
@@ -1073,6 +1073,7 @@ static int dlfb_ops_set_par(struct fb_in
 		return result;
 
 	dev->current_mode = fvs;
+	info->fix.line_length = info->var.xres * (info->var.bits_per_pixel / 8);
 
 	if (dev->fb_count == 0) {
 
#69 lore raw

PATCH 65/328 xfrm: fix 'passing zero to ERR_PTR()' warning

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: YueHaibing <[email protected]>

commit 934ffce1343f22ed5e2d0bd6da4440f4848074de upstream.

Fix a static code checker warning:

net/xfrm/xfrm_policy.c:1836 xfrm_resolve_and_create_bundle() warn: passing zero to 'ERR_PTR'

xfrm_tmpl_resolve return 0 just means no xdst found, return NULL instead of passing zero to ERR_PTR.

Fixes d809ec895505 ("xfrm: do not assume that template resolving always returns xfrms")
---
 net/xfrm/xfrm_policy.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/xfrm/xfrm_policy.c +4 -1
@@ -1692,7 +1692,10 @@ xfrm_resolve_and_create_bundle(struct xf
 	/* Try to instantiate a bundle */
 	err = xfrm_tmpl_resolve(pols, num_pols, fl, xfrm, family);
 	if (err <= 0) {
-		if (err != 0 && err != -EAGAIN)
+		if (err == 0)
+			return NULL;
+
+		if (err != -EAGAIN)
 			XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLERROR);
 		return ERR_PTR(err);
 	}
#70 lore raw

PATCH 66/328 ALSA: seq: Fix poll() error return

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <[email protected]>

commit a49a71f6e25da2acc637fcd31e73debd96ca18f8 upstream.

The sanity checks in ALSA sequencer and OSS sequencer emulation codes return falsely -ENXIO from poll callback. They should be EPOLLERR instead.

This was caught thanks to the recent change to the return value.

[bwh: Backported to 3.16: s/EPOLLERR/POLLERR/]
---
 sound/core/seq/oss/seq_oss.c   | 2 +-
 sound/core/seq/seq_clientmgr.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
sound/core/seq/oss/seq_oss.c +1 -1
@@ -194,7 +194,7 @@ odev_poll(struct file *file, poll_table
 	struct seq_oss_devinfo *dp;
 	dp = file->private_data;
 	if (snd_BUG_ON(!dp))
-		return -ENXIO;
+		return POLLERR;
 	return snd_seq_oss_poll(dp, file, wait);
 }
 
sound/core/seq/seq_clientmgr.c +1 -1
@@ -1110,7 +1110,7 @@ static unsigned int snd_seq_poll(struct
 
 	/* check client structures are in place */
 	if (snd_BUG_ON(!client))
-		return -ENXIO;
+		return POLLERR;
 
 	if ((snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_INPUT) &&
 	    client->data.user.fifo) {
#71 lore raw

PATCH 67/328 ALSA: vx: Fix possible transfer overflow

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <[email protected]>

commit 874e1f6fad9a5184b67f4cee37c1335cd2cc5677 upstream.

The pseudo DMA transfer codes in VX222 and VX-pocket driver have a slight bug where they check the buffer boundary wrongly, and may overflow. Also, the zero sample count might be handled badly for the playback (although it shouldn't happen in theory). This patch addresses these issues.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=141541

---
 sound/drivers/vx/vx_pcm.c   |  6 ++++--
 sound/pci/vx222/vx222_ops.c | 12 ++++++------
 sound/pcmcia/vx/vxp_ops.c   | 12 ++++++------
 3 files changed, 16 insertions(+), 14 deletions(-)
sound/drivers/vx/vx_pcm.c +4 -2
@@ -1071,8 +1071,10 @@ static void vx_pcm_capture_update(struct
 		/* ok, let's accelerate! */
 		int align = pipe->align * 3;
 		space = (count / align) * align;
-		vx_pseudo_dma_read(chip, runtime, pipe, space);
-		count -= space;
+		if (space > 0) {
+			vx_pseudo_dma_read(chip, runtime, pipe, space);
+			count -= space;
+		}
 	}
 	/* read the rest of bytes */
 	while (count > 0) {
sound/pci/vx222/vx222_ops.c +6 -6
@@ -264,12 +264,12 @@ static void vx2_dma_write(struct vx_core
 
 	/* Transfer using pseudo-dma.
 	 */
-	if (offset + count > pipe->buffer_bytes) {
+	if (offset + count >= pipe->buffer_bytes) {
 		int length = pipe->buffer_bytes - offset;
 		count -= length;
 		length >>= 2; /* in 32bit words */
 		/* Transfer using pseudo-dma. */
-		while (length-- > 0) {
+		for (; length > 0; length--) {
 			outl(cpu_to_le32(*addr), port);
 			addr++;
 		}
@@ -279,7 +279,7 @@ static void vx2_dma_write(struct vx_core
 	pipe->hw_ptr += count;
 	count >>= 2; /* in 32bit words */
 	/* Transfer using pseudo-dma. */
-	while (count-- > 0) {
+	for (; count > 0; count--) {
 		outl(cpu_to_le32(*addr), port);
 		addr++;
 	}
@@ -302,12 +302,12 @@ static void vx2_dma_read(struct vx_core
 	vx2_setup_pseudo_dma(chip, 0);
 	/* Transfer using pseudo-dma.
 	 */
-	if (offset + count > pipe->buffer_bytes) {
+	if (offset + count >= pipe->buffer_bytes) {
 		int length = pipe->buffer_bytes - offset;
 		count -= length;
 		length >>= 2; /* in 32bit words */
 		/* Transfer using pseudo-dma. */
-		while (length-- > 0)
+		for (; length > 0; length--)
 			*addr++ = le32_to_cpu(inl(port));
 		addr = (u32 *)runtime->dma_area;
 		pipe->hw_ptr = 0;
@@ -315,7 +315,7 @@ static void vx2_dma_read(struct vx_core
 	pipe->hw_ptr += count;
 	count >>= 2; /* in 32bit words */
 	/* Transfer using pseudo-dma. */
-	while (count-- > 0)
+	for (; count > 0; count--)
 		*addr++ = le32_to_cpu(inl(port));
 
 	vx2_release_pseudo_dma(chip);
sound/pcmcia/vx/vxp_ops.c +6 -6
@@ -369,12 +369,12 @@ static void vxp_dma_write(struct vx_core
 	unsigned short *addr = (unsigned short *)(runtime->dma_area + offset);
 
 	vx_setup_pseudo_dma(chip, 1);
-	if (offset + count > pipe->buffer_bytes) {
+	if (offset + count >= pipe->buffer_bytes) {
 		int length = pipe->buffer_bytes - offset;
 		count -= length;
 		length >>= 1; /* in 16bit words */
 		/* Transfer using pseudo-dma. */
-		while (length-- > 0) {
+		for (; length > 0; length--) {
 			outw(cpu_to_le16(*addr), port);
 			addr++;
 		}
@@ -384,7 +384,7 @@ static void vxp_dma_write(struct vx_core
 	pipe->hw_ptr += count;
 	count >>= 1; /* in 16bit words */
 	/* Transfer using pseudo-dma. */
-	while (count-- > 0) {
+	for (; count > 0; count--) {
 		outw(cpu_to_le16(*addr), port);
 		addr++;
 	}
@@ -411,12 +411,12 @@ static void vxp_dma_read(struct vx_core
 	if (snd_BUG_ON(count % 2))
 		return;
 	vx_setup_pseudo_dma(chip, 0);
-	if (offset + count > pipe->buffer_bytes) {
+	if (offset + count >= pipe->buffer_bytes) {
 		int length = pipe->buffer_bytes - offset;
 		count -= length;
 		length >>= 1; /* in 16bit words */
 		/* Transfer using pseudo-dma. */
-		while (length-- > 0)
+		for (; length > 0; length--)
 			*addr++ = le16_to_cpu(inw(port));
 		addr = (unsigned short *)runtime->dma_area;
 		pipe->hw_ptr = 0;
@@ -424,7 +424,7 @@ static void vxp_dma_read(struct vx_core
 	pipe->hw_ptr += count;
 	count >>= 1; /* in 16bit words */
 	/* Transfer using pseudo-dma. */
-	while (count-- > 1)
+	for (; count > 1; count--)
 		*addr++ = le16_to_cpu(inw(port));
 	/* Disable DMA */
 	pchip->regDIALOG &= ~VXP_DLG_DMAREAD_SEL_MASK;
#72 lore raw

PATCH 68/328 ALSA: vx222: Fix invalid endian conversions

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <[email protected]>

commit fff71a4c050ba46e305d910c837b99ba1728135e upstream.

The endian conversions used in vx2_dma_read() and vx2_dma_write() are superfluous and even wrong on big-endian machines, as inl() and outl() already do conversions. Kill them.

Spotted by sparse, a warning like:
sound/pci/vx222/vx222_ops.c:278:30: warning: incorrect type in argument 1 (different base types)

---
 sound/pci/vx222/vx222_ops.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
sound/pci/vx222/vx222_ops.c +4 -4
@@ -270,7 +270,7 @@ static void vx2_dma_write(struct vx_core
 		length >>= 2; /* in 32bit words */
 		/* Transfer using pseudo-dma. */
 		for (; length > 0; length--) {
-			outl(cpu_to_le32(*addr), port);
+			outl(*addr, port);
 			addr++;
 		}
 		addr = (u32 *)runtime->dma_area;
@@ -280,7 +280,7 @@ static void vx2_dma_write(struct vx_core
 	count >>= 2; /* in 32bit words */
 	/* Transfer using pseudo-dma. */
 	for (; count > 0; count--) {
-		outl(cpu_to_le32(*addr), port);
+		outl(*addr, port);
 		addr++;
 	}
 
@@ -308,7 +308,7 @@ static void vx2_dma_read(struct vx_core
 		length >>= 2; /* in 32bit words */
 		/* Transfer using pseudo-dma. */
 		for (; length > 0; length--)
-			*addr++ = le32_to_cpu(inl(port));
+			*addr++ = inl(port);
 		addr = (u32 *)runtime->dma_area;
 		pipe->hw_ptr = 0;
 	}
@@ -316,7 +316,7 @@ static void vx2_dma_read(struct vx_core
 	count >>= 2; /* in 32bit words */
 	/* Transfer using pseudo-dma. */
 	for (; count > 0; count--)
-		*addr++ = le32_to_cpu(inl(port));
+		*addr++ = inl(port);
 
 	vx2_release_pseudo_dma(chip);
 }
#73 lore raw

PATCH 69/328 ALSA: vxpocket: Fix invalid endian conversions

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <[email protected]>

commit 3acd3e3bab95ec3622ff98da313290ee823a0f68 upstream.

The endian conversions used in vxp_dma_read() and vxp_dma_write() are superfluous and even wrong on big-endian machines, as inw() and outw() already do conversions. Kill them.

---
 sound/pcmcia/vx/vxp_ops.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
sound/pcmcia/vx/vxp_ops.c +5 -5
@@ -375,7 +375,7 @@ static void vxp_dma_write(struct vx_core
 		length >>= 1; /* in 16bit words */
 		/* Transfer using pseudo-dma. */
 		for (; length > 0; length--) {
-			outw(cpu_to_le16(*addr), port);
+			outw(*addr, port);
 			addr++;
 		}
 		addr = (unsigned short *)runtime->dma_area;
@@ -385,7 +385,7 @@ static void vxp_dma_write(struct vx_core
 	count >>= 1; /* in 16bit words */
 	/* Transfer using pseudo-dma. */
 	for (; count > 0; count--) {
-		outw(cpu_to_le16(*addr), port);
+		outw(*addr, port);
 		addr++;
 	}
 	vx_release_pseudo_dma(chip);
@@ -417,7 +417,7 @@ static void vxp_dma_read(struct vx_core
 		length >>= 1; /* in 16bit words */
 		/* Transfer using pseudo-dma. */
 		for (; length > 0; length--)
-			*addr++ = le16_to_cpu(inw(port));
+			*addr++ = inw(port);
 		addr = (unsigned short *)runtime->dma_area;
 		pipe->hw_ptr = 0;
 	}
@@ -425,12 +425,12 @@ static void vxp_dma_read(struct vx_core
 	count >>= 1; /* in 16bit words */
 	/* Transfer using pseudo-dma. */
 	for (; count > 1; count--)
-		*addr++ = le16_to_cpu(inw(port));
+		*addr++ = inw(port);
 	/* Disable DMA */
 	pchip->regDIALOG &= ~VXP_DLG_DMAREAD_SEL_MASK;
 	vx_outb(chip, DIALOG, pchip->regDIALOG);
 	/* Read the last word (16 bits) */
-	*addr = le16_to_cpu(inw(port));
+	*addr = inw(port);
 	/* Disable 16-bit accesses */
 	pchip->regDIALOG &= ~VXP_DLG_DMA16_SEL_MASK;
 	vx_outb(chip, DIALOG, pchip->regDIALOG);
#74 lore raw

PATCH 70/328 ALSA: cs5535audio: Fix invalid endian conversion

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <[email protected]>

commit 69756930f2de0457d51db7d505a1e4f40e9fd116 upstream.

One place in cs5535audio_build_dma_packets() does an extra conversion via cpu_to_le32(); namely jmpprd_addr is passed to setup_prd() ops, which writes the value via cs_writel(). That is, the callback does the conversion by itself, and we don't need to convert beforehand.

This patch fixes that bogus conversion.

---
 sound/pci/cs5535audio/cs5535audio.h     | 6 +++---
 sound/pci/cs5535audio/cs5535audio_pcm.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)
sound/pci/cs5535audio/cs5535audio.h +3 -3
@@ -66,9 +66,9 @@ struct cs5535audio_dma_ops {
 };
 
 struct cs5535audio_dma_desc {
-	u32 addr;
-	u16 size;
-	u16 ctlreserved;
+	__le32 addr;
+	__le16 size;
+	__le16 ctlreserved;
 };
 
 struct cs5535audio_dma {
sound/pci/cs5535audio/cs5535audio_pcm.c +2 -2
@@ -158,8 +158,8 @@ static int cs5535audio_build_dma_packets
 	lastdesc->addr = cpu_to_le32((u32) dma->desc_buf.addr);
 	lastdesc->size = 0;
 	lastdesc->ctlreserved = cpu_to_le16(PRD_JMP);
-	jmpprd_addr = cpu_to_le32(lastdesc->addr +
-				  (sizeof(struct cs5535audio_dma_desc)*periods));
+	jmpprd_addr = (u32)dma->desc_buf.addr +
+		sizeof(struct cs5535audio_dma_desc) * periods;
 
 	dma->substream = substream;
 	dma->period_bytes = period_bytes;
#75 lore raw

PATCH 71/328 fuse: don't wake up reserved req in fuse_conn_kill()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Miklos Szeredi <[email protected]>

commit 0c4dd4ba1426c599072511dcf95a15ee5e12725b upstream.

Waking up reserved_req_waitq from fuse_conn_kill() doesn't make sense since we aren't chaging ff->reserved_req here, which is what this waitqueue signals.

---
 fs/fuse/inode.c | 1 -
 1 file changed, 1 deletion(-)
fs/fuse/inode.c +0 -1
@@ -387,7 +387,6 @@ void fuse_conn_kill(struct fuse_conn *fc
 	kill_fasync(&fc->fasync, SIGIO, POLL_IN);
 	wake_up_all(&fc->waitq);
 	wake_up_all(&fc->blocked_waitq);
-	wake_up_all(&fc->reserved_req_waitq);
 }
 EXPORT_SYMBOL_GPL(fuse_conn_kill);
 
#76 lore raw

PATCH 72/328 fuse: flush requests on umount

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Miklos Szeredi <[email protected]>

commit 580640ba5d331eb5631a5de46941c98f5ed90886 upstream.

Use fuse_abort_conn() instead of fuse_conn_kill() in fuse_put_super(). This flushes and aborts requests still on any queues. But since we've already reset fc->connected, those requests would not be useful anyway and would be flushed when the fuse device is closed.

Next patches will rely on requests being flushed before the superblock is destroyed.

Use fuse_abort_conn() in cuse_process_init_reply() too, since it makes no difference there, and we can get rid of fuse_conn_kill().

---
 fs/fuse/cuse.c   |  2 +-
 fs/fuse/fuse_i.h |  2 --
 fs/fuse/inode.c  | 16 +---------------
 3 files changed, 2 insertions(+), 18 deletions(-)
fs/fuse/cuse.c +1 -1
@@ -415,7 +415,7 @@ err_unlock:
 err_region:
 	unregister_chrdev_region(devt, 1);
 err:
-	fuse_conn_kill(fc);
+	fuse_abort_conn(fc);
 	goto out;
 }
 
fs/fuse/fuse_i.h +0 -2
@@ -804,8 +804,6 @@ void fuse_invalidate_atime(struct inode
  */
 struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
 
-void fuse_conn_kill(struct fuse_conn *fc);
-
 /**
  * Initialize fuse_conn
  */
fs/fuse/inode.c +1 -15
@@ -376,27 +376,13 @@ static void fuse_bdi_destroy(struct fuse
 		bdi_destroy(&fc->bdi);
 }
 
-void fuse_conn_kill(struct fuse_conn *fc)
-{
-	spin_lock(&fc->lock);
-	fc->connected = 0;
-	fc->blocked = 0;
-	fc->initialized = 1;
-	spin_unlock(&fc->lock);
-	/* Flush all readers on this fs */
-	kill_fasync(&fc->fasync, SIGIO, POLL_IN);
-	wake_up_all(&fc->waitq);
-	wake_up_all(&fc->blocked_waitq);
-}
-EXPORT_SYMBOL_GPL(fuse_conn_kill);
-
 static void fuse_put_super(struct super_block *sb)
 {
 	struct fuse_conn *fc = get_fuse_conn_super(sb);
 
 	fuse_send_destroy(fc);
 
-	fuse_conn_kill(fc);
+	fuse_abort_conn(fc);
 	mutex_lock(&fuse_mutex);
 	list_del(&fc->entry);
 	fuse_ctl_remove_conn(fc);
#77 lore raw

PATCH 73/328 fuse: Fix oops at process_init_reply()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Miklos Szeredi <[email protected]>

commit e8f3bd773d22f488724dffb886a1618da85c2966 upstream.

syzbot is hitting NULL pointer dereference at process_init_reply(). This is because deactivate_locked_super() is called before response for initial request is processed.

Fix this by aborting and waiting for all requests (including FUSE_INIT) before resetting fc->sb.

Original patch by Tetsuo Handa <[email protected]>.

Fixes e27c9d3877a0 ("fuse: fuse: add time_gran to INIT_OUT")

[bwh: Backported to 3.16:
- Drop second argument to fuse_abort_conn()
- fuse_wait_aborted() is not needed]

---

fs/fuse/inode.c +10 -12
@@ -380,9 +380,6 @@ static void fuse_put_super(struct super_
 {
 	struct fuse_conn *fc = get_fuse_conn_super(sb);
 
-	fuse_send_destroy(fc);
-
-	fuse_abort_conn(fc);
 	mutex_lock(&fuse_mutex);
 	list_del(&fc->entry);
 	fuse_ctl_remove_conn(fc);
@@ -1124,16 +1121,24 @@ static struct dentry *fuse_mount(struct
 	return mount_nodev(fs_type, flags, raw_data, fuse_fill_super);
 }
 
-static void fuse_kill_sb_anon(struct super_block *sb)
+static void fuse_sb_destroy(struct super_block *sb)
 {
 	struct fuse_conn *fc = get_fuse_conn_super(sb);
 
 	if (fc) {
+		fuse_send_destroy(fc);
+
+		fuse_abort_conn(fc);
+
 		down_write(&fc->killsb);
 		fc->sb = NULL;
 		up_write(&fc->killsb);
 	}
+}
 
+static void fuse_kill_sb_anon(struct super_block *sb)
+{
+	fuse_sb_destroy(sb);
 	kill_anon_super(sb);
 }
 
@@ -1156,14 +1161,7 @@ static struct dentry *fuse_mount_blk(str
 
 static void fuse_kill_sb_blk(struct super_block *sb)
 {
-	struct fuse_conn *fc = get_fuse_conn_super(sb);
-
-	if (fc) {
-		down_write(&fc->killsb);
-		fc->sb = NULL;
-		up_write(&fc->killsb);
-	}
-
+	fuse_sb_destroy(sb);
 	kill_block_super(sb);
 }
 
#78 lore raw

PATCH 74/328 fuse: Don't access pipe->buffers without pipe_lock()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Andrey Ryabinin <[email protected]>

commit a2477b0e67c52f4364a47c3ad70902bc2a61bd4c upstream.

fuse_dev_splice_write() reads pipe->buffers to determine the size of 'bufs' array before taking the pipe_lock(). This is not safe as another thread might change the 'pipe->buffers' between the allocation and taking the pipe_lock(). So we end up with too small 'bufs' array.

Move the bufs allocations inside pipe_lock()/pipe_unlock() to fix this.

Fixes dd3bb14f44a6 ("fuse: support splice() writing to fuse device")
[bwh: Backported to 3.16: adjust context]
---
 fs/fuse/dev.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/fuse/dev.c +5 -2
@@ -1913,11 +1913,14 @@ static ssize_t fuse_dev_splice_write(str
 	if (!fc)
 		return -EPERM;
 
+	pipe_lock(pipe);
+
 	bufs = kmalloc(pipe->buffers * sizeof(struct pipe_buffer), GFP_KERNEL);
-	if (!bufs)
+	if (!bufs) {
+		pipe_unlock(pipe);
 		return -ENOMEM;
+	}
 
-	pipe_lock(pipe);
 	nbuf = 0;
 	rem = 0;
 	for (idx = 0; idx < pipe->nrbufs && rem < len; idx++)
#79 lore raw

PATCH 75/328 fuse: Add missed unlock_page() to fuse_readpages_fill()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Kirill Tkhai <[email protected]>

commit 109728ccc5933151c68d1106e4065478a487a323 upstream.

The above error path returns with page unlocked, so this place seems also to behave the same.

Fixes f8dbdf81821b ("fuse: rework fuse_readpages()")
---
 fs/fuse/file.c | 1 +
 1 file changed, 1 insertion(+)
fs/fuse/file.c +1 -0
@@ -911,6 +911,7 @@ static int fuse_readpages_fill(void *_da
 	}
 
 	if (WARN_ON(req->num_pages >= req->max_pages)) {
+		unlock_page(page);
 		fuse_put_request(fc, req);
 		return -EIO;
 	}
#80 lore raw

PATCH 76/328 block: move bio_integrity_{intervals,bytes} into blkdev.h

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Greg Edwards <[email protected]>

commit 359f642700f2ff05d9c94cd9216c97af7b8e9553 upstream.

This allows bio_integrity_bytes() to be called from drivers instead of open coding it.

[bwh: Backported to 3.16: bio_integrity_intervals() was called
bio_integrity_hw_sectors() and had a different implementation. Move it without renaming.]

---
 block/bio-integrity.c  | 22 ----------------------
 include/linux/blkdev.h | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 22 deletions(-)
block/bio-integrity.c +0 -26
@@ -194,32 +194,6 @@ int bio_integrity_enabled(struct bio *bi
 EXPORT_SYMBOL(bio_integrity_enabled);
 
 /**
- * bio_integrity_hw_sectors - Convert 512b sectors to hardware ditto
- * @bi:		blk_integrity profile for device
- * @sectors:	Number of 512 sectors to convert
- *
- * Description: The block layer calculates everything in 512 byte
- * sectors but integrity metadata is done in terms of the hardware
- * sector size of the storage device.  Convert the block layer sectors
- * to physical sectors.
- */
-static inline unsigned int bio_integrity_hw_sectors(struct blk_integrity *bi,
-						    unsigned int sectors)
-{
-	/* At this point there are only 512b or 4096b DIF/EPP devices */
-	if (bi->sector_size == 4096)
-		return sectors >>= 3;
-
-	return sectors;
-}
-
-static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi,
-					       unsigned int sectors)
-{
-	return bio_integrity_hw_sectors(bi, sectors) * bi->tuple_size;
-}
-
-/**
  * bio_integrity_tag_size - Retrieve integrity tag space
  * @bio:	bio to inspect
  *
include/linux/blkdev.h +38 -0
@@ -1542,6 +1542,32 @@ queue_max_integrity_segments(struct requ
 	return q->limits.max_integrity_segments;
 }
 
+/**
+ * bio_integrity_hw_sectors - Convert 512b sectors to hardware ditto
+ * @bi:		blk_integrity profile for device
+ * @sectors:	Number of 512 sectors to convert
+ *
+ * Description: The block layer calculates everything in 512 byte
+ * sectors but integrity metadata is done in terms of the hardware
+ * sector size of the storage device.  Convert the block layer sectors
+ * to physical sectors.
+ */
+static inline unsigned int bio_integrity_hw_sectors(struct blk_integrity *bi,
+						    unsigned int sectors)
+{
+	/* At this point there are only 512b or 4096b DIF/EPP devices */
+	if (bi->sector_size == 4096)
+		return sectors >>= 3;
+
+	return sectors;
+}
+
+static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi,
+					       unsigned int sectors)
+{
+	return bio_integrity_hw_sectors(bi, sectors) * bi->tuple_size;
+}
+
 #else /* CONFIG_BLK_DEV_INTEGRITY */
 
 struct bio;
@@ -1608,6 +1634,18 @@ static inline bool blk_integrity_is_init
 {
 	return 0;
 }
+
+static inline unsigned int bio_integrity_hw_sectors(struct blk_integrity *bi,
+						   unsigned int sectors)
+{
+	return 0;
+}
+
+static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi,
+					       unsigned int sectors)
+{
+	return 0;
+}
 
 #endif /* CONFIG_BLK_DEV_INTEGRITY */
 
#81 lore raw

PATCH 77/328 scsi: virtio_scsi: fix pi_bytes{out,in} on 4 KiB block size devices

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Greg Edwards <[email protected]>

commit cdcdcaae8450a975e7d07e1bfec21f9b8c016d0c upstream.

When the underlying device is a 4 KiB logical block size device with a protection interval exponent of 0, i.e. 4096 bytes data + 8 bytes PI, the driver miscalculates the pi_bytes{out,in} by a factor of 8x (64 bytes).

This leads to errors on all reads and writes on 4 KiB logical block size devices when CONFIG_BLK_DEV_INTEGRITY is enabled and the VIRTIO_SCSI_F_T10_PI feature bit has been negotiated.

Fixes e6dc783a38ec0 ("virtio-scsi: Enable DIF/DIX modes in SCSI host LLD")
[bwh: Backported to 3.16: adjust context]

---

drivers/scsi/virtio_scsi.c +4 -2
@@ -500,9 +500,11 @@ static void virtio_scsi_init_hdr_pi(stru
 	bi = blk_get_integrity(rq->rq_disk);
 
 	if (sc->sc_data_direction == DMA_TO_DEVICE)
-		cmd_pi->pi_bytesout = blk_rq_sectors(rq) * bi->tuple_size;
+		cmd_pi->pi_bytesout = bio_integrity_bytes(bi,
+							blk_rq_sectors(rq));
 	else if (sc->sc_data_direction == DMA_FROM_DEVICE)
-		cmd_pi->pi_bytesin = blk_rq_sectors(rq) * bi->tuple_size;
+		cmd_pi->pi_bytesin = bio_integrity_bytes(bi,
+							blk_rq_sectors(rq));
 }
 
 static int virtscsi_queuecommand(struct virtio_scsi *vscsi,
#82 lore raw

PATCH 78/328 ALSA: virmidi: Fix too long output trigger loop

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <[email protected]>

commit 50e9ffb1996a5d11ff5040a266585bad4ceeca0a upstream.

The virmidi output trigger tries to parse the all available bytes and process sequencer events as much as possible. In a normal situation, this is supposed to be relatively short, but a program may give a huge buffer and it'll take a long time in a single spin lock, which may eventually lead to a soft lockup.

This patch simply adds a workaround, a cond_resched() call in the loop if applicable. A better solution would be to move the event processor into a work, but let's put a duct-tape quickly at first.

---
 sound/core/seq/seq_virmidi.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
sound/core/seq/seq_virmidi.c +10 -0
@@ -163,6 +163,7 @@ static void snd_virmidi_output_trigger(s
 	int count, res;
 	unsigned char buf[32], *pbuf;
 	unsigned long flags;
+	bool check_resched = !in_atomic();
 
 	if (up) {
 		vmidi->trigger = 1;
@@ -200,6 +201,15 @@ static void snd_virmidi_output_trigger(s
 					vmidi->event.type = SNDRV_SEQ_EVENT_NONE;
 				}
 			}
+			if (!check_resched)
+				continue;
+			/* do temporary unlock & cond_resched() for avoiding
+			 * CPU soft lockup, which may happen via a write from
+			 * a huge rawmidi buffer
+			 */
+			spin_unlock_irqrestore(&substream->runtime->lock, flags);
+			cond_resched();
+			spin_lock_irqsave(&substream->runtime->lock, flags);
 		}
 	out:
 		spin_unlock_irqrestore(&substream->runtime->lock, flags);
#83 lore raw

PATCH 79/328 media: dvb-usb-v2/gl861: ensure USB message buffers DMA'able

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Akihiro Tsukada <[email protected]>

commit 86f65c218123c4e36fd855fbbc38147ffaf29974 upstream.

i2c message buf might be on stack.

[bwh: Backported to 3.16: adjust context]
---
 drivers/media/usb/dvb-usb-v2/gl861.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
drivers/media/usb/dvb-usb-v2/gl861.c +17 -3
@@ -20,6 +20,8 @@ static int gl861_i2c_msg(struct dvb_usb_
 	u16 value = addr << (8 + 1);
 	int wo = (rbuf == NULL || rlen == 0); /* write-only */
 	u8 req, type;
+	u8 *buf;
+	int ret;
 
 	if (wo) {
 		req = GL861_REQ_I2C_WRITE;
@@ -42,11 +44,23 @@ static int gl861_i2c_msg(struct dvb_usb_
 				KBUILD_MODNAME, wlen);
 		return -EINVAL;
 	}
-
+	buf = NULL;
+	if (rlen > 0) {
+		buf = kmalloc(rlen, GFP_KERNEL);
+		if (!buf)
+			return -ENOMEM;
+	}
 	msleep(1); /* avoid I2C errors */
 
-	return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type,
-			       value, index, rbuf, rlen, 2000);
+	ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type,
+			      value, index, buf, rlen, 2000);
+	if (rlen > 0) {
+		if (ret > 0)
+			memcpy(rbuf, buf, rlen);
+		kfree(buf);
+	}
+
+	return ret;
 }
 
 /* I2C */
#84 lore raw

PATCH 80/328 media: gl861: fix probe of dvb_usb_gl861

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mika Båtsman <[email protected]>

commit 48db0089bff6f9154f6bd98ce7a6ae3786fa8ebe upstream.

Probe of dvb_usb_gl861 was working at least with v4.4. Noticed the issue with v4.13 but according to similar issues the problem started with v4.9.

[   15.288065] transfer buffer not dma capable
[   15.288090] WARNING: CPU: 2 PID: 493 at drivers/usb/core/hcd.c:1595 usb_hcd_map_urb_for_dma+0x4e2/0x640
...CUT...
[   15.288791] dvb_usb_gl861: probe of 3-7:1.0 failed with error -5

Tested with MSI Mega Sky 580 DVB-T Tuner [GL861]

[[email protected]: rebased on the top of upstream]
[bwh: Backported to 3.16: adjust context]
---
 drivers/media/usb/dvb-usb-v2/gl861.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/media/usb/dvb-usb-v2/gl861.c +10 -11
@@ -26,10 +26,14 @@ static int gl861_i2c_msg(struct dvb_usb_
 	if (wo) {
 		req = GL861_REQ_I2C_WRITE;
 		type = GL861_WRITE;
+		buf = kmemdup(wbuf, wlen, GFP_KERNEL);
 	} else { /* rw */
 		req = GL861_REQ_I2C_READ;
 		type = GL861_READ;
+		buf = kmalloc(rlen, GFP_KERNEL);
 	}
+	if (!buf)
+		return -ENOMEM;
 
 	switch (wlen) {
 	case 1:
@@ -42,24 +46,19 @@ static int gl861_i2c_msg(struct dvb_usb_
 	default:
 		dev_err(&d->udev->dev, "%s: wlen=%d, aborting\n",
 				KBUILD_MODNAME, wlen);
+		kfree(buf);
 		return -EINVAL;
 	}
-	buf = NULL;
-	if (rlen > 0) {
-		buf = kmalloc(rlen, GFP_KERNEL);
-		if (!buf)
-			return -ENOMEM;
-	}
+
 	msleep(1); /* avoid I2C errors */
 
 	ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type,
 			      value, index, buf, rlen, 2000);
-	if (rlen > 0) {
-		if (ret > 0)
-			memcpy(rbuf, buf, rlen);
-		kfree(buf);
-	}
 
+	if (!wo && ret > 0)
+		memcpy(rbuf, buf, rlen);
+
+	kfree(buf);
 	return ret;
 }
 
#85 lore raw

PATCH 81/328 partitions/aix: fix usage of uninitialized lv_info and lvname structures

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mauricio Faria de Oliveira <[email protected]>

commit 14cb2c8a6c5dae57ee3e2da10fa3db2b9087e39e upstream.

The if-block that sets a successful return value in aix_partition() uses 'lvip[].pps_per_lv' and 'n[].name' potentially uninitialized.

For example, if 'numlvs' is zero or alloc_lvn() fails, neither is initialized, but are used anyway if alloc_pvd() succeeds after it.

So, make the alloc_pvd() call conditional on their initialization.

This has been hit when attaching an apparently corrupted/stressed AIX LUN, misleading the kernel to pr_warn() invalid data and hang.

[...] partition (null) (11 pp's found) is not contiguous [...] partition (null) (2 pp's found) is not contiguous [...] partition (null) (3 pp's found) is not contiguous [...] partition (null) (64 pp's found) is not contiguous

Fixes 6ceea22bbbc8 ("partitions: add aix lvm partition support files")
---
 block/partitions/aix.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
block/partitions/aix.c +3 -2
@@ -177,7 +177,7 @@ int aix_partition(struct parsed_partitio
 	u32 vgda_sector = 0;
 	u32 vgda_len = 0;
 	int numlvs = 0;
-	struct pvd *pvd;
+	struct pvd *pvd = NULL;
 	struct lv_info {
 		unsigned short pps_per_lv;
 		unsigned short pps_found;
@@ -231,10 +231,11 @@ int aix_partition(struct parsed_partitio
 				if (lvip[i].pps_per_lv)
 					foundlvs += 1;
 			}
+			/* pvd loops depend on n[].name and lvip[].pps_per_lv */
+			pvd = alloc_pvd(state, vgda_sector + 17);
 		}
 		put_dev_sector(sect);
 	}
-	pvd = alloc_pvd(state, vgda_sector + 17);
 	if (pvd) {
 		int numpps = be16_to_cpu(pvd->pp_count);
 		int psn_part1 = be32_to_cpu(pvd->psn_part1);
#86 lore raw

PATCH 82/328 partitions/aix: append null character to print data from disk

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mauricio Faria de Oliveira <[email protected]>

commit d43fdae7bac2def8c4314b5a49822cb7f08a45f1 upstream.

Even if properly initialized, the lvname array (i.e., strings) is read from disk, and might contain corrupt data (e.g., lack the null terminating character for strings).

So, make sure the partition name string used in pr_warn() has the null terminating character.

Fixes 6ceea22bbbc8 ("partitions: add aix lvm partition support files")
---
 block/partitions/aix.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
block/partitions/aix.c +6 -2
@@ -282,10 +282,14 @@ int aix_partition(struct parsed_partitio
 				next_lp_ix += 1;
 		}
 		for (i = 0; i < state->limit; i += 1)
-			if (lvip[i].pps_found && !lvip[i].lv_is_contiguous)
+			if (lvip[i].pps_found && !lvip[i].lv_is_contiguous) {
+				char tmp[sizeof(n[i].name) + 1]; // null char
+
+				snprintf(tmp, sizeof(tmp), "%s", n[i].name);
 				pr_warn("partition %s (%u pp's found) is "
 					"not contiguous\n",
-					n[i].name, lvip[i].pps_found);
+					tmp, lvip[i].pps_found);
+			}
 		kfree(pvd);
 	}
 	kfree(n);
#87 lore raw

PATCH 83/328 iio: ad9523: Fix return value for ad952x_store()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Lars-Peter Clausen <[email protected]>

commit 9a5094ca29ea9b1da301b31fd377c0c0c4c23034 upstream.

A sysfs write callback function needs to either return the number of consumed characters or an error.

The ad952x_store() function currently returns 0 if the input value was "0", this will signal that no characters have been consumed and the function will be called repeatedly in a loop indefinitely. Fix this by returning number of supplied characters to indicate that the whole input string has been consumed.

Fixes cd1678f96329 ("iio: frequency: New driver for AD9523 SPI Low Jitter Clock Generator")
---
 drivers/iio/frequency/ad9523.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/frequency/ad9523.c +1 -1
@@ -507,7 +507,7 @@ static ssize_t ad9523_store(struct devic
 		return ret;
 
 	if (!state)
-		return 0;
+		return len;
 
 	mutex_lock(&indio_dev->mlock);
 	switch ((u32)this_attr->address) {
#88 lore raw

PATCH 84/328 net: mvneta: fix mtu change on port without link

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Yelena Krivosheev <[email protected]>

commit 8466baf788ec3e18836bd9c91ba0b1a07af25878 upstream.

It is incorrect to enable TX/RX queues (call by mvneta_port_up()) for port without link. Indeed MTU change for interface without link causes TX queues to stuck.

Fixes c5aff18204da ("net: mvneta: driver for Marvell Armada 370/XP

network unit")

[gregory.clement: adding Fixes tags and rewording commit log]
---
 drivers/net/ethernet/marvell/mvneta.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/ethernet/marvell/mvneta.c +0 -1
@@ -2475,7 +2475,6 @@ static int mvneta_change_mtu(struct net_
 	}
 
 	mvneta_start_dev(pp);
-	mvneta_port_up(pp);
 
 	netdev_update_features(dev);
 
#89 lore raw

PATCH 85/328 pinctrl: imx: off by one in imx_pinconf_group_dbg_show()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dan Carpenter <[email protected]>

commit b4859f3edb47825f62d1b2efdd75fe7945996f49 upstream.

The > should really be >= here. It's harmless because pinctrl_generic_get_group() will return a NULL if group is invalid.

Fixes ae75ff814538 ("pinctrl: pinctrl-imx: add imx pinctrl core driver")
[bwh: Backported to 3.16: adjust filename, context]
---
 drivers/pinctrl/pinctrl-imx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-imx.c +1 -1
@@ -388,7 +388,7 @@ static void imx_pinconf_group_dbg_show(s
 	const char *name;
 	int i, ret;
 
-	if (group > info->ngroups)
+	if (group >= info->ngroups)
 		return;
 
 	seq_printf(s, "\n");
#90 lore raw

PATCH 86/328 udl-kms: change down_interruptible to down

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mikulas Patocka <[email protected]>

commit 8456b99c16d193c4c3b7df305cf431e027f0189c upstream.

If we leave urbs around, it causes not only leak, but also memory corruption. This patch fixes the function udl_free_urb_list, so that it always waits for all urbs that are in progress.

---
 drivers/gpu/drm/udl/udl_main.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/gpu/drm/udl/udl_main.c +1 -6
@@ -141,18 +141,13 @@ static void udl_free_urb_list(struct drm
 	struct list_head *node;
 	struct urb_node *unode;
 	struct urb *urb;
-	int ret;
 	unsigned long flags;
 
 	DRM_DEBUG("Waiting for completes and freeing all render urbs\n");
 
 	/* keep waiting and freeing, until we've got 'em all */
 	while (count--) {
-
-		/* Getting interrupted means a leak, but ok at shutdown*/
-		ret = down_interruptible(&udl->urbs.limit_sem);
-		if (ret)
-			break;
+		down(&udl->urbs.limit_sem);
 
 		spin_lock_irqsave(&udl->urbs.lock, flags);
 
#91 lore raw

PATCH 87/328 udl-kms: handle allocation failure

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mikulas Patocka <[email protected]>

commit 542bb9788a1f485eb1a2229178f665d8ea166156 upstream.

Allocations larger than PAGE_ALLOC_COSTLY_ORDER are unreliable and they may fail anytime. This patch fixes the udl kms driver so that when a large alloactions fails, it tries to do multiple smaller allocations.

[bwh: Backported to 3.16: adjust context]
---
 drivers/gpu/drm/udl/udl_main.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/gpu/drm/udl/udl_main.c +18 -10
@@ -171,17 +171,22 @@ static void udl_free_urb_list(struct drm
 static int udl_alloc_urb_list(struct drm_device *dev, int count, size_t size)
 {
 	struct udl_device *udl = dev->dev_private;
-	int i = 0;
 	struct urb *urb;
 	struct urb_node *unode;
 	char *buf;
+	size_t wanted_size = count * size;
 
 	spin_lock_init(&udl->urbs.lock);
 
+retry:
 	udl->urbs.size = size;
 	INIT_LIST_HEAD(&udl->urbs.list);
 
-	while (i < count) {
+	sema_init(&udl->urbs.limit_sem, 0);
+	udl->urbs.count = 0;
+	udl->urbs.available = 0;
+
+	while (udl->urbs.count * size < wanted_size) {
 		unode = kzalloc(sizeof(struct urb_node), GFP_KERNEL);
 		if (!unode)
 			break;
@@ -197,11 +202,16 @@ static int udl_alloc_urb_list(struct drm
 		}
 		unode->urb = urb;
 
-		buf = usb_alloc_coherent(udl->ddev->usbdev, MAX_TRANSFER, GFP_KERNEL,
+		buf = usb_alloc_coherent(udl->ddev->usbdev, size, GFP_KERNEL,
 					 &urb->transfer_dma);
 		if (!buf) {
 			kfree(unode);
 			usb_free_urb(urb);
+			if (size > PAGE_SIZE) {
+				size /= 2;
+				udl_free_urb_list(dev);
+				goto retry;
+			}
 			break;
 		}
 
@@ -212,16 +222,14 @@ static int udl_alloc_urb_list(struct drm
 
 		list_add_tail(&unode->entry, &udl->urbs.list);
 
-		i++;
+		up(&udl->urbs.limit_sem);
+		udl->urbs.count++;
+		udl->urbs.available++;
 	}
 
-	sema_init(&udl->urbs.limit_sem, i);
-	udl->urbs.count = i;
-	udl->urbs.available = i;
-
-	DRM_DEBUG("allocated %d %d byte urbs\n", i, (int) size);
+	DRM_DEBUG("allocated %d %d byte urbs\n", udl->urbs.count, (int) size);
 
-	return i;
+	return udl->urbs.count;
 }
 
 struct urb *udl_get_urb(struct drm_device *dev)
#92 lore raw

PATCH 88/328 udl-kms: fix crash due to uninitialized memory

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mikulas Patocka <[email protected]>

commit 09a00abe3a9941c2715ca83eb88172cd2f54d8fd upstream.

We must use kzalloc when allocating the fb_deferred_io structure. Otherwise, the field first_io is undefined and it causes a crash.

---
 drivers/gpu/drm/udl/udl_fb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/udl/udl_fb.c +1 -1
@@ -344,7 +344,7 @@ static int udl_fb_open(struct fb_info *i
 
 		struct fb_deferred_io *fbdefio;
 
-		fbdefio = kmalloc(sizeof(struct fb_deferred_io), GFP_KERNEL);
+		fbdefio = kzalloc(sizeof(struct fb_deferred_io), GFP_KERNEL);
 
 		if (fbdefio) {
 			fbdefio->delay = DL_DEFIO_WRITE_DELAY;
#93 lore raw

PATCH 89/328 ath10k: prevent active scans on potential unusable channels

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Sven Eckelmann <[email protected]>

commit 3f259111583801013cb605bb4414aa529adccf1c upstream.

The QCA4019 hw1.0 firmware 10.4-3.2.1-00050 and 10.4-3.5.3-00053 (and most likely all other) seem to ignore the WMI_CHAN_FLAG_DFS flag during the scan. This results in transmission (probe requests) on channels which are not "available" for transmissions.

Since the firmware is closed source and nothing can be done from our side to fix the problem in it, the driver has to work around this problem. The WMI_CHAN_FLAG_PASSIVE seems to be interpreted by the firmware to not scan actively on a channel unless an AP was detected on it. Simple probe requests will then be transmitted by the STA on the channel.

ath10k must therefore also use this flag when it queues a radar channel for scanning. This should reduce the chance of an active scan when the channel might be "unusable" for transmissions.

Fixes e8a50f8ba44b ("ath10k: introduce DFS implementation")
---
 drivers/net/wireless/ath/ath10k/mac.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/wireless/ath/ath10k/mac.c +7 -0
@@ -1724,6 +1724,13 @@ static int ath10k_update_channel_list(st
 			passive = channel->flags & IEEE80211_CHAN_NO_IR;
 			ch->passive = passive;
 
+			/* the firmware is ignoring the "radar" flag of the
+			 * channel and is scanning actively using Probe Requests
+			 * on "Radar detection"/DFS channels which are not
+			 * marked as "available"
+			 */
+			ch->passive |= ch->chan_radar;
+
 			ch->freq = channel->center_freq;
 			ch->min_power = 0;
 			ch->max_power = channel->max_power * 2;
#94 lore raw

PATCH 90/328 ext4: check for NUL characters in extended attribute's name

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Theodore Ts'o <[email protected]>

commit 7d95178c77014dbd8dce36ee40bbbc5e6c121ff5 upstream.

Extended attribute names are defined to be NUL-terminated, so the name must not contain a NUL character. This is important because there are places when remove extended attribute, the code uses strlen to determine the length of the entry. That should probably be fixed at some point, but code is currently really messy, so the simplest fix for now is to simply validate that the extended attributes are sane.

https://bugzilla.kernel.org/show_bug.cgi?id=200401

[bwh: Backported to 3.16: return -EIO instead of -EFSCORRUPTED]
---
 fs/ext4/xattr.c | 2 ++
 1 file changed, 2 insertions(+)
fs/ext4/xattr.c +2 -0
@@ -193,6 +193,8 @@ ext4_xattr_check_names(struct ext4_xattr
 		struct ext4_xattr_entry *next = EXT4_XATTR_NEXT(e);
 		if ((void *)next >= end)
 			return -EIO;
+		if (strnlen(e->e_name, e->e_name_len) != e->e_name_len)
+			return -EIO;
 		e = next;
 	}
 
#95 lore raw

PATCH 91/328 tracing: Do not call start/stop() functions when tracing_on does not change

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: "Steven Rostedt (VMware)" <[email protected]>

commit f143641bfef9a4a60c57af30de26c63057e7e695 upstream.

Currently, when one echo's in 1 into tracing_on, the current tracer's "start()" function is executed, even if tracing_on was already one. This can lead to strange side effects. One being that if the hwlat tracer is enabled, and someone does "echo 1 > tracing_on" into tracing_on, the hwlat tracer's start() function is called again which will recreate another kernel thread, and make it unable to remove the old one.

Fixes 2df8f8a6a897e ("tracing: Fix regression with irqsoff tracer and tracing_on file")
---
 kernel/trace/trace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/trace/trace.c +3 -1
@@ -6180,7 +6180,9 @@ rb_simple_write(struct file *filp, const
 
 	if (buffer) {
 		mutex_lock(&trace_types_lock);
-		if (val) {
+		if (!!val == tracer_tracing_is_on(tr)) {
+			val = 0; /* do nothing */
+		} else if (val) {
 			tracer_tracing_on(tr);
 			if (tr->current_trace->start)
 				tr->current_trace->start(tr);
#96 lore raw

PATCH 93/328 ext4: fix spectre gadget in ext4_mb_regular_allocator()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Jeremy Cline <[email protected]>

commit 1a5d5e5d51e75a5bca67dadbcea8c841934b7b85 upstream.

'ac->ac_g_ex.fe_len' is a user-controlled value which is used in the derivation of 'ac->ac_2order'. 'ac->ac_2order', in turn, is used to index arrays which makes it a potential spectre gadget. Fix this by sanitizing the value assigned to 'ac->ac2_order'. This covers the following accesses found with the help of smatch:

* fs/ext4/mballoc.c:1896 ext4_mb_simple_scan_group() warn: potential spectre issue 'grp->bb_counters' [w] (local cap)

* fs/ext4/mballoc.c:445 mb_find_buddy() warn: potential spectre issue 'EXT4_SB(e4b->bd_sb)->s_mb_offsets' [r] (local cap)

* fs/ext4/mballoc.c:446 mb_find_buddy() warn: potential spectre issue 'EXT4_SB(e4b->bd_sb)->s_mb_maxs' [r] (local cap)

[bwh: Backported to 3.16: adjust context]
---
 fs/ext4/mballoc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ext4/mballoc.c +3 -1
@@ -26,6 +26,7 @@
 #include <linux/log2.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/nospec.h>
 #include <trace/events/ext4.h>
 
 #ifdef CONFIG_EXT4_DEBUG
@@ -2124,7 +2125,8 @@ ext4_mb_regular_allocator(struct ext4_al
 		 * This should tell if fe_len is exactly power of 2
 		 */
 		if ((ac->ac_g_ex.fe_len & (~(1 << (i - 1)))) == 0)
-			ac->ac_2order = i - 1;
+			ac->ac_2order = array_index_nospec(i - 1,
+							   sb->s_blocksize_bits + 2);
 	}
 
 	/* if stream allocation is enabled, use global goal */
#97 lore raw

PATCH 94/328 IB/IPoIB: Set ah valid flag in multicast send flow

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Denis Drozdov <[email protected]>

commit 75da96067ade4e7854379ec2f7834f3497652b1a upstream.

The change of ipoib_ah data structure with adding "valid" flag and checks of ah->valid in ipoib_start_xmit affected multicast packet flow.

Since the multicast flow doesn't invoke path_rec_start, "ah->valid" flag remains unset, so that ipoib_start_xmit end up with neigh_refresh_path instead of sending the packet using neigh.

"ah->valid" has to be set in multicast send flow. As a result IPoIB starts sending packets via neigh immediately and eliminates 60sec delay of neigh keep alive interval.

The typical example of this issue are two sequential arpings:

arping 11.134.208.9 -> got response (mcast_send) arping 11.134.208.9 -> no response (ah->valid = 0)

Fixes fa9391dbad4b ("RDMA/ipoib: Update paths on CLIENT_REREG/SM_CHANGE events")
---
 drivers/infiniband/ulp/ipoib/ipoib_multicast.c | 1 +
 1 file changed, 1 insertion(+)
drivers/infiniband/ulp/ipoib/ipoib_multicast.c +1 -0
@@ -734,6 +734,7 @@ out:
 			if (neigh && list_empty(&neigh->list)) {
 				kref_get(&mcast->ah->ref);
 				neigh->ah	= mcast->ah;
+				neigh->ah->valid = 1;
 				list_add_tail(&neigh->list, &mcast->neigh_list);
 			}
 		}
#98 lore raw

PATCH 95/328 uio: potential double frees if __uio_register_device() fails

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dan Carpenter <[email protected]>

commit f019f07ecf6a6b8bd6d7853bce70925d90af02d1 upstream.

The uio_unregister_device() function assumes that if "info->uio_dev" is non-NULL that means "info" is fully allocated. Setting info->uio_de has to be the last thing in the function.

In the current code, if request_threaded_irq() fails then we return with info->uio_dev set to non-NULL but info is not fully allocated and it can lead to double frees.

Fixes beafc54c4e2f ("UIO: Add the User IO core code")
---
 drivers/uio/uio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/uio/uio.c +1 -2
@@ -852,8 +852,6 @@ int __uio_register_device(struct module
 	if (ret)
 		goto err_uio_dev_add_attributes;
 
-	info->uio_dev = idev;
-
 	if (info->irq && (info->irq != UIO_IRQ_CUSTOM)) {
 		ret = devm_request_irq(idev->dev, info->irq, uio_interrupt,
 				  info->irq_flags, info->name, idev);
@@ -861,6 +859,7 @@ int __uio_register_device(struct module
 			goto err_request_irq;
 	}
 
+	info->uio_dev = idev;
 	return 0;
 
 err_request_irq:
#99 lore raw

PATCH 96/328 scsi: sysfs: Introduce sysfs_{un,}break_active_protection()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Bart Van Assche <[email protected]>

commit 2afc9166f79b8f6da5f347f48515215ceee4ae37 upstream.

Introduce these two functions and export them such that the next patch can add calls to these functions from the SCSI core.

---
 fs/sysfs/file.c       | 44 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/sysfs.h | 14 ++++++++++++++
 2 files changed, 58 insertions(+)
fs/sysfs/file.c +44 -0
@@ -357,6 +357,50 @@ int sysfs_chmod_file(struct kobject *kob
 EXPORT_SYMBOL_GPL(sysfs_chmod_file);
 
 /**
+ * sysfs_break_active_protection - break "active" protection
+ * @kobj: The kernel object @attr is associated with.
+ * @attr: The attribute to break the "active" protection for.
+ *
+ * With sysfs, just like kernfs, deletion of an attribute is postponed until
+ * all active .show() and .store() callbacks have finished unless this function
+ * is called. Hence this function is useful in methods that implement self
+ * deletion.
+ */
+struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
+						  const struct attribute *attr)
+{
+	struct kernfs_node *kn;
+
+	kobject_get(kobj);
+	kn = kernfs_find_and_get(kobj->sd, attr->name);
+	if (kn)
+		kernfs_break_active_protection(kn);
+	return kn;
+}
+EXPORT_SYMBOL_GPL(sysfs_break_active_protection);
+
+/**
+ * sysfs_unbreak_active_protection - restore "active" protection
+ * @kn: Pointer returned by sysfs_break_active_protection().
+ *
+ * Undo the effects of sysfs_break_active_protection(). Since this function
+ * calls kernfs_put() on the kernfs node that corresponds to the 'attr'
+ * argument passed to sysfs_break_active_protection() that attribute may have
+ * been removed between the sysfs_break_active_protection() and
+ * sysfs_unbreak_active_protection() calls, it is not safe to access @kn after
+ * this function has returned.
+ */
+void sysfs_unbreak_active_protection(struct kernfs_node *kn)
+{
+	struct kobject *kobj = kn->parent->priv;
+
+	kernfs_unbreak_active_protection(kn);
+	kernfs_put(kn);
+	kobject_put(kobj);
+}
+EXPORT_SYMBOL_GPL(sysfs_unbreak_active_protection);
+
+/**
  * sysfs_remove_file_ns - remove an object attribute with a custom ns tag
  * @kobj: object we're acting for
  * @attr: attribute descriptor
include/linux/sysfs.h +14 -0
@@ -204,6 +204,9 @@ int __must_check sysfs_create_files(stru
 				   const struct attribute **attr);
 int __must_check sysfs_chmod_file(struct kobject *kobj,
 				  const struct attribute *attr, umode_t mode);
+struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
+						  const struct attribute *attr);
+void sysfs_unbreak_active_protection(struct kernfs_node *kn);
 void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
 			  const void *ns);
 bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr);
@@ -314,6 +317,17 @@ static inline int sysfs_chmod_file(struc
 	return 0;
 }
 
+static inline struct kernfs_node *
+sysfs_break_active_protection(struct kobject *kobj,
+			      const struct attribute *attr)
+{
+	return NULL;
+}
+
+static inline void sysfs_unbreak_active_protection(struct kernfs_node *kn)
+{
+}
+
 static inline void sysfs_remove_file_ns(struct kobject *kobj,
 					const struct attribute *attr,
 					const void *ns)
#100 lore raw

PATCH 97/328 scsi: core: Avoid that SCSI device removal through sysfs triggers a deadlock

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Bart Van Assche <[email protected]>

commit 0ee223b2e1f67cb2de9c0e3247c510d846e74d63 upstream.

A long time ago the unfortunate decision was taken to add a self-deletion attribute to the sysfs SCSI device directory. That decision was unfortunate because self-deletion is really tricky. We can't drop that attribute because widely used user space software depends on it, namely the rescan-scsi-bus.sh script. Hence this patch that avoids that writing into that attribute triggers a deadlock. See also commit 7973cbd9fbd9 ("[PATCH] add sysfs attributes to scan and delete scsi_devices").

This patch avoids that self-removal triggers the following deadlock:

======================================================
WARNING: possible circular locking dependency detected 4.18.0-rc2-dbg+ #5 Not tainted
------------------------------------------------------
modprobe/6539 is trying to acquire lock:
000000008323c4cd (kn->count#202){++++}, at: kernfs_remove_by_name_ns+0x45/0x90

but task is already holding lock:
00000000a6ec2c69 (&shost->scan_mutex){+.+.}, at: scsi_remove_host+0x21/0x150 [scsi_mod]

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #1 (&shost->scan_mutex){+.+.}:

       __mutex_lock+0xfe/0xc70
       mutex_lock_nested+0x1b/0x20
       scsi_remove_device+0x26/0x40 [scsi_mod]
       sdev_store_delete+0x27/0x30 [scsi_mod]
       dev_attr_store+0x3e/0x50
       sysfs_kf_write+0x87/0xa0
       kernfs_fop_write+0x190/0x230
       __vfs_write+0xd2/0x3b0
       vfs_write+0x101/0x270
       ksys_write+0xab/0x120
       __x64_sys_write+0x43/0x50
       do_syscall_64+0x77/0x230
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> #0 (kn->count#202){++++}:

       lock_acquire+0xd2/0x260
       __kernfs_remove+0x424/0x4a0
       kernfs_remove_by_name_ns+0x45/0x90
       remove_files.isra.1+0x3a/0x90
       sysfs_remove_group+0x5c/0xc0
       sysfs_remove_groups+0x39/0x60
       device_remove_attrs+0x82/0xb0
       device_del+0x251/0x580
       __scsi_remove_device+0x19f/0x1d0 [scsi_mod]
       scsi_forget_host+0x37/0xb0 [scsi_mod]
       scsi_remove_host+0x9b/0x150 [scsi_mod]
       sdebug_driver_remove+0x4b/0x150 [scsi_debug]
       device_release_driver_internal+0x241/0x360
       device_release_driver+0x12/0x20
       bus_remove_device+0x1bc/0x290
       device_del+0x259/0x580
       device_unregister+0x1a/0x70
       sdebug_remove_adapter+0x8b/0xf0 [scsi_debug]
       scsi_debug_exit+0x76/0xe8 [scsi_debug]
       __x64_sys_delete_module+0x1c1/0x280
       do_syscall_64+0x77/0x230
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

other info that might help us debug this:

 Possible unsafe locking scenario:
       CPU0                    CPU1
       ----                    ----
  lock(&shost->scan_mutex);
                               lock(kn->count#202);
                               lock(&shost->scan_mutex);

lock(kn->count#202);

*** DEADLOCK ***

2 locks held by modprobe/6539:
#0: 00000000efaf9298 (&dev->mutex){....}, at: device_release_driver_internal+0x68/0x360 #1: 00000000a6ec2c69 (&shost->scan_mutex){+.+.}, at: scsi_remove_host+0x21/0x150 [scsi_mod]

stack backtrace:
CPU: 10 PID: 6539 Comm: modprobe Not tainted 4.18.0-rc2-dbg+ #5
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014
Call Trace:
 dump_stack+0xa4/0xf5
 print_circular_bug.isra.34+0x213/0x221
 __lock_acquire+0x1a7e/0x1b50
 lock_acquire+0xd2/0x260
 __kernfs_remove+0x424/0x4a0
 kernfs_remove_by_name_ns+0x45/0x90
 remove_files.isra.1+0x3a/0x90
 sysfs_remove_group+0x5c/0xc0
 sysfs_remove_groups+0x39/0x60
 device_remove_attrs+0x82/0xb0
 device_del+0x251/0x580
 __scsi_remove_device+0x19f/0x1d0 [scsi_mod]
 scsi_forget_host+0x37/0xb0 [scsi_mod]
 scsi_remove_host+0x9b/0x150 [scsi_mod]
 sdebug_driver_remove+0x4b/0x150 [scsi_debug]
 device_release_driver_internal+0x241/0x360
 device_release_driver+0x12/0x20
 bus_remove_device+0x1bc/0x290
 device_del+0x259/0x580
 device_unregister+0x1a/0x70
 sdebug_remove_adapter+0x8b/0xf0 [scsi_debug]
 scsi_debug_exit+0x76/0xe8 [scsi_debug]
 __x64_sys_delete_module+0x1c1/0x280
 do_syscall_64+0x77/0x230
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

See also https://www.mail-archive.com/[email protected]/msg54525.html.

Fixes ac0ece9174ac ("scsi: use device_remove_file_self() instead of device_schedule_callback()")
Cc Greg Kroah-Hartman <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
 drivers/scsi/scsi_sysfs.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/scsi/scsi_sysfs.c +18 -2
@@ -651,8 +651,24 @@ static ssize_t
 sdev_store_delete(struct device *dev, struct device_attribute *attr,
 		  const char *buf, size_t count)
 {
-	if (device_remove_file_self(dev, attr))
-		scsi_remove_device(to_scsi_device(dev));
+	struct kernfs_node *kn;
+
+	kn = sysfs_break_active_protection(&dev->kobj, &attr->attr);
+	WARN_ON_ONCE(!kn);
+	/*
+	 * Concurrent writes into the "delete" sysfs attribute may trigger
+	 * concurrent calls to device_remove_file() and scsi_remove_device().
+	 * device_remove_file() handles concurrent removal calls by
+	 * serializing these and by ignoring the second and later removal
+	 * attempts.  Concurrent calls of scsi_remove_device() are
+	 * serialized. The second and later calls of scsi_remove_device() are
+	 * ignored because the first call of that function changes the device
+	 * state into SDEV_DEL.
+	 */
+	device_remove_file(dev, attr);
+	scsi_remove_device(to_scsi_device(dev));
+	if (kn)
+		sysfs_unbreak_active_protection(kn);
 	return count;
 };
 static DEVICE_ATTR(delete, S_IWUSR, NULL, sdev_store_delete);
#101 lore raw

PATCH 98/328 xfrm: Validate address prefix lengths in the xfrm selector.

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Steffen Klassert <[email protected]>

commit 07bf7908950a8b14e81aa1807e3c667eab39287a upstream.

We don't validate the address prefix lengths in the xfrm selector we got from userspace. This can lead to undefined behaviour in the address matching functions if the prefix is too big for the given address family. Fix this by checking the prefixes and refuse SA/policy insertation when a prefix is invalid.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/xfrm/xfrm_user.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
net/xfrm/xfrm_user.c +12 -0
@@ -150,10 +150,16 @@ static int verify_newsa_info(struct xfrm
 	err = -EINVAL;
 	switch (p->family) {
 	case AF_INET:
+		if (p->sel.prefixlen_d > 32 || p->sel.prefixlen_s > 32)
+			goto out;
+
 		break;
 
 	case AF_INET6:
 #if IS_ENABLED(CONFIG_IPV6)
+		if (p->sel.prefixlen_d > 128 || p->sel.prefixlen_s > 128)
+			goto out;
+
 		break;
 #else
 		err = -EAFNOSUPPORT;
@@ -1227,10 +1233,16 @@ static int verify_newpolicy_info(struct
 
 	switch (p->sel.family) {
 	case AF_INET:
+		if (p->sel.prefixlen_d > 32 || p->sel.prefixlen_s > 32)
+			return -EINVAL;
+
 		break;
 
 	case AF_INET6:
 #if IS_ENABLED(CONFIG_IPV6)
+		if (p->sel.prefixlen_d > 128 || p->sel.prefixlen_s > 128)
+			return -EINVAL;
+
 		break;
 #else
 		return  -EAFNOSUPPORT;
#102 lore raw

PATCH 99/328 crypto: blkcipher - fix crash flushing dcache in error path

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Eric Biggers <[email protected]>

commit 0868def3e4100591e7a1fdbf3eed1439cc8f7ca3 upstream.

Like the skcipher_walk case:

scatterwalk_done() is only meant to be called after a nonzero number of bytes have been processed, since scatterwalk_pagedone() will flush the dcache of the *previous* page. But in the error case of blkcipher_walk_done(), e.g. if the input wasn't an integer number of blocks, scatterwalk_done() was actually called after advancing 0 bytes. This caused a crash ("BUG: unable to handle kernel paging request") during '!PageSlab(page)' on architectures like arm and arm64 that define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE, provided that the input was page-aligned as in that case walk->offset == 0.

Fix it by reorganizing blkcipher_walk_done() to skip the scatterwalk_advance() and scatterwalk_done() if an error has occurred.

This bug was found by syzkaller fuzzing.

Reproducer, assuming ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE:

	#include <linux/if_alg.h>
	#include <sys/socket.h>
	#include <unistd.h>

	int main()
	{
		struct sockaddr_alg addr = {
			.salg_type = "skcipher",
			.salg_name = "ecb(aes-generic)",
		};
		char buffer[4096] __attribute__((aligned(4096))) = { 0 };
		int fd;

		fd = socket(AF_ALG, SOCK_SEQPACKET, 0);
		bind(fd, (void *)&addr, sizeof(addr));
		setsockopt(fd, SOL_ALG, ALG_SET_KEY, buffer, 16);
		fd = accept(fd, NULL, NULL);
		write(fd, buffer, 15);
		read(fd, buffer, 15);
	}
Fixes 5cde0af2a982 ("[CRYPTO] cipher: Added block cipher type")
---
 crypto/blkcipher.c | 54 ++++++++++++++++++++++------------------------
 1 file changed, 26 insertions(+), 28 deletions(-)
crypto/blkcipher.c +26 -28
@@ -70,19 +70,18 @@ static inline u8 *blkcipher_get_spot(u8
 	return max(start, end_page);
 }
 
-static inline unsigned int blkcipher_done_slow(struct blkcipher_walk *walk,
-					       unsigned int bsize)
+static inline void blkcipher_done_slow(struct blkcipher_walk *walk,
+				       unsigned int bsize)
 {
 	u8 *addr;
 
 	addr = (u8 *)ALIGN((unsigned long)walk->buffer, walk->alignmask + 1);
 	addr = blkcipher_get_spot(addr, bsize);
 	scatterwalk_copychunks(addr, &walk->out, bsize, 1);
-	return bsize;
 }
 
-static inline unsigned int blkcipher_done_fast(struct blkcipher_walk *walk,
-					       unsigned int n)
+static inline void blkcipher_done_fast(struct blkcipher_walk *walk,
+				       unsigned int n)
 {
 	if (walk->flags & BLKCIPHER_WALK_COPY) {
 		blkcipher_map_dst(walk);
@@ -96,49 +95,48 @@ static inline unsigned int blkcipher_don
 
 	scatterwalk_advance(&walk->in, n);
 	scatterwalk_advance(&walk->out, n);
-
-	return n;
 }
 
 int blkcipher_walk_done(struct blkcipher_desc *desc,
 			struct blkcipher_walk *walk, int err)
 {
-	unsigned int nbytes = 0;
+	unsigned int n; /* bytes processed */
+	bool more;
 
-	if (likely(err >= 0)) {
-		unsigned int n = walk->nbytes - err;
+	if (unlikely(err < 0))
+		goto finish;
 
-		if (likely(!(walk->flags & BLKCIPHER_WALK_SLOW)))
-			n = blkcipher_done_fast(walk, n);
-		else if (WARN_ON(err)) {
+	n = walk->nbytes - err;
+	walk->total -= n;
+	more = (walk->total != 0);
+
+	if (likely(!(walk->flags & BLKCIPHER_WALK_SLOW))) {
+		blkcipher_done_fast(walk, n);
+	} else {
+		if (WARN_ON(err)) {
+			/* unexpected case; didn't process all bytes */
 			err = -EINVAL;
-			goto err;
-		} else
-			n = blkcipher_done_slow(walk, n);
-
-		nbytes = walk->total - n;
-		err = 0;
+			goto finish;
+		}
+		blkcipher_done_slow(walk, n);
 	}
 
-	scatterwalk_done(&walk->in, 0, nbytes);
-	scatterwalk_done(&walk->out, 1, nbytes);
-
-err:
-	walk->total = nbytes;
-	walk->nbytes = nbytes;
+	scatterwalk_done(&walk->in, 0, more);
+	scatterwalk_done(&walk->out, 1, more);
 
-	if (nbytes) {
+	if (more) {
 		crypto_yield(desc->flags);
 		return blkcipher_walk_next(desc, walk);
 	}
-
+	err = 0;
+finish:
+	walk->nbytes = 0;
 	if (walk->iv != desc->info)
 		memcpy(desc->info, walk->iv, walk->ivsize);
 	if (walk->buffer != walk->page)
 		kfree(walk->buffer);
 	if (walk->page)
 		free_page((unsigned long)walk->page);
-
 	return err;
 }
 EXPORT_SYMBOL_GPL(blkcipher_walk_done);
#103 lore raw

PATCH 100/328 crypto: ablkcipher - fix crash flushing dcache in error path

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Eric Biggers <[email protected]>

commit 318abdfbe708aaaa652c79fb500e9bd60521f9dc upstream.

Like the skcipher_walk and blkcipher_walk cases:

scatterwalk_done() is only meant to be called after a nonzero number of bytes have been processed, since scatterwalk_pagedone() will flush the dcache of the *previous* page. But in the error case of ablkcipher_walk_done(), e.g. if the input wasn't an integer number of blocks, scatterwalk_done() was actually called after advancing 0 bytes. This caused a crash ("BUG: unable to handle kernel paging request") during '!PageSlab(page)' on architectures like arm and arm64 that define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE, provided that the input was page-aligned as in that case walk->offset == 0.

Fix it by reorganizing ablkcipher_walk_done() to skip the scatterwalk_advance() and scatterwalk_done() if an error has occurred.

Fixes bf06099db18a ("crypto: skcipher - Add ablkcipher_walk interfaces")
---
 crypto/ablkcipher.c | 57 +++++++++++++++++++++------------------------
 1 file changed, 26 insertions(+), 31 deletions(-)
crypto/ablkcipher.c +26 -31
@@ -72,11 +72,9 @@ static inline u8 *ablkcipher_get_spot(u8
 	return max(start, end_page);
 }
 
-static inline unsigned int ablkcipher_done_slow(struct ablkcipher_walk *walk,
-						unsigned int bsize)
+static inline void ablkcipher_done_slow(struct ablkcipher_walk *walk,
+					unsigned int n)
 {
-	unsigned int n = bsize;
-
 	for (;;) {
 		unsigned int len_this_page = scatterwalk_pagelen(&walk->out);
 
@@ -88,17 +86,13 @@ static inline unsigned int ablkcipher_do
 		n -= len_this_page;
 		scatterwalk_start(&walk->out, scatterwalk_sg_next(walk->out.sg));
 	}
-
-	return bsize;
 }
 
-static inline unsigned int ablkcipher_done_fast(struct ablkcipher_walk *walk,
-						unsigned int n)
+static inline void ablkcipher_done_fast(struct ablkcipher_walk *walk,
+					unsigned int n)
 {
 	scatterwalk_advance(&walk->in, n);
 	scatterwalk_advance(&walk->out, n);
-
-	return n;
 }
 
 static int ablkcipher_walk_next(struct ablkcipher_request *req,
@@ -108,39 +102,40 @@ int ablkcipher_walk_done(struct ablkciph
 			 struct ablkcipher_walk *walk, int err)
 {
 	struct crypto_tfm *tfm = req->base.tfm;
-	unsigned int nbytes = 0;
+	unsigned int n; /* bytes processed */
+	bool more;
 
-	if (likely(err >= 0)) {
-		unsigned int n = walk->nbytes - err;
+	if (unlikely(err < 0))
+		goto finish;
 
-		if (likely(!(walk->flags & ABLKCIPHER_WALK_SLOW)))
-			n = ablkcipher_done_fast(walk, n);
-		else if (WARN_ON(err)) {
+	n = walk->nbytes - err;
+	walk->total -= n;
+	more = (walk->total != 0);
+
+	if (likely(!(walk->flags & ABLKCIPHER_WALK_SLOW))) {
+		ablkcipher_done_fast(walk, n);
+	} else {
+		if (WARN_ON(err)) {
+			/* unexpected case; didn't process all bytes */
 			err = -EINVAL;
-			goto err;
-		} else
-			n = ablkcipher_done_slow(walk, n);
-
-		nbytes = walk->total - n;
-		err = 0;
+			goto finish;
+		}
+		ablkcipher_done_slow(walk, n);
 	}
 
-	scatterwalk_done(&walk->in, 0, nbytes);
-	scatterwalk_done(&walk->out, 1, nbytes);
+	scatterwalk_done(&walk->in, 0, more);
+	scatterwalk_done(&walk->out, 1, more);
 
-err:
-	walk->total = nbytes;
-	walk->nbytes = nbytes;
-
-	if (nbytes) {
+	if (more) {
 		crypto_yield(req->base.flags);
 		return ablkcipher_walk_next(req, walk);
 	}
-
+	err = 0;
+finish:
+	walk->nbytes = 0;
 	if (walk->iv != req->info)
 		memcpy(req->info, walk->iv, tfm->crt_ablkcipher.ivsize);
 	kfree(walk->iv_buffer);
-
 	return err;
 }
 EXPORT_SYMBOL_GPL(ablkcipher_walk_done);
#104 lore raw

PATCH 101/328 pinctrl: berlin: fix 'pctrl->functions' allocation in berlin_pinctrl_build_state

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: YueHaibing <[email protected]>

commit b5031b7db77dc47f474f0efc2b2552c32b7bb59d upstream.

fixes following Smatch static check warning:

drivers/pinctrl/berlin/berlin.c:237 berlin_pinctrl_build_state()
warn: passing devm_ allocated variable to kfree. 'pctrl->functions'

As we will be calling krealloc() on pointer 'pctrl->functions', which means kfree() will be called in there, devm_kzalloc() shouldn't be used with the allocation in the first place. Fix the warning by calling kcalloc() and managing the free procedure in error path on our own.

Fixes 3de68d331c24 ("pinctrl: berlin: add the core pinctrl driver for Marvell Berlin SoCs")

[bwh: Backported to 3.16: berlin_pinctrl_state() was not yet converted
to devm_kcalloc()]

---
 drivers/pinctrl/berlin/berlin.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/pinctrl/berlin/berlin.c +8 -5
@@ -237,9 +237,8 @@ static int berlin_pinctrl_build_state(st
 	}
 
 	/* we will reallocate later */
-	pctrl->functions = devm_kzalloc(&pdev->dev,
-					max_functions * sizeof(*pctrl->functions),
-					GFP_KERNEL);
+	pctrl->functions = kcalloc(max_functions,
+				   sizeof(*pctrl->functions), GFP_KERNEL);
 	if (!pctrl->functions)
 		return -ENOMEM;
 
@@ -277,8 +276,10 @@ static int berlin_pinctrl_build_state(st
 				function++;
 			}
 
-			if (!found)
+			if (!found) {
+				kfree(pctrl->functions);
 				return -EINVAL;
+			}
 
 			if (!function->groups) {
 				function->groups =
@@ -286,8 +287,10 @@ static int berlin_pinctrl_build_state(st
 						     function->ngroups * sizeof(char *),
 						     GFP_KERNEL);
 
-				if (!function->groups)
+				if (!function->groups) {
+					kfree(pctrl->functions);
 					return -ENOMEM;
+				}
 			}
 
 			groups = function->groups;
#105 lore raw

PATCH 102/328 ieee802154: 6lowpan: ensure header compression does not corrupt ipv6 header

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Simon Vincent <[email protected]>

commit f19f4f9525cf32f97341fac20ce66392e86a1b67 upstream.

The 6lowpan ipv6 header compression was causing problems for other interfaces that expected a ipv6 header to still be in place, as we were replacing the ipv6 header with a compressed version. This happened if you sent a packet to a multicast address as the packet would be output on 802.15.4, ethernet, and also be sent to the loopback interface. The skb data was shared between these interfaces so all interfaces ended up with a compressed ipv6 header.

The solution is to ensure that before we do any header compression we are not sharing the skb or skb data with any other interface. If we are then we must take a copy of the skb and skb data before modifying the ipv6 header. The only place we can copy the skb is inside the xmit function so we don't leave dangling references to skb.

This patch moves all the header compression to inside the xmit function. Very little code has been changed it has mostly been moved from lowpan_header_create to lowpan_xmit. At the top of the xmit function we now check if the skb is shared and if so copy it. In lowpan_header_create all we do now is store the source and destination addresses for use later when we compress the header.

---
 net/ieee802154/6lowpan_rtnl.c | 125 ++++++++++++++++++++++++----------
 1 file changed, 89 insertions(+), 36 deletions(-)
net/ieee802154/6lowpan_rtnl.c +89 -36
@@ -71,6 +71,21 @@ struct lowpan_dev_record {
 	struct list_head list;
 };
 
+/* don't save pan id, it's intra pan */
+struct lowpan_addr {
+	u8 mode;
+	union {
+		/* IPv6 needs big endian here */
+		__be64 extended_addr;
+		__be16 short_addr;
+	} u;
+};
+
+struct lowpan_addr_info {
+	struct lowpan_addr daddr;
+	struct lowpan_addr saddr;
+};
+
 static inline struct
 lowpan_dev_info *lowpan_dev_info(const struct net_device *dev)
 {
@@ -84,6 +99,14 @@ static inline void lowpan_address_flip(u
 		(dest)[IEEE802154_ADDR_LEN - i - 1] = (src)[i];
 }
 
+static inline struct
+lowpan_addr_info *lowpan_skb_priv(const struct sk_buff *skb)
+{
+	WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct lowpan_addr_info));
+	return (struct lowpan_addr_info *)(skb->data -
+			sizeof(struct lowpan_addr_info));
+}
+
 static int lowpan_header_create(struct sk_buff *skb,
 			   struct net_device *dev,
 			   unsigned short type, const void *_daddr,
@@ -91,8 +114,7 @@ static int lowpan_header_create(struct s
 {
 	const u8 *saddr = _saddr;
 	const u8 *daddr = _daddr;
-	struct ieee802154_addr sa, da;
-	struct ieee802154_mac_cb *cb = mac_cb_init(skb);
+	struct lowpan_addr_info *info;
 
 	/* TODO:
 	 * if this package isn't ipv6 one, where should it be routed?
@@ -106,41 +128,17 @@ static int lowpan_header_create(struct s
 	raw_dump_inline(__func__, "saddr", (unsigned char *)saddr, 8);
 	raw_dump_inline(__func__, "daddr", (unsigned char *)daddr, 8);
 
-	lowpan_header_compress(skb, dev, type, daddr, saddr, len);
-
-	/* NOTE1: I'm still unsure about the fact that compression and WPAN
-	 * header are created here and not later in the xmit. So wait for
-	 * an opinion of net maintainers.
-	 */
-	/* NOTE2: to be absolutely correct, we must derive PANid information
-	 * from MAC subif of the 'dev' and 'real_dev' network devices, but
-	 * this isn't implemented in mainline yet, so currently we assign 0xff
-	 */
-	cb->type = IEEE802154_FC_TYPE_DATA;
+	info = lowpan_skb_priv(skb);
 
-	/* prepare wpan address data */
-	sa.mode = IEEE802154_ADDR_LONG;
-	sa.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
-	sa.extended_addr = ieee802154_devaddr_from_raw(saddr);
+	/* TODO: Currently we only support extended_addr */
+	info->daddr.mode = IEEE802154_ADDR_LONG;
+	memcpy(&info->daddr.u.extended_addr, daddr,
+	       sizeof(info->daddr.u.extended_addr));
+	info->saddr.mode = IEEE802154_ADDR_LONG;
+	memcpy(&info->saddr.u.extended_addr, saddr,
+	       sizeof(info->daddr.u.extended_addr));
 
-	/* intra-PAN communications */
-	da.pan_id = sa.pan_id;
-
-	/* if the destination address is the broadcast address, use the
-	 * corresponding short address
-	 */
-	if (lowpan_is_addr_broadcast(daddr)) {
-		da.mode = IEEE802154_ADDR_SHORT;
-		da.short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
-	} else {
-		da.mode = IEEE802154_ADDR_LONG;
-		da.extended_addr = ieee802154_devaddr_from_raw(daddr);
-	}
-
-	cb->ackreq = !lowpan_is_addr_broadcast(daddr);
-
-	return dev_hard_header(skb, lowpan_dev_info(dev)->real_dev,
-			type, (void *)&da, (void *)&sa, 0);
+	return 0;
 }
 
 static int lowpan_give_skb_to_devices(struct sk_buff *skb,
@@ -338,13 +336,68 @@ err:
 	return rc;
 }
 
+static int lowpan_header(struct sk_buff *skb, struct net_device *dev)
+{
+	struct ieee802154_addr sa, da;
+	struct ieee802154_mac_cb *cb = mac_cb_init(skb);
+	struct lowpan_addr_info info;
+	void *daddr, *saddr;
+
+	memcpy(&info, lowpan_skb_priv(skb), sizeof(info));
+
+	/* TODO: Currently we only support extended_addr */
+	daddr = &info.daddr.u.extended_addr;
+	saddr = &info.saddr.u.extended_addr;
+
+	lowpan_header_compress(skb, dev, ETH_P_IPV6, daddr, saddr, skb->len);
+
+	cb->type = IEEE802154_FC_TYPE_DATA;
+
+	/* prepare wpan address data */
+	sa.mode = IEEE802154_ADDR_LONG;
+	sa.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
+	sa.extended_addr = ieee802154_devaddr_from_raw(saddr);
+
+	/* intra-PAN communications */
+	da.pan_id = sa.pan_id;
+
+	/* if the destination address is the broadcast address, use the
+	 * corresponding short address
+	 */
+	if (lowpan_is_addr_broadcast((const u8 *)daddr)) {
+		da.mode = IEEE802154_ADDR_SHORT;
+		da.short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
+		cb->ackreq = false;
+	} else {
+		da.mode = IEEE802154_ADDR_LONG;
+		da.extended_addr = ieee802154_devaddr_from_raw(daddr);
+		cb->ackreq = true;
+	}
+
+	return dev_hard_header(skb, lowpan_dev_info(dev)->real_dev,
+			ETH_P_IPV6, (void *)&da, (void *)&sa, 0);
+}
+
 static netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct ieee802154_hdr wpan_hdr;
-	int max_single;
+	int max_single, ret;
 
 	pr_debug("package xmit\n");
 
+	/* We must take a copy of the skb before we modify/replace the ipv6
+	 * header as the header could be used elsewhere
+	 */
+	skb = skb_unshare(skb, GFP_ATOMIC);
+	if (!skb)
+		return NET_XMIT_DROP;
+
+	ret = lowpan_header(skb, dev);
+	if (ret < 0) {
+		kfree_skb(skb);
+		return NET_XMIT_DROP;
+	}
+
 	if (ieee802154_hdr_peek(skb, &wpan_hdr) < 0) {
 		kfree_skb(skb);
 		return NET_XMIT_DROP;
#106 lore raw

PATCH 103/328 net: 6lowpan: fix reserved space for single frames

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Alexander Aring <[email protected]>

commit ac74f87c789af40936a80131c4759f3e72579c3a upstream.

This patch fixes patch add handling to take care tail and headroom for single 6lowpan frames. We need to be sure we have a skb with the right head and tailroom for single frames. This patch do it by using skb_copy_expand() if head and tailroom is not enough allocated by upper layer.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=195059

[bwh: Backported to 3.16:
- s/ldev/dev/
- Adjust filename]

---
 net/ieee802154/6lowpan_rtnl.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
net/ieee802154/6lowpan_rtnl.c +18 -3
@@ -388,9 +388,24 @@ static netdev_tx_t lowpan_xmit(struct sk
 	/* We must take a copy of the skb before we modify/replace the ipv6
 	 * header as the header could be used elsewhere
 	 */
-	skb = skb_unshare(skb, GFP_ATOMIC);
-	if (!skb)
-		return NET_XMIT_DROP;
+	if (unlikely(skb_headroom(skb) < dev->needed_headroom ||
+		     skb_tailroom(skb) < dev->needed_tailroom)) {
+		struct sk_buff *nskb;
+
+		nskb = skb_copy_expand(skb, dev->needed_headroom,
+				       dev->needed_tailroom, GFP_ATOMIC);
+		if (likely(nskb)) {
+			consume_skb(skb);
+			skb = nskb;
+		} else {
+			kfree_skb(skb);
+			return NET_XMIT_DROP;
+		}
+	} else {
+		skb = skb_unshare(skb, GFP_ATOMIC);
+		if (!skb)
+			return NET_XMIT_DROP;
+	}
 
 	ret = lowpan_header(skb, dev);
 	if (ret < 0) {
#107 lore raw

PATCH 104/328 mac802154: common tx error path

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Varka Bhadram <[email protected]>

commit f55889128a776b51581394b20abd0b470304cf95 upstream.

This patch introduce the common error path on failure of Tx by inserting the label 'err_tx'.

---
 net/mac802154/tx.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
net/mac802154/tx.c +8 -7
@@ -89,8 +89,7 @@ netdev_tx_t mac802154_tx(struct mac80215
 
 	if (!(priv->phy->channels_supported[page] & (1 << chan))) {
 		WARN_ON(1);
-		kfree_skb(skb);
-		return NETDEV_TX_OK;
+		goto err_tx;
 	}
 
 	mac802154_monitors_rx(mac802154_to_priv(&priv->hw), skb);
@@ -102,12 +101,10 @@ netdev_tx_t mac802154_tx(struct mac80215
 		data[1] = crc >> 8;
 	}
 
-	if (skb_cow_head(skb, priv->hw.extra_tx_headroom)) {
-		kfree_skb(skb);
-		return NETDEV_TX_OK;
-	}
+	if (skb_cow_head(skb, priv->hw.extra_tx_headroom))
+		goto err_tx;
 
-	work = kzalloc(sizeof(struct xmit_work), GFP_ATOMIC);
+	work = kzalloc(sizeof(*work), GFP_ATOMIC);
 	if (!work) {
 		kfree_skb(skb);
 		return NETDEV_TX_BUSY;
@@ -128,4 +125,8 @@ netdev_tx_t mac802154_tx(struct mac80215
 	queue_work(priv->dev_workqueue, &work->work);
 
 	return NETDEV_TX_OK;
+
+err_tx:
+	kfree_skb(skb);
+	return NETDEV_TX_OK;
 }
#108 lore raw

PATCH 105/328 mac802154: tx: cleanup crc calculation

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Alexander Aring <[email protected]>

commit b7eec52bcb7ab93a8cce0f718f42fa17d6d91745 upstream.

[bwh: Backported to 3.16: adjust context]

---

net/mac802154/tx.c +3 -4
@@ -95,10 +95,9 @@ netdev_tx_t mac802154_tx(struct mac80215
 	mac802154_monitors_rx(mac802154_to_priv(&priv->hw), skb);
 
 	if (!(priv->hw.flags & IEEE802154_HW_OMIT_CKSUM)) {
-		u16 crc = crc_ccitt(0, skb->data, skb->len);
-		u8 *data = skb_put(skb, 2);
-		data[0] = crc & 0xff;
-		data[1] = crc >> 8;
+		__le16 crc = cpu_to_le16(crc_ccitt(0, skb->data, skb->len));
+
+		memcpy(skb_put(skb, 2), &crc, 2);
 	}
 
 	if (skb_cow_head(skb, priv->hw.extra_tx_headroom))
#109 lore raw

PATCH 106/328 mac802154: tx: use put_unaligned_le16 for copy crc

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Alexander Aring <[email protected]>

commit 061ef8f915988839b12460c47ebfcf3700e124f0 upstream.

This patch replaces the memcpy with a put_unaligned_le16. The placement of crc inside of PSDU can also be unaligned. With memcpy this can fail on some architectures.

[bwh: Backported to 3.16: adjust context]
---
 net/mac802154/tx.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/mac802154/tx.c +3 -2
@@ -24,6 +24,7 @@
 #include <linux/netdevice.h>
 #include <linux/if_arp.h>
 #include <linux/crc-ccitt.h>
+#include <asm/unaligned.h>
 
 #include <net/ieee802154_netdev.h>
 #include <net/mac802154.h>
@@ -95,9 +96,9 @@ netdev_tx_t mac802154_tx(struct mac80215
 	mac802154_monitors_rx(mac802154_to_priv(&priv->hw), skb);
 
 	if (!(priv->hw.flags & IEEE802154_HW_OMIT_CKSUM)) {
-		__le16 crc = cpu_to_le16(crc_ccitt(0, skb->data, skb->len));
+		u16 crc = crc_ccitt(0, skb->data, skb->len);
 
-		memcpy(skb_put(skb, 2), &crc, 2);
+		put_unaligned_le16(crc, skb_put(skb, 2));
 	}
 
 	if (skb_cow_head(skb, priv->hw.extra_tx_headroom))
#110 lore raw

PATCH 107/328 net: mac802154: tx: expand tailroom if necessary

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Alexander Aring <[email protected]>

commit f9c52831133050c6b82aa8b6831c92da2bbf2a0b upstream.

This patch is necessary if case of AF_PACKET or other socket interface which I am aware of it and didn't allocated the necessary room.

[bwh: Backported to 3.16:
- Substitute literal number for IEEE802154_FCS_LEN
- Adjust context]

---

net/mac802154/tx.c +13 -1
@@ -96,8 +96,20 @@ netdev_tx_t mac802154_tx(struct mac80215
 	mac802154_monitors_rx(mac802154_to_priv(&priv->hw), skb);
 
 	if (!(priv->hw.flags & IEEE802154_HW_OMIT_CKSUM)) {
-		u16 crc = crc_ccitt(0, skb->data, skb->len);
+		struct sk_buff *nskb;
+		u16 crc;
 
+		if (unlikely(skb_tailroom(skb) < 2)) {
+			nskb = skb_copy_expand(skb, 0, 2, GFP_ATOMIC);
+			if (likely(nskb)) {
+				consume_skb(skb);
+				skb = nskb;
+			} else {
+				goto err_tx;
+			}
+		}
+
+		crc = crc_ccitt(0, skb->data, skb->len);
 		put_unaligned_le16(crc, skb_put(skb, 2));
 	}
 
#111 lore raw

PATCH 108/328 percpu_counter: batch size aware __percpu_counter_compare()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dave Chinner <[email protected]>

commit 80188b0d77d7426b494af739ac129e0e684acb84 upstream.

XFS uses non-stanard batch sizes for avoiding frequent global counter updates on it's allocated inode counters, as they increment or decrement in batches of 64 inodes. Hence the standard percpu counter batch of 32 means that the counter is effectively a global counter. Currently Xfs uses a batch size of 128 so that it doesn't take the global lock on every single modification.

However, Xfs also needs to compare accurately against zero, which means we need to use percpu_counter_compare(), and that has a hard-coded batch size of 32, and hence will spuriously fail to detect when it is supposed to use precise comparisons and hence the accounting goes wrong.

Add __percpu_counter_compare() to take a custom batch size so we can use it sanely in XFS and factor percpu_counter_compare() to use it.

---
 include/linux/percpu_counter.h | 13 ++++++++++++-
 lib/percpu_counter.c           |  6 +++---
 2 files changed, 15 insertions(+), 4 deletions(-)
include/linux/percpu_counter.h +12 -1
@@ -40,7 +40,12 @@ void percpu_counter_destroy(struct percp
 void percpu_counter_set(struct percpu_counter *fbc, s64 amount);
 void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch);
 s64 __percpu_counter_sum(struct percpu_counter *fbc);
-int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs);
+int __percpu_counter_compare(struct percpu_counter *fbc, s64 rhs, s32 batch);
+
+static inline int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs)
+{
+	return __percpu_counter_compare(fbc, rhs, percpu_counter_batch);
+}
 
 static inline void percpu_counter_add(struct percpu_counter *fbc, s64 amount)
 {
@@ -114,6 +119,12 @@ static inline int percpu_counter_compare
 		return 0;
 }
 
+static inline int
+__percpu_counter_compare(struct percpu_counter *fbc, s64 rhs, s32 batch)
+{
+	return percpu_counter_compare(fbc, rhs);
+}
+
 static inline void
 percpu_counter_add(struct percpu_counter *fbc, s64 amount)
 {
lib/percpu_counter.c +3 -3
@@ -193,13 +193,13 @@ static int percpu_counter_hotcpu_callbac
  * Compare counter against given value.
  * Return 1 if greater, 0 if equal and -1 if less
  */
-int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs)
+int __percpu_counter_compare(struct percpu_counter *fbc, s64 rhs, s32 batch)
 {
 	s64	count;
 
 	count = percpu_counter_read(fbc);
 	/* Check to see if rough count will be sufficient for comparison */
-	if (abs(count - rhs) > (percpu_counter_batch*num_online_cpus())) {
+	if (abs(count - rhs) > (batch * num_online_cpus())) {
 		if (count > rhs)
 			return 1;
 		else
@@ -214,7 +214,7 @@ int percpu_counter_compare(struct percpu
 	else
 		return 0;
 }
-EXPORT_SYMBOL(percpu_counter_compare);
+EXPORT_SYMBOL(__percpu_counter_compare);
 
 static int __init percpu_counter_startup(void)
 {
#112 lore raw

PATCH 109/328 btrfs: use correct compare function of dirty_metadata_bytes

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Ethan Lien <[email protected]>

commit d814a49198eafa6163698bdd93961302f3a877a4 upstream.

We use customized, nodesize batch value to update dirty_metadata_bytes. We should also use batch version of compare function or we will easily goto fast path and get false result from percpu_counter_compare().

Fixes e2d845211eda ("Btrfs: use percpu counter for dirty metadata count")

[bwh: Backported to 3.16: In __btrfs_btree_balance_dirty(), use
root->fs_info instead of fs_info]

---
 fs/btrfs/disk-io.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
fs/btrfs/disk-io.c +6 -4
@@ -991,8 +991,9 @@ static int btree_writepages(struct addre
 
 		fs_info = BTRFS_I(mapping->host)->root->fs_info;
 		/* this is a bit racy, but that's ok */
-		ret = percpu_counter_compare(&fs_info->dirty_metadata_bytes,
-					     BTRFS_DIRTY_METADATA_THRESH);
+		ret = __percpu_counter_compare(&fs_info->dirty_metadata_bytes,
+					     BTRFS_DIRTY_METADATA_THRESH,
+					     fs_info->dirty_metadata_batch);
 		if (ret < 0)
 			return 0;
 	}
@@ -3793,8 +3794,9 @@ static void __btrfs_btree_balance_dirty(
 	if (flush_delayed)
 		btrfs_balance_delayed_items(root);
 
-	ret = percpu_counter_compare(&root->fs_info->dirty_metadata_bytes,
-				     BTRFS_DIRTY_METADATA_THRESH);
+	ret = __percpu_counter_compare(&root->fs_info->dirty_metadata_bytes,
+				     BTRFS_DIRTY_METADATA_THRESH,
+				     root->fs_info->dirty_metadata_batch);
 	if (ret > 0) {
 		balance_dirty_pages_ratelimited(
 				   root->fs_info->btree_inode->i_mapping);
#113 lore raw

PATCH 110/328 Btrfs: fix btrfs_write_inode vs delayed iput deadlock

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Josef Bacik <[email protected]>

commit 3c4276936f6fbe52884b4ea4e6cc120b890a0f9f upstream.

We recently ran into the following deadlock involving btrfs_write_inode():

[  +0.005066]  __schedule+0x38e/0x8c0
[  +0.007144]  schedule+0x36/0x80
[  +0.006447]  bit_wait+0x11/0x60
[  +0.006446]  __wait_on_bit+0xbe/0x110
[  +0.007487]  ? bit_wait_io+0x60/0x60
[  +0.007319]  __inode_wait_for_writeback+0x96/0xc0
[  +0.009568]  ? autoremove_wake_function+0x40/0x40
[  +0.009565]  inode_wait_for_writeback+0x21/0x30
[  +0.009224]  evict+0xb0/0x190
[  +0.006099]  iput+0x1a8/0x210
[  +0.006103]  btrfs_run_delayed_iputs+0x73/0xc0
[  +0.009047]  btrfs_commit_transaction+0x799/0x8c0
[  +0.009567]  btrfs_write_inode+0x81/0xb0
[  +0.008008]  __writeback_single_inode+0x267/0x320
[  +0.009569]  writeback_sb_inodes+0x25b/0x4e0
[  +0.008702]  wb_writeback+0x102/0x2d0
[  +0.007487]  wb_workfn+0xa4/0x310
[  +0.006794]  ? wb_workfn+0xa4/0x310
[  +0.007143]  process_one_work+0x150/0x410
[  +0.008179]  worker_thread+0x6d/0x520
[  +0.007490]  kthread+0x12c/0x160
[  +0.006620]  ? put_pwq_unlocked+0x80/0x80
[  +0.008185]  ? kthread_park+0xa0/0xa0
[  +0.007484]  ? do_syscall_64+0x53/0x150
[  +0.007837]  ret_from_fork+0x29/0x40

Writeback calls:

btrfs_write_inode
btrfs_commit_transaction
btrfs_run_delayed_iputs

If iput() is called on that same inode, evict() will wait for writeback forever.

btrfs_write_inode() was originally added way back in 4730a4bc5bf3 ("btrfs_dirty_inode") to support O_SYNC writes. However, ->write_inode() hasn't been used for O_SYNC since 148f948ba877 ("vfs: Introduce new helpers for syncing after writing to O_SYNC file or IS_SYNC inode"), so btrfs_write_inode() is actually unnecessary (and leads to a bunch of unnecessary commits). Get rid of it, which also gets rid of the deadlock.

[Omar: new commit message]
[bwh: Backported to 3.16: deleted function is slightly different]

---

fs/btrfs/inode.c +0 -25
@@ -5542,31 +5542,6 @@ err:
 	return ret;
 }
 
-int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc)
-{
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	struct btrfs_trans_handle *trans;
-	int ret = 0;
-	bool nolock = false;
-
-	if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags))
-		return 0;
-
-	if (btrfs_fs_closing(root->fs_info) && btrfs_is_free_space_inode(inode))
-		nolock = true;
-
-	if (wbc->sync_mode == WB_SYNC_ALL) {
-		if (nolock)
-			trans = btrfs_join_transaction_nolock(root);
-		else
-			trans = btrfs_join_transaction(root);
-		if (IS_ERR(trans))
-			return PTR_ERR(trans);
-		ret = btrfs_commit_transaction(trans, root);
-	}
-	return ret;
-}
-
 /*
  * This is somewhat expensive, updating the tree every time the
  * inode changes.  But, it is most likely to find the inode in cache.
fs/btrfs/super.c +0 -1
@@ -1852,7 +1852,6 @@ static const struct super_operations btr
 	.sync_fs	= btrfs_sync_fs,
 	.show_options	= btrfs_show_options,
 	.show_devname	= btrfs_show_devname,
-	.write_inode	= btrfs_write_inode,
 	.alloc_inode	= btrfs_alloc_inode,
 	.destroy_inode	= btrfs_destroy_inode,
 	.statfs		= btrfs_statfs,
#114 lore raw

PATCH 111/328 btrfs: rename total_bytes to avoid confusion

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Anand Jain <[email protected]>

commit 3c1dbdf54a31f4f049a33214c3096595988786bf upstream.

we are assigning number_devices to the total_bytes, that's very confusing for a moment

---
 fs/btrfs/volumes.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
fs/btrfs/volumes.c +5 -5
@@ -2039,7 +2039,7 @@ int btrfs_init_new_device(struct btrfs_r
 	struct list_head *devices;
 	struct super_block *sb = root->fs_info->sb;
 	struct rcu_string *name;
-	u64 total_bytes;
+	u64 tmp;
 	int seeding_dev = 0;
 	int ret = 0;
 
@@ -2142,13 +2142,13 @@ int btrfs_init_new_device(struct btrfs_r
 	if (!blk_queue_nonrot(bdev_get_queue(bdev)))
 		root->fs_info->fs_devices->rotating = 1;
 
-	total_bytes = btrfs_super_total_bytes(root->fs_info->super_copy);
+	tmp = btrfs_super_total_bytes(root->fs_info->super_copy);
 	btrfs_set_super_total_bytes(root->fs_info->super_copy,
-				    total_bytes + device->total_bytes);
+				    tmp + device->total_bytes);
 
-	total_bytes = btrfs_super_num_devices(root->fs_info->super_copy);
+	tmp = btrfs_super_num_devices(root->fs_info->super_copy);
 	btrfs_set_super_num_devices(root->fs_info->super_copy,
-				    total_bytes + 1);
+				    tmp + 1);
 
 	/* add sysfs device entry */
 	btrfs_kobj_add_device(root->fs_info, device);
#115 lore raw

PATCH 112/328 ASoC: wm8994: Mark expected switch fall-through

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: "Gustavo A. R. Silva" <[email protected]>

commit 2cea1542859bc812f1ec51ea71c06e927e5b922e upstream.

In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.

Addresses-Coverity-ID: 115050 ("Missing break in switch")

---
 sound/soc/codecs/wm8994.c | 1 +
 1 file changed, 1 insertion(+)
sound/soc/codecs/wm8994.c +1 -0
@@ -2427,6 +2427,7 @@ static int wm8994_set_dai_sysclk(struct
 			snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
 					    WM8994_OPCLK_ENA, 0);
 		}
+		/* fall through */
 
 	default:
 		return -EINVAL;
#116 lore raw

PATCH 113/328 ASoC: wm8994: Fix missing break in switch

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: "Gustavo A. R. Silva" <[email protected]>

commit ad0eaee6195db1db1749dd46b9e6f4466793d178 upstream.

Add missing break statement in order to prevent the code from falling through to the default case.

Addresses-Coverity-ID: 115050 ("Missing break in switch")

---
 sound/soc/codecs/wm8994.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/wm8994.c +1 -1
@@ -2427,7 +2427,7 @@ static int wm8994_set_dai_sysclk(struct
 			snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
 					    WM8994_OPCLK_ENA, 0);
 		}
-		/* fall through */
+		break;
 
 	default:
 		return -EINVAL;
#117 lore raw

PATCH 114/328 powerpc/pseries: Avoid using the size greater than RTAS_ERROR_LOG_MAX.

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mahesh Salgaonkar <[email protected]>

commit 74e96bf44f430cf7a01de19ba6cf49b361cdfd6e upstream.

The global mce data buffer that used to copy rtas error log is of 2048 (RTAS_ERROR_LOG_MAX) bytes in size. Before the copy we read extended_log_length from rtas error log header, then use max of extended_log_length and RTAS_ERROR_LOG_MAX as a size of data to be copied. Ideally the platform (phyp) will never send extended error log with size > 2048. But if that happens, then we have a risk of buffer overrun and corruption. Fix this by using min_t instead.

Fixes d368514c3097 ("powerpc: Fix corruption when grabbing FWNMI data")
---
 arch/powerpc/platforms/pseries/ras.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/pseries/ras.c +1 -1
@@ -309,7 +309,7 @@ static struct rtas_error_log *fwnmi_get_
 		int len, error_log_length;
 
 		error_log_length = 8 + rtas_error_extended_log_length(h);
-		len = max_t(int, error_log_length, RTAS_ERROR_LOG_MAX);
+		len = min_t(int, error_log_length, RTAS_ERROR_LOG_MAX);
 		memset(global_mce_data_buf, 0, RTAS_ERROR_LOG_MAX);
 		memcpy(global_mce_data_buf, h, len);
 		errhdr = (struct rtas_error_log *)global_mce_data_buf;
#118 lore raw

PATCH 115/328 dm cache metadata: save in-core policy_hint_size to on-disk superblock

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mike Snitzer <[email protected]>

commit fd2fa95416188a767a63979296fa3e169a9ef5ec upstream.

policy_hint_size starts as 0 during __write_initial_superblock(). It isn't until the policy is loaded that policy_hint_size is set in-core (cmd->policy_hint_size). But it never got recorded in the on-disk superblock because __commit_transaction() didn't deal with transfering the in-core cmd->policy_hint_size to the on-disk superblock.

The in-core cmd->policy_hint_size gets initialized by metadata_open()'s __begin_transaction_flags() which re-reads all superblock fields. Because the superblock's policy_hint_size was never properly stored, when the cache was created, hints_array_available() would always return false when re-activating a previously created cache. This means __load_mappings() always considered the hints invalid and never made use of the hints (these hints served to optimize).

Another detremental side-effect of this oversight is the cache_check utility would fail with: "invalid hint width: 0"

---
 drivers/md/dm-cache-metadata.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/dm-cache-metadata.c +2 -1
@@ -324,7 +324,7 @@ static int __write_initial_superblock(st
 	disk_super->version = cpu_to_le32(MAX_CACHE_VERSION);
 	memset(disk_super->policy_name, 0, sizeof(disk_super->policy_name));
 	memset(disk_super->policy_version, 0, sizeof(disk_super->policy_version));
-	disk_super->policy_hint_size = 0;
+	disk_super->policy_hint_size = cpu_to_le32(0);
 
 	__copy_sm_root(cmd, disk_super);
 
@@ -635,6 +635,7 @@ static int __commit_transaction(struct d
 	disk_super->policy_version[0] = cpu_to_le32(cmd->policy_version[0]);
 	disk_super->policy_version[1] = cpu_to_le32(cmd->policy_version[1]);
 	disk_super->policy_version[2] = cpu_to_le32(cmd->policy_version[2]);
+	disk_super->policy_hint_size = cpu_to_le32(cmd->policy_hint_size);
 
 	disk_super->read_hits = cpu_to_le32(cmd->stats.read_hits);
 	disk_super->read_misses = cpu_to_le32(cmd->stats.read_misses);
#119 lore raw

PATCH 116/328 smb3: fill in statfs fsid and correct namelen

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Steve French <[email protected]>

commit 21ba3845b59c733a79ed4fe1c4f3732e7ece9df7 upstream.

Fil in the correct namelen (typically 255 not 4096) in the statfs response and also fill in a reasonably unique fsid (in this case taken from the volume id, and the creation time of the volume).

In the case of the POSIX statfs all fields are now filled in, and in the case of non-POSIX mounts, all fields are filled in which can be.

[bwh: Backported to 3.16: Only use cifs_tcon::vol_{serial_number,create_time}
if CONFIG_CIFS_SMB2 is enabled]

---
 fs/cifs/cifsfs.c  | 18 ++++++++++--------
 fs/cifs/smb2ops.c |  2 ++
 fs/cifs/smb2pdu.c |  8 ++++++++
 fs/cifs/smb2pdu.h | 11 +++++++++++
 4 files changed, 31 insertions(+), 8 deletions(-)
fs/cifs/cifsfs.c +12 -8
@@ -190,14 +190,18 @@ cifs_statfs(struct dentry *dentry, struc
 
 	xid = get_xid();
 
-	/*
-	 * PATH_MAX may be too long - it would presumably be total path,
-	 * but note that some servers (includinng Samba 3) have a shorter
-	 * maximum path.
-	 *
-	 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
-	 */
-	buf->f_namelen = PATH_MAX;
+	if (le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength) > 0)
+		buf->f_namelen =
+		       le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength);
+	else
+		buf->f_namelen = PATH_MAX;
+
+#ifdef CONFIG_CIFS_SMB2
+	buf->f_fsid.val[0] = tcon->vol_serial_number;
+	/* are using part of create time for more randomness, see man statfs */
+	buf->f_fsid.val[1] =  (int)le64_to_cpu(tcon->vol_create_time);
+#endif
+
 	buf->f_files = 0;	/* undefined */
 	buf->f_ffree = 0;	/* unlimited */
 
fs/cifs/smb2ops.c +2 -0
@@ -263,6 +263,8 @@ smb3_qfs_tcon(const unsigned int xid, st
 	SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
 			FS_DEVICE_INFORMATION);
 	SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
+			FS_VOLUME_INFORMATION);
+	SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
 			FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
 	SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
 	return;
fs/cifs/smb2pdu.c +8 -0
@@ -2614,6 +2614,9 @@ SMB2_QFS_attr(const unsigned int xid, st
 	} else if (level == FS_SECTOR_SIZE_INFORMATION) {
 		max_len = sizeof(struct smb3_fs_ss_info);
 		min_len = sizeof(struct smb3_fs_ss_info);
+	} else if (level == FS_VOLUME_INFORMATION) {
+		max_len = sizeof(struct smb3_fs_vol_info) + MAX_VOL_LABEL_LEN;
+		min_len = sizeof(struct smb3_fs_vol_info);
 	} else {
 		cifs_dbg(FYI, "Invalid qfsinfo level %d\n", level);
 		return -EINVAL;
@@ -2650,6 +2653,11 @@ SMB2_QFS_attr(const unsigned int xid, st
 		tcon->ss_flags = le32_to_cpu(ss_info->Flags);
 		tcon->perf_sector_size =
 			le32_to_cpu(ss_info->PhysicalBytesPerSectorForPerf);
+	} else if (level == FS_VOLUME_INFORMATION) {
+		struct smb3_fs_vol_info *vol_info = (struct smb3_fs_vol_info *)
+			(offset + (char *)rsp);
+		tcon->vol_serial_number = vol_info->VolumeSerialNumber;
+		tcon->vol_create_time = vol_info->VolumeCreationTime;
 	}
 
 qfsattr_exit:
fs/cifs/smb2pdu.h +11 -0
@@ -946,6 +946,17 @@ struct smb3_fs_ss_info {
 	__le32 ByteOffsetForPartitionAlignment;
 } __packed;
 
+/* volume info struct - see MS-FSCC 2.5.9 */
+#define MAX_VOL_LABEL_LEN	32
+struct smb3_fs_vol_info {
+	__le64	VolumeCreationTime;
+	__u32	VolumeSerialNumber;
+	__le32	VolumeLabelLength; /* includes trailing null */
+	__u8	SupportsObjects; /* True if eg like NTFS, supports objects */
+	__u8	Reserved;
+	__u8	VolumeLabel[0]; /* variable len */
+} __packed;
+
 /* partial list of QUERY INFO levels */
 #define FILE_DIRECTORY_INFORMATION	1
 #define FILE_FULL_DIRECTORY_INFORMATION 2
#120 lore raw

PATCH 117/328 cifs: add missing debug entries for kconfig options

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Steve French <[email protected]>

commit 950132afd59385caf6e2b84e5235d069fa10681d upstream.

/proc/fs/cifs/DebugData displays the features (Kconfig options) used to build cifs.ko but it was missing some, and needed comma separator. These can be useful in debugging certain problems so we know which optional features were enabled in the user's build. Also clarify them, by making them more closely match the corresponding CONFIG_CIFS_* parm.

Old format:
Features: dfs fscache posix spnego xattr acl

New format:
Features: DFS,FSCACHE,SMB_DIRECT,STATS,DEBUG2,ALLOW_INSECURE_LEGACY,CIFS_POSIX,UPCALL(SPNEGO),XATTR,ACL

---
 fs/cifs/cifs_debug.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)
fs/cifs/cifs_debug.c +23 -7
@@ -141,25 +141,41 @@ static int cifs_debug_data_proc_show(str
 	seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
 	seq_printf(m, "Features:");
 #ifdef CONFIG_CIFS_DFS_UPCALL
-	seq_printf(m, " dfs");
+	seq_printf(m, " DFS");
 #endif
 #ifdef CONFIG_CIFS_FSCACHE
-	seq_printf(m, " fscache");
+	seq_printf(m, ",FSCACHE");
+#endif
+#ifdef CONFIG_CIFS_SMB_DIRECT
+	seq_printf(m, ",SMB_DIRECT");
+#endif
+#ifdef CONFIG_CIFS_STATS2
+	seq_printf(m, ",STATS2");
+#elif defined(CONFIG_CIFS_STATS)
+	seq_printf(m, ",STATS");
+#endif
+#ifdef CONFIG_CIFS_DEBUG2
+	seq_printf(m, ",DEBUG2");
+#elif defined(CONFIG_CIFS_DEBUG)
+	seq_printf(m, ",DEBUG");
+#endif
+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
+	seq_printf(m, ",ALLOW_INSECURE_LEGACY");
 #endif
 #ifdef CONFIG_CIFS_WEAK_PW_HASH
-	seq_printf(m, " lanman");
+	seq_printf(m, ",WEAK_PW_HASH");
 #endif
 #ifdef CONFIG_CIFS_POSIX
-	seq_printf(m, " posix");
+	seq_printf(m, ",CIFS_POSIX");
 #endif
 #ifdef CONFIG_CIFS_UPCALL
-	seq_printf(m, " spnego");
+	seq_printf(m, ",UPCALL(SPNEGO)");
 #endif
 #ifdef CONFIG_CIFS_XATTR
-	seq_printf(m, " xattr");
+	seq_printf(m, ",XATTR");
 #endif
 #ifdef CONFIG_CIFS_ACL
-	seq_printf(m, " acl");
+	seq_printf(m, ",ACL");
 #endif
 	seq_putc(m, '\n');
 	seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
#121 lore raw

PATCH 118/328 PCI: mvebu: Fix I/O space end address calculation

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Thomas Petazzoni <[email protected]>

commit dfd0309fd7b30a5baffaf47b2fccb88b46d64d69 upstream.

pcie->realio.end should be the address of last byte of the area, therefore using resource_size() of another resource is not correct, we must substract 1 to get the address of the last byte.

Fixes 11be65472a427 ("PCI: mvebu: Adapt to the new device tree layout")
[bwh: Backported to 3.16: adjust filename]
---
 drivers/pci/host/pci-mvebu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/host/pci-mvebu.c +1 -1
@@ -940,7 +940,7 @@ static int mvebu_pcie_probe(struct platf
 		pcie->realio.start = PCIBIOS_MIN_IO;
 		pcie->realio.end = min_t(resource_size_t,
 					 IO_SPACE_LIMIT,
-					 resource_size(&pcie->io));
+					 resource_size(&pcie->io) - 1);
 	} else
 		pcie->realio = pcie->io;
 
#122 lore raw

PATCH 119/328 media: rtl28xxu: be sure that it won't go past the array size

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mauro Carvalho Chehab <[email protected]>

commit 845b978a871bff3707eee611b32e4be0b9a94dd2 upstream.

smatch warns that the RC query code could go past the array size:

	drivers/media/usb/dvb-usb-v2/rtl28xxu.c:1757 rtl2832u_rc_query() error: buffer overflow 'buf' 128 <= 130
	drivers/media/usb/dvb-usb-v2/rtl28xxu.c:1758 rtl2832u_rc_query() error: buffer overflow 'buf' 128 <= 130

The driver logic gets the length of the IR RX buffer with:

        ret = rtl28xxu_rd_reg(d, IR_RX_BC, &buf[0]);
	...
        len = buf[0];

In thesis, this could range between 0 and 255 [1].

While this should never happen in practice, due to hardware limits, smatch is right when it complains about that, as there's nothing at the logic that would prevent it. So, if for whatever reason, buf[0] gets filled by rtl28xx read functions with a value bigger than 128, it will go past the array.

So, add an explicit check.

[1] I've no idea why smatch thinks that the maximum value is 130. I double-checked the code several times. Was unable to find any reason for assuming 130. Perhaps smatch is not properly parsing u8 here?

Fixes b5cbaa43a676 ("[media] rtl28xx: initial support for rtl2832u")
[bwh: Backported to 3.16: adjust context]
---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/dvb-usb-v2/rtl28xxu.c +1 -1
@@ -1379,7 +1379,7 @@ static int rtl2832u_rc_query(struct dvb_
 		goto exit;
 
 	ret = rtl28xx_rd_reg(d, IR_RX_BC, &buf[0]);
-	if (ret)
+	if (ret || buf[0] > sizeof(buf))
 		goto err;
 
 	len = buf[0];
#123 lore raw

PATCH 120/328 scsi: aic94xx: fix an error code in aic94xx_init()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dan Carpenter <[email protected]>

commit 0756c57bce3d26da2592d834d8910b6887021701 upstream.

We accidentally return success instead of -ENOMEM on this error path.

---
 drivers/scsi/aic94xx/aic94xx_init.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/aic94xx/aic94xx_init.c +3 -1
@@ -1047,8 +1047,10 @@ static int __init aic94xx_init(void)
 
 	aic94xx_transport_template =
 		sas_domain_attach_transport(&aic94xx_transport_functions);
-	if (!aic94xx_transport_template)
+	if (!aic94xx_transport_template) {
+		err = -ENOMEM;
 		goto out_destroy_caches;
+	}
 
 	err = pci_register_driver(&aic94xx_pci_driver);
 	if (err)
#124 lore raw

PATCH 121/328 b43/leds: Ensure NUL-termination of LED name string

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Michael Büsch <[email protected]>

commit 2aa650d1950fce94f696ebd7db30b8830c2c946f upstream.

strncpy might not NUL-terminate the string, if the name equals the buffer size. Use strlcpy instead.

[bwh: Backported to 3.16: adjust filename]
---
 drivers/net/wireless/b43/leds.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/b43/leds.c +1 -1
@@ -131,7 +131,7 @@ static int b43_register_led(struct b43_w
 	led->wl = dev->wl;
 	led->index = led_index;
 	led->activelow = activelow;
-	strncpy(led->name, name, sizeof(led->name));
+	strlcpy(led->name, name, sizeof(led->name));
 	atomic_set(&led->state, 0);
 
 	led->led_dev.name = led->name;
#125 lore raw

PATCH 122/328 b43legacy/leds: Ensure NUL-termination of LED name string

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Michael Büsch <[email protected]>

commit 4d77a89e3924b12f4a5628b21237e57ab4703866 upstream.

strncpy might not NUL-terminate the string, if the name equals the buffer size. Use strlcpy instead.

[bwh: Backported to 3.16: adjust filename]
---
 drivers/net/wireless/b43legacy/leds.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/b43legacy/leds.c +1 -1
@@ -101,7 +101,7 @@ static int b43legacy_register_led(struct
 	led->dev = dev;
 	led->index = led_index;
 	led->activelow = activelow;
-	strncpy(led->name, name, sizeof(led->name));
+	strlcpy(led->name, name, sizeof(led->name));
 
 	led->led_dev.name = led->name;
 	led->led_dev.default_trigger = default_trigger;
#126 lore raw

PATCH 123/328 powerpc: Fix size calculation using resource_size()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dan Carpenter <[email protected]>

commit c42d3be0c06f0c1c416054022aa535c08a1f9b39 upstream.

The problem is the the calculation should be "end - start + 1" but the plus one is missing in this calculation.

Fixes 8626816e905e ("powerpc: add support for MPIC message register API")
---
 arch/powerpc/sysdev/mpic_msgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/sysdev/mpic_msgr.c +1 -1
@@ -196,7 +196,7 @@ static int mpic_msgr_probe(struct platfo
 
 	/* IO map the message register block. */
 	of_address_to_resource(np, 0, &rsrc);
-	msgr_block_addr = ioremap(rsrc.start, rsrc.end - rsrc.start);
+	msgr_block_addr = ioremap(rsrc.start, resource_size(&rsrc));
 	if (!msgr_block_addr) {
 		dev_err(&dev->dev, "Failed to iomap MPIC message registers");
 		return -EFAULT;
#127 lore raw

PATCH 124/328 powerpc/fadump: handle crash memory ranges array index overflow

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Hari Bathini <[email protected]>

commit 1bd6a1c4b80a28d975287630644e6b47d0f977a5 upstream.

Crash memory ranges is an array of memory ranges of the crashing kernel to be exported as a dump via /proc/vmcore file. The size of the array is set based on INIT_MEMBLOCK_REGIONS, which works alright in most cases where memblock memory regions count is less than INIT_MEMBLOCK_REGIONS value. But this count can grow beyond INIT_MEMBLOCK_REGIONS value since commit 142b45a72e22 ("memblock: Add array resizing support").

On large memory systems with a few DLPAR operations, the memblock memory regions count could be larger than INIT_MEMBLOCK_REGIONS value. On such systems, registering fadump results in crash or other system failures like below:

task: c00007f39a290010 ti: c00000000b738000 task.ti: c00000000b738000
NIP: c000000000047df4 LR: c0000000000f9e58 CTR: c00000000010f180
REGS: c00000000b73b570 TRAP: 0300 Tainted: G L X (4.4.140+)
MSR: 8000000000009033 <SF,EE,ME,IR,DR,RI,LE> CR: 22004484 XER: 20000000
CFAR: c000000000008500 DAR: 000007a450000000 DSISR: 40000000 SOFTE: 0
...
NIP [c000000000047df4] smp_send_reschedule+0x24/0x80
LR [c0000000000f9e58] resched_curr+0x138/0x160

  Call Trace:
    resched_curr+0x138/0x160 (unreliable)
    check_preempt_curr+0xc8/0xf0
    ttwu_do_wakeup+0x38/0x150
    try_to_wake_up+0x224/0x4d0
    __wake_up_common+0x94/0x100
    ep_poll_callback+0xac/0x1c0
    __wake_up_common+0x94/0x100
    __wake_up_sync_key+0x70/0xa0
    sock_def_readable+0x58/0xa0
    unix_stream_sendmsg+0x2dc/0x4c0
    sock_sendmsg+0x68/0xa0
    ___sys_sendmsg+0x2cc/0x2e0
    __sys_sendmsg+0x5c/0xc0
    SyS_socketcall+0x36c/0x3f0
    system_call+0x3c/0x100

as array index overflow is not checked for while setting up crash memory ranges causing memory corruption. To resolve this issue, dynamically allocate memory for crash memory ranges and resize it incrementally, in units of pagesize, on hitting array size limit.

Fixes 2df173d9e85d ("fadump: Initialize elfcore header and add PT_LOAD program headers.")
[mpe: Just use PAGE_SIZE directly, fixup variable placement]

[bwh: Backported to 3.16:
- register_fadump() returns void
- Include <linux/slab.h> for kfree(), krealloc()]

---

arch/powerpc/include/asm/fadump.h +0 -3
@@ -194,9 +194,6 @@ struct fadump_crash_info_header {
 	struct cpumask	cpu_online_mask;
 };
 
-/* Crash memory ranges */
-#define INIT_CRASHMEM_RANGES	(INIT_MEMBLOCK_REGIONS + 2)
-
 struct fad_crash_memory_ranges {
 	unsigned long long	base;
 	unsigned long long	size;
arch/powerpc/kernel/fadump.c +78 -14

174 lines not on this page · raw message

#128 lore raw

PATCH 125/328 powerpc/pseries: Fix endianness while restoring of r3 in MCE handler.

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mahesh Salgaonkar <[email protected]>

commit cd813e1cd7122f2c261dce5b54d1e0c97f80e1a5 upstream.

During Machine Check interrupt on pseries platform, register r3 points RTAS extended event log passed by hypervisor. Since hypervisor uses r3 to pass pointer to rtas log, it stores the original r3 value at the start of the memory (first 8 bytes) pointed by r3. Since hypervisor stores this info and rtas log is in BE format, linux should make sure to restore r3 value in correct endian format.

Without this patch when MCE handler, after recovery, returns to code that that caused the MCE may end up with Data SLB access interrupt for invalid address followed by kernel panic or hang.

Severe Machine check interrupt [Recovered]

    NIP [d00000000ca301b8]: init_module+0x1b8/0x338 [bork_kernel]
    Initiator: CPU
    Error type: SLB [Multihit]
      Effective address: d00000000ca70000
  cpu 0xa: Vector: 380 (Data SLB Access) at [c0000000fc7775b0]
      pc: c0000000009694c0: vsnprintf+0x80/0x480
      lr: c0000000009698e0: vscnprintf+0x20/0x60
      sp: c0000000fc777830
     msr: 8000000002009033
     dar: a803a30c000000d0
    current = 0xc00000000bc9ef00
    paca    = 0xc00000001eca5c00	 softe: 3	 irq_happened: 0x01
      pid   = 8860, comm = insmod
  vscnprintf+0x20/0x60
  vprintk_emit+0xb4/0x4b0
  vprintk_func+0x5c/0xd0
  printk+0x38/0x4c
  init_module+0x1c0/0x338 [bork_kernel]
  do_one_initcall+0x54/0x230
  do_init_module+0x8c/0x248
  load_module+0x12b8/0x15b0
  sys_finit_module+0xa8/0x110
  system_call+0x58/0x6c
  --- Exception: c00 (System Call) at 00007fff8bda0644
  SP (7fffdfbfe980) is in userspace

This patch fixes this issue.

Fixes a08a53ea4c97 ("powerpc/le: Enable RTAS events support")
---
 arch/powerpc/platforms/pseries/ras.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/pseries/ras.c +1 -1
@@ -298,7 +298,7 @@ static struct rtas_error_log *fwnmi_get_
 	}
 
 	savep = __va(regs->gpr[3]);
-	regs->gpr[3] = savep[0];	/* restore original r3 */
+	regs->gpr[3] = be64_to_cpu(savep[0]);	/* restore original r3 */
 
 	/* If it isn't an extended log we can use the per cpu 64bit buffer */
 	h = (struct rtas_error_log *)&savep[1];
#129 lore raw

PATCH 126/328 uprobes: Use synchronize_rcu() not synchronize_sched()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: "Steven Rostedt (VMware)" <[email protected]>

commit 016f8ffc48cb01d1e7701649c728c5d2e737d295 upstream.

While debugging another bug, I was looking at all the synchronize*() functions being used in kernel/trace, and noticed that trace_uprobes was using synchronize_sched(), with a comment to synchronize with {u,ret}_probe_trace_func(). When looking at those functions, the data is protected with "rcu_read_lock()" and not with "rcu_read_lock_sched()". This is using the wrong synchronize_*() function.

Fixes 70ed91c6ec7f8 ("tracing/uprobes: Support ftrace_event_file base multibuffer")
---
 kernel/trace/trace_uprobe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_uprobe.c +1 -1
@@ -949,7 +949,7 @@ probe_event_disable(struct trace_uprobe
 
 		list_del_rcu(&link->list);
 		/* synchronize with u{,ret}probe_trace_func */
-		synchronize_sched();
+		synchronize_rcu();
 		kfree(link);
 
 		if (!list_empty(&tu->tp.files))
#130 lore raw

PATCH 127/328 net/9p/client.c: version pointer uninitialized

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Tomas Bortoli <[email protected]>

commit 7913690dcc5e18e235769fd87c34143072f5dbea upstream.

The p9_client_version() does not initialize the version pointer. If the call to p9pdu_readf() returns an error and version has not been allocated in p9pdu_readf(), then the program will jump to the "error" label and will try to free the version pointer. If version is not initialized, free() will be called with uninitialized, garbage data and will provoke a crash.

---
 net/9p/client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/9p/client.c +1 -1
@@ -938,7 +938,7 @@ static int p9_client_version(struct p9_c
 {
 	int err = 0;
 	struct p9_req_t *req;
-	char *version;
+	char *version = NULL;
 	int msize;
 
 	p9_debug(P9_DEBUG_9P, ">>> TVERSION msize %d protocol %d\n",
#131 lore raw

PATCH 128/328 9p/net: Fix zero-copy path in the 9p virtio transport

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Chirantan Ekbote <[email protected]>

commit d28c756caee6e414d9ba367d0b92da24145af2a8 upstream.

The zero-copy optimization when reading or writing large chunks of data is quite useful. However, the 9p messages created through the zero-copy write path have an incorrect message size: it should be the size of the header + size of the data being written but instead it's just the size of the header.

This only works if the server ignores the size field of the message and otherwise breaks the framing of the protocol. Fix this by re-writing the message size field with the correct value.

Tested by running dd if=/dev/zero of=out bs=4k count=1 inside a virtio-9p mount.

---
 net/9p/trans_virtio.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/9p/trans_virtio.c +7 -0
@@ -378,6 +378,7 @@ p9_virtio_zc_request(struct p9_client *c
 	p9_debug(P9_DEBUG_TRANS, "virtio request\n");
 
 	if (uodata) {
+		__le32 sz;
 		out_nr_pages = p9_nr_pages(uodata, outlen);
 		out_pages = kmalloc(sizeof(struct page *) * out_nr_pages,
 				    GFP_NOFS);
@@ -393,6 +394,12 @@ p9_virtio_zc_request(struct p9_client *c
 			out_pages = NULL;
 			goto err_out;
 		}
+		/* The size field of the message must include the length of the
+		 * header and the length of the data.  We didn't actually know
+		 * the length of the data until this point so add it in now.
+		 */
+		sz = cpu_to_le32(req->tc->size + outlen);
+		memcpy(&req->tc->sdata[0], &sz, sizeof(sz));
 	}
 	if (uidata) {
 		in_nr_pages = p9_nr_pages(uidata, inlen);
#132 lore raw

PATCH 129/328 net/9p/trans_fd.c: fix race-condition by flushing workqueue before the kfree()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Tomas Bortoli <[email protected]>

commit 430ac66eb4c5b5c4eb846b78ebf65747510b30f1 upstream.

The patch adds the flush in p9_mux_poll_stop() as it the function used by p9_conn_destroy(), in turn called by p9_fd_close() to stop the async polling associated with the data regarding the connection.

To: Eric Van Hensbergen <[email protected]>
To: Ron Minnich <[email protected]>
To: Latchesar Ionkov <[email protected]>

---
 net/9p/trans_fd.c | 2 ++
 1 file changed, 2 insertions(+)
net/9p/trans_fd.c +2 -0
@@ -185,6 +185,8 @@ static void p9_mux_poll_stop(struct p9_c
 	spin_lock_irqsave(&p9_poll_lock, flags);
 	list_del_init(&m->poll_pending_link);
 	spin_unlock_irqrestore(&p9_poll_lock, flags);
+
+	flush_work(&p9_poll_work);
 }
 
 /**
#133 lore raw

PATCH 130/328 fs/9p/xattr.c: catch the error of p9_client_clunk when setting xattr failed

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: piaojun <[email protected]>

commit 3111784bee81591ea2815011688d28b65df03627 upstream.

In my testing, v9fs_fid_xattr_set will return successfully even if the backend ext4 filesystem has no space to store xattr key-value. That will cause inconsistent behavior between front end and back end. The reason is that lsetxattr will be triggered by p9_client_clunk, and unfortunately we did not catch the error. This patch will catch the error to notify upper caller.

p9_client_clunk (in 9p)
p9_client_rpc(clnt, P9_TCLUNK, "d", fid->fid);
v9fs_clunk (in qemu)
put_fid
free_fid
v9fs_xattr_fid_clunk
v9fs_co_lsetxattr
s->ops->lsetxattr
ext4_xattr_user_set (in host ext4 filesystem)

Cc Eric Van Hensbergen <[email protected]>
Cc Ron Minnich <[email protected]>
Cc Latchesar Ionkov <[email protected]>
Cc Andrew Morton <[email protected]>
[bwh: Backported to 3.16: adjust context]
---
 fs/9p/xattr.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/9p/xattr.c +4 -2
@@ -121,7 +121,7 @@ int v9fs_fid_xattr_set(struct p9_fid *fi
 		   const void *value, size_t value_len, int flags)
 {
 	u64 offset = 0;
-	int retval, msize, write_count;
+	int retval, err, msize, write_count;
 
 	p9_debug(P9_DEBUG_VFS, "name = %s value_len = %zu flags = %d\n",
 		 name, value_len, flags);
@@ -158,7 +158,9 @@ int v9fs_fid_xattr_set(struct p9_fid *fi
 	}
 	retval = 0;
 err:
-	p9_client_clunk(fid);
+	err = p9_client_clunk(fid);
+	if (!retval && err)
+		retval = err;
 	return retval;
 }
 
#134 lore raw

PATCH 131/328 9p: fix multiple NULL-pointer-dereferences

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Tomas Bortoli <[email protected]>

commit 10aa14527f458e9867cf3d2cc6b8cb0f6704448b upstream.

Added checks to prevent GPFs from raising.

[bwh: Backported to 3.16:
- Drop changes in trans_xen.c

---

net/9p/trans_fd.c +4 -1
@@ -934,7 +934,7 @@ p9_fd_create_tcp(struct p9_client *clien
 	if (err < 0)
 		return err;
 
-	if (valid_ipaddr4(addr) < 0)
+	if (addr == NULL || valid_ipaddr4(addr) < 0)
 		return -EINVAL;
 
 	csocket = NULL;
@@ -982,6 +982,9 @@ p9_fd_create_unix(struct p9_client *clie
 
 	csocket = NULL;
 
+	if (addr == NULL)
+		return -EINVAL;
+
 	if (strlen(addr) >= UNIX_PATH_MAX) {
 		pr_err("%s (%d): address too long: %s\n",
 		       __func__, task_pid_nr(current), addr);
net/9p/trans_rdma.c +3 -0
@@ -623,6 +623,9 @@ rdma_create_trans(struct p9_client *clie
 	struct ib_qp_init_attr qp_attr;
 	struct ib_device_attr devattr;
 
+	if (addr == NULL)
+		return -EINVAL;
+
 	/* Parse the transport specific mount options */
 	err = parse_opts(args, &opts);
 	if (err < 0)
net/9p/trans_virtio.c +3 -0
@@ -622,6 +622,9 @@ p9_virtio_create(struct p9_client *clien
 	int ret = -ENOENT;
 	int found = 0;
 
+	if (devname == NULL)
+		return -EINVAL;
+
 	mutex_lock(&virtio_9p_lock);
 	list_for_each_entry(chan, &virtio_chan_list, chan_list) {
 		if (!strncmp(devname, chan->tag, chan->tag_len) &&
#135 lore raw

PATCH 132/328 9p/virtio: fix off-by-one error in sg list bounds check

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: jiangyiwen <[email protected]>

commit 23cba9cbde0bba05d772b335fe5f66aa82b9ad19 upstream.

Because the value of limit is VIRTQUEUE_NUM, if index is equal to limit, it will cause sg array out of bounds, so correct the judgement of BUG_ON.

---
 net/9p/trans_virtio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/9p/trans_virtio.c +2 -1
@@ -193,7 +193,7 @@ static int pack_sg_list(struct scatterli
 		s = rest_of_page(data);
 		if (s > count)
 			s = count;
-		BUG_ON(index > limit);
+		BUG_ON(index >= limit);
 		/* Make sure we don't terminate early. */
 		sg_unmark_end(&sg[index]);
 		sg_set_buf(&sg[index++], data, s);
@@ -239,6 +239,7 @@ pack_sg_list_p(struct scatterlist *sg, i
 		s = rest_of_page(data);
 		if (s > count)
 			s = count;
+		BUG_ON(index >= limit);
 		/* Make sure we don't terminate early. */
 		sg_unmark_end(&sg[index]);
 		sg_set_page(&sg[index++], pdata[i++], s, data_off);
#136 lore raw

PATCH 133/328 KVM: arm/arm64: Skip updating PMD entry if no change

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Punit Agrawal <[email protected]>

commit 86658b819cd0a9aa584cd84453ed268a6f013770 upstream.

Contention on updating a PMD entry by a large number of vcpus can lead to duplicate work when handling stage 2 page faults. As the page table update follows the break-before-make requirement of the architecture, it can lead to repeated refaults due to clearing the entry and flushing the tlbs.

This problem is more likely when -

* there are large number of vcpus
* the mapping is large block mapping

such as when using PMD hugepages (512MB) with 64k pages.

Fix this by skipping the page table update if there is no change in the entry being updated.

Fixes ad361f093c1e ("KVM: ARM: Support hugetlbfs backed huge pages")
[bwh: Backported to 3.16: adjust filename]
---
 arch/arm/kvm/mmu.c | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)
arch/arm/kvm/mmu.c +27 -11
@@ -685,19 +685,35 @@ static int stage2_set_pmd_huge(struct kv
 	pmd = stage2_get_pmd(kvm, cache, addr);
 	VM_BUG_ON(!pmd);
 
-	/*
-	 * Mapping in huge pages should only happen through a fault.  If a
-	 * page is merged into a transparent huge page, the individual
-	 * subpages of that huge page should be unmapped through MMU
-	 * notifiers before we get here.
-	 *
-	 * Merging of CompoundPages is not supported; they should become
-	 * splitting first, unmapped, merged, and mapped back in on-demand.
-	 */
-	VM_BUG_ON(pmd_present(*pmd) && pmd_pfn(*pmd) != pmd_pfn(*new_pmd));
-
 	old_pmd = *pmd;
 	if (pmd_present(old_pmd)) {
+		/*
+		 * Multiple vcpus faulting on the same PMD entry, can
+		 * lead to them sequentially updating the PMD with the
+		 * same value. Following the break-before-make
+		 * (pmd_clear() followed by tlb_flush()) process can
+		 * hinder forward progress due to refaults generated
+		 * on missing translations.
+		 *
+		 * Skip updating the page table if the entry is
+		 * unchanged.
+		 */
+		if (pmd_val(old_pmd) == pmd_val(*new_pmd))
+			return 0;
+
+		/*
+		 * Mapping in huge pages should only happen through a
+		 * fault.  If a page is merged into a transparent huge
+		 * page, the individual subpages of that huge page
+		 * should be unmapped through MMU notifiers before we
+		 * get here.
+		 *
+		 * Merging of CompoundPages is not supported; they
+		 * should become splitting first, unmapped, merged,
+		 * and mapped back in on-demand.
+		 */
+		VM_BUG_ON(pmd_pfn(old_pmd) != pmd_pfn(*new_pmd));
+
 		pmd_clear(pmd);
 		kvm_tlb_flush_vmid_ipa(kvm, addr);
 	} else {
#137 lore raw

PATCH 134/328 KVM: arm/arm64: Skip updating PTE entry if no change

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Punit Agrawal <[email protected]>

commit 976d34e2dab10ece5ea8fe7090b7692913f89084 upstream.

When there is contention on faulting in a particular page table entry at stage 2, the break-before-make requirement of the architecture can lead to additional refaulting due to TLB invalidation.

Avoid this by skipping a page table update if the new value of the PTE matches the previous value.

Fixes d5d8184d35c9 ("KVM: ARM: Memory virtualization setup")
[bwh: Backported to 3.16: adjust filename]
---
 arch/arm/kvm/mmu.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/kvm/mmu.c +4 -0
@@ -758,6 +758,10 @@ static int stage2_set_pte(struct kvm *kv
 	/* Create 2nd stage page table mapping - Level 3 */
 	old_pte = *pte;
 	if (pte_present(old_pte)) {
+		/* Skip page table update if there is no change */
+		if (pte_val(old_pte) == pte_val(*new_pte))
+			return 0;
+
 		kvm_set_pte(pte, __pte(0));
 		kvm_tlb_flush_vmid_ipa(kvm, addr);
 	} else {
#138 lore raw

PATCH 135/328 l2tp: use sk_dst_check() to avoid race on sk->sk_dst_cache

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Wei Wang <[email protected]>

commit 6d37fa49da1e8db8fb1995be22ac837ca41ac8a8 upstream.

In l2tp code, if it is a L2TP_UDP_ENCAP tunnel, tunnel->sk points to a UDP socket. User could call sendmsg() on both this tunnel and the UDP socket itself concurrently. As l2tp_xmit_skb() holds socket lock and call __sk_dst_check() to refresh sk->sk_dst_cache, while udpv6_sendmsg() is lockless and call sk_dst_check() to refresh sk->sk_dst_cache, there could be a race and cause the dst cache to be freed multiple times. So we fix l2tp side code to always call sk_dst_check() to garantee xchg() is called when refreshing sk->sk_dst_cache to avoid race conditions.

Syzkaller reported stack trace:

BUG: KASAN: use-after-free in atomic_read include/asm-generic/atomic-instrumented.h:21 [inline]
BUG: KASAN: use-after-free in atomic_fetch_add_unless include/linux/atomic.h:575 [inline]
BUG: KASAN: use-after-free in atomic_add_unless include/linux/atomic.h:597 [inline]
BUG: KASAN: use-after-free in dst_hold_safe include/net/dst.h:308 [inline]
BUG: KASAN: use-after-free in ip6_hold_safe+0xe6/0x670 net/ipv6/route.c:1029
Read of size 4 at addr ffff8801aea9a880 by task syz-executor129/4829

CPU: 0 PID: 4829 Comm: syz-executor129 Not tainted 4.18.0-rc7-next-20180802+ #30
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x1c9/0x2b4 lib/dump_stack.c:113
 print_address_description+0x6c/0x20b mm/kasan/report.c:256
 kasan_report_error mm/kasan/report.c:354 [inline]
 kasan_report.cold.7+0x242/0x30d mm/kasan/report.c:412
 check_memory_region_inline mm/kasan/kasan.c:260 [inline]
 check_memory_region+0x13e/0x1b0 mm/kasan/kasan.c:267
 kasan_check_read+0x11/0x20 mm/kasan/kasan.c:272
 atomic_read include/asm-generic/atomic-instrumented.h:21 [inline]
 atomic_fetch_add_unless include/linux/atomic.h:575 [inline]
 atomic_add_unless include/linux/atomic.h:597 [inline]
 dst_hold_safe include/net/dst.h:308 [inline]
 ip6_hold_safe+0xe6/0x670 net/ipv6/route.c:1029
 rt6_get_pcpu_route net/ipv6/route.c:1249 [inline]
 ip6_pol_route+0x354/0xd20 net/ipv6/route.c:1922
 ip6_pol_route_output+0x54/0x70 net/ipv6/route.c:2098
 fib6_rule_lookup+0x283/0x890 net/ipv6/fib6_rules.c:122
 ip6_route_output_flags+0x2c5/0x350 net/ipv6/route.c:2126
 ip6_dst_lookup_tail+0x1278/0x1da0 net/ipv6/ip6_output.c:978
 ip6_dst_lookup_flow+0xc8/0x270 net/ipv6/ip6_output.c:1079
 ip6_sk_dst_lookup_flow+0x5ed/0xc50 net/ipv6/ip6_output.c:1117
 udpv6_sendmsg+0x2163/0x36b0 net/ipv6/udp.c:1354
 inet_sendmsg+0x1a1/0x690 net/ipv4/af_inet.c:798
 sock_sendmsg_nosec net/socket.c:622 [inline]
 sock_sendmsg+0xd5/0x120 net/socket.c:632
 ___sys_sendmsg+0x51d/0x930 net/socket.c:2115
 __sys_sendmmsg+0x240/0x6f0 net/socket.c:2210
 __do_sys_sendmmsg net/socket.c:2239 [inline]
 __se_sys_sendmmsg net/socket.c:2236 [inline]
 __x64_sys_sendmmsg+0x9d/0x100 net/socket.c:2236
 do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x446a29
Code: e8 ac b8 02 00 48 83 c4 18 c3 0f 1f 80 00 00 00 00 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 eb 08 fc ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007f4de5532db8 EFLAGS: 00000246 ORIG_RAX: 0000000000000133
RAX: ffffffffffffffda RBX: 00000000006dcc38 RCX: 0000000000446a29
RDX: 00000000000000b8 RSI: 0000000020001b00 RDI: 0000000000000003
RBP: 00000000006dcc30 R08: 00007f4de5533700 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000006dcc3c
R13: 00007ffe2b830fdf R14: 00007f4de55339c0 R15: 0000000000000001
Fixes 71b1391a4128 ("l2tp: ensure sk->dst is still valid")
Reported-by [email protected]
Cc Guillaume Nault <[email protected]>
Cc David Ahern <[email protected]>
Cc Cong Wang <[email protected]>
---
 net/l2tp/l2tp_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/l2tp/l2tp_core.c +1 -1
@@ -1195,7 +1195,7 @@ int l2tp_xmit_skb(struct l2tp_session *s
 
 	/* Get routing info from the tunnel socket */
 	skb_dst_drop(skb);
-	skb_dst_set(skb, dst_clone(__sk_dst_check(sk, 0)));
+	skb_dst_set(skb, sk_dst_check(sk, 0));
 
 	inet = inet_sk(sk);
 	fl = &inet->cork.fl;
#139 lore raw

PATCH 136/328 xtensa: limit offsets in __loop_cache_{all,page}

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Max Filippov <[email protected]>

commit be75de25251f7cf3e399ca1f584716a95510d24a upstream.

When building kernel for xtensa cores with big cache lines (e.g. 128 bytes or more) __loop_cache_all and __loop_cache_page may generate assembly instructions with immediate fields that are too big. This results in the following build errors:

arch/xtensa/mm/misc.S: Assembler messages:
arch/xtensa/mm/misc.S:464: Error: operand 2 of 'diwbi' has invalid value '256' arch/xtensa/mm/misc.S:464: Error: operand 2 of 'diwbi' has invalid value '384' arch/xtensa/kernel/head.S: Assembler messages:
arch/xtensa/kernel/head.S:172: Error: operand 2 of 'diu' has invalid value '256' arch/xtensa/kernel/head.S:172: Error: operand 2 of 'diu' has invalid value '384' arch/xtensa/kernel/head.S:176: Error: operand 2 of 'iiu' has invalid value '256' arch/xtensa/kernel/head.S:176: Error: operand 2 of 'iiu' has invalid value '384' arch/xtensa/kernel/head.S:255: Error: operand 2 of 'diwb' has invalid value '256' arch/xtensa/kernel/head.S:255: Error: operand 2 of 'diwb' has invalid value '384'

Add parameter max_immed to these macros and use it to limit values of immediate operands. Extract common code of these macros into the new macro __loop_cache_unroll.

[bwh: Backported to 3.16: adjust context]
---
 arch/xtensa/include/asm/cacheasm.h | 65 ++++++++++++++++++------------
 1 file changed, 40 insertions(+), 25 deletions(-)
arch/xtensa/include/asm/cacheasm.h +40 -25
@@ -31,16 +31,32 @@
  *
  */
 
-	.macro	__loop_cache_all ar at insn size line_width
 
-	movi	\ar, 0
+	.macro	__loop_cache_unroll ar at insn size line_width max_immed
+
+	.if	(1 << (\line_width)) > (\max_immed)
+	.set	_reps, 1
+	.elseif	(2 << (\line_width)) > (\max_immed)
+	.set	_reps, 2
+	.else
+	.set	_reps, 4
+	.endif
+
+	__loopi	\ar, \at, \size, (_reps << (\line_width))
+	.set	_index, 0
+	.rep	_reps
+	\insn	\ar, _index << (\line_width)
+	.set	_index, _index + 1
+	.endr
+	__endla	\ar, \at, _reps << (\line_width)
+
+	.endm
+
 
-	__loopi	\ar, \at, \size, (4 << (\line_width))
-	\insn	\ar, 0 << (\line_width)
-	\insn	\ar, 1 << (\line_width)
-	\insn	\ar, 2 << (\line_width)
-	\insn	\ar, 3 << (\line_width)
-	__endla	\ar, \at, 4 << (\line_width)
+	.macro	__loop_cache_all ar at insn size line_width max_immed
+
+	movi	\ar, 0
+	__loop_cache_unroll \ar, \at, \insn, \size, \line_width, \max_immed
 
 	.endm
 
@@ -57,14 +73,9 @@
 	.endm
 
 
-	.macro	__loop_cache_page ar at insn line_width
+	.macro	__loop_cache_page ar at insn line_width max_immed
 
-	__loopi	\ar, \at, PAGE_SIZE, 4 << (\line_width)
-	\insn	\ar, 0 << (\line_width)
-	\insn	\ar, 1 << (\line_width)
-	\insn	\ar, 2 << (\line_width)
-	\insn	\ar, 3 << (\line_width)
-	__endla	\ar, \at, 4 << (\line_width)
+	__loop_cache_unroll \ar, \at, \insn, PAGE_SIZE, \line_width, \max_immed
 
 	.endm
 
@@ -73,7 +84,8 @@
 
 	.macro	___unlock_dcache_all ar at
 
-	__loop_cache_all \ar \at diu XCHAL_DCACHE_SIZE XCHAL_DCACHE_LINEWIDTH
+	__loop_cache_all \ar \at diu XCHAL_DCACHE_SIZE \
+		XCHAL_DCACHE_LINEWIDTH 240
 
 	.endm
 
@@ -83,21 +95,24 @@
 
 	.macro	___unlock_icache_all ar at
 
-	__loop_cache_all \ar \at iiu XCHAL_ICACHE_SIZE XCHAL_ICACHE_LINEWIDTH
+	__loop_cache_all \ar \at iiu XCHAL_ICACHE_SIZE \
+		XCHAL_ICACHE_LINEWIDTH 240
 
 	.endm
 #endif
 
 	.macro	___flush_invalidate_dcache_all ar at
 
-	__loop_cache_all \ar \at diwbi XCHAL_DCACHE_SIZE XCHAL_DCACHE_LINEWIDTH
+	__loop_cache_all \ar \at diwbi XCHAL_DCACHE_SIZE \
+		XCHAL_DCACHE_LINEWIDTH 240
 
 	.endm
 
 
 	.macro	___flush_dcache_all ar at
 
-	__loop_cache_all \ar \at diwb XCHAL_DCACHE_SIZE XCHAL_DCACHE_LINEWIDTH
+	__loop_cache_all \ar \at diwb XCHAL_DCACHE_SIZE \
+		XCHAL_DCACHE_LINEWIDTH 240
 
 	.endm
 
@@ -105,7 +120,7 @@
 	.macro	___invalidate_dcache_all ar at
 
 	__loop_cache_all \ar \at dii __stringify(DCACHE_WAY_SIZE) \
-			 XCHAL_DCACHE_LINEWIDTH
+			 XCHAL_DCACHE_LINEWIDTH 1020
 
 	.endm
 
@@ -113,7 +128,7 @@
 	.macro	___invalidate_icache_all ar at
 
 	__loop_cache_all \ar \at iii __stringify(ICACHE_WAY_SIZE) \
-			 XCHAL_ICACHE_LINEWIDTH
+			 XCHAL_ICACHE_LINEWIDTH 1020
 
 	.endm
 
@@ -150,27 +165,27 @@
 
 	.macro	___flush_invalidate_dcache_page ar as
 
-	__loop_cache_page \ar \as dhwbi XCHAL_DCACHE_LINEWIDTH
+	__loop_cache_page \ar \as dhwbi XCHAL_DCACHE_LINEWIDTH 1020
 
 	.endm
 
 
 	.macro ___flush_dcache_page ar as
 
-	__loop_cache_page \ar \as dhwb XCHAL_DCACHE_LINEWIDTH
+	__loop_cache_page \ar \as dhwb XCHAL_DCACHE_LINEWIDTH 1020
 
 	.endm
 
 
 	.macro	___invalidate_dcache_page ar as
 
-	__loop_cache_page \ar \as dhi XCHAL_DCACHE_LINEWIDTH
+	__loop_cache_page \ar \as dhi XCHAL_DCACHE_LINEWIDTH 1020
 
 	.endm
 
 
 	.macro	___invalidate_icache_page ar as
 
-	__loop_cache_page \ar \as ihi XCHAL_ICACHE_LINEWIDTH
+	__loop_cache_page \ar \as ihi XCHAL_ICACHE_LINEWIDTH 1020
 
 	.endm
#140 lore raw

PATCH 137/328 xtensa: increase ranges in ___invalidate_{i,d}cache_all

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Max Filippov <[email protected]>

commit fec3259c9f747c039f90e99570540114c8d81a14 upstream.

Cache invalidation macros use cache line size to iterate over invalidated cache lines, assuming that all cache ways are invalidated by single instruction, but xtensa ISA recommends to not assume that for future compatibility:
In some implementations all ways at index Addry-1..z are invalidated regardless of the specified way, but for future compatibility this behavior should not be assumed.

Iterate over all cache ways in ___invalidate_icache_all and ___invalidate_dcache_all.

[bwh: Backported to 3.16: adjust context]
---
 arch/xtensa/include/asm/cacheasm.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/xtensa/include/asm/cacheasm.h +2 -2
@@ -119,7 +119,7 @@
 
 	.macro	___invalidate_dcache_all ar at
 
-	__loop_cache_all \ar \at dii __stringify(DCACHE_WAY_SIZE) \
+	__loop_cache_all \ar \at dii XCHAL_DCACHE_SIZE \
 			 XCHAL_DCACHE_LINEWIDTH 1020
 
 	.endm
@@ -127,7 +127,7 @@
 
 	.macro	___invalidate_icache_all ar at
 
-	__loop_cache_all \ar \at iii __stringify(ICACHE_WAY_SIZE) \
+	__loop_cache_all \ar \at iii XCHAL_ICACHE_SIZE \
 			 XCHAL_ICACHE_LINEWIDTH 1020
 
 	.endm
#141 lore raw

PATCH 138/328 ubifs: Fix synced_i_size calculation for xattr inodes

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Richard Weinberger <[email protected]>

commit 59965593205fa4044850d35ee3557cf0b7edcd14 upstream.

In ubifs_jnl_update() we sync parent and child inodes to the flash, in case of xattrs, the parent inode (AKA host inode) has a non-zero data_len. Therefore we need to adjust synced_i_size too.

This issue was reported by ubifs self tests unter a xattr related work
load.
UBIFS error (ubi0:0 pid 1896): dbg_check_synced_i_size: ui_size is 4, synced_i_size is 0, but inode is clean UBIFS error (ubi0:0 pid 1896): dbg_check_synced_i_size: i_ino 65, i_mode 0x81a4, i_size 4

Fixes 1e51764a3c2a ("UBIFS: add new flash file system")
[bwh: Backported to 3.16: s/host_ui/dir_ui/]
---
 fs/ubifs/journal.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/ubifs/journal.c +5 -0
@@ -657,6 +657,11 @@ int ubifs_jnl_update(struct ubifs_info *
 	spin_lock(&ui->ui_lock);
 	ui->synced_i_size = ui->ui_size;
 	spin_unlock(&ui->ui_lock);
+	if (xent) {
+		spin_lock(&dir_ui->ui_lock);
+		dir_ui->synced_i_size = dir_ui->ui_size;
+		spin_unlock(&dir_ui->ui_lock);
+	}
 	mark_inode_clean(c, ui);
 	mark_inode_clean(c, dir_ui);
 	return 0;
#142 lore raw

PATCH 139/328 ubifs: Fix memory leak in lprobs self-check

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Richard Weinberger <[email protected]>

commit eef19816ada3abd56d9f20c88794cc2fea83ebb2 upstream.

Allocate the buffer after we return early.
Otherwise memory is being leaked.

Fixes 1e51764a3c2a ("UBIFS: add new flash file system")
---
 fs/ubifs/lprops.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ubifs/lprops.c +4 -4
@@ -1091,10 +1091,6 @@ static int scan_check_cb(struct ubifs_in
 		}
 	}
 
-	buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-
 	/*
 	 * After an unclean unmount, empty and freeable LEBs
 	 * may contain garbage - do not scan them.
@@ -1113,6 +1109,10 @@ static int scan_check_cb(struct ubifs_in
 		return LPT_SCAN_CONTINUE;
 	}
 
+	buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
 	sleb = ubifs_scan(c, lnum, 0, buf, 0);
 	if (IS_ERR(sleb)) {
 		ret = PTR_ERR(sleb);
#143 lore raw

PATCH 140/328 ubifs: Check data node size before truncate

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Richard Weinberger <[email protected]>

commit 95a22d2084d72ea067d8323cc85677dba5d97cae upstream.

Check whether the size is within bounds before using it. If the size is not correct, abort and dump the bad data node.

Cc Kees Cook <[email protected]>
Cc Silvio Cesare <[email protected]>
Fixes 1e51764a3c2ac ("UBIFS: add new flash file system")
[bwh: Backported to 3.16: Drop first argument to ubifs_err()]
---
 fs/ubifs/journal.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
fs/ubifs/journal.c +10 -1
@@ -1186,7 +1186,16 @@ int ubifs_jnl_truncate(struct ubifs_info
 		else if (err)
 			goto out_free;
 		else {
-			if (le32_to_cpu(dn->size) <= dlen)
+			int dn_len = le32_to_cpu(dn->size);
+
+			if (dn_len <= 0 || dn_len > UBIFS_BLOCK_SIZE) {
+				ubifs_err("bad data node (block %u, inode %lu)",
+					  blk, inode->i_ino);
+				ubifs_dump_node(c, dn);
+				goto out_free;
+			}
+
+			if (dn_len <= dlen)
 				dlen = 0; /* Nothing to do */
 			else {
 				int compr_type = le16_to_cpu(dn->compr_type);
#144 lore raw

PATCH 141/328 drm/i915: set DP Main Stream Attribute for color range on DDI platforms

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Jani Nikula <[email protected]>

commit 6209c285e7a5e68dbcdf8fd2456c6dd68433806b upstream.

Since Haswell we have no color range indication either in the pipe or port registers for DP. Instead, there's a separate register for setting the DP Main Stream Attributes (MSA) directly. The MSA register definition makes no references to colorimetry, just a vague reference to the DP spec. The connection to the color range was lost.

Apparently we've failed to set the proper MSA bit for limited, or CEA, range ever since the first DDI platforms. We've started setting other MSA parameters since commit dae847991a43 ("drm/i915: add intel_ddi_set_pipe_settings").

Without the crucial bit of information, the DP sink has no way of knowing the source is actually transmitting limited range RGB, leading to "washed out" colors. With the colorimetry information, compliant sinks should be able to handle the limited range properly. Native (i.e. non-LSPCON) HDMI was not affected because we do pass the color range via AVI infoframes.

Though not the root cause, the problem was made worse for DDI platforms with commit 55bc60db5988 ("drm/i915: Add "Automatic" mode for the "Broadcast RGB" property"), which selects limited range RGB automatically based on the mode, as per the DP, HDMI and CEA specs.

After all these years, the fix boils down to flipping one bit.

[Per testing reports, this fixes DP sinks, but not the LSPCON. My
educated guess is that the LSPCON fails to turn the CEA range MSA into AVI infoframes for HDMI.]

References: https://bugs.freedesktop.org/show_bug.cgi?id=100023
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107476
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=94921

Cc Paulo Zanoni <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Ville Syrjälä <[email protected]>
(cherry picked from commit dc5977da99ea28094b8fa4e9bacbd29bedc41de5)

[bwh: Backported to 3.16:
- s/crtc_state->/intel_crtc->config./
- Adjust context, indentation]

---
 drivers/gpu/drm/i915/i915_reg.h  | 1 +
 drivers/gpu/drm/i915/intel_ddi.c | 4 ++++
 2 files changed, 5 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +1 -0
@@ -5918,6 +5918,7 @@ enum punit_power_well {
 #define  TRANS_MSA_10_BPC		(2<<5)
 #define  TRANS_MSA_12_BPC		(3<<5)
 #define  TRANS_MSA_16_BPC		(4<<5)
+#define  TRANS_MSA_CEA_RANGE		(1 << 3)
 
 /* LCPLL Control */
 #define LCPLL_CTL			0x130040
drivers/gpu/drm/i915/intel_ddi.c +4 -0
@@ -929,6 +929,10 @@ void intel_ddi_set_pipe_settings(struct
 	if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
 
 		temp = TRANS_MSA_SYNC_CLK;
+
+		if (intel_crtc->config.limited_color_range)
+			temp |= TRANS_MSA_CEA_RANGE;
+
 		switch (intel_crtc->config.pipe_bpp) {
 		case 18:
 			temp |= TRANS_MSA_6_BPC;
#145 lore raw

PATCH 142/328 mfd: sm501: Set coherent_dma_mask when creating subdevices

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Guenter Roeck <[email protected]>

commit 2f606da78230f09cf1a71fde6ee91d0c710fa2b2 upstream.

Instantiating the sm501 OHCI subdevice results in a kernel warning.

sm501-usb sm501-usb: SM501 OHCI
sm501-usb sm501-usb: new USB bus registered, assigned bus number 1

WARNING: CPU: 0 PID: 1 at ./include/linux/dma-mapping.h:516
ohci_init+0x194/0x2d8
Modules linked in:

CPU: 0 PID: 1 Comm: swapper Tainted: G        W

4.18.0-rc7-00178-g0b5b1f9a78b5 #1
PC is at ohci_init+0x194/0x2d8
PR is at ohci_init+0x168/0x2d8
PC : 8c27844c SP : 8f81dd94 SR : 40008001
TEA : 29613060
R0 : 00000000 R1 : 00000000 R2 : 00000000 R3 : 00000202 R4 : 8fa98b88 R5 : 8c277e68 R6 : 00000000 R7 : 00000000 R8 : 8f965814 R9 : 8c388100 R10 : 8fa98800 R11 : 8fa98928 R12 : 8c48302c R13 : 8fa98920 R14 : 8c48302c
MACH: 00000096 MACL: 0000017c GBR : 00000000 PR : 8c278420

Call trace:
 [<(ptrval)>] usb_add_hcd+0x1e8/0x6ec
 [<(ptrval)>] _dev_info+0x0/0x54
 [<(ptrval)>] arch_local_save_flags+0x0/0x8
 [<(ptrval)>] arch_local_irq_restore+0x0/0x24
 [<(ptrval)>] ohci_hcd_sm501_drv_probe+0x114/0x2d8

...

Initialize coherent_dma_mask when creating SM501 subdevices to fix the problem.

Fixes b6d6454fdb66f ("mfd: SM501 core driver")
---
 drivers/mfd/sm501.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mfd/sm501.c +1 -0
@@ -714,6 +714,7 @@ sm501_create_subdev(struct sm501_devdata
 	smdev->pdev.name = name;
 	smdev->pdev.id = sm->pdev_id;
 	smdev->pdev.dev.parent = sm->dev;
+	smdev->pdev.dev.coherent_dma_mask = 0xffffffff;
 
 	if (res_count) {
 		smdev->pdev.resource = (struct resource *)(smdev+1);
#146 lore raw

PATCH 143/328 s390/pci: fix out of bounds access during irq setup

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Sebastian Ott <[email protected]>

commit 866f3576a72b2233a76dffb80290f8086dc49e17 upstream.

During interrupt setup we allocate interrupt vectors, walk the list of msi descriptors, and fill in the message data. Requesting more interrupts than supported on s390 can lead to an out of bounds access.

When we restrict the number of interrupts we should also stop walking the msi list after all supported interrupts are handled.

---
 arch/s390/pci/pci.c | 2 ++
 1 file changed, 2 insertions(+)
arch/s390/pci/pci.c +2 -0
@@ -397,6 +397,8 @@ int arch_setup_msi_irqs(struct pci_dev *
 	hwirq = 0;
 	list_for_each_entry(msi, &pdev->msi_list, list) {
 		rc = -EIO;
+		if (hwirq >= msi_vecs)
+			break;
 		irq = irq_alloc_desc(0);	/* Alloc irq on node 0 */
 		if (irq < 0)
 			goto out_msi;
#147 lore raw

PATCH 144/328 netfilter: nft_set: fix allocation size overflow in privsize callback.

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Taehee Yoo <[email protected]>

commit 4ef360dd6a65f6ef337645e1b65e744034754b19 upstream.

In order to determine allocation size of set, ->privsize is invoked. At this point, both desc->size and size of each data structure of set are used. desc->size means number of element that is given by user. desc->size is u32 type. so that upperlimit of set element is 4294967295. but return type of ->privsize is also u32. hence overflow can occurred.

test commands:
%nft add table ip filter
%nft add set ip filter hash1 { type ipv4_addr \; size 4294967295 \; } %nft list ruleset

splat looks like:

[ 1239.202910] kasan: CONFIG_KASAN_INLINE enabled
[ 1239.208788] kasan: GPF could be caused by NULL-ptr deref or user memory access
[ 1239.217625] general protection fault: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN PTI
[ 1239.219329] CPU: 0 PID: 1603 Comm: nft Not tainted 4.18.0-rc5+ #7
[ 1239.229091] RIP: 0010:nft_hash_walk+0x1d2/0x310 [nf_tables_set]
[ 1239.229091] Code: 84 d2 7f 10 4c 89 e7 89 44 24 38 e8 d8 5a 17 e0 8b 44 24 38 48 8d 7b 10 41 0f b6 0c 24 48 89 fa 48 89 fe 48 c1 ea 03 83 e6 07 <42> 0f b6 14 3a 40 38 f2 7f 1a 84 d2 74 16
[ 1239.229091] RSP: 0018:ffff8801118cf358 EFLAGS: 00010246
[ 1239.229091] RAX: 0000000000000000 RBX: 0000000000020400 RCX: 0000000000000001
[ 1239.229091] RDX: 0000000000004082 RSI: 0000000000000000 RDI: 0000000000020410
[ 1239.229091] RBP: ffff880114d5a988 R08: 0000000000007e94 R09: ffff880114dd8030
[ 1239.229091] R10: ffff880114d5a988 R11: ffffed00229bb006 R12: ffff8801118cf4d0
[ 1239.229091] R13: ffff8801118cf4d8 R14: 0000000000000000 R15: dffffc0000000000
[ 1239.229091] FS:  00007f5a8fe0b700(0000) GS:ffff88011b600000(0000) knlGS:0000000000000000
[ 1239.229091] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 1239.229091] CR2: 00007f5a8ecc27b0 CR3: 000000010608e000 CR4: 00000000001006f0
[ 1239.229091] Call Trace:
[ 1239.229091]  ? nft_hash_remove+0xf0/0xf0 [nf_tables_set]
[ 1239.229091]  ? memset+0x1f/0x40
[ 1239.229091]  ? __nla_reserve+0x9f/0xb0
[ 1239.229091]  ? memcpy+0x34/0x50
[ 1239.229091]  nf_tables_dump_set+0x9a1/0xda0 [nf_tables]
[ 1239.229091]  ? __kmalloc_reserve.isra.29+0x2e/0xa0
[ 1239.229091]  ? nft_chain_hash_obj+0x630/0x630 [nf_tables]
[ 1239.229091]  ? nf_tables_commit+0x2c60/0x2c60 [nf_tables]
[ 1239.229091]  netlink_dump+0x470/0xa20
[ 1239.229091]  __netlink_dump_start+0x5ae/0x690
[ 1239.229091]  nft_netlink_dump_start_rcu+0xd1/0x160 [nf_tables]
[ 1239.229091]  nf_tables_getsetelem+0x2e5/0x4b0 [nf_tables]
[ 1239.229091]  ? nft_get_set_elem+0x440/0x440 [nf_tables]
[ 1239.229091]  ? nft_chain_hash_obj+0x630/0x630 [nf_tables]
[ 1239.229091]  ? nf_tables_dump_obj_done+0x70/0x70 [nf_tables]
[ 1239.229091]  ? nla_parse+0xab/0x230
[ 1239.229091]  ? nft_get_set_elem+0x440/0x440 [nf_tables]
[ 1239.229091]  nfnetlink_rcv_msg+0x7f0/0xab0 [nfnetlink]
[ 1239.229091]  ? nfnetlink_bind+0x1d0/0x1d0 [nfnetlink]
[ 1239.229091]  ? debug_show_all_locks+0x290/0x290
[ 1239.229091]  ? sched_clock_cpu+0x132/0x170
[ 1239.229091]  ? find_held_lock+0x39/0x1b0
[ 1239.229091]  ? sched_clock_local+0x10d/0x130
[ 1239.229091]  netlink_rcv_skb+0x211/0x320
[ 1239.229091]  ? nfnetlink_bind+0x1d0/0x1d0 [nfnetlink]
[ 1239.229091]  ? netlink_ack+0x7b0/0x7b0
[ 1239.229091]  ? ns_capable_common+0x6e/0x110
[ 1239.229091]  nfnetlink_rcv+0x2d1/0x310 [nfnetlink]
[ 1239.229091]  ? nfnetlink_rcv_batch+0x10f0/0x10f0 [nfnetlink]
[ 1239.229091]  ? netlink_deliver_tap+0x829/0x930
[ 1239.229091]  ? lock_acquire+0x265/0x2e0
[ 1239.229091]  netlink_unicast+0x406/0x520
[ 1239.509725]  ? netlink_attachskb+0x5b0/0x5b0
[ 1239.509725]  ? find_held_lock+0x39/0x1b0
[ 1239.509725]  netlink_sendmsg+0x987/0xa20
[ 1239.509725]  ? netlink_unicast+0x520/0x520
[ 1239.509725]  ? _copy_from_user+0xa9/0xc0
[ 1239.509725]  __sys_sendto+0x21a/0x2c0
[ 1239.509725]  ? __ia32_sys_getpeername+0xa0/0xa0
[ 1239.509725]  ? retint_kernel+0x10/0x10
[ 1239.509725]  ? sched_clock_cpu+0x132/0x170
[ 1239.509725]  ? find_held_lock+0x39/0x1b0
[ 1239.509725]  ? lock_downgrade+0x540/0x540
[ 1239.509725]  ? up_read+0x1c/0x100
[ 1239.509725]  ? __do_page_fault+0x763/0x970
[ 1239.509725]  ? retint_user+0x18/0x18
[ 1239.509725]  __x64_sys_sendto+0x177/0x180
[ 1239.509725]  do_syscall_64+0xaa/0x360
[ 1239.509725]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
[ 1239.509725] RIP: 0033:0x7f5a8f468e03
[ 1239.509725] Code: 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb d0 0f 1f 84 00 00 00 00 00 83 3d 49 c9 2b 00 00 75 13 49 89 ca b8 2c 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 34 c3 48 83 ec 08 e8
[ 1239.509725] RSP: 002b:00007ffd78d0b778 EFLAGS: 00000246 ORIG_RAX: 000000000000002c
[ 1239.509725] RAX: ffffffffffffffda RBX: 00007ffd78d0c890 RCX: 00007f5a8f468e03
[ 1239.509725] RDX: 0000000000000034 RSI: 00007ffd78d0b7e0 RDI: 0000000000000003
[ 1239.509725] RBP: 00007ffd78d0b7d0 R08: 00007f5a8f15c160 R09: 000000000000000c
[ 1239.509725] R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffd78d0b7e0
[ 1239.509725] R13: 0000000000000034 R14: 00007f5a8f9aff60 R15: 00005648040094b0
[ 1239.509725] Modules linked in: nf_tables_set nf_tables nfnetlink ip_tables x_tables
[ 1239.670713] ---[ end trace 39375adcda140f11 ]---
[ 1239.676016] RIP: 0010:nft_hash_walk+0x1d2/0x310 [nf_tables_set]
[ 1239.682834] Code: 84 d2 7f 10 4c 89 e7 89 44 24 38 e8 d8 5a 17 e0 8b 44 24 38 48 8d 7b 10 41 0f b6 0c 24 48 89 fa 48 89 fe 48 c1 ea 03 83 e6 07 <42> 0f b6 14 3a 40 38 f2 7f 1a 84 d2 74 16
[ 1239.705108] RSP: 0018:ffff8801118cf358 EFLAGS: 00010246
[ 1239.711115] RAX: 0000000000000000 RBX: 0000000000020400 RCX: 0000000000000001
[ 1239.719269] RDX: 0000000000004082 RSI: 0000000000000000 RDI: 0000000000020410
[ 1239.727401] RBP: ffff880114d5a988 R08: 0000000000007e94 R09: ffff880114dd8030
[ 1239.735530] R10: ffff880114d5a988 R11: ffffed00229bb006 R12: ffff8801118cf4d0
[ 1239.743658] R13: ffff8801118cf4d8 R14: 0000000000000000 R15: dffffc0000000000
[ 1239.751785] FS:  00007f5a8fe0b700(0000) GS:ffff88011b600000(0000) knlGS:0000000000000000
[ 1239.760993] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 1239.767560] CR2: 00007f5a8ecc27b0 CR3: 000000010608e000 CR4: 00000000001006f0
[ 1239.775679] Kernel panic - not syncing: Fatal exception
[ 1239.776630] Kernel Offset: 0x1f000000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff)
[ 1239.776630] Rebooting in 5 seconds..
Fixes 20a69341f2d0 ("netfilter: nf_tables: add netlink set API")

[bwh: Backported to 3.16:
- Drop changes to nft_rhash_privsize() and in nft_set_bitmap.c
- Adjust filenames]

---

include/net/netfilter/nf_tables.h +2 -2
@@ -183,7 +183,7 @@ enum nft_set_class {
  *	@class: lookup performance class
  */
 struct nft_set_estimate {
-	unsigned int		size;
+	u64			size;
 	enum nft_set_class	class;
 };
 
@@ -215,7 +215,7 @@ struct nft_set_ops {
 						const struct nft_set *set,
 						struct nft_set_iter *iter);
 
-	unsigned int			(*privsize)(const struct nlattr * const nla[]);
+	u64				(*privsize)(const struct nlattr * const nla[]);
 	bool				(*estimate)(const struct nft_set_desc *desc,
 						    u32 features,
 						    struct nft_set_estimate *est);
net/netfilter/nf_tables_api.c +1 -1
@@ -2519,7 +2519,7 @@ static int nf_tables_newset(struct sock
 	struct nft_set *set;
 	struct nft_ctx ctx;
 	char name[IFNAMSIZ];
-	unsigned int size;
+	u64 size;
 	bool create;
 	u32 ktype, dtype, flags, policy;
 	struct nft_set_desc desc;
net/netfilter/nft_hash.c +1 -1
@@ -327,7 +327,7 @@ cont:
 	}
 }
 
-static unsigned int nft_hash_privsize(const struct nlattr * const nla[])
+static u64 nft_hash_privsize(const struct nlattr * const nla[])
 {
 	return sizeof(struct nft_hash);
 }
net/netfilter/nft_rbtree.c +1 -1
@@ -211,7 +211,7 @@ cont:
 	spin_unlock_bh(&nft_rbtree_lock);
 }
 
-static unsigned int nft_rbtree_privsize(const struct nlattr * const nla[])
+static u64 nft_rbtree_privsize(const struct nlattr * const nla[])
 {
 	return sizeof(struct nft_rbtree);
 }
#148 lore raw

PATCH 145/328 netfilter: nf_tables: fix register ordering

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Florian Westphal <[email protected]>

commit d209df3e7f7002d9099fdb0f6df0f972b4386a63 upstream.

We must register nfnetlink ops last, as that exposes nf_tables to userspace. Without this, we could theoretically get nfnetlink request before net->nft state has been initialized.

Fixes 99633ab29b213 ("netfilter: nf_tables: complete net namespace support")

[bwh: Backported to 3.16:
- We don't call nft_chain_filter_{init,fini}() or {,un}register_netdevice_notifier()
- Adjust context]

---

net/netfilter/nf_tables_api.c +7 -1
@@ -4042,6 +4042,10 @@ static int __init nf_tables_module_init(
 {
 	int err;
 
+	err = register_pernet_subsys(&nf_tables_net_ops);
+	if (err < 0)
+		return err;
+
 	info = kmalloc(sizeof(struct nft_expr_info) * NFT_RULE_MAXEXPRS,
 		       GFP_KERNEL);
 	if (info == NULL) {
@@ -4053,17 +4057,19 @@ static int __init nf_tables_module_init(
 	if (err < 0)
 		goto err2;
 
+	/* must be last */
 	err = nfnetlink_subsys_register(&nf_tables_subsys);
 	if (err < 0)
 		goto err3;
 
 	pr_info("nf_tables: (c) 2007-2009 Patrick McHardy <[email protected]>\n");
-	return register_pernet_subsys(&nf_tables_net_ops);
+	return err;
 err3:
 	nf_tables_core_module_exit();
 err2:
 	kfree(info);
 err1:
+	unregister_pernet_subsys(&nf_tables_net_ops);
 	return err;
 }
 
#149 lore raw

PATCH 146/328 tracing/blktrace: Fix to allow setting same value

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: "Steven Rostedt (VMware)" <[email protected]>

commit 757d9140072054528b13bbe291583d9823cde195 upstream.

Masami Hiramatsu reported:

Current trace-enable attribute in sysfs returns an error if user writes the same setting value as current one, e.g.

    # cat /sys/block/sda/trace/enable
    0
    # echo 0 > /sys/block/sda/trace/enable
    bash: echo: write error: Invalid argument
    # echo 1 > /sys/block/sda/trace/enable
    # echo 1 > /sys/block/sda/trace/enable
    bash: echo: write error: Device or resource busy

But this is not a preferred behavior, it should ignore if new setting is same as current one. This fixes the problem as below.

    # cat /sys/block/sda/trace/enable
    0
    # echo 0 > /sys/block/sda/trace/enable
    # echo 1 > /sys/block/sda/trace/enable
    # echo 1 > /sys/block/sda/trace/enable
Cc Ingo Molnar <[email protected]>
Cc Jens Axboe <[email protected]>
Fixes cd649b8bb830d ("blktrace: remove sysfs_blk_trace_enable_show/store()")
---
 kernel/trace/blktrace.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/trace/blktrace.c +4 -0
@@ -1778,6 +1778,10 @@ static ssize_t sysfs_blk_trace_attr_stor
 	mutex_lock(&q->blk_trace_mutex);
 
 	if (attr == &dev_attr_enable) {
+		if (!!value == !!q->blk_trace) {
+			ret = 0;
+			goto out_unlock_bdev;
+		}
 		if (value)
 			ret = blk_trace_setup_queue(q, bdev);
 		else
#150 lore raw

PATCH 147/328 arm64: mm: check for upper PAGE_SHIFT bits in pfn_valid()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Greg Hackmann <[email protected]>

commit 5ad356eabc47d26a92140a0c4b20eba471c10de3 upstream.

ARM64's pfn_valid() shifts away the upper PAGE_SHIFT bits of the input before seeing if the PFN is valid. This leads to false positives when some of the upper bits are set, but the lower bits match a valid PFN.

For example, the following userspace code looks up a bogus entry in /proc/kpageflags:

    int pagemap = open("/proc/self/pagemap", O_RDONLY);
    int pageflags = open("/proc/kpageflags", O_RDONLY);
    uint64_t pfn, val;

    lseek64(pagemap, [...], SEEK_SET);
    read(pagemap, &pfn, sizeof(pfn));
    if (pfn & (1UL << 63)) {        /* valid PFN */
        pfn &= ((1UL << 55) - 1);   /* clear flag bits */
        pfn |= (1UL << 55);
        lseek64(pageflags, pfn * sizeof(uint64_t), SEEK_SET);
        read(pageflags, &val, sizeof(val));
    }

On ARM64 this causes the userspace process to crash with SIGSEGV rather than reading (1 << KPF_NOPAGE). kpageflags_read() treats the offset as valid, and stable_page_flags() will try to access an address between the user and kernel address ranges.

Fixes c1cc1552616d ("arm64: MMU initialisation")
[bwh: Backported to 3.16: Keep using memblock_is_memory()]
---
 arch/arm64/mm/init.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm64/mm/init.c +5 -1
@@ -113,7 +113,11 @@ static void __init zone_sizes_init(unsig
 #ifdef CONFIG_HAVE_ARCH_PFN_VALID
 int pfn_valid(unsigned long pfn)
 {
-	return memblock_is_memory(pfn << PAGE_SHIFT);
+	phys_addr_t addr = pfn << PAGE_SHIFT;
+
+	if ((addr >> PAGE_SHIFT) != pfn)
+		return 0;
+	return memblock_is_memory(addr);
 }
 EXPORT_SYMBOL(pfn_valid);
 #endif
#151 lore raw

PATCH 148/328 KVM: PPC: Book3S HV: Don't truncate HPTE index in xlate function

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Paul Mackerras <[email protected]>

commit 46dec40fb741f00f1864580130779aeeaf24fb3d upstream.

This fixes a bug which causes guest virtual addresses to get translated to guest real addresses incorrectly when the guest is using the HPT MMU and has more than 256GB of RAM, or more specifically has a HPT larger than 2GB. This has showed up in testing as a failure of the host to emulate doorbell instructions correctly on POWER9 for HPT guests with more than 256GB of RAM.

The bug is that the HPTE index in kvmppc_mmu_book3s_64_hv_xlate() is stored as an int, and in forming the HPTE address, the index gets shifted left 4 bits as an int before being signed-extended to 64 bits. The simple fix is to make the variable a long int, matching the return type of kvmppc_hv_find_lock_hpte(), which is what calculates the index.

Fixes 697d3899dcb4 ("KVM: PPC: Implement MMIO emulation support for Book3S HV guests")
[bwh: Backported to 3.16: adjust context]
---
 arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/book3s_64_mmu_hv.c +1 -1
@@ -451,7 +451,7 @@ static int kvmppc_mmu_book3s_64_hv_xlate
 	unsigned long pp, key;
 	unsigned long v, gr;
 	unsigned long *hptep;
-	int index;
+	long int index;
 	int virtmode = vcpu->arch.shregs.msr & (data ? MSR_DR : MSR_IR);
 
 	/* Get SLB entry */
#152 lore raw

PATCH 149/328 powerpc/powernv/pci: Work around races in PCI bridge enabling

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Benjamin Herrenschmidt <[email protected]>

commit db2173198b9513f7add8009f225afa1f1c79bcc6 upstream.

The generic code is racy when multiple children of a PCI bridge try to enable it simultaneously.

This leads to drivers trying to access a device through a not-yet-enabled bridge, and this EEH errors under various circumstances when using parallel driver probing.

There is work going on to fix that properly in the PCI core but it will take some time.

x86 gets away with it because (outside of hotplug), the BIOS enables all the bridges at boot time.

This patch does the same thing on powernv by enabling all bridges that have child devices at boot time, thus avoiding subsequent races. It's suitable for backporting to stable and distros, while the proper PCI fix will probably be significantly more invasive.

[bwh: Backported to 3.16:
- Use dev_err() instead of pci_err()
- Adjust context]

---
 arch/powerpc/platforms/powernv/pci-ioda.c | 37 +++++++++++++++++++++++
 1 file changed, 37 insertions(+)
arch/powerpc/platforms/powernv/pci-ioda.c +37 -0
@@ -1132,6 +1132,41 @@ static void pnv_pci_ioda_create_dbgfs(vo
 #endif /* CONFIG_DEBUG_FS */
 }
 
+static void pnv_pci_enable_bridge(struct pci_bus *bus)
+{
+	struct pci_dev *dev = bus->self;
+	struct pci_bus *child;
+
+	/* Empty bus ? bail */
+	if (list_empty(&bus->devices))
+		return;
+
+	/*
+	 * If there's a bridge associated with that bus enable it. This works
+	 * around races in the generic code if the enabling is done during
+	 * parallel probing. This can be removed once those races have been
+	 * fixed.
+	 */
+	if (dev) {
+		int rc = pci_enable_device(dev);
+		if (rc)
+			dev_err(&dev->dev, "Error enabling bridge (%d)\n", rc);
+		pci_set_master(dev);
+	}
+
+	/* Perform the same to child busses */
+	list_for_each_entry(child, &bus->children, node)
+		pnv_pci_enable_bridge(child);
+}
+
+static void pnv_pci_enable_bridges(void)
+{
+	struct pci_controller *hose;
+
+	list_for_each_entry(hose, &hose_list, list_node)
+		pnv_pci_enable_bridge(hose->bus);
+}
+
 static void pnv_pci_ioda_fixup(void)
 {
 	pnv_pci_ioda_setup_PEs();
@@ -1140,6 +1175,8 @@ static void pnv_pci_ioda_fixup(void)
 
 	pnv_pci_ioda_create_dbgfs();
 
+	pnv_pci_enable_bridges();
+
 #ifdef CONFIG_EEH
 	eeh_probe_mode_set(EEH_PROBE_MODE_DEV);
 	eeh_addr_cache_build();
#153 lore raw

PATCH 150/328 x86/process: Re-export start_thread()

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Rian Hunter <[email protected]>

commit dc76803e57cc86589c4efcb5362918f9b0c0436f upstream.

The consolidation of the start_thread() functions removed the export unintentionally. This breaks binfmt handlers built as a module.

Add it back.

Fixes e634d8fc792c ("x86-64: merge the standard and compat start_thread() functions")
Cc "H. Peter Anvin" <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Vitaly Kuznetsov <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Dmitry Safonov <[email protected]>
Cc Josh Poimboeuf <[email protected]>
---
 arch/x86/kernel/process_64.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/kernel/process_64.c +1 -0
@@ -254,6 +254,7 @@ start_thread(struct pt_regs *regs, unsig
 	start_thread_common(regs, new_ip, new_sp,
 			    __USER_CS, __USER_DS, 0);
 }
+EXPORT_SYMBOL_GPL(start_thread);
 
 #ifdef CONFIG_IA32_EMULATION
 void start_thread_ia32(struct pt_regs *regs, u32 new_ip, u32 new_sp)
#154 lore raw

PATCH 151/328 iscsi-target: nullify session in failed login sequence

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Sagi Grimberg <[email protected]>

commit a0b3b9b2409b409c677f7eb1e0485b816a5848f7 upstream.

In case login sequence failed, make sure conn->sess is NULL before calling wait_conn as some transports (iser) may rely on that (waiting for session commands).

---
 drivers/target/iscsi/iscsi_target_login.c | 1 +
 1 file changed, 1 insertion(+)
drivers/target/iscsi/iscsi_target_login.c +1 -0
@@ -1209,6 +1209,7 @@ void iscsi_target_login_sess_out(struct
 	}
 	kfree(conn->sess->sess_ops);
 	kfree(conn->sess);
+	conn->sess = NULL;
 
 old_sess_out:
 	iscsi_stop_login_thread_timer(np);
#155 lore raw

PATCH 152/328 ISCSI: fix minor memory leak

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Evgenii Lepikhin <[email protected]>

commit a928d28d4487402e6bd18bea1b8cc2b2ec6e6d8f upstream.

This patch adds a missing kfree for sess->sess_ops memory upon transport_init_session() failure.

---
 drivers/target/iscsi/iscsi_target_login.c | 1 +
 1 file changed, 1 insertion(+)
drivers/target/iscsi/iscsi_target_login.c +1 -0
@@ -348,6 +348,7 @@ static int iscsi_login_zero_tsih_s1(
 	if (IS_ERR(sess->se_sess)) {
 		iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
 				ISCSI_LOGIN_STATUS_NO_RESOURCES);
+		kfree(sess->sess_ops);
 		kfree(sess);
 		return -ENOMEM;
 	}
#156 lore raw

PATCH 153/328 iscsi target: fix session creation failure handling

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mike Christie <[email protected]>

commit 26abc916a898d34c5ad159315a2f683def3c5555 upstream.

The problem is that iscsi_login_zero_tsih_s1 sets conn->sess early in iscsi_login_set_conn_values. If the function fails later like when we alloc the idr it does kfree(sess) and leaves the conn->sess pointer set. iscsi_login_zero_tsih_s1 then returns -Exyz and we then call iscsi_target_login_sess_out and access the freed memory.

This patch has iscsi_login_zero_tsih_s1 either completely setup the session or completely tear it down, so later in iscsi_target_login_sess_out we can just check for it being set to the connection.

Fixes 0957627a9960 ("iscsi-target: Fix sess allocation leak in...")
---
 drivers/target/iscsi/iscsi_target_login.c | 35 ++++++++++++++---------
 1 file changed, 21 insertions(+), 14 deletions(-)
drivers/target/iscsi/iscsi_target_login.c +21 -14
@@ -323,8 +323,7 @@ static int iscsi_login_zero_tsih_s1(
 		pr_err("idr_alloc() for sess_idr failed\n");
 		iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
 				ISCSI_LOGIN_STATUS_NO_RESOURCES);
-		kfree(sess);
-		return -ENOMEM;
+		goto free_sess;
 	}
 
 	sess->creation_time = get_jiffies_64();
@@ -340,20 +339,28 @@ static int iscsi_login_zero_tsih_s1(
 				ISCSI_LOGIN_STATUS_NO_RESOURCES);
 		pr_err("Unable to allocate memory for"
 				" struct iscsi_sess_ops.\n");
-		kfree(sess);
-		return -ENOMEM;
+		goto remove_idr;
 	}
 
 	sess->se_sess = transport_init_session(TARGET_PROT_NORMAL);
 	if (IS_ERR(sess->se_sess)) {
 		iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
 				ISCSI_LOGIN_STATUS_NO_RESOURCES);
-		kfree(sess->sess_ops);
-		kfree(sess);
-		return -ENOMEM;
+		goto free_ops;
 	}
 
 	return 0;
+
+free_ops:
+	kfree(sess->sess_ops);
+remove_idr:
+	spin_lock_bh(&sess_idr_lock);
+	idr_remove(&sess_idr, sess->session_index);
+	spin_unlock_bh(&sess_idr_lock);
+free_sess:
+	kfree(sess);
+	conn->sess = NULL;
+	return -ENOMEM;
 }
 
 static int iscsi_login_zero_tsih_s2(
@@ -1201,13 +1208,13 @@ void iscsi_target_login_sess_out(struct
 				   ISCSI_LOGIN_STATUS_INIT_ERR);
 	if (!zero_tsih || !conn->sess)
 		goto old_sess_out;
-	if (conn->sess->se_sess)
-		transport_free_session(conn->sess->se_sess);
-	if (conn->sess->session_index != 0) {
-		spin_lock_bh(&sess_idr_lock);
-		idr_remove(&sess_idr, conn->sess->session_index);
-		spin_unlock_bh(&sess_idr_lock);
-	}
+
+	transport_free_session(conn->sess->se_sess);
+
+	spin_lock_bh(&sess_idr_lock);
+	idr_remove(&sess_idr, conn->sess->session_index);
+	spin_unlock_bh(&sess_idr_lock);
+
 	kfree(conn->sess->sess_ops);
 	kfree(conn->sess);
 	conn->sess = NULL;
#157 lore raw

PATCH 154/328 fs/quota: Fix spectre gadget in do_quotactl

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Jeremy Cline <[email protected]>

commit 7b6924d94a60c6b8c1279ca003e8744e6cd9e8b1 upstream.

'type' is user-controlled, so sanitize it after the bounds check to avoid using it in speculative execution. This covers the following potential gadgets detected with the help of smatch:

* fs/ext4/super.c:5741 ext4_quota_read() warn: potential spectre issue 'sb_dqopt(sb)->files' [r]
* fs/ext4/super.c:5778 ext4_quota_write() warn: potential spectre issue 'sb_dqopt(sb)->files' [r]
* fs/f2fs/super.c:1552 f2fs_quota_read() warn: potential spectre issue 'sb_dqopt(sb)->files' [r]
* fs/f2fs/super.c:1608 f2fs_quota_write() warn: potential spectre issue 'sb_dqopt(sb)->files' [r]
* fs/quota/dquot.c:412 mark_info_dirty() warn: potential spectre issue 'sb_dqopt(sb)->info' [w]
* fs/quota/dquot.c:933 dqinit_needed() warn: potential spectre issue 'dquots' [r]
* fs/quota/dquot.c:2112 dquot_commit_info() warn: potential spectre issue 'dqopt->ops' [r]
* fs/quota/dquot.c:2362 vfs_load_quota_inode() warn: potential spectre issue 'dqopt->files' [w] (local cap)
* fs/quota/dquot.c:2369 vfs_load_quota_inode() warn: potential spectre issue 'dqopt->ops' [w] (local cap)
* fs/quota/dquot.c:2370 vfs_load_quota_inode() warn: potential spectre issue 'dqopt->info' [w] (local cap)
* fs/quota/quota.c:110 quota_getfmt() warn: potential spectre issue 'sb_dqopt(sb)->info' [r]
* fs/quota/quota_v2.c:84 v2_check_quota_file() warn: potential spectre issue 'quota_magics' [w]
* fs/quota/quota_v2.c:85 v2_check_quota_file() warn: potential spectre issue 'quota_versions' [w]
* fs/quota/quota_v2.c:96 v2_read_file_info() warn: potential spectre issue 'dqopt->info' [r]
* fs/quota/quota_v2.c:172 v2_write_file_info() warn: potential spectre issue 'dqopt->info' [r]

Additionally, a quick inspection indicates there are array accesses with 'type' in quota_on() and quota_off() functions which are also addressed by this.

[bwh: Backported to 3.16: The maximum valid quota type is command-dependent.
Introduce a local variable rather than repeating the expression.]

---

fs/quota/quota.c +4 -1
@@ -17,6 +17,7 @@
 #include <linux/quotaops.h>
 #include <linux/types.h>
 #include <linux/writeback.h>
+#include <linux/nospec.h>
 
 static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
 				     qid_t id)
@@ -405,10 +406,12 @@ static int quota_rmxquota(struct super_b
 static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
 		       void __user *addr, struct path *path)
 {
+	unsigned int max_quotas = XQM_COMMAND(cmd) ? XQM_MAXQUOTAS : MAXQUOTAS;
 	int ret;
 
-	if (type >= (XQM_COMMAND(cmd) ? XQM_MAXQUOTAS : MAXQUOTAS))
+	if (type >= max_quotas)
 		return -EINVAL;
+	type = array_index_nospec(type, max_quotas);
 	if (!sb->s_qcop)
 		return -ENOSYS;
 
#158 lore raw

PATCH 155/328 reiserfs: fix broken xattr handling (heap corruption, bad retval)

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Jann Horn <[email protected]>

commit a13f085d111e90469faf2d9965eb39b11c114d7e upstream.

This fixes the following issues:

- When a buffer size is supplied to reiserfs_listxattr() such that each individual name fits, but the concatenation of all names doesn't fit, reiserfs_listxattr() overflows the supplied buffer. This leads to a kernel heap overflow (verified using KASAN) followed by an out-of-bounds usercopy and is therefore a security bug.

- When a buffer size is supplied to reiserfs_listxattr() such that a name doesn't fit, -ERANGE should be returned. But reiserfs instead just truncates the list of names; I have verified that if the only xattr on a file has a longer name than the supplied buffer length, listxattr() incorrectly returns zero.

With my patch applied, -ERANGE is returned in both cases and the memory corruption doesn't happen anymore.

Credit for making me clean this code up a bit goes to Al Viro, who pointed out that the ->actor calling convention is suboptimal and should be changed.

Fixes 48b32a3553a5 ("reiserfs: use generic xattr handlers")
Cc Eric Biggers <[email protected]>
Cc Al Viro <[email protected]>

[bwh: Backported to 3.16:
- The xattr handler's list operation does the copy, so also update the buffer size we pass to it
- Adjust context]

---

fs/reiserfs/xattr.c +4 -2
@@ -822,10 +822,12 @@ static int listxattr_filler(void *buf, c
 			return 0;
 		if (b->buf) {
 			size = handler->list(b->dentry, b->buf + b->pos,
-					 b->size, name, namelen,
+					 b->size - b->pos, name, namelen,
 					 handler->flags);
-			if (size > b->size)
+			if (b->pos + size > b->size) {
+				b->pos = -ERANGE;
 				return -ERANGE;
+			}
 		} else {
 			size = handler->list(b->dentry, NULL, 0, name,
 					     namelen, handler->flags);
#159 lore raw

PATCH 156/328 apparmor: remove no-op permission check in policy_unpack

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: John Johansen <[email protected]>

commit c037bd615885f1d9d3bdb48531bace79fae1505d upstream.

The patch 736ec752d95e: "AppArmor: policy routines for loading and unpacking policy" from Jul 29, 2010, leads to the following static checker warning:

security/apparmor/policy_unpack.c:410 verify_accept()
warn: bitwise AND condition is false here

security/apparmor/policy_unpack.c:413 verify_accept()
warn: bitwise AND condition is false here

security/apparmor/policy_unpack.c

   392  #define DFA_VALID_PERM_MASK             0xffffffff
   393  #define DFA_VALID_PERM2_MASK            0xffffffff
   394
   395  /**
   396   * verify_accept - verify the accept tables of a dfa
   397   * @dfa: dfa to verify accept tables of (NOT NULL)
   398   * @flags: flags governing dfa
   399   *
   400   * Returns: 1 if valid accept tables else 0 if error
   401   */

402 static bool verify_accept(struct aa_dfa *dfa, int flags) 403 {
404 int i;
405
406 /* verify accept permissions */
407 for (i = 0; i < dfa->tables[YYTD_ID_ACCEPT]->td_lolen; i++) {
408 int mode = ACCEPT_TABLE(dfa)[i];
409
410 if (mode & ~DFA_VALID_PERM_MASK)
411 return 0;
412
413 if (ACCEPT_TABLE2(dfa)[i] & ~DFA_VALID_PERM2_MASK)
414 return 0;

Fixes 736ec752d95e ("AppArmor: policy routines for loading and unpacking policy")
---
 security/apparmor/policy_unpack.c | 32 -------------------------------
 1 file changed, 32 deletions(-)
security/apparmor/policy_unpack.c +0 -32
@@ -290,32 +290,6 @@ static int unpack_strdup(struct aa_ext *
 	return res;
 }
 
-#define DFA_VALID_PERM_MASK		0xffffffff
-#define DFA_VALID_PERM2_MASK		0xffffffff
-
-/**
- * verify_accept - verify the accept tables of a dfa
- * @dfa: dfa to verify accept tables of (NOT NULL)
- * @flags: flags governing dfa
- *
- * Returns: 1 if valid accept tables else 0 if error
- */
-static bool verify_accept(struct aa_dfa *dfa, int flags)
-{
-	int i;
-
-	/* verify accept permissions */
-	for (i = 0; i < dfa->tables[YYTD_ID_ACCEPT]->td_lolen; i++) {
-		int mode = ACCEPT_TABLE(dfa)[i];
-
-		if (mode & ~DFA_VALID_PERM_MASK)
-			return 0;
-
-		if (ACCEPT_TABLE2(dfa)[i] & ~DFA_VALID_PERM2_MASK)
-			return 0;
-	}
-	return 1;
-}
 
 /**
  * unpack_dfa - unpack a file rule dfa
@@ -351,15 +325,9 @@ static struct aa_dfa *unpack_dfa(struct
 		if (IS_ERR(dfa))
 			return dfa;
 
-		if (!verify_accept(dfa, flags))
-			goto fail;
 	}
 
 	return dfa;
-
-fail:
-	aa_put_dfa(dfa);
-	return ERR_PTR(-EPROTO);
 }
 
 /**
#160 lore raw

PATCH 157/328 getxattr: use correct xattr length

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Christian Brauner <[email protected]>

commit 82c9a927bc5df6e06b72d206d24a9d10cced4eb5 upstream.

When running in a container with a user namespace, if you call getxattr with name = "system.posix_acl_access" and size % 8 != 4, then getxattr silently skips the user namespace fixup that it normally does resulting in un-fixed-up data being returned.
This is caused by posix_acl_fix_xattr_to_user() being passed the total buffer size and not the actual size of the xattr as returned by vfs_getxattr().
This commit passes the actual length of the xattr as returned by vfs_getxattr() down.

A reproducer for the issue is:

touch acl_posix

setfacl -m user:0:rwx acl_posix

and the compile:

  #define _GNU_SOURCE
  #include <errno.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  #include <sys/types.h>
  #include <unistd.h>
  #include <attr/xattr.h>

  /* Run in user namespace with nsuid 0 mapped to uid != 0 on the host. */
  int main(int argc, void **argv)
  {
          ssize_t ret1, ret2;
          char buf1[128], buf2[132];
          int fret = EXIT_SUCCESS;
          char *file;
          if (argc < 2) {
                  fprintf(stderr,
                          "Please specify a file with "
                          "\"system.posix_acl_access\" permissions set\n");
                  _exit(EXIT_FAILURE);
          }
          file = argv[1];

          ret1 = getxattr(file, "system.posix_acl_access",
                          buf1, sizeof(buf1));
          if (ret1 < 0) {
                  fprintf(stderr, "%s - Failed to retrieve "
                                  "\"system.posix_acl_access\" "
                                  "from \"%s\"\n", strerror(errno), file);
                  _exit(EXIT_FAILURE);
          }

          ret2 = getxattr(file, "system.posix_acl_access",
                          buf2, sizeof(buf2));
          if (ret2 < 0) {
                  fprintf(stderr, "%s - Failed to retrieve "
                                  "\"system.posix_acl_access\" "
                                  "from \"%s\"\n", strerror(errno), file);
                  _exit(EXIT_FAILURE);
          }

          if (ret1 != ret2) {
                  fprintf(stderr, "The value of \"system.posix_acl_"
                                  "access\" for file \"%s\" changed "
                                  "between two successive calls\n", file);
                  _exit(EXIT_FAILURE);
          }

          for (ssize_t i = 0; i < ret2; i++) {
                  if (buf1[i] == buf2[i])
                          continue;

                  fprintf(stderr,
                          "Unexpected different in byte %zd: "
                          "%02x != %02x\n", i, buf1[i], buf2[i]);
                  fret = EXIT_FAILURE;
          }

          if (fret == EXIT_SUCCESS)
                  fprintf(stderr, "Test passed\n");
          else
                  fprintf(stderr, "Test failed\n");

          _exit(fret);

}
and run:

./tester acl_posix

On a non-fixed up kernel this should return something like:

  root@c1:/# ./t
  Unexpected different in byte 16: ffffffa0 != 00
  Unexpected different in byte 17: ffffff86 != 00
  Unexpected different in byte 18: 01 != 00

and on a fixed kernel:

  root@c1:~# ./t
  Test passed
Fixes 2f6f0654ab61 ("userns: Convert vfs posix_acl support to use kuids and kgids")
---
 fs/xattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xattr.c +1 -1
@@ -466,7 +466,7 @@ getxattr(struct dentry *d, const char __
 	if (error > 0) {
 		if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) ||
 		    (strcmp(kname, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
-			posix_acl_fix_xattr_to_user(kvalue, size);
+			posix_acl_fix_xattr_to_user(kvalue, error);
 		if (size && copy_to_user(value, kvalue, error))
 			error = -EFAULT;
 	} else if (error == -ERANGE && size >= XATTR_SIZE_MAX) {
#161 lore raw

PATCH 158/328 mm: move tlb_table_flush to tlb_flush_mmu_free

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Nicholas Piggin <[email protected]>

commit db7ddef301128dad394f1c0f77027f86ee9a4edb upstream.

There is no need to call this from tlb_flush_mmu_tlbonly, it logically belongs with tlb_flush_mmu_free. This makes future fixes simpler.

[ This was originally done to allow code consolidation for the
mmu_notifier fix, but it also ends up helping simplify the
HAVE_RCU_TABLE_INVALIDATE fix. - Linus ]

Cc Peter Zijlstra <[email protected]>
[bwh: Backported to 3.16: adjust context]
---
 mm/memory.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/memory.c +3 -3
@@ -236,15 +236,15 @@ static void tlb_flush_mmu_tlbonly(struct
 {
 	tlb->need_flush = 0;
 	tlb_flush(tlb);
-#ifdef CONFIG_HAVE_RCU_TABLE_FREE
-	tlb_table_flush(tlb);
-#endif
 }
 
 static void tlb_flush_mmu_free(struct mmu_gather *tlb)
 {
 	struct mmu_gather_batch *batch;
 
+#ifdef CONFIG_HAVE_RCU_TABLE_FREE
+	tlb_table_flush(tlb);
+#endif
 	for (batch = &tlb->local; batch; batch = batch->next) {
 		free_pages_and_swap_cache(batch->pages, batch->nr);
 		batch->nr = 0;
#162 lore raw

PATCH 159/328 mm/tlb: Remove tlb_remove_table() non-concurrent condition

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Peter Zijlstra <[email protected]>

commit a6f572084fbee8b30f91465f4a085d7a90901c57 upstream.

Will noted that only checking mm_users is incorrect; we should also check mm_count in order to cover CPUs that have a lazy reference to this mm (and could do speculative TLB operations).

If removing this turns out to be a performance issue, we can re-instate a more complete check, but in tlb_table_flush() eliding the call_rcu_sched().

Fixes 267239116987 ("mm, powerpc: move the RCU page-table freeing into generic code")
Cc Nicholas Piggin <[email protected]>
Cc David Miller <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Michael Ellerman <[email protected]>
---
 mm/memory.c | 9 ---------
 1 file changed, 9 deletions(-)
mm/memory.c +0 -9
@@ -359,15 +359,6 @@ void tlb_remove_table(struct mmu_gather
 
 	tlb->need_flush = 1;
 
-	/*
-	 * When there's less then two users of this mm there cannot be a
-	 * concurrent page-table walk.
-	 */
-	if (atomic_read(&tlb->mm->mm_users) < 2) {
-		__tlb_remove_table(table);
-		return;
-	}
-
 	if (*batch == NULL) {
 		*batch = (struct mmu_table_batch *)__get_free_page(GFP_NOWAIT | __GFP_NOWARN);
 		if (*batch == NULL) {
#163 lore raw

PATCH 160/328 cifs: check kmalloc before use

In reply to Ben Hutchings

3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Nicholas Mc Guire <[email protected]>

commit 126c97f4d0d1b5b956e8b0740c81a2b2a2ae548c upstream.

The kmalloc was not being checked - if it fails issue a warning and return -ENOMEM to the caller.

Fixes b8da344b74c8 ("cifs: dynamic allocation of ntlmssp blob")
---
 fs/cifs/sess.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/cifs/sess.c +6 -0
@@ -398,6 +398,12 @@ int build_ntlmssp_auth_blob(unsigned cha
 		goto setup_ntlmv2_ret;
 	}
 	*pbuffer = kmalloc(size_of_ntlmssp_blob(ses), GFP_KERNEL);
+	if (!*pbuffer) {
+		rc = -ENOMEM;
+		cifs_dbg(VFS, "Error %d during NTLMSSP allocation\n", rc);
+		*buflen = 0;
+		goto setup_ntlmv2_ret;
+	}
 	sec_blob = (AUTHENTICATE_MESSAGE *)*pbuffer;
 
 	memcpy(sec_blob->Signature, NTLMSSP_SIGNATURE, 8);