3.16.57-rc1 review
Subsystems (16)
PATCH 124/410 crypto: hash - prevent using keyed hashes without setting key
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 9fa68f620041be04720d0cbfb1bd3ddfc6310b24 upstream.
Currently, almost none of the keyed hash algorithms check whether a key has been set before proceeding. Some algorithms are okay with this and will effectively just use a key of all 0's or some other bogus default. However, others will severely break, as demonstrated using "hmac(sha3-512-generic)", the unkeyed use of which causes a kernel crash via a (potentially exploitable) stack buffer overflow.
A while ago, this problem was solved for AF_ALG by pairing each hash transform with a 'has_key' bool. However, there are still other places in the kernel where userspace can specify an arbitrary hash algorithm by name, and the kernel uses it as unkeyed hash without checking whether it is really unkeyed. Examples of this include:
- KEYCTL_DH_COMPUTE, via the KDF extension
- dm-verity
- dm-crypt, via the ESSIV support
- dm-integrity, via the "internal hash" mode with no key given
- drbd (Distributed Replicated Block Device)
This bug is especially bad for KEYCTL_DH_COMPUTE as that requires no privileges to call.
Fix the bug for all users by adding a flag CRYPTO_TFM_NEED_KEY to the ->crt_flags of each hash transform that indicates whether the transform still needs to be keyed or not. Then, make the hash init, import, and digest functions return -ENOKEY if the key is still needed.
The new flag also replaces the 'has_key' bool which algif_hash was previously using, thereby simplifying the algif_hash implementation.
[bwh: Backported to 3.16:
- In hash_accept_parent_nokey(), update initialisation of ds to use tfm
- Adjust context]
---
crypto/ahash.c +17 -5
@@ -203,11 +203,18 @@ int crypto_ahash_setkey(struct crypto_ah unsigned int keylen) {unsigned long alignmask =crypto_ahash_alignmask (tfm); +int err;if ((unsigned long )key & alignmask) -return ahash_setkey_unaligned (tfm, key, keylen); + err =ahash_setkey_unaligned (tfm, key, keylen); +else + err = tfm->setkey (tfm, key, keylen); + +if (err) +return err; -return tfm->setkey (tfm, key, keylen); +crypto_ahash_clear_flags (tfm,CRYPTO_TFM_NEED_KEY ); +return 0 ; }EXPORT_SYMBOL_GPL (crypto_ahash_setkey);
@@ -380,7 +387,12 @@ EXPORT_SYMBOL_GPL(crypto_ahash_finup);int crypto_ahash_digest (struct ahash_request *req) { -return crypto_ahash_op (req,crypto_ahash_reqtfm (req)->digest); +struct crypto_ahash *tfm =crypto_ahash_reqtfm (req); + +if (crypto_ahash_get_flags (tfm) &CRYPTO_TFM_NEED_KEY ) +return -ENOKEY ; + +return crypto_ahash_op (req, tfm->digest); }EXPORT_SYMBOL_GPL (crypto_ahash_digest);
@@ -466,7 +478,6 @@ static int crypto_ahash_init_tfm(structstruct ahash_alg *alg =crypto_ahash_alg (hash); hash->setkey = ahash_nosetkey; - hash->has_setkey = false; hash->export = ahash_no_export; hash->import = ahash_no_import;
@@ -481,7 +492,8 @@ static int crypto_ahash_init_tfm(structif (alg->setkey) { hash->setkey = alg->setkey; - hash->has_setkey = true; +if (!(alg->halg.base.cra_flags &CRYPTO_ALG_OPTIONAL_KEY )) +crypto_ahash_set_flags (hash,CRYPTO_TFM_NEED_KEY ); }if (alg->export) hash->export = alg->export;
crypto/algif_hash.c +12 -42
106 lines not on this page · raw message
crypto/shash.c +21 -4
@@ -57,11 +57,18 @@ int crypto_shash_setkey(struct crypto_sh {struct shash_alg *shash =crypto_shash_alg (tfm);unsigned long alignmask =crypto_shash_alignmask (tfm); +int err;if ((unsigned long )key & alignmask) -return shash_setkey_unaligned (tfm, key, keylen); + err =shash_setkey_unaligned (tfm, key, keylen); +else + err = shash->setkey (tfm, key, keylen); + +if (err) +return err; -return shash->setkey (tfm, key, keylen); +crypto_shash_clear_flags (tfm,CRYPTO_TFM_NEED_KEY ); +return 0 ; }EXPORT_SYMBOL_GPL (crypto_shash_setkey);
@@ -180,6 +187,9 @@ int crypto_shash_digest(struct shash_desstruct shash_alg *shash =crypto_shash_alg (tfm);unsigned long alignmask =crypto_shash_alignmask (tfm); +if (crypto_shash_get_flags (tfm) &CRYPTO_TFM_NEED_KEY ) +return -ENOKEY ; +if (((unsigned long )data | (unsigned long )out) & alignmask)return shash_digest_unaligned (desc, data, len, out);
@@ -359,7 +369,8 @@ int crypto_init_shash_ops_async(struct c crt->digest = shash_async_digest; crt->setkey = shash_async_setkey; - crt->has_setkey = alg->setkey != shash_no_setkey; +crypto_ahash_set_flags (crt,crypto_shash_get_flags (shash) & +CRYPTO_TFM_NEED_KEY );if (alg->export) crt->export = shash_async_export;
@@ -519,8 +530,14 @@ static unsigned int crypto_shash_ctxsizestatic int crypto_shash_init_tfm (struct crypto_tfm *tfm) {struct crypto_shash *hash =__crypto_shash_cast (tfm); +struct shash_alg *alg =crypto_shash_alg (hash); + + hash->descsize = alg->descsize; + +if (crypto_shash_alg_has_setkey (alg) && + !(alg->base.cra_flags &CRYPTO_ALG_OPTIONAL_KEY )) +crypto_shash_set_flags (hash,CRYPTO_TFM_NEED_KEY ); - hash->descsize =crypto_shash_alg (hash)->descsize;return 0 ; }
include/crypto/hash.h +24 -10
@@ -94,7 +94,6 @@ struct crypto_ahash { unsigned int keylen);unsigned int reqsize; -bool has_setkey;struct crypto_tfm base; };
@@ -183,11 +182,6 @@ static inline void *ahash_request_ctx(stint crypto_ahash_setkey (struct crypto_ahash *tfm,const u8 *key,unsigned int keylen); -static inline bool crypto_ahash_has_setkey (struct crypto_ahash *tfm) -{ -return tfm->has_setkey; -} -int crypto_ahash_finup (struct ahash_request *req);int crypto_ahash_final (struct ahash_request *req);int crypto_ahash_digest (struct ahash_request *req);
@@ -199,12 +193,22 @@ static inline int crypto_ahash_export(ststatic inline int crypto_ahash_import (struct ahash_request *req,const void *in) { -return crypto_ahash_reqtfm (req)->import (req, in); +struct crypto_ahash *tfm =crypto_ahash_reqtfm (req); + +if (crypto_ahash_get_flags (tfm) &CRYPTO_TFM_NEED_KEY ) +return -ENOKEY ; + +return tfm->import (req, in); }static inline int crypto_ahash_init (struct ahash_request *req) { -return crypto_ahash_reqtfm (req)->init (req); +struct crypto_ahash *tfm =crypto_ahash_reqtfm (req); + +if (crypto_ahash_get_flags (tfm) &CRYPTO_TFM_NEED_KEY ) +return -ENOKEY ; + +return tfm->init (req); }static inline int crypto_ahash_update (struct ahash_request *req)
@@ -343,12 +347,22 @@ static inline int crypto_shash_export(ststatic inline int crypto_shash_import (struct shash_desc *desc,const void *in) { -return crypto_shash_alg (desc->tfm)->import (desc, in); +struct crypto_shash *tfm = desc->tfm; + +if (crypto_shash_get_flags (tfm) &CRYPTO_TFM_NEED_KEY ) +return -ENOKEY ; + +return crypto_shash_alg (tfm)->import (desc, in); }static inline int crypto_shash_init (struct shash_desc *desc) { -return crypto_shash_alg (desc->tfm)->init (desc); +struct crypto_shash *tfm = desc->tfm; + +if (crypto_shash_get_flags (tfm) &CRYPTO_TFM_NEED_KEY ) +return -ENOKEY ; + +return crypto_shash_alg (tfm)->init (desc); } int crypto_shash_update(struct shash_desc *desc, const u8 *data,
include/linux/crypto.h +2 -0
@@ -103,6 +103,8 @@/* * Transform masks and values (for crt_flags). */ +#define CRYPTO_TFM_NEED_KEY 0x00000001 +#define CRYPTO_TFM_REQ_MASK 0x000fff00#define CRYPTO_TFM_RES_MASK 0xfff00000
PATCH 125/410 signal/openrisc: Fix do_unaligned_access to send the proper signal
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Eric W. Biederman" <[email protected]>
commit 500d58300571b6602341b041f97c082a461ef994 upstream.
While reviewing the signal sending on openrisc the do_unaligned_access function stood out because it is obviously wrong. A comment about an si_code set above when actually si_code is never set. Leading to a random si_code being sent to userspace in the event of an unaligned access.
Looking further SIGBUS BUS_ADRALN is the proper pair of signal and si_code to send for an unaligned access. That is what other architectures do and what is required by posix.
Given that do_unaligned_access is broken in a way that no one can be relying on it on openrisc fix the code to just do the right thing.
--- arch/openrisc/kernel/traps.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/openrisc/kernel/traps.c +5 -5
@@ -302,12 +302,12 @@ asmlinkage void do_unaligned_access(strusiginfo_t info;if (user_mode (regs)) { -/* Send a SIGSEGV */ - info.si_signo =SIGSEGV ; +/* Send a SIGBUS */ + info.si_signo =SIGBUS ; info.si_errno =0 ; -/* info.si_code has been set above */ - info.si_addr = (void *)address; -force_sig_info (SIGSEGV , &info, current); + info.si_code =BUS_ADRALN ; + info.si_addr = (void __user *)address; +force_sig_info (SIGBUS , &info, current); }else {printk ("KERNEL: Unaligned Access 0x%.8lx\n" , address);show_registers (regs);
PATCH 126/410 mn10300/misalignment: Use SIGSEGV SEGV_MAPERR to report a failed user copy
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Eric W. Biederman" <[email protected]>
commit 6ac1dc736b323011a55ecd1fc5897c24c4f77cbd upstream.
Setting si_code to 0 is the same a setting si_code to SI_USER which is definitely not correct. With si_code set to SI_USER si_pid and si_uid will be copied to userspace instead of si_addr. Which is very wrong.
So fix this by using a sensible si_code (SEGV_MAPERR) for this failure.
--- arch/mn10300/mm/misalignment.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mn10300/mm/misalignment.c +1 -1
@@ -437,7 +437,7 @@ transfer_failed: info.si_signo =SIGSEGV ; info.si_errno =0 ; - info.si_code =0 ; + info.si_code =SEGV_MAPERR ; info.si_addr = (void *) regs->pc;force_sig_info (SIGSEGV , &info, current);return ;
PATCH 127/410 NFS: Add a cond_resched() to nfs_commit_release_pages()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <[email protected]>
commit 7f1bda447c9bd48b415acedba6b830f61591601f upstream.
The commit list can get very large, and so we need a cond_resched() in nfs_commit_release_pages() in order to ensure we don't hog the CPU for excessive periods of time.
--- fs/nfs/write.c | 2 ++ 1 file changed, 2 insertions(+)
fs/nfs/write.c +2 -0
@@ -1661,6 +1661,8 @@ static void nfs_commit_release_pages(strset_bit (NFS_CONTEXT_RESEND_WRITES , &req->wb_context->flags); next:nfs_unlock_and_release_request (req); +/* Latency breaker */ +cond_resched (); }nfs_init_cinfo (&cinfo, data->inode, data->dreq);if (atomic_dec_and_test (&cinfo.mds->rpcs_out))
PATCH 128/410 NFS: Fix 2 use after free issues in the I/O code
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <[email protected]>
commit 196639ebbe63a037fe9a80669140bd292d8bcd80 upstream.
The writeback code wants to send a commit after processing the pages, which is why we want to delay releasing the struct path until after that's done.
Also, the layout code expects that we do not free the inode before we've put the layout segments in pnfs_writehdr_free() and pnfs_readhdr_free()
--- fs/nfs/internal.h | 1 - fs/nfs/pagelist.c | 26 ++++++++++++-------------- fs/nfs/pnfs.c | 2 -- 3 files changed, 12 insertions(+), 17 deletions(-)
fs/nfs/internal.h +0 -1
@@ -249,7 +249,6 @@ int nfs_iocounter_wait(struct nfs_io_couextern const struct nfs_pageio_ops nfs_pgio_rw_ops;struct nfs_pgio_header *nfs_pgio_header_alloc (const struct nfs_rw_ops *);void nfs_pgio_header_free (struct nfs_pgio_header *); -void nfs_pgio_data_destroy (struct nfs_pgio_header *);int nfs_generic_pgio (struct nfs_pageio_descriptor *,struct nfs_pgio_header *);int nfs_initiate_pgio (struct rpc_clnt *,struct nfs_pgio_header *,const struct rpc_call_ops *,int ,int );
fs/nfs/pagelist.c +12 -14
@@ -508,16 +508,6 @@ struct nfs_pgio_header *nfs_pgio_header_ }EXPORT_SYMBOL_GPL (nfs_pgio_header_alloc); -/* -* nfs_pgio_header_free - Free a read or write header -* @hdr: The header to free -*/ -void nfs_pgio_header_free (struct nfs_pgio_header *hdr) -{ - hdr->rw_ops->rw_free_header (hdr); -} -EXPORT_SYMBOL_GPL (nfs_pgio_header_free); -/** * nfs_pgio_data_destroy - make @hdr suitable for reuse *
@@ -526,14 +516,24 @@ EXPORT_SYMBOL_GPL(nfs_pgio_header_free);* * @hdr: A header that has had nfs_generic_pgio called */ -void nfs_pgio_data_destroy (struct nfs_pgio_header *hdr) +static void nfs_pgio_data_destroy (struct nfs_pgio_header *hdr) {if (hdr->args.context)put_nfs_open_context (hdr->args.context);if (hdr->page_array.pagevec != hdr->page_array.page_array)kfree (hdr->page_array.pagevec); } -EXPORT_SYMBOL_GPL (nfs_pgio_data_destroy); + +/* +* nfs_pgio_header_free - Free a read or write header +* @hdr: The header to free +*/ +void nfs_pgio_header_free (struct nfs_pgio_header *hdr) +{ +nfs_pgio_data_destroy (hdr); + hdr->rw_ops->rw_free_header (hdr); +} +EXPORT_SYMBOL_GPL (nfs_pgio_header_free);/** * nfs_pgio_rpcsetup - Set up arguments for a pageio call
@@ -648,7 +648,6 @@ static int nfs_pgio_error(struct nfs_pag struct nfs_pgio_header *hdr) {set_bit (NFS_IOHDR_REDO , &hdr->flags); -nfs_pgio_data_destroy (hdr); hdr->completion_ops->completion (hdr); desc->pg_completion_ops->error_cleanup (&desc->pg_list);return -ENOMEM ;
@@ -663,7 +662,6 @@ static void nfs_pgio_release(void *calldstruct nfs_pgio_header *hdr = calldata;if (hdr->rw_ops->rw_release) hdr->rw_ops->rw_release (hdr); -nfs_pgio_data_destroy (hdr); hdr->completion_ops->completion (hdr); }
fs/nfs/pnfs.c +0 -2
@@ -1557,7 +1557,6 @@ pnfs_write_through_mds(struct nfs_pageionfs_pageio_reset_write_mds (desc); desc->pg_recoalesce =1 ; } -nfs_pgio_data_destroy (hdr); hdr->release (hdr); }
@@ -1695,7 +1694,6 @@ pnfs_read_through_mds(struct nfs_pageio_nfs_pageio_reset_read_mds (desc); desc->pg_recoalesce =1 ; } -nfs_pgio_data_destroy (hdr); hdr->release (hdr); }
PATCH 129/410 nfs/pnfs: fix nfs_direct_req ref leak when i/o falls back to the mds
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Scott Mayhew <[email protected]>
commit ba4a76f703ab7eb72941fdaac848502073d6e9ee upstream.
Currently when falling back to doing I/O through the MDS (via pnfs_{read|write}_through_mds), the client frees the nfs_pgio_header without releasing the reference taken on the dreq
via pnfs_generic_pg_{read|write}pages -> nfs_pgheader_init -> nfs_direct_pgio_init. It then takes another reference on the dreq via nfs_generic_pg_pgios -> nfs_pgheader_init -> nfs_direct_pgio_init and as a result the requester will become stuck in inode_dio_wait. Once that happens, other processes accessing the inode will become stuck as well.
Ensure that pnfs_read_through_mds() and pnfs_write_through_mds() clean up correctly by calling hdr->completion_ops->completion() instead of calling hdr->release() directly.
This can be reproduced (sometimes) by performing "storage failover takeover" commands on NetApp filer while doing direct I/O from a client.
This can also be reproduced using SystemTap to simulate a failure while doing direct I/O from a client (from Dave Wysochanski <[email protected]>):
stap -v -g -e 'probe module("nfs_layout_nfsv41_files").function("nfs4_fl_prepare_ds").return { $return=NULL; exit(); }'
--- fs/nfs/pnfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/nfs/pnfs.c +2 -2
@@ -1557,7 +1557,7 @@ pnfs_write_through_mds(struct nfs_pageionfs_pageio_reset_write_mds (desc); desc->pg_recoalesce =1 ; } - hdr->release (hdr); + hdr->completion_ops->completion (hdr); } static enum pnfs_try_status
@@ -1694,7 +1694,7 @@ pnfs_read_through_mds(struct nfs_pageio_nfs_pageio_reset_read_mds (desc); desc->pg_recoalesce =1 ; } - hdr->release (hdr); + hdr->completion_ops->completion (hdr); }/*
PATCH 130/410 console/dummy: leave .con_font_get set to NULL
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nicolas Pitre <[email protected]>
commit 724ba8b30b044aa0d94b1cd374fc15806cdd6f18 upstream.
When this method is set, the caller expects struct console_font fields to be properly initialized when it returns. Leave it unset otherwise nonsensical (leaked kernel stack) values are returned to user space.
--- drivers/video/console/dummycon.c | 1 - 1 file changed, 1 deletion(-)
drivers/video/console/dummycon.c +0 -1
@@ -71,7 +71,6 @@ const struct consw dummy_con = { .con_switch = DUMMY, .con_blank = DUMMY, .con_font_set = DUMMY, - .con_font_get = DUMMY, .con_font_default = DUMMY, .con_font_copy = DUMMY, .con_set_palette = DUMMY,
PATCH 131/410 ASoC: au1x: Fix timeout tests in au1xac97c_ac97_read()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
commit 123af9043e93cb6f235207d260d50f832cdb5439 upstream.
The loop timeout doesn't work because it's a post op and ends with "tmo" set to -1. I changed it from a post-op to a pre-op and I changed the initial the starting value from 5 to 6 so we still iterate 5 times. I left the other as it was because it's a large number.
--- sound/soc/au1x/ac97c.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/au1x/ac97c.c +3 -3
@@ -91,8 +91,8 @@ static unsigned short au1xac97c_ac97_rea do { mutex_lock(&ctx->lock); - tmo = 5; - while ((RD(ctx, AC97_STATUS) & STAT_CP) && tmo--) + tmo = 6; + while ((RD(ctx, AC97_STATUS) & STAT_CP) && --tmo) udelay(21); /* wait an ac97 frame time */ if (!tmo) { pr_debug("ac97rd timeout #1\n");
@@ -105,7 +105,7 @@ static unsigned short au1xac97c_ac97_rea* poll, Forrest, poll... */ tmo =0x10000 ; -while ((RD (ctx,AC97_STATUS ) &STAT_CP ) && tmo--) +while ((RD (ctx,AC97_STATUS ) &STAT_CP ) && --tmo) asmvolatile ("nop" ); data =RD (ctx,AC97_CMDRESP );
PATCH 132/410 IB/mlx4: Fix incorrectly releasing steerable UD QPs when have only ETH ports
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jack Morgenstein <[email protected]>
commit 852f6927594d0d3e8632c889b2ab38cbc46476ad upstream.
Allocating steerable UD QPs depends on having at least one IB port, while releasing those QPs does not.
As a result, when there are only ETH ports, the IB (RoCE) driver requests releasing a qp range whose base qp is zero, with qp count zero.
When SR-IOV is enabled, and the VF driver is running on a VM over a hypervisor which treats such qp release calls as errors (rather than NOPs), we see lines in the VM message log like:
mlx4_core 0002:00:02.0: Failed to release qp range base:0 cnt:0
Fix this by adding a check for a zero count in mlx4_release_qp_range() (which thus treats releasing 0 qps as a nop), and eliminating the check for device managed flow steering when releasing steerable UD QPs. (Freeing ib_uc_qpns_bitmap unconditionally is also OK, since it remains NULL when steerable UD QPs are not allocated).
--- drivers/infiniband/hw/mlx4/main.c | 13 +++++-------- drivers/net/ethernet/mellanox/mlx4/qp.c | 3 +++ 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/infiniband/hw/mlx4/main.c +5 -8
@@ -2272,9 +2272,8 @@ err_steer_free_bitmap:kfree (ibdev->ib_uc_qpns_bitmap); err_steer_qp_release: -if (ibdev->steering_support ==MLX4_STEERING_MODE_DEVICE_MANAGED ) -mlx4_qp_release_range (dev, ibdev->steer_qpn_base, - ibdev->steer_qpn_count); +mlx4_qp_release_range (dev, ibdev->steer_qpn_base, + ibdev->steer_qpn_count); err_counter:for (; i; --i)if (ibdev->counters[i -1 ] !=-1 )
@@ -2373,11 +2372,9 @@ static void mlx4_ib_remove(struct mlx4_d ibdev->iboe.nb.notifier_call =NULL ; } -if (ibdev->steering_support ==MLX4_STEERING_MODE_DEVICE_MANAGED ) { -mlx4_qp_release_range (dev, ibdev->steer_qpn_base, - ibdev->steer_qpn_count); -kfree (ibdev->ib_uc_qpns_bitmap); - } +mlx4_qp_release_range (dev, ibdev->steer_qpn_base, + ibdev->steer_qpn_count); +kfree (ibdev->ib_uc_qpns_bitmap);if (ibdev->iboe.nb_inet.notifier_call) {if (unregister_inetaddr_notifier (&ibdev->iboe.nb_inet))
drivers/net/ethernet/mellanox/mlx4/qp.c +3 -0
@@ -257,6 +257,9 @@ void mlx4_qp_release_range(struct mlx4_du64 in_param =0 ;int err; +if (!cnt) +return ; +if (mlx4_is_mfunc (dev)) {set_param_l (&in_param, base_qpn);set_param_h (&in_param, cnt);
PATCH 133/410 hrtimer: Ensure POSIX compliance (relative CLOCK_REALTIME hrtimers)
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Anna-Maria Gleixner <[email protected]>
commit 48d0c9becc7f3c66874c100c126459a9da0fdced upstream.
The POSIX specification defines that relative CLOCK_REALTIME timers are not affected by clock modifications. Those timers have to use CLOCK_MONOTONIC to ensure POSIX compliance.
The introduction of the additional HRTIMER_MODE_PINNED mode broke this requirement for pinned timers.
There is no user space visible impact because user space timers are not using pinned mode, but for consistency reasons this needs to be fixed.
Check whether the mode has the HRTIMER_MODE_REL bit set instead of comparing with HRTIMER_MODE_ABS.
--- kernel/hrtimer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/hrtimer.c +6 -1
@@ -1197,7 +1197,12 @@ static void __hrtimer_init(struct hrtime cpu_base = &__raw_get_cpu_var (hrtimer_bases); -if (clock_id ==CLOCK_REALTIME && mode !=HRTIMER_MODE_ABS ) +/* +* POSIX magic: Relative CLOCK_REALTIME timers are not affected by +* clock modifications, so they needs to become CLOCK_MONOTONIC to +* ensure POSIX compliance. +*/ +if (clock_id ==CLOCK_REALTIME && mode &HRTIMER_MODE_REL ) clock_id =CLOCK_MONOTONIC ; base =hrtimer_clockid_to_base (clock_id);
PATCH 134/410 USB: cdc-acm: Do not log urb submission errors on disconnect
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit f0386c083c2ce85284dc0b419d7b89c8e567c09f upstream.
When disconnected sometimes the cdc-acm driver logs errors like these:
[20278.039417] cdc_acm 2-2:2.1: urb 9 failed submission with -19 [20278.042924] cdc_acm 2-2:2.1: urb 10 failed submission with -19 [20278.046449] cdc_acm 2-2:2.1: urb 11 failed submission with -19 [20278.049920] cdc_acm 2-2:2.1: urb 12 failed submission with -19 [20278.053442] cdc_acm 2-2:2.1: urb 13 failed submission with -19 [20278.056915] cdc_acm 2-2:2.1: urb 14 failed submission with -19 [20278.060418] cdc_acm 2-2:2.1: urb 15 failed submission with -19
Silence these by not logging errors when the result is -ENODEV.
--- drivers/usb/class/cdc-acm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/class/cdc-acm.c +1 -1
@@ -378,7 +378,7 @@ static int acm_submit_read_urb(struct ac res =usb_submit_urb (acm->read_urbs[index], mem_flags);if (res) { -if (res != -EPERM ) { +if (res != -EPERM && res != -ENODEV ) {dev_err (&acm->data->dev,"%s - usb_submit_urb failed: %d\n" , __func__, res);
PATCH 135/410 uas: Log error codes when logging errors
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit ce39fe6fa115d9fea0112c907773a400b98d2463 upstream.
--- drivers/usb/storage/uas.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/usb/storage/uas.c +12 -5
@@ -928,7 +928,8 @@ static int uas_eh_bus_reset_handler(struusb_unlock_device (udev);if (err) { -shost_printk (KERN_INFO , sdev->host,"%s FAILED\n" , __func__); +shost_printk (KERN_INFO , sdev->host,"%s FAILED err %d\n" , + __func__, err);return FAILED ; }
@@ -1188,13 +1189,16 @@ static int uas_post_reset(struct usb_intstruct Scsi_Host *shost =usb_get_intfdata (intf);struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata;unsigned long flags; +int err;if (devinfo->shutdown)return 0 ; -if (uas_configure_endpoints (devinfo) !=0 ) { + err =uas_configure_endpoints (devinfo); +if (err) {shost_printk (KERN_ERR , shost, -"%s: alloc streams error after reset" , __func__); +"%s: alloc streams error %d after reset" , + __func__, err);return 1 ; }
@@ -1232,10 +1236,13 @@ static int uas_reset_resume(struct usb_istruct Scsi_Host *shost =usb_get_intfdata (intf);struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata;unsigned long flags; +int err; -if (uas_configure_endpoints (devinfo) !=0 ) { + err =uas_configure_endpoints (devinfo); +if (err) {shost_printk (KERN_ERR , shost, -"%s: alloc streams error after reset" , __func__); +"%s: alloc streams error %d after reset" , + __func__, err);return -EIO ; }
PATCH 136/410 usb: uas: unconditionally bring back host after reset
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Neukum <[email protected]>
commit cbeef22fd611c4f47c494b821b2b105b8af970bb upstream.
Quoting Hans:
If we return 1 from our post_reset handler, then our disconnect handler will be called immediately afterwards. Since pre_reset blocks all scsi requests our disconnect handler will then hang in the scsi_remove_host call.
This is esp. bad because our disconnect handler hanging for ever also stops the USB subsys from enumerating any new USB devices, causes commands like lsusb to hang, etc.
In practice this happens when unplugging some uas devices because the hub code may see the device as needing a warm-reset and calls usb_reset_device before seeing the disconnect. In this case uas_configure_endpoints fails with -ENODEV. We do not want to print an error for this, so this commit also silences the shost_printk for -ENODEV.
ENDQUOTE
However, if we do that we better drop any unconditional execution and report to the SCSI subsystem that we have undergone a reset but we are not operational now.
--- drivers/usb/storage/uas.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/usb/storage/uas.c +3 -4
@@ -1195,20 +1195,19 @@ static int uas_post_reset(struct usb_intreturn 0 ; err =uas_configure_endpoints (devinfo); -if (err) { +if (err && err !=ENODEV )shost_printk (KERN_ERR , shost,"%s: alloc streams error %d after reset" , __func__, err); -return 1 ; - } +/* we must unblock the host in every case lest we deadlock */ spin_lock_irqsave (shost->host_lock, flags);scsi_report_bus_reset (shost,0 );spin_unlock_irqrestore (shost->host_lock, flags);scsi_unblock_requests (shost); -return 0 ; +return err ?1 :0 ; }static int uas_suspend (struct usb_interface *intf,pm_message_t message)
PATCH 137/410 NFS: commit direct writes even if they fail partially
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "J. Bruce Fields" <[email protected]>
commit 1b8d97b0a837beaf48a8449955b52c650a7114b4 upstream.
If some of the WRITE calls making up an O_DIRECT write syscall fail, we neglect to commit, even if some of the WRITEs succeed.
We also depend on the commit code to free the reference count on the nfs_page taken in the "if (request_commit)" case at the end of nfs_direct_write_completion(). The problem was originally noticed because ENOSPC's encountered partway through a write would result in a closed file being sillyrenamed when it should have been unlinked.
--- fs/nfs/direct.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/nfs/direct.c +1 -3
@@ -732,10 +732,8 @@ static void nfs_direct_write_completion(spin_lock (&dreq->lock); -if (test_bit (NFS_IOHDR_ERROR , &hdr->flags)) { - dreq->flags =0 ; +if (test_bit (NFS_IOHDR_ERROR , &hdr->flags)) dreq->error = hdr->error; - }if (dreq->error !=0 ) bit =NFS_IOHDR_ERROR ;else {
PATCH 138/410 dm thin: fix documentation relative to low water mark threshold
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: mulhern <[email protected]>
commit 9b28a1102efc75d81298198166ead87d643a29ce upstream.
Fixes:
1. The use of "exceeds" when the opposite of exceeds, falls below, was meant.
2. Properly speaking, a table can not exceed a threshold.
It emphasizes the important point, which is that it is the userspace daemon's responsibility to check for low free space when a device is resumed, since it won't get a special event indicating low free space in that situation.
--- Documentation/device-mapper/thin-provisioning.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
Documentation/device-mapper/thin-provisioning.txt +5 -3
@@ -112,9 +112,11 @@ $low_water_mark is expressed in blocks o free space on the data device drops below this level then a dm event will be triggered which a userspace daemon should catch allowing it to extend the pool device. Only one such event will be sent. -Resuming a device with a new table itself triggers an event so the -userspace daemon can use this to detect a situation where a new table -already exceeds the threshold. + +No special event is triggered if a just resumed device's free space is below +the low water mark. However, resuming a device always triggers an +event; a userspace daemon should verify that free space exceeds the low +water mark when handling this event. A low water mark for the metadata device is maintained in the kernel and will trigger a dm event if free space on the metadata device drops below
PATCH 139/410 ubi: Fix race condition between ubi volume creation and udev
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Clay McClure <[email protected]>
commit a51a0c8d213594bc094cb8e54aad0cb6d7f7b9a6 upstream.
Similar to commit 714fb87e8bc0 ("ubi: Fix race condition between ubi device creation and udev"), we should make the volume active before registering it.
--- drivers/mtd/ubi/vmt.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/mtd/ubi/vmt.c +10 -5
@@ -308,6 +308,12 @@ int ubi_create_volume(struct ubi_device vol->last_eb_bytes = vol->usable_leb_size; } +/* Make volume "available" before it becomes accessible via sysfs */ +spin_lock (&ubi->volumes_lock); + ubi->volumes[vol_id] = vol; + ubi->vol_count +=1 ; +spin_unlock (&ubi->volumes_lock); +/* Register character device for the volume */ cdev_init (&vol->cdev, &ubi_vol_cdev_operations); vol->cdev.owner =THIS_MODULE ;
@@ -350,11 +356,6 @@ int ubi_create_volume(struct ubi_deviceif (err) goto out_sysfs; -spin_lock (&ubi->volumes_lock); - ubi->volumes[vol_id] = vol; - ubi->vol_count +=1 ; -spin_unlock (&ubi->volumes_lock); -ubi_volume_notify (ubi, vol,UBI_VOLUME_ADDED );self_check_volumes (ubi);return err;
@@ -374,6 +375,10 @@ out_sysfs: out_cdev:cdev_del (&vol->cdev); out_mapping: +spin_lock (&ubi->volumes_lock); + ubi->volumes[vol_id] =NULL ; + ubi->vol_count -=1 ; +spin_unlock (&ubi->volumes_lock);if (do_free)kfree (vol->eba_tbl); out_acc:
PATCH 140/410 mtd: ubi: wl: Fix error return code in ubi_wl_init()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Wei Yongjun <[email protected]>
commit 7233982ade15eeac05c6f351e8d347406e6bcd2f upstream.
Fix to return error code -ENOMEM from the kmem_cache_alloc() error handling case instead of 0, as done elsewhere in this function.
attach")
--- drivers/mtd/ubi/wl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/mtd/ubi/wl.c +6 -2
@@ -1925,8 +1925,10 @@ int ubi_wl_init(struct ubi_device *ubi,cond_resched (); e =kmem_cache_alloc (ubi_wl_entry_slab,GFP_KERNEL ); -if (!e) +if (!e) { + err = -ENOMEM ; goto out_free; + } e->pnum = aeb->pnum; e->ec = aeb->ec;
@@ -1966,8 +1968,10 @@ int ubi_wl_init(struct ubi_device *ubi,cond_resched (); e =kmem_cache_alloc (ubi_wl_entry_slab,GFP_KERNEL ); -if (!e) +if (!e) { + err = -ENOMEM ; goto out_free; + } e->pnum = aeb->pnum; e->ec = aeb->ec;
PATCH 141/410 nfs: Do not convert nfs_idmap_cache_timeout to jiffies
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Chochol <[email protected]>
commit cbebc6ef4fc830f4040d4140bf53484812d5d5d9 upstream.
Since commit 57e62324e469 ("NFS: Store the legacy idmapper result in the keyring") nfs_idmap_cache_timeout changed units from jiffies to seconds. Unfortunately sysctl interface was not updated accordingly.
As a effect updating /proc/sys/fs/nfs/idmap_cache_timeout with some value will incorrectly multiply this value by HZ.
Also reading /proc/sys/fs/nfs/idmap_cache_timeout will show real value divided by HZ.
--- fs/nfs/nfs4sysctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/nfs4sysctl.c +1 -1
@@ -31,7 +31,7 @@ static struct ctl_table nfs4_cb_sysctls[ .data = &nfs_idmap_cache_timeout, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = proc_dointvec_jiffies, + .proc_handler = proc_dointvec, }, { } };
PATCH 142/410 drm/ttm: fix adding foreign BOs to the swap LRU
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Christian König <[email protected]>
commit ed704a43e84cc536081423dcd3491acf2791aaeb upstream.
It doesn't make any sense to try to swap out imported BOs.
--- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
@@ -175,7 +175,7 @@ void ttm_bo_add_to_lru(struct ttm_bufferlist_add_tail (&bo->lru, &man->lru);kref_get (&bo->list_kref); -if (bo->ttm !=NULL ) { +if (bo->ttm && !(bo->ttm->page_flags &TTM_PAGE_FLAG_SG )) {list_add_tail (&bo->swap, &bo->glob->swap_lru);kref_get (&bo->list_kref); }
PATCH 143/410 drm/ttm: Don't add swapped BOs to swap-LRU list
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Felix Kuehling <[email protected]>
commit fd5002d6a3c602664b07668a24df4ef7a43bf078 upstream.
A BO that's already swapped would be added back to the swap-LRU list for example if its validation failed under high memory pressure. This could later lead to swapping it out again and leaking previous swap storage.
This commit adds a condition to prevent that from happening.
v2: Check page_flags instead of swap_storage
--- drivers/gpu/drm/ttm/ttm_bo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo.c +2 -1
@@ -175,7 +175,8 @@ void ttm_bo_add_to_lru(struct ttm_bufferlist_add_tail (&bo->lru, &man->lru);kref_get (&bo->list_kref); -if (bo->ttm && !(bo->ttm->page_flags &TTM_PAGE_FLAG_SG )) { +if (bo->ttm && !(bo->ttm->page_flags & + (TTM_PAGE_FLAG_SG |TTM_PAGE_FLAG_SWAPPED ))) {list_add_tail (&bo->swap, &bo->glob->swap_lru);kref_get (&bo->list_kref); }
PATCH 144/410 MIPS: Fix clean of vmlinuz.{32,ecoff,bin,srec}
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: James Hogan <[email protected]>
commit 5f2483eb2423152445b39f2db59d372f523e664e upstream.
Make doesn't expand shell style "vmlinuz.{32,ecoff,bin,srec}" to the 4 separate files, so none of these files get cleaned up by make clean. List the files separately instead.
Patchwork: https://patchwork.linux-mips.org/patch/18491/
--- arch/mips/boot/compressed/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arch/mips/boot/compressed/Makefile +5 -1
@@ -117,4 +117,8 @@ OBJCOPYFLAGS_vmlinuz.srec := $(OBJCOPYFL vmlinuz.srec: vmlinuz $(call cmd,objcopy) -clean-files := $(objtree)/vmlinuz $(objtree)/vmlinuz.{32,ecoff,bin,srec} +clean-files += $(objtree)/vmlinuz +clean-files += $(objtree)/vmlinuz.32 +clean-files += $(objtree)/vmlinuz.ecoff +clean-files += $(objtree)/vmlinuz.bin +clean-files += $(objtree)/vmlinuz.srec
PATCH 145/410 kernfs: fix regression in kernfs_fop_write caused by wrong type
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
commit ba87977a49913129962af8ac35b0e13e0fa4382d upstream.
Commit b7ce40cff0b9 ("kernfs: cache atomic_write_len in kernfs_open_file") changes type of local variable 'len' from ssize_t to size_t. This change caused that the *ppos value is updated also when the previous write callback failed.
Mentioned snippet:
...
len = ops->write(...); <- return value can be negative
...
if (len > 0) <- true here in this case
*ppos += len;
...
--- fs/kernfs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/kernfs/file.c +1 -1
@@ -267,7 +267,7 @@ static ssize_t kernfs_fop_write(struct f {struct kernfs_open_file *of =kernfs_of (file);const struct kernfs_ops *ops; -size_t len; +ssize_t len;char *buf;if (of->atomic_write_len) {
PATCH 146/410 alpha: fix reboot on Avanti platform
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 55fc633c41a08ce9244ff5f528f420b16b1e04d6 upstream.
We need to define NEED_SRM_SAVE_RESTORE on the Avanti, otherwise we get machine check exception when attempting to reboot the machine.
--- arch/alpha/kernel/pci_impl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/alpha/kernel/pci_impl.h +2 -1
@@ -143,7 +143,8 @@ struct pci_iommu_arena };#if defined(CONFIG_ALPHA_SRM ) && \ - (defined(CONFIG_ALPHA_CIA ) || defined(CONFIG_ALPHA_LCA )) + (defined(CONFIG_ALPHA_CIA ) || defined(CONFIG_ALPHA_LCA ) || \ + defined(CONFIG_ALPHA_AVANTI ))# define NEED_SRM_SAVE_RESTORE #else # undef NEED_SRM_SAVE_RESTORE
PATCH 147/410 alpha: fix crash if pthread_create races with signal delivery
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 21ffceda1c8b3807615c40d440d7815e0c85d366 upstream.
On alpha, a process will crash if it attempts to start a thread and a signal is delivered at the same time. The crash can be reproduced with this program: https://cygwin.com/ml/cygwin/2014-11/msg00473.html
The reason for the crash is this:
* we call the clone syscall
* we go to the function copy_process
* copy process calls copy_thread_tls, it is a wrapper around copy_thread
* copy_thread sets the tls pointer: childti->pcb.unique = regs->r20
* copy_thread sets regs->r20 to zero
* we go back to copy_process
* copy process checks "if (signal_pending(current))" and returns -ERESTARTNOINTR
* the clone syscall is restarted, but this time, regs->r20 is zero, so the new thread is created with zero tls pointer
* the new thread crashes in start_thread when attempting to access tls
The comment in the code says that setting the register r20 is some compatibility with OSF/1. But OSF/1 doesn't use the CLONE_SETTLS flag, so we don't have to zero r20 if CLONE_SETTLS is set. This patch fixes the bug by zeroing regs->r20 only if CLONE_SETTLS is not set.
--- arch/alpha/kernel/process.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/alpha/kernel/process.c +2 -1
@@ -274,12 +274,13 @@ copy_thread(unsigned long clone_flags, uapplication calling fork. */ if (clone_flags &CLONE_SETTLS ) childti->pcb.unique = regs->r20; +else + regs->r20 =0 ;/* OSF/1 has some strange fork() semantics. */ childti->pcb.usp = usp ?:rdusp (); *childregs = *regs; childregs->r0 =0 ; childregs->r19 =0 ; childregs->r20 =1 ;/* OSF/1 has some strange fork() semantics. */ - regs->r20 =0 ; stack = ((struct switch_stack *) regs) -1 ; *childstack = *stack; childstack->r26 = (unsigned long ) ret_from_fork;
PATCH 148/410 staging: lustre: libcfs: Prevent harmless read underflow
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
commit 134aecbc25fd77645baaea5467b2a7ed8e9d1ea7 upstream.
Because this is a post-op instead of a pre-op, then it means we check if knl_buffer[-1] is a space. It doesn't really hurt anything, but it causes a static checker warning so let's fix it.
--- drivers/staging/lustre/lustre/libcfs/tracefile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/libcfs/tracefile.c +1 -1
@@ -767,7 +767,7 @@ int cfs_trace_copyin_string(char *knl_bureturn -EFAULT ; nob =strnlen (knl_buffer, usr_buffer_nob); -while (nob-- >=0 )/* strip trailing whitespace */ +while (--nob >=0 )/* strip trailing whitespace */ if (!isspace (knl_buffer[nob]))break ;
PATCH 149/410 usb: option: Add support for FS040U modem
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: OKAMOTO Yoshiaki <[email protected]>
commit 69341bd15018da0a662847e210f9b2380c71e623 upstream.
FS040U modem is manufactured by omega, and sold by Fujisoft. This patch adds ID of the modem to use option1 driver. Interface 3 is used as qmi_wwan, so the interface is ignored.
--- drivers/usb/serial/option.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/usb/serial/option.c +5 -0
@@ -385,6 +385,9 @@ static void option_instat_callback(struc#define FOUR_G_SYSTEMS_PRODUCT_W14 0x9603#define FOUR_G_SYSTEMS_PRODUCT_W100 0x9b01 +/* Fujisoft products */ +#define FUJISOFT_PRODUCT_FS040U 0x9b02 +/* iBall 3.5G connect wireless modem */ #define IBALL_3_5G_CONNECT 0x9605
@@ -1908,6 +1911,8 @@ static const struct usb_device_id option { USB_DEVICE(LONGCHEER_VENDOR_ID, FOUR_G_SYSTEMS_PRODUCT_W100), .driver_info = (kernel_ulong_t)&four_g_w100_blacklist }, + {USB_DEVICE(LONGCHEER_VENDOR_ID, FUJISOFT_PRODUCT_FS040U), + .driver_info = (kernel_ulong_t)&net_intf3_blacklist}, { USB_DEVICE_INTERFACE_CLASS(LONGCHEER_VENDOR_ID, SPEEDUP_PRODUCT_SU9800, 0xff) }, { USB_DEVICE_INTERFACE_CLASS(LONGCHEER_VENDOR_ID, 0x9801, 0xff), .driver_info = (kernel_ulong_t)&net_intf3_blacklist },
PATCH 150/410 staging: rts5208: Fix "seg_no" calculation in reset_ms_card()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
commit 7f7aeea7cf30368b9fdb86dcc9d2c8a3ebc65dfb upstream.
I get some static checker warnings like this:
drivers/staging/rts5208/ms.c:2607 ms_build_l2p_tbl()
error: buffer underflow 'ms_card->segment' (-1)-16The problem is that we memset "ms_card" to zero at the start of the reset_ms_card() function. That means that when we try to calculate "ms_card->total_block / 512 - 1" then it's just always -1. The fix is to calculate "seg_no" before doing the memset().
This is a static checker fix, and I am not able to test it. My theory is that reset_ms_card() gets very little testing which is why this bug exists.
--- drivers/staging/rts5208/ms.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/rts5208/ms.c +2 -1
@@ -2397,6 +2397,7 @@ BUILD_FAIL:int reset_ms_card (struct rtsx_chip *chip) {struct ms_info *ms_card = &(chip->ms_card); +int seg_no = ms_card->total_block /512 -1 ;int retval;memset (ms_card,0 ,sizeof (struct ms_info ));
@@ -2430,7 +2431,7 @@ int reset_ms_card(struct rtsx_chip *chip/* Build table for the last segment, * to check if L2P table block exists, erasing it */ - retval =ms_build_l2p_tbl (chip, ms_card->total_block /512 -1 ); + retval =ms_build_l2p_tbl (chip, seg_no);if (retval !=STATUS_SUCCESS )TRACE_RET (chip,STATUS_FAIL ); }
PATCH 151/410 CDC-ACM: apply quirk for card reader
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Neukum <[email protected]>
commit df1cc78a52491f71d8170d513d0f6f114faa1bda upstream.
This devices drops random bytes from messages if you talk to it too fast.
--- drivers/usb/class/cdc-acm.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/class/cdc-acm.c +3 -0
@@ -1708,6 +1708,9 @@ static const struct usb_device_id acm_id { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */ .driver_info =SINGLE_RX_URB ,/* firmware bug */ }, + { USB_DEVICE(0x11ca, 0x0201), /* VeriFone Mx870 Gadget Serial */ + .driver_info = SINGLE_RX_URB, + }, { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ },
PATCH 152/410 USB: serial: add support for multi-port simple drivers
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit b9f040389e23fb95fde36cb0a3c2c516fb3e9d1c upstream.
Add support for multi-port simple drivers.
--- drivers/usb/serial/usb-serial-simple.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/serial/usb-serial-simple.c +3 -2
@@ -20,7 +20,7 @@#include <linux/usb.h> #include <linux/usb/serial.h> -#define DEVICE (vendor,IDS ) \ +#define DEVICE_N (vendor,IDS , nport) \ static const struct usb_device_id vendor##_id_table[] = { \ IDS(), \ { }, \
@@ -31,9 +31,10 @@ static struct usb_serial_driver vendor## .name = #vendor, \ }, \ .id_table = vendor##_id_table, \ - .num_ports = 1, \ + .num_ports = nport, \ }; +#define DEVICE (vendor,IDS ) DEVICE_N(vendor, IDS, 1)/* ZIO Motherboard USB driver */ #define ZIO_IDS () \
PATCH 153/410 USB: serial: add Novatel Wireless GPS driver
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit c5cd24d7b179a415df263e5b18b72f6e3aaf81e0 upstream.
Add simple driver for Novatel Wireless GPS receivers.
--- drivers/usb/serial/Kconfig | 1 + drivers/usb/serial/usb-serial-simple.c | 7 +++++++ 2 files changed, 8 insertions(+)
drivers/usb/serial/Kconfig +1 -0
@@ -62,6 +62,7 @@ config USB_SERIAL_SIMPLE - Google USB serial devices - HP4x calculators - a number of Motorola phones + - Novatel Wireless GPS receivers - Siemens USB/MPI adapter. - ViVOtech ViVOpay USB device. - Infineon Modem Flashloader USB interface
drivers/usb/serial/usb-serial-simple.c +7 -0
@@ -75,6 +75,11 @@ DEVICE(vivopay, VIVOPAY_IDS); { USB_DEVICE(0x22b8, 0x2c64) } /* Motorola V950 phone */DEVICE (moto_modem,MOTO_IDS ); +/* Novatel Wireless GPS driver */ +#define NOVATEL_IDS () \ + { USB_DEVICE(0x09d7, 0x0100) }/* NovAtel FlexPack GPS */ +DEVICE_N (novatel_gps,NOVATEL_IDS ,3 ); +/* HP4x (48/49) Generic Serial driver */ #define HP4X_IDS () \ { USB_DEVICE(0x03f0, 0x0121) }
@@ -99,6 +104,7 @@ static struct usb_serial_driver * const &google_device, &vivopay_device, &moto_modem_device, + &novatel_gps_device, &hp4x_device, &suunto_device, &siemens_mpi_device,
@@ -112,6 +118,7 @@ static const struct usb_device_id id_tabGOOGLE_IDS (),VIVOPAY_IDS (),MOTO_IDS (), +NOVATEL_IDS (),HP4X_IDS (),SUUNTO_IDS (), SIEMENS_IDS(),
PATCH 154/410 USB: serial: add Medtronic CareLink USB driver
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit cff9c2339a6d5105d7f6b1f9a96dd1d239cc76ac upstream.
Add simple driver for Medtronic CareLink USB devices.
--- drivers/usb/serial/Kconfig | 1 + drivers/usb/serial/usb-serial-simple.c | 7 +++++++ 2 files changed, 8 insertions(+)
drivers/usb/serial/Kconfig +1 -0
@@ -58,6 +58,7 @@ config USB_SERIAL_SIMPLE handles a wide range of very simple devices, all in one driver. Specifically, it supports: - Suunto ANT+ USB device. + - Medtronic CareLink USB device - Fundamental Software dongle. - Google USB serial devices - HP4x calculators
drivers/usb/serial/usb-serial-simple.c +7 -0
@@ -36,6 +36,11 @@ static struct usb_serial_driver vendor###define DEVICE (vendor,IDS ) DEVICE_N(vendor, IDS, 1) +/* Medtronic CareLink USB driver */ +#define CARELINK_IDS () \ + { USB_DEVICE(0x0a21, 0x8001) }/* MMT-7305WW */ +DEVICE (carelink,CARELINK_IDS ); +/* ZIO Motherboard USB driver */ #define ZIO_IDS () \ { USB_DEVICE(0x1CBE, 0x0103) }
@@ -98,6 +103,7 @@ DEVICE(siemens_mpi, SIEMENS_IDS);/* All of the above structures mushed into two lists */ static struct usb_serial_driver *const serial_drivers[] = { + &carelink_device, &zio_device, &funsoft_device, &flashloader_device,
@@ -112,6 +118,7 @@ static struct usb_serial_driver * const };static const struct usb_device_id id_table[] = { +CARELINK_IDS (),ZIO_IDS (),FUNSOFT_IDS (),FLASHLOADER_IDS (),
PATCH 155/410 USB: serial: simple: add Motorola Tetra driver
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 46fe895e22ab3845515ec06b01eaf1282b342e29 upstream.
Add new Motorola Tetra (simple) driver for Motorola Solutions TETRA PEI devices.
D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 P: Vendor=0cad ProdID=9011 Rev=24.16 S: Manufacturer=Motorola Solutions Inc. S: Product=Motorola Solutions TETRA PEI interface C: #Ifs= 2 Cfg#= 1 Atr=80 MxPwr=500mA I: If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=00 Prot=00 Driver=(none) I: If#= 1 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=00 Prot=00 Driver=(none)
Note that these devices do not support the CDC SET_CONTROL_LINE_STATE request (for any interface).
--- drivers/usb/serial/Kconfig | 1 + drivers/usb/serial/usb-serial-simple.c | 7 +++++++ 2 files changed, 8 insertions(+)
drivers/usb/serial/Kconfig +1 -0
@@ -63,6 +63,7 @@ config USB_SERIAL_SIMPLE - Google USB serial devices - HP4x calculators - a number of Motorola phones + - Motorola Tetra devices - Novatel Wireless GPS receivers - Siemens USB/MPI adapter. - ViVOtech ViVOpay USB device.
drivers/usb/serial/usb-serial-simple.c +7 -0
@@ -80,6 +80,11 @@ DEVICE(vivopay, VIVOPAY_IDS); { USB_DEVICE(0x22b8, 0x2c64) } /* Motorola V950 phone */DEVICE (moto_modem,MOTO_IDS ); +/* Motorola Tetra driver */ +#define MOTOROLA_TETRA_IDS () \ + { USB_DEVICE(0x0cad, 0x9011) }/* Motorola Solutions TETRA PEI */ +DEVICE (motorola_tetra,MOTOROLA_TETRA_IDS ); +/* Novatel Wireless GPS driver */ #define NOVATEL_IDS () \ { USB_DEVICE(0x09d7, 0x0100) }/* NovAtel FlexPack GPS */
@@ -110,6 +115,7 @@ static struct usb_serial_driver * const &google_device, &vivopay_device, &moto_modem_device, + &motorola_tetra_device, &novatel_gps_device, &hp4x_device, &suunto_device,
@@ -125,6 +131,7 @@ static const struct usb_device_id id_tabGOOGLE_IDS (),VIVOPAY_IDS (),MOTO_IDS (), +MOTOROLA_TETRA_IDS (),NOVATEL_IDS (),HP4X_IDS (), SUUNTO_IDS(),
PATCH 156/410 usbip: prevent bind loops on devices attached to vhci_hcd
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Shuah Khan <[email protected]>
commit ef54cf0c600fb8f5737fb001a9e357edda1a1de8 upstream.
usbip host binds to devices attached to vhci_hcd on the same server when user does attach over localhost or specifies the server as the remote.
usbip attach -r localhost -b busid
or
usbip attach -r servername (or server IP)
Unbind followed by bind works, however device is left in a bad state with accesses via the attached busid result in errors and system hangs during shutdown.
Fix it to check and bail out if the device is already attached to vhci_hcd.
--- drivers/staging/usbip/userspace/src/usbip_bind.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/staging/usbip/userspace/src/usbip_bind.c +9 -0
@@ -144,6 +144,7 @@ static int bind_device(char *busid)int rc;struct udev *udev;struct udev_device *dev; +const char *devpath;/* Check whether the device with this bus ID exists. */ udev =udev_new ();
@@ -152,8 +153,16 @@ static int bind_device(char *busid)err ("device with the specified bus ID does not exist" );return -1 ; } + devpath =udev_device_get_devpath (dev);udev_unref (udev); +/* If the device is already attached to vhci_hcd - bail out */ +if (strstr (devpath,USBIP_VHCI_DRV_NAME )) { +err ("bind loop detected: device: %s is attached to %s\n" , + devpath,USBIP_VHCI_DRV_NAME ); +return -1 ; + } + rc =unbind_other (busid);if (rc ==UNBIND_ST_FAILED ) {err ("could not unbind driver from device on busid %s" , busid);
PATCH 157/410 usbip: list: don't list devices attached to vhci_hcd
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Shuah Khan <[email protected]>
commit ef824501f50846589f02173d73ce3fe6021a9d2a upstream.
usbip host lists devices attached to vhci_hcd on the same server when user does attach over localhost or specifies the server as the remote.
usbip attach -r localhost -b busid
or
usbip attach -r servername (or server IP)
Fix it to check and not list devices that are attached to vhci_hcd.
--- drivers/staging/usbip/userspace/src/usbip_list.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/staging/usbip/userspace/src/usbip_list.c +9 -0
@@ -180,6 +180,7 @@ static int list_devices(bool parsable)const char *busid;char product_name[128 ];int ret =-1 ; +const char *devpath;/* Create libudev context. */ udev =udev_new ();
@@ -202,6 +203,14 @@ static int list_devices(bool parsable) path =udev_list_entry_get_name (dev_list_entry); dev =udev_device_new_from_syspath (udev, path); +/* Ignore devices attached to vhci_hcd */ + devpath =udev_device_get_devpath (dev); +if (strstr (devpath,USBIP_VHCI_DRV_NAME )) { +dbg ("Skip the device %s already attached to %s\n" , + devpath,USBIP_VHCI_DRV_NAME ); +continue ; + } +/* Get device information. */ idVendor =udev_device_get_sysattr_value (dev,"idVendor" ); idProduct =udev_device_get_sysattr_value (dev,"idProduct" );
PATCH 158/410 NFS: reject request for id_legacy key without auxdata
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 49686cbbb3ebafe42e63868222f269d8053ead00 upstream.
nfs_idmap_legacy_upcall() is supposed to be called with 'aux' pointing to a 'struct idmap', via the call to request_key_with_auxdata() in nfs_idmap_request_key().
However it can also be reached via the request_key() system call in which case 'aux' will be NULL, causing a NULL pointer dereference in nfs_idmap_prepare_pipe_upcall(), assuming that the key description is valid enough to get that far.
Fix this by making nfs_idmap_legacy_upcall() negate the key if no auxdata is provided.
As usual, this bug was found by syzkaller. A simple reproducer using the command-line keyctl program is:
keyctl request2 id_legacy uid:0 '' @s
pbwh: Backported to 3.16: adjust filename]
--- fs/nfs/idmap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/nfs/idmap.c +5 -1
@@ -577,9 +577,13 @@ static int nfs_idmap_legacy_upcall(strucstruct idmap_msg *im;struct idmap *idmap = (struct idmap *)aux;struct key *key = cons->key; -int ret = -ENOMEM ; +int ret = -ENOKEY ; + +if (!aux) + goto out1;/* msg and im are freed in idmap_pipe_destroy_msg */ + ret = -ENOMEM ; data =kzalloc (sizeof (*data),GFP_KERNEL );if (!data) goto out1;
PATCH 159/410 btrfs: Handle btrfs_set_extent_delalloc failure in fixup worker
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nikolay Borisov <[email protected]>
commit f3038ee3a3f1017a1cbe9907e31fa12d366c5dcb upstream.
This function was introduced by 247e743cbe6e ("Btrfs: Use async helpers to deal with pages that have been improperly dirtied") and it didn't do any error handling then. This function might very well fail in ENOMEM situation, yet it's not handled, this could lead to inconsistent state. So let's handle the failure by setting the mapping error bit.
--- fs/btrfs/inode.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
fs/btrfs/inode.c +9 -1
@@ -1847,7 +1847,15 @@ again: goto out; } -btrfs_set_extent_delalloc (inode, page_start, page_end, &cached_state); + ret =btrfs_set_extent_delalloc (inode, page_start, page_end, + &cached_state); +if (ret) { +mapping_set_error (page->mapping, ret); +end_extent_writepage (page, ret, page_start, page_end); +ClearPageChecked (page); + goto out; + } +ClearPageChecked (page);set_page_dirty (page); out:
PATCH 160/410 scsi: fas216: fix sense buffer initialization
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
commit 96d5eaa9bb74d299508d811d865c2c41b38b0301 upstream.
While testing with the ARM specific memset() macro removed, I ran into a compiler warning that shows an old bug:
drivers/scsi/arm/fas216.c: In function 'fas216_rq_sns_done':drivers/scsi/arm/fas216.c:2014:40: error: argument to 'sizeof' in 'memset' call is the same expression as the destination; did you mean to provide an explicit length? [-Werror=sizeof-pointer-memaccess]
It turns out that the definition of the scsi_cmd structure changed back in linux-2.6.25, so now we clear only four bytes (sizeof(pointer)) instead of 96 (SCSI_SENSE_BUFFERSIZE). I did not check whether we actually need to initialize the buffer here, but it's clear that if we do it, we should use the correct size.
--- drivers/scsi/arm/fas216.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/arm/fas216.c +1 -1
@@ -2009,7 +2009,7 @@ static void fas216_rq_sns_done(FAS216_In* have valid data in the sense buffer that could * confuse the higher levels. */ -memset (SCpnt->sense_buffer,0 ,sizeof (SCpnt->sense_buffer)); +memset (SCpnt->sense_buffer,0 ,SCSI_SENSE_BUFFERSIZE );//printk("scsi%d.%c: sense buffer: ", info->host->host_no, '0' + SCpnt->device->id); //{ int i; for (i = 0; i < 32; i++) printk("%02x ", SCpnt->sense_buffer[i]); printk("\n"); } /*
PATCH 161/410 s390: fix handling of -1 in set{,fs}[gu]id16 syscalls
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eugene Syromiatnikov <[email protected]>
commit 6dd0d2d22aa363fec075cb2577ba273ac8462e94 upstream.
For some reason, the implementation of some 16-bit ID system calls (namely, setuid16/setgid16 and setfsuid16/setfsgid16) used type cast instead of low2highgid/low2highuid macros for converting [GU]IDs, which led to incorrect handling of value of -1 (which ought to be considered invalid).
Discovered by strace test suite.
--- arch/s390/kernel/compat_linux.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/s390/kernel/compat_linux.c +4 -4
@@ -110,7 +110,7 @@ COMPAT_SYSCALL_DEFINE2(s390_setregid16, COMPAT_SYSCALL_DEFINE1(s390_setgid16, u16, gid) { -return sys_setgid ((gid_t )gid); +return sys_setgid (low2highgid (gid)); }COMPAT_SYSCALL_DEFINE2 (s390_setreuid16, u16, ruid, u16, euid)
@@ -120,7 +120,7 @@ COMPAT_SYSCALL_DEFINE2(s390_setreuid16, COMPAT_SYSCALL_DEFINE1(s390_setuid16, u16, uid) { -return sys_setuid ((uid_t )uid); +return sys_setuid (low2highuid (uid)); }COMPAT_SYSCALL_DEFINE3 (s390_setresuid16, u16, ruid, u16, euid, u16, suid)
@@ -173,12 +173,12 @@ COMPAT_SYSCALL_DEFINE3(s390_getresgid16, COMPAT_SYSCALL_DEFINE1(s390_setfsuid16, u16, uid) { -return sys_setfsuid ((uid_t )uid); +return sys_setfsuid (low2highuid (uid)); } COMPAT_SYSCALL_DEFINE1(s390_setfsgid16, u16, gid) { -return sys_setfsgid ((gid_t )gid); +return sys_setfsgid (low2highgid (gid)); }static int groups16_to_user (u16 __user *grouplist,struct group_info *group_info)
PATCH 162/410 HID: roccat: prevent an out of bounds read in kovaplus_profile_activated()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
commit 7ad81482cad67cbe1ec808490d1ddfc420c42008 upstream.
We get the "new_profile_index" value from the mouse device when we're handling raw events. Smatch taints it as untrusted data and complains that we need a bounds check. This seems like a reasonable warning otherwise there is a small read beyond the end of the array.
--- drivers/hid/hid-roccat-kovaplus.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/hid/hid-roccat-kovaplus.c +2 -0
@@ -37,6 +37,8 @@ static uint kovaplus_convert_event_cpi(ustatic void kovaplus_profile_activated (struct kovaplus_device *kovaplus,uint new_profile_index) { +if (new_profile_index >=ARRAY_SIZE (kovaplus->profile_settings)) +return ; kovaplus->actual_profile = new_profile_index; kovaplus->actual_cpi = kovaplus->profile_settings[new_profile_index].cpi_startup_level; kovaplus->actual_x_sensitivity = kovaplus->profile_settings[new_profile_index].sensitivity_x;
PATCH 163/410 Input: edt-ft5x06 - fix error handling for factory mode on non-M06
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 4b3e910d7f430ab76dd37131bb75129878950163 upstream.
When attempting enter factory mode on firmware that does not support it, we'd error out, but leave the device with interrupts disabled, and thus touch not working. Fix it by moving the check before we disable interrupts/allocate memory for debug buffers.
[bwh: Backported to 3.16:
- s/EDT_M06/M06/
- Adjust context]
--- drivers/input/touchscreen/edt-ft5x06.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/input/touchscreen/edt-ft5x06.c +6 -8
@@ -491,6 +491,12 @@ static int edt_ft5x06_factory_mode(strucint ret;int error; +if (tsdata->version !=M06 ) { +dev_err (&client->dev, +"No factory mode support for non-M06 devices\n" ); +return -EINVAL ; + } +disable_irq (client->irq);if (!tsdata->raw_buffer) {
@@ -504,9 +510,6 @@ static int edt_ft5x06_factory_mode(struc }/* mode register is 0x3c when in the work mode */ -if (tsdata->version ==M09 ) - goto m09_out; - error =edt_ft5x06_register_write (tsdata,WORK_REGISTER_OPMODE ,0x03 );if (error) { dev_err(&client->dev,
@@ -539,11 +542,6 @@ err_out:enable_irq (client->irq);return error; - -m09_out: -dev_err (&client->dev,"No factory mode support for M09\n" ); -return -EINVAL ; - }static int edt_ft5x06_work_mode (struct edt_ft5x06_ts_data *tsdata)
PATCH 164/410 cifs: Fix missing put_xid in cifs_file_strict_mmap
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Wilcox <[email protected]>
commit f04a703c3d613845ae3141bfaf223489de8ab3eb upstream.
If cifs_zap_mapping() returned an error, we would return without putting the xid that we got earlier. Restructure cifs_file_strict_mmap() and cifs_file_mmap() to be more similar to each other and have a single point of return that always puts the xid.
--- fs/cifs/file.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
fs/cifs/file.c +12 -14
@@ -3116,20 +3116,18 @@ static struct vm_operations_struct cifs_int cifs_file_strict_mmap (struct file *file,struct vm_area_struct *vma) { -int rc, xid; +int xid, rc =0 ;struct inode *inode =file_inode (file); xid =get_xid (); -if (!CIFS_CACHE_READ (CIFS_I (inode))) { +if (!CIFS_CACHE_READ (CIFS_I (inode))) rc =cifs_zap_mapping (inode); -if (rc) -return rc; - } - - rc =generic_file_mmap (file, vma); -if (rc ==0 ) +if (!rc) + rc =generic_file_mmap (file, vma); +if (!rc) vma->vm_ops = &cifs_file_vm_ops; +free_xid (xid);return rc; }
@@ -3139,16 +3137,16 @@ int cifs_file_mmap(struct file *file, stint rc, xid; xid =get_xid (); + rc =cifs_revalidate_file (file); -if (rc) { +if (rc)cifs_dbg (FYI ,"Validation prior to mmap failed, error=%d\n" , rc); -free_xid (xid); -return rc; - } - rc =generic_file_mmap (file, vma); -if (rc ==0 ) +if (!rc) + rc =generic_file_mmap (file, vma); +if (!rc) vma->vm_ops = &cifs_file_vm_ops; +free_xid (xid);return rc; }
PATCH 165/410 cifs: Fix autonegotiate security settings mismatch
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Daniel N Pettersson <[email protected]>
commit 9aca7e454415f7878b28524e76bebe1170911a88 upstream.
Autonegotiation gives a security settings mismatch error if the SMB server selects an SMBv3 dialect that isn't SMB3.02. The exact error is "protocol revalidation - security settings mismatch".
This can be tested using Samba v4.2 or by setting the global Samba setting max protocol = SMB3_00.
The check that fails in smb3_validate_negotiate is the dialect verification of the negotiate info response. This is because it tries to verify against the protocol_id in the global smbdefault_values. The protocol_id in smbdefault_values is SMB3.02.
In SMB2_negotiate the protocol_id in smbdefault_values isn't updated, it is global so it probably shouldn't be, but server->dialect is.
This patch changes the check in smb3_validate_negotiate to use server->dialect instead of server->vals->protocol_id. The patch works with autonegotiate and when using a specific version in the vers mount option.
--- fs/cifs/smb2pdu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/cifs/smb2pdu.c +1 -2
@@ -541,8 +541,7 @@ int smb3_validate_negotiate(const unsign }/* check validate negotiate info response matches what we got earlier */ -if (pneg_rsp->Dialect != -cpu_to_le16 (tcon->ses->server->vals->protocol_id)) +if (pneg_rsp->Dialect !=cpu_to_le16 (tcon->ses->server->dialect)) goto vneg_out;if (pneg_rsp->SecurityMode !=cpu_to_le16 (tcon->ses->server->sec_mode))
PATCH 166/410 USB: serial: pl2303: new device id for Chilitag
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit d08dd3f3dd2ae351b793fc5b76abdbf0fd317b12 upstream.
This adds a new device id for Chilitag devices to the pl2303 driver.
--- drivers/usb/serial/pl2303.c | 1 + drivers/usb/serial/pl2303.h | 1 + 2 files changed, 2 insertions(+)
drivers/usb/serial/pl2303.c +1 -0
@@ -39,6 +39,7 @@ static const struct usb_device_id id_tab { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ2) }, { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_DCU11) }, { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ3) }, + { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_CHILITAG) }, { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_PHAROS) }, { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_ALDIGA) }, { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_MMX) },
drivers/usb/serial/pl2303.h +1 -0
@@ -17,6 +17,7 @@#define PL2303_PRODUCT_ID_DCU11 0x1234#define PL2303_PRODUCT_ID_PHAROS 0xaaa0#define PL2303_PRODUCT_ID_RSAQ3 0xaaa2 +#define PL2303_PRODUCT_ID_CHILITAG 0xaaa8#define PL2303_PRODUCT_ID_ALDIGA 0x0611#define PL2303_PRODUCT_ID_MMX 0x0612#define PL2303_PRODUCT_ID_GPRS 0x0609
PATCH 167/410 lkdtm: fix handle_irq_event symbol for INT_HW_IRQ_EN
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Delalande <[email protected]>
commit 5be2a5011c039506e2862650c928acfb2e3d7b9c upstream.
Function handle_IRQ_event was retired in v2.6.39 and replaced with handle_irq_event but nobody changed it in lkdtm so INT_HW_IRQ_EN has been broken for a while.
--- drivers/misc/lkdtm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/lkdtm.c +1 -1
@@ -566,7 +566,7 @@ static int lkdtm_register_cpoint(enum cn lkdtm.entry = (kprobe_opcode_t *) jp_do_irq;break ;case CN_INT_HW_IRQ_EN : - lkdtm.kp.symbol_name ="handle_IRQ_event" ; + lkdtm.kp.symbol_name ="handle_irq_event" ; lkdtm.entry = (kprobe_opcode_t *) jp_handle_irq_event;break ;case CN_INT_TASKLET_ENTRY :
PATCH 168/410 android: binder: use VM_ALLOC to get vm area
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ganesh Mahendran <[email protected]>
commit aac6830ec1cb681544212838911cdc57f2638216 upstream.
VM_IOREMAP is used to access hardware through a mechanism called I/O mapped memory. Android binder is a IPC machanism which will not access I/O memory.
And VM_IOREMAP has alignment requiement which may not needed in binder.
__get_vm_area_node()
{
...
if (flags & VM_IOREMAP)
align = 1ul << clamp_t(int, fls_long(size),
PAGE_SHIFT, IOREMAP_MAX_ORDER);
...
}This patch will save some kernel vm area, especially for 32bit os.
In 32bit OS, kernel vm area is only 240MB. We may got below error when launching a app:
<3>[ 4482.440053] binder_alloc: binder_alloc_mmap_handler: 15728 8ce67000-8cf65000 get_vm_area failed -12 <3>[ 4483.218817] binder_alloc: binder_alloc_mmap_handler: 15745 8ce67000-8cf65000 get_vm_area failed -12
----
V3: update comments
V2: update comments
--- drivers/staging/android/binder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/android/binder.c +1 -1
@@ -2808,7 +2808,7 @@ static int binder_mmap(struct file *filp goto err_already_mapped; } - area =get_vm_area (vma->vm_end - vma->vm_start,VM_IOREMAP ); + area =get_vm_area (vma->vm_end - vma->vm_start,VM_ALLOC );if (area ==NULL ) { ret = -ENOMEM ; failure_string ="get_vm_area" ;
PATCH 169/410 jffs2: Fix use-after-free bug in jffs2_iget()'s error handling path
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jake Daryll Obina <[email protected]>
commit 5bdd0c6f89fba430e18d636493398389dadc3b17 upstream.
If jffs2_iget() fails for a newly-allocated inode, jffs2_do_clear_inode() can get called twice in the error handling path, the first call in jffs2_iget() itself and the second through iget_failed(). This can result to a use-after-free error in the second jffs2_do_clear_inode() call, such as shown by the oops below wherein the second jffs2_do_clear_inode() call was trying to free node fragments that were already freed in the first jffs2_do_clear_inode() call.
[ 78.178860] jffs2: error: (1904) jffs2_do_read_inode_internal: CRC failed for read_inode of inode 24 at physical location 0x1fc00c [ 78.178914] Unable to handle kernel paging request at virtual address 6b6b6b6b6b6b6b7b [ 78.185871] pgd = ffffffc03a567000 [ 78.188794] [6b6b6b6b6b6b6b7b] *pgd=0000000000000000, *pud=0000000000000000 [ 78.194968] Internal error: Oops: 96000004 [#1] PREEMPT SMP ... [ 78.513147] PC is at rb_first_postorder+0xc/0x28 [ 78.516503] LR is at jffs2_kill_fragtree+0x28/0x90 [jffs2] [ 78.520672] pc : [<ffffff8008323d28>] lr : [<ffffff8000eb1cc8>] pstate: 60000105 [ 78.526757] sp : ffffff800cea38f0 [ 78.528753] x29: ffffff800cea38f0 x28: ffffffc01f3f8e80 [ 78.532754] x27: 0000000000000000 x26: ffffff800cea3c70 [ 78.536756] x25: 00000000dc67c8ae x24: ffffffc033d6945d [ 78.540759] x23: ffffffc036811740 x22: ffffff800891a5b8 [ 78.544760] x21: 0000000000000000 x20: 0000000000000000 [ 78.548762] x19: ffffffc037d48910 x18: ffffff800891a588 [ 78.552764] x17: 0000000000000800 x16: 0000000000000c00 [ 78.556766] x15: 0000000000000010 x14: 6f2065646f6e695f [ 78.560767] x13: 6461657220726f66 x12: 2064656c69616620 [ 78.564769] x11: 435243203a6c616e x10: 7265746e695f6564 [ 78.568771] x9 : 6f6e695f64616572 x8 : ffffffc037974038 [ 78.572774] x7 : bbbbbbbbbbbbbbbb x6 : 0000000000000008 [ 78.576775] x5 : 002f91d85bd44a2f x4 : 0000000000000000 [ 78.580777] x3 : 0000000000000000 x2 : 000000403755e000 [ 78.584779] x1 : 6b6b6b6b6b6b6b6b x0 : 6b6b6b6b6b6b6b6b ... [ 79.038551] [<ffffff8008323d28>] rb_first_postorder+0xc/0x28 [ 79.042962] [<ffffff8000eb5578>] jffs2_do_clear_inode+0x88/0x100 [jffs2] [ 79.048395] [<ffffff8000eb9ddc>] jffs2_evict_inode+0x3c/0x48 [jffs2] [ 79.053443] [<ffffff8008201ca8>] evict+0xb0/0x168 [ 79.056835] [<ffffff8008202650>] iput+0x1c0/0x200 [ 79.060228] [<ffffff800820408c>] iget_failed+0x30/0x3c [ 79.064097] [<ffffff8000eba0c0>] jffs2_iget+0x2d8/0x360 [jffs2] [ 79.068740] [<ffffff8000eb0a60>] jffs2_lookup+0xe8/0x130 [jffs2] [ 79.073434] [<ffffff80081f1a28>] lookup_slow+0x118/0x190 [ 79.077435] [<ffffff80081f4708>] walk_component+0xfc/0x28c [ 79.081610] [<ffffff80081f4dd0>] path_lookupat+0x84/0x108 [ 79.085699] [<ffffff80081f5578>] filename_lookup+0x88/0x100 [ 79.089960] [<ffffff80081f572c>] user_path_at_empty+0x58/0x6c [ 79.094396] [<ffffff80081ebe14>] vfs_statx+0xa4/0x114 [ 79.098138] [<ffffff80081ec44c>] SyS_newfstatat+0x58/0x98 [ 79.102227] [<ffffff800808354c>] __sys_trace_return+0x0/0x4 [ 79.106489] Code: d65f03c0 f9400001 b40000e1 aa0103e0 (f9400821)
The jffs2_do_clear_inode() call in jffs2_iget() is unnecessary since iget_failed() will eventually call jffs2_do_clear_inode() if needed, so just remove it.
--- fs/jffs2/fs.c | 1 - 1 file changed, 1 deletion(-)
fs/jffs2/fs.c +0 -1
@@ -363,7 +363,6 @@ error_io: ret = -EIO ; error:mutex_unlock (&f->sem); -jffs2_do_clear_inode (c, f);iget_failed (inode);return ERR_PTR (ret); }
PATCH 170/410 cifs: fix memory leak when password is supplied multiple times
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
commit d6ccf4997e62fb6629f9f003980dca5292138b7b upstream.
Unlikely but possible. When password is supplied multiple times, we have to free the previous allocation.
--- fs/cifs/connect.c | 2 ++ 1 file changed, 2 insertions(+)
fs/cifs/connect.c +2 -0
@@ -1614,6 +1614,7 @@ cifs_parse_mount_options(const char *mou tmp_end++;if (!(tmp_end < end && tmp_end[1 ] == delim)) {/* No it is not. Set the password to NULL */ +kfree (vol->password); vol->password =NULL ;break ; }
@@ -1651,6 +1652,7 @@ cifs_parse_mount_options(const char *mou options = end; } +kfree (vol->password);/* Now build new password string */ temp_len =strlen (value); vol->password =kzalloc (temp_len+1 ,GFP_KERNEL );
PATCH 171/410 CIFS: zero sensitive data when freeing
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Aurelien Aptel <[email protected]>
commit 97f4b7276b829a8927ac903a119bef2f963ccc58 upstream.
also replaces memset()+kfree() by kzfree().
--- fs/cifs/cifsencrypt.c | 3 +-- fs/cifs/connect.c | 6 +++--- fs/cifs/misc.c | 14 ++++---------- 3 files changed, 8 insertions(+), 15 deletions(-)
fs/cifs/cifsencrypt.c +1 -2
@@ -303,9 +303,8 @@ int calc_lanman_hash(const char *passwor {int i;int rc; -char password_with_pad[CIFS_ENCPWD_SIZE ]; +char password_with_pad[CIFS_ENCPWD_SIZE ] = {0 }; -memset (password_with_pad,0 ,CIFS_ENCPWD_SIZE );if (password)strncpy (password_with_pad, password,CIFS_ENCPWD_SIZE );
fs/cifs/connect.c +3 -3
@@ -1614,7 +1614,7 @@ cifs_parse_mount_options(const char *mou tmp_end++;if (!(tmp_end < end && tmp_end[1 ] == delim)) {/* No it is not. Set the password to NULL */ -kfree (vol->password); +kzfree (vol->password); vol->password =NULL ;break ; }
@@ -1652,7 +1652,7 @@ cifs_parse_mount_options(const char *mou options = end; } -kfree (vol->password); +kzfree (vol->password);/* Now build new password string */ temp_len =strlen (value); vol->password =kzalloc (temp_len+1 ,GFP_KERNEL );
@@ -4039,7 +4039,7 @@ cifs_construct_tcon(struct cifs_sb_inforeset_cifs_unix_caps (0 , tcon,NULL , vol_info); out:kfree (vol_info->username); -kfree (vol_info->password); +kzfree (vol_info->password);kfree (vol_info);return tcon;
fs/cifs/misc.c +4 -10
@@ -99,14 +99,11 @@ sesInfoFree(struct cifs_ses *buf_to_freekfree (buf_to_free->serverOS);kfree (buf_to_free->serverDomain);kfree (buf_to_free->serverNOS); -if (buf_to_free->password) { -memset (buf_to_free->password,0 ,strlen (buf_to_free->password)); -kfree (buf_to_free->password); - } +kzfree (buf_to_free->password);kfree (buf_to_free->user_name);kfree (buf_to_free->domainName); -kfree (buf_to_free->auth_key.response); -kfree (buf_to_free); +kzfree (buf_to_free->auth_key.response); +kzfree (buf_to_free); } struct cifs_tcon *
@@ -137,10 +134,7 @@ tconInfoFree(struct cifs_tcon *buf_to_fr }atomic_dec (&tconInfoAllocCount);kfree (buf_to_free->nativeFileSystem); -if (buf_to_free->password) { -memset (buf_to_free->password,0 ,strlen (buf_to_free->password)); -kfree (buf_to_free->password); - } +kzfree (buf_to_free->password);kfree (buf_to_free); }
PATCH 172/410 staging: iio: adc: remove the use of CamelCase
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ioana Ciornei <[email protected]>
commit 5f7e280f5ae61450a7aecd9feefe3f032b6a5abf upstream.
Remove the use of CamelCase to follow the kernel naming conventions
--- drivers/staging/iio/adc/ad7192.c | 10 +++++----- drivers/staging/iio/adc/ad7192.h | 2 +- drivers/staging/iio/adc/ad7280a.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-)
drivers/staging/iio/adc/ad7192.c +5 -5
@@ -125,7 +125,7 @@#define AD7192_GPOCON_P1DAT (1 << 1)/* P1 state */ #define AD7192_GPOCON_P0DAT (1 << 0)/* P0 state */ -#define AD7192_INT_FREQ_MHz 4915200 +#define AD7192_INT_FREQ_MHZ 4915200/* NOTE: * The AD7190/2/5 features a dual use data out ready DOUT/RDY output.
@@ -226,14 +226,14 @@ static int ad7192_setup(struct ad7192_stswitch (pdata->clock_source_sel) {case AD7192_CLK_EXT_MCLK1_2 :case AD7192_CLK_EXT_MCLK2 : - st->mclk = AD7192_INT_FREQ_MHz; + st->mclk =AD7192_INT_FREQ_MHZ ;break ;case AD7192_CLK_INT :case AD7192_CLK_INT_CO : -if (pdata->ext_clk_Hz) - st->mclk = pdata->ext_clk_Hz; +if (pdata->ext_clk_hz) + st->mclk = pdata->ext_clk_hz;else - st->mclk = AD7192_INT_FREQ_MHz; + st->mclk =AD7192_INT_FREQ_MHZ ;break ;default : ret = -EINVAL ;
drivers/staging/iio/adc/ad7192.h +1 -1
@@ -34,7 +34,7 @@struct ad7192_platform_data {u16 vref_mv;u8 clock_source_sel; -u32 ext_clk_Hz; +u32 ext_clk_hz;bool refin2_en;bool rej60_en;bool sinc3_en;
drivers/staging/iio/adc/ad7280a.c +2 -2
@@ -89,7 +89,7 @@#define AD7280A_ALL_CELLS (0xAD << 16) -#define AD7280A_MAX_SPI_CLK_Hz 700000/* < 1MHz */ +#define AD7280A_MAX_SPI_CLK_HZ 700000/* < 1MHz */ #define AD7280A_MAX_CHAIN 8#define AD7280A_CELLS_PER_DEV 6#define AD7280A_BITS 12
@@ -850,7 +850,7 @@ static int ad7280_probe(struct spi_devicad7280_crc8_build_table (st->crc_tab); - st->spi->max_speed_hz = AD7280A_MAX_SPI_CLK_Hz; + st->spi->max_speed_hz =AD7280A_MAX_SPI_CLK_HZ ; st->spi->mode =SPI_MODE_1 ;spi_setup (st->spi);
PATCH 173/410 staging: iio: adc: ad7192: fix external frequency setting
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Alexandru Ardelean <[email protected]>
commit e31b617d0a63c6558485aaa730fd162faa95a766 upstream.
The external clock frequency was set only when selecting the internal clock, which is fixed at 4.9152 Mhz.
This is incorrect, since it should be set when any of the external clock or crystal settings is selected.
Added range validation for the external (crystal/clock) frequency setting.
Valid values are between 2.4576 and 5.12 Mhz.
--- drivers/staging/iio/adc/ad7192.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/staging/iio/adc/ad7192.c +19 -8
@@ -125,6 +125,8 @@#define AD7192_GPOCON_P1DAT (1 << 1)/* P1 state */ #define AD7192_GPOCON_P0DAT (1 << 0)/* P0 state */ +#define AD7192_EXT_FREQ_MHZ_MIN 2457600 +#define AD7192_EXT_FREQ_MHZ_MAX 5120000#define AD7192_INT_FREQ_MHZ 4915200/* NOTE:
@@ -200,6 +202,12 @@ static int ad7192_calibrate_all(struct a ARRAY_SIZE(ad7192_calib_arr)); } +static inline bool ad7192_valid_external_frequency (u32 freq) +{ +return (freq >=AD7192_EXT_FREQ_MHZ_MIN && + freq <=AD7192_EXT_FREQ_MHZ_MAX ); +} +static int ad7192_setup (struct ad7192_state *st,const struct ad7192_platform_data *pdata) {
@@ -224,17 +232,20 @@ static int ad7192_setup(struct ad7192_stdev_warn (&st->sd.spi->dev,"device ID query failed (0x%X)\n" , id);switch (pdata->clock_source_sel) { -case AD7192_CLK_EXT_MCLK1_2 : -case AD7192_CLK_EXT_MCLK2 : - st->mclk =AD7192_INT_FREQ_MHZ ; -break ;case AD7192_CLK_INT :case AD7192_CLK_INT_CO : -if (pdata->ext_clk_hz) - st->mclk = pdata->ext_clk_hz; -else - st->mclk =AD7192_INT_FREQ_MHZ ; + st->mclk =AD7192_INT_FREQ_MHZ ;break ; +case AD7192_CLK_EXT_MCLK1_2 : +case AD7192_CLK_EXT_MCLK2 : +if (ad7192_valid_external_frequency (pdata->ext_clk_hz)) { + st->mclk = pdata->ext_clk_hz; +break ; + } +dev_err (&st->sd.spi->dev,"Invalid frequency setting %u\n" , + pdata->ext_clk_hz); + ret = -EINVAL ; + goto out;default : ret = -EINVAL ; goto out;
PATCH 174/410 RDMA/mlx5: Avoid memory leak in case of XRCD dealloc failure
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
commit b081808a66345ba725b77ecd8d759bee874cd937 upstream.
Failure in XRCD FW deallocation command leaves memory leaked and returns error to the user which he can't do anything about it.
This patch changes behavior to always free memory and always return success to the user.
--- drivers/infiniband/hw/mlx5/qp.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/infiniband/hw/mlx5/qp.c +1 -4
@@ -3050,12 +3050,9 @@ int mlx5_ib_dealloc_xrcd(struct ib_xrcdint err; err =mlx5_core_xrcd_dealloc (&dev->mdev, xrcdn); -if (err) { +if (err)mlx5_ib_warn (dev,"failed to dealloc xrcdn 0x%x\n" , xrcdn); -return err; - }kfree (xrcd); -return 0 ; }
PATCH 175/410 media: cxusb, dib0700: ignore XC2028_I2C_FLUSH
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mauro Carvalho Chehab <[email protected]>
commit 9893b905e743ded332575ca04486bd586c0772f7 upstream.
The XC2028_I2C_FLUSH only needs to be implemented on a few devices. Others can safely ignore it.
That prevents filling the dmesg with lots of messages like:
dib0700: stk7700ph_xc3028_callback: unknown command 2, arg 0
--- drivers/media/usb/dvb-usb/cxusb.c | 2 ++ drivers/media/usb/dvb-usb/dib0700_devices.c | 1 + 2 files changed, 3 insertions(+)
drivers/media/usb/dvb-usb/cxusb.c +2 -0
@@ -816,6 +816,8 @@ static int dvico_bluebird_xc2028_callbaccase XC2028_RESET_CLK :deb_info ("%s: XC2028_RESET_CLK %d\n" , __func__, arg);break ; +case XC2028_I2C_FLUSH : +break ;default :deb_info ("%s: unknown command %d, arg %d\n" , __func__, command, arg);
drivers/media/usb/dvb-usb/dib0700_devices.c +1 -0
@@ -405,6 +405,7 @@ static int stk7700ph_xc3028_callback(voidib7000p_set_gpio (adap->fe_adap[0 ].fe,8 ,0 ,1 );break ;case XC2028_RESET_CLK : +case XC2028_I2C_FLUSH :break ;default : err("%s: unknown command %d, arg %d\n", __func__,
PATCH 176/410 vhost_net: stop device during reset owner
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jason Wang <[email protected]>
commit 4cd879515d686849eec5f718aeac62a70b067d82 upstream.
We don't stop device before reset owner, this means we could try to serve any virtqueue kick before reset dev->worker. This will result a warn since the work was pending at llist during owner resetting. Fix this by stopping device during owner reset.
--- drivers/vhost/net.c | 1 + 1 file changed, 1 insertion(+)
drivers/vhost/net.c +1 -0
@@ -1009,6 +1009,7 @@ static long vhost_net_reset_owner(struct }vhost_net_stop (n, &tx_sock, &rx_sock);vhost_net_flush (n); +vhost_dev_stop (&n->dev);vhost_dev_reset_owner (&n->dev, memory);vhost_net_vq_reset (n); done:
PATCH 177/410 rbd: whitelist RBD_FEATURE_OPERATIONS feature bit
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Dryomov <[email protected]>
commit e573427a440fd67d3f522357d7ac901d59281948 upstream.
This feature bit restricts older clients from performing certain maintenance operations against an image (e.g. clone, snap create). krbd does not perform maintenance operations.
---
drivers/block/rbd.c +5 -2
@@ -117,8 +117,11 @@ static int atomic_dec_return_safe(atomic#define RBD_FEATURE_LAYERING (1<<0)#define RBD_FEATURE_STRIPINGV2 (1<<1) -#define RBD_FEATURES_ALL \ - (RBD_FEATURE_LAYERING | RBD_FEATURE_STRIPINGV2) +#define RBD_FEATURE_OPERATIONS (1<<8) + +#define RBD_FEATURES_ALL (RBD_FEATURE_LAYERING | \ + RBD_FEATURE_STRIPINGV2 | \ + RBD_FEATURE_OPERATIONS)/* Features supported by this (client software) implementation. */
PATCH 178/410 drm/radeon: adjust tested variable
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Julia Lawall <[email protected]>
commit 3a61b527b4e1f285d21b6e9e623dc45cf8bb391f upstream.
Check the variable that was most recently initialized.
The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@@
expression x, y, f, g, e, m;
statement S1,S2,S3,S4;
@@
x = f(...);
if (\(<+...x...+>\&e\)) S1 else S2
(
x = g(...);
|
m = g(...,&x,...);
|
y = g(...);
*if (e)
S3 else S4
)
// </smpl>
--- drivers/gpu/drm/radeon/radeon_uvd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_uvd.c +1 -1
@@ -950,7 +950,7 @@ int radeon_uvd_calc_upll_dividers(struct/* calc dclk divider with current vco freq */ dclk_div =radeon_uvd_calc_upll_post_div (vco_freq, dclk, pd_min, pd_even); -if (vclk_div > pd_max) +if (dclk_div > pd_max)break ;/* vco is too big, it has to stop */ /* calc score with current vco freq */
PATCH 179/410 scsi: ibmvfc: fix misdefined reserved field in ibmvfc_fcp_rsp_info
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Tyrel Datwyler <[email protected]>
commit c39813652700f3df552b6557530f1e5f782dbe2f upstream.
The fcp_rsp_info structure as defined in the FC spec has an initial 3 bytes reserved field. The ibmvfc driver mistakenly defined this field as 4 bytes resulting in the rsp_code field being defined in what should be the start of the second reserved field and thus always being reported as zero by the driver.
Ideally, we should wire ibmvfc up with libfc for the sake of code deduplication, and ease of maintaining standardized structures in a single place. However, for now simply fixup the definition in ibmvfc for backporting to distros on older kernels. Wiring up with libfc will be done in a followup patch.
--- drivers/scsi/ibmvscsi/ibmvfc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/ibmvscsi/ibmvfc.h +1 -1
@@ -366,7 +366,7 @@ enum ibmvfc_fcp_rsp_info_codes { };struct ibmvfc_fcp_rsp_info { -u16 reserved; +u8 reserved[3 ];u8 rsp_code;u8 reserved2[4 ]; }__attribute__((packed,aligned (2 )));
PATCH 180/410 netfilter: ipt_CLUSTERIP: fix out-of-bounds accesses in clusterip_tg_check()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Vyukov <[email protected]>
commit 1a38956cce5eabd7b74f94bab70265e4df83165e upstream.
Commit 136e92bbec0a switched local_nodes from an array to a bitmask but did not add proper bounds checks. As the result clusterip_config_init_nodelist() can both over-read ipt_clusterip_tgt_info.local_nodes and over-write clusterip_config.local_nodes.
Add bounds checks for both.
--- net/ipv4/netfilter/ipt_CLUSTERIP.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
net/ipv4/netfilter/ipt_CLUSTERIP.c +13 -3
@@ -366,7 +366,7 @@ static int clusterip_tg_check(const strustruct ipt_clusterip_tgt_info *cipinfo = par->targinfo;const struct ipt_entry *e = par->entryinfo;struct clusterip_config *config; -int ret; +int ret, i; if (cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP && cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP_SPT &&
@@ -380,8 +380,18 @@ static int clusterip_tg_check(const strupr_info ("Please specify destination IP\n" );return -EINVAL ; } - -/* FIXME: further sanity checks */ +if (cipinfo->num_local_nodes >ARRAY_SIZE (cipinfo->local_nodes)) { +pr_info ("bad num_local_nodes %u\n" , cipinfo->num_local_nodes); +return -EINVAL ; + } +for (i =0 ; i < cipinfo->num_local_nodes; i++) { +if (cipinfo->local_nodes[i] -1 >= +sizeof (config->local_nodes) *8 ) { +pr_info ("bad local_nodes[%d] %u\n" , + i, cipinfo->local_nodes[i]); +return -EINVAL ; + } + } config =clusterip_config_find_get (par->net, e->ip.dst.s_addr,1 );if (!config) {
PATCH 181/410 netfilter: on sockopt() acquire sock lock only in the required scope
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
commit 3f34cfae1238848fd53f25e5c8fd59da57901f4b upstream.
Syzbot reported several deadlocks in the netfilter area caused by rtnl lock and socket lock being acquired with a different order on different code paths, leading to backtraces like the following one:
======================================================
WARNING: possible circular locking dependency detected 4.15.0-rc9+ #212 Not tainted
------------------------------------------------------
syzkaller041579/3682 is trying to acquire lock:
(sk_lock-AF_INET6){+.+.}, at: [<000000008775e4dd>] lock_sockinclude/net/sock.h:1463 [inline]
(sk_lock-AF_INET6){+.+.}, at: [<000000008775e4dd>]
do_ipv6_setsockopt.isra.8+0x3c5/0x39d0 net/ipv6/ipv6_sockglue.c:167
but task is already holding lock:
(rtnl_mutex){+.+.}, at: [<000000004342eaa9>] rtnl_lock+0x17/0x20net/core/rtnetlink.c:74
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (rtnl_mutex){+.+.}:
__mutex_lock_common kernel/locking/mutex.c:756 [inline]
__mutex_lock+0x16f/0x1a80 kernel/locking/mutex.c:893
mutex_lock_nested+0x16/0x20 kernel/locking/mutex.c:908
rtnl_lock+0x17/0x20 net/core/rtnetlink.c:74
register_netdevice_notifier+0xad/0x860 net/core/dev.c:1607
tee_tg_check+0x1a0/0x280 net/netfilter/xt_TEE.c:106
xt_check_target+0x22c/0x7d0 net/netfilter/x_tables.c:845
check_target net/ipv6/netfilter/ip6_tables.c:538 [inline]
find_check_entry.isra.7+0x935/0xcf0
net/ipv6/netfilter/ip6_tables.c:580
translate_table+0xf52/0x1690 net/ipv6/netfilter/ip6_tables.c:749
do_replace net/ipv6/netfilter/ip6_tables.c:1165 [inline]
do_ip6t_set_ctl+0x370/0x5f0 net/ipv6/netfilter/ip6_tables.c:1691
nf_sockopt net/netfilter/nf_sockopt.c:106 [inline]
nf_setsockopt+0x67/0xc0 net/netfilter/nf_sockopt.c:115
ipv6_setsockopt+0x115/0x150 net/ipv6/ipv6_sockglue.c:928
udpv6_setsockopt+0x45/0x80 net/ipv6/udp.c:1422
sock_common_setsockopt+0x95/0xd0 net/core/sock.c:2978
SYSC_setsockopt net/socket.c:1849 [inline]
SyS_setsockopt+0x189/0x360 net/socket.c:1828
entry_SYSCALL_64_fastpath+0x29/0xa0-> #0 (sk_lock-AF_INET6){+.+.}:
lock_acquire+0x1d5/0x580 kernel/locking/lockdep.c:3914
lock_sock_nested+0xc2/0x110 net/core/sock.c:2780
lock_sock include/net/sock.h:1463 [inline]
do_ipv6_setsockopt.isra.8+0x3c5/0x39d0 net/ipv6/ipv6_sockglue.c:167
ipv6_setsockopt+0xd7/0x150 net/ipv6/ipv6_sockglue.c:922
udpv6_setsockopt+0x45/0x80 net/ipv6/udp.c:1422
sock_common_setsockopt+0x95/0xd0 net/core/sock.c:2978
SYSC_setsockopt net/socket.c:1849 [inline]
SyS_setsockopt+0x189/0x360 net/socket.c:1828
entry_SYSCALL_64_fastpath+0x29/0xa0other info that might help us debug this:
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(rtnl_mutex);
lock(sk_lock-AF_INET6);
lock(rtnl_mutex); lock(sk_lock-AF_INET6);
*** DEADLOCK ***
1 lock held by syzkaller041579/3682:
#0: (rtnl_mutex){+.+.}, at: [<000000004342eaa9>] rtnl_lock+0x17/0x20net/core/rtnetlink.c:74
The problem, as Florian noted, is that nf_setsockopt() is always called with the socket held, even if the lock itself is required only for very tight scopes and only for some operation.
This patch addresses the issues moving the lock_sock() call only where really needed, namely in ipv*_getorigdst(), so that nf_setsockopt() does not need anymore to acquire both locks.
--- net/ipv4/ip_sockglue.c | 14 ++++---------- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 6 +++++- net/ipv6/ipv6_sockglue.c | 17 +++++------------ net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 18 ++++++++++++------ 4 files changed, 26 insertions(+), 29 deletions(-)
net/ipv4/ip_sockglue.c +4 -10
@@ -1106,11 +1106,8 @@ int ip_setsockopt(struct sock *sk, int lif (err == -ENOPROTOOPT && optname !=IP_HDRINCL && optname !=IP_IPSEC_POLICY && optname !=IP_XFRM_POLICY && - !ip_mroute_opt (optname)) { -lock_sock (sk); + !ip_mroute_opt (optname)) err =nf_setsockopt (sk,PF_INET , optname, optval, optlen); -release_sock (sk); - }#endif return err; }
@@ -1135,12 +1132,9 @@ int compat_ip_setsockopt(struct sock *skif (err == -ENOPROTOOPT && optname !=IP_HDRINCL && optname !=IP_IPSEC_POLICY && optname !=IP_XFRM_POLICY && - !ip_mroute_opt (optname)) { -lock_sock (sk); - err =compat_nf_setsockopt (sk,PF_INET , optname, - optval, optlen); -release_sock (sk); - } + !ip_mroute_opt (optname)) + err =compat_nf_setsockopt (sk,PF_INET , optname, optval, + optlen);#endif return err; }
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +5 -1
@@ -269,15 +269,19 @@ getorigdst(struct sock *sk, int optval,struct nf_conntrack_tuple tuple;memset (&tuple,0 ,sizeof (tuple)); + +lock_sock (sk); tuple.src.u3.ip = inet->inet_rcv_saddr; tuple.src.u.tcp.port = inet->inet_sport; tuple.dst.u3.ip = inet->inet_daddr; tuple.dst.u.tcp.port = inet->inet_dport; tuple.src.l3num =PF_INET ; tuple.dst.protonum = sk->sk_protocol; +release_sock (sk);/* We only do TCP and SCTP at the moment: is there a better way? */ -if (sk->sk_protocol !=IPPROTO_TCP && sk->sk_protocol !=IPPROTO_SCTP ) { +if (tuple.dst.protonum !=IPPROTO_TCP && + tuple.dst.protonum !=IPPROTO_SCTP ) {pr_debug ("SO_ORIGINAL_DST: Not a TCP/SCTP socket\n" );return -ENOPROTOOPT ; }
net/ipv6/ipv6_sockglue.c +5 -12
@@ -871,12 +871,8 @@ int ipv6_setsockopt(struct sock *sk, int#ifdef CONFIG_NETFILTER /* we need to exclude all possible ENOPROTOOPTs except default case */ if (err == -ENOPROTOOPT && optname !=IPV6_IPSEC_POLICY && - optname !=IPV6_XFRM_POLICY ) { -lock_sock (sk); - err =nf_setsockopt (sk,PF_INET6 , optname, optval, - optlen); -release_sock (sk); - } + optname !=IPV6_XFRM_POLICY ) + err =nf_setsockopt (sk,PF_INET6 , optname, optval, optlen);#endif return err; }
@@ -907,12 +903,9 @@ int compat_ipv6_setsockopt(struct sock *#ifdef CONFIG_NETFILTER /* we need to exclude all possible ENOPROTOOPTs except default case */ if (err == -ENOPROTOOPT && optname !=IPV6_IPSEC_POLICY && - optname !=IPV6_XFRM_POLICY ) { -lock_sock (sk); - err =compat_nf_setsockopt (sk,PF_INET6 , optname, - optval, optlen); -release_sock (sk); - } + optname !=IPV6_XFRM_POLICY ) + err =compat_nf_setsockopt (sk,PF_INET6 , optname, optval, + optlen);#endif return err; }
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +12 -6
@@ -240,20 +240,27 @@ static struct nf_hook_ops ipv6_conntrackstatic int ipv6_getorigdst (struct sock *sk,int optval,void __user *user,int *len) { -const struct inet_sock *inet =inet_sk (sk); +struct nf_conntrack_tuple tuple = { .src.l3num =NFPROTO_IPV6 };const struct ipv6_pinfo *inet6 =inet6_sk (sk); +const struct inet_sock *inet =inet_sk (sk);const struct nf_conntrack_tuple_hash *h;struct sockaddr_in6 sin6; -struct nf_conntrack_tuple tuple = { .src.l3num =NFPROTO_IPV6 };struct nf_conn *ct; +__be32 flow_label; +int bound_dev_if; +lock_sock (sk); tuple.src.u3.in6 = sk->sk_v6_rcv_saddr; tuple.src.u.tcp.port = inet->inet_sport; tuple.dst.u3.in6 = sk->sk_v6_daddr; tuple.dst.u.tcp.port = inet->inet_dport; tuple.dst.protonum = sk->sk_protocol; + bound_dev_if = sk->sk_bound_dev_if; + flow_label = inet6->flow_label; +release_sock (sk); -if (sk->sk_protocol !=IPPROTO_TCP && sk->sk_protocol !=IPPROTO_SCTP ) +if (tuple.dst.protonum !=IPPROTO_TCP && + tuple.dst.protonum !=IPPROTO_SCTP )return -ENOPROTOOPT ;if (*len <0 || (unsigned int ) *len <sizeof (sin6))
@@ -271,14 +278,13 @@ ipv6_getorigdst(struct sock *sk, int opt sin6.sin6_family =AF_INET6 ; sin6.sin6_port = ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.u.tcp.port; - sin6.sin6_flowinfo = inet6->flow_label &IPV6_FLOWINFO_MASK ; + sin6.sin6_flowinfo = flow_label &IPV6_FLOWINFO_MASK ;memcpy (&sin6.sin6_addr, &ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.u3.in6,sizeof (sin6.sin6_addr));nf_ct_put (ct); - sin6.sin6_scope_id =ipv6_iface_scope_id (&sin6.sin6_addr, - sk->sk_bound_dev_if); + sin6.sin6_scope_id =ipv6_iface_scope_id (&sin6.sin6_addr, bound_dev_if);return copy_to_user (user, &sin6,sizeof (sin6)) ? -EFAULT :0 ; }
PATCH 182/410 Revert "apple-gmux: lock iGP IO to protect from vgaarb changes"
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Wunner <[email protected]>
commit d6fa7588fd7a8def4c747c0c574ce85d453e3788 upstream.
Commit 4eebd5a4e726 ("apple-gmux: lock iGP IO to protect from vgaarb changes") amended this driver's ->probe hook to lock decoding of normal (non-legacy) I/O space accesses to the integrated GPU on dual-GPU MacBook Pros. The lock stays in place until the driver is unbound.
The change was made to work around an issue with the out-of-tree nvidia graphics driver (available at http://www.nvidia.com/object/unix.html).
It contains the following sequence in nvidia/nv.c:
#if defined(CONFIG_VGA_ARB) && !defined(NVCPU_PPC64LE) #if defined(VGA_DEFAULT_DEVICE) vga_tryget(VGA_DEFAULT_DEVICE, VGA_RSRC_LEGACY_MASK); #endif vga_set_legacy_decoding(dev, VGA_RSRC_NONE); #endif
This code was reported to cause deadlocks with VFIO already in 2013:
https://devtalk.nvidia.com/default/topic/545560
I've reported the issue to Nvidia developers once more in 2017:
https://www.spinics.net/lists/dri-devel/msg138754.html
On the MacBookPro10,1, this code apparently breaks backlight control (which is handled by apple-gmux via an I/O region starting at 0x700), as reported by Petri Hodju:
https://bugzilla.kernel.org/show_bug.cgi?id=86121
I tried to replicate Petri's observations on my MacBook9,1, which uses the same Intel Ivy Bridge + Nvidia GeForce GT 650M architecture, to no avail. On my machine apple-gmux' I/O region remains accessible even with the nvidia driver loaded and commit 4eebd5a4e726 reverted. Petri reported that apple-gmux becomes accessible again after a suspend/resume cycle because the BIOS changed the VGA routing on the root port to the Nvidia GPU. Perhaps this is a BIOS issue after all that can be fixed with an update?
In any case, the change made by commit 4eebd5a4e726 has turned out to cause two new issues:
* Wilfried Klaebe reports a deadlock when launching Xorg because it opens /dev/vga_arbiter and calls vga_get(), but apple-gmux is holding a lock on I/O space indefinitely. It looks like apple-gmux' current behavior is an abuse of the vgaarb API as locks are not meant to be held for longer periods:
https://bugzilla.kernel.org/show_bug.cgi?id=88861#c11
https://bugzilla.kernel.org/attachment.cgi?id=217541
* On dual GPU MacBook Pros introduced since 2013, the integrated GPU is powergated on boot und thus becomes invisible to Linux unless a custom EFI protocol is used to leave it powered on. (A patch exists but is not in mainline yet due to several negative side effects.) On these machines, locking I/O to the integrated GPU (as done by 4eebd5a4e726) fails and backlight control is therefore broken:
https://bugzilla.kernel.org/show_bug.cgi?id=105051
So let's revert commit 4eebd5a4e726 please. Users experiencing the issue with the proprietary nvidia driver can comment out the above- quoted problematic code as a workaround (or try updating the BIOS).
--- drivers/platform/x86/apple-gmux.c | 48 +------------------------------ 1 file changed, 1 insertion(+), 47 deletions(-)
drivers/platform/x86/apple-gmux.c +1 -47
@@ -22,7 +22,6 @@#include <linux/delay.h> #include <linux/pci.h> #include <linux/vga_switcheroo.h> -#include <linux/vgaarb.h> #include <acpi/video.h> #include <asm/io.h>
@@ -32,7 +31,6 @@ struct apple_gmux_data {bool indexed;struct mutex index_lock; -struct pci_dev *pdev;struct backlight_device *bdev;/* switcheroo data */
@@ -417,23 +415,6 @@ static int gmux_resume(struct device *dereturn 0 ; } -static struct pci_dev *gmux_get_io_pdev (void ) -{ -struct pci_dev *pdev =NULL ; - -while ((pdev =pci_get_class (PCI_CLASS_DISPLAY_VGA <<8 , pdev))) { -u16 cmd; - -pci_read_config_word (pdev,PCI_COMMAND , &cmd); -if (!(cmd &PCI_COMMAND_IO )) -continue ; - -return pdev; - } - -return NULL ; -} -static int gmux_probe (struct pnp_dev *pnp,const struct pnp_device_id *id) {struct apple_gmux_data *gmux_data;
@@ -444,7 +425,6 @@ static int gmux_probe(struct pnp_dev *pnint ret = -ENXIO ;acpi_status status;unsigned long long gpe; -struct pci_dev *pdev =NULL ;if (apple_gmux_data)return -EBUSY ;
@@ -495,7 +475,7 @@ static int gmux_probe(struct pnp_dev *pn ver_minor = (version >>16 ) &0xff ; ver_release = (version >>8 ) &0xff ; }else { -pr_info ("gmux device not present or IO disabled\n" ); +pr_info ("gmux device not present\n" ); ret = -ENODEV ; goto err_release; }
@@ -503,23 +483,6 @@ static int gmux_probe(struct pnp_dev *pnpr_info ("Found gmux version %d.%d.%d [%s]\n" , ver_major, ver_minor, ver_release, (gmux_data->indexed ?"indexed" :"classic" )); -/* -* Apple systems with gmux are EFI based and normally don't use -* VGA. In addition changing IO+MEM ownership between IGP and dGPU -* disables IO/MEM used for backlight control on some systems. -* Lock IO+MEM to GPU with active IO to prevent switch. -*/ - pdev =gmux_get_io_pdev (); -if (pdev &&vga_tryget (pdev, -VGA_RSRC_NORMAL_IO |VGA_RSRC_NORMAL_MEM )) { -pr_err ("IO+MEM vgaarb-locking for PCI:%s failed\n" , -pci_name (pdev)); - ret = -EBUSY ; - goto err_release; - }else if (pdev) -pr_info ("locked IO for PCI:%s\n" ,pci_name (pdev)); - gmux_data->pdev = pdev; -memset (&props,0 ,sizeof (props)); props.type =BACKLIGHT_PLATFORM ; props.max_brightness =gmux_read32 (gmux_data,GMUX_PORT_MAX_BRIGHTNESS );
@@ -611,10 +574,6 @@ err_enable_gpe: err_notify:backlight_device_unregister (bdev); err_release: -if (gmux_data->pdev) -vga_put (gmux_data->pdev, -VGA_RSRC_NORMAL_IO |VGA_RSRC_NORMAL_MEM ); -pci_dev_put (pdev);release_region (gmux_data->iostart, gmux_data->iolen); err_free:kfree (gmux_data);
@@ -634,11 +593,6 @@ static void gmux_remove(struct pnp_dev * &gmux_notify_handler); } -if (gmux_data->pdev) { -vga_put (gmux_data->pdev, -VGA_RSRC_NORMAL_IO |VGA_RSRC_NORMAL_MEM ); -pci_dev_put (gmux_data->pdev); - }backlight_device_unregister (gmux_data->bdev);release_region (gmux_data->iostart, gmux_data->iolen);
PATCH 183/410 mm: pin address_space before dereferencing it while isolating an LRU page
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mel Gorman <[email protected]>
commit 69d763fc6d3aee787a3e8c8c35092b4f4960fa5d upstream.
Minchan Kim asked the following question -- what locks protects address_space destroying when race happens between inode trauncation and __isolate_lru_page? Jan Kara clarified by describing the race as follows
CPU1 CPU2
truncate(inode) __isolate_lru_page()
...
truncate_inode_page(mapping, page);
delete_from_page_cache(page)
spin_lock_irqsave(&mapping->tree_lock, flags);
__delete_from_page_cache(page, NULL)
page_cache_tree_delete(..)
... mapping = page_mapping(page);
page->mapping = NULL;
...
spin_unlock_irqrestore(&mapping->tree_lock, flags);
page_cache_free_page(mapping, page)
put_page(page)
if (put_page_testzero(page)) -> false- inode now has no pages and can be freed including embedded address_space
if (mapping && !mapping->a_ops->migratepage)
- we've dereferenced mapping which is potentially already free.
The race is theoretically possible but unlikely. Before the delete_from_page_cache, truncate_cleanup_page is called so the page is likely to be !PageDirty or PageWriteback which gets skipped by the only caller that checks the mappping in __isolate_lru_page. Even if the race occurs, a substantial amount of work has to happen during a tiny window with no preemption but it could potentially be done using a virtual machine to artifically slow one CPU or halt it during the critical window.
This patch should eliminate the race with truncation by try-locking the page before derefencing mapping and aborting if the lock was not acquired. There was a suggestion from Huang Ying to use RCU as a side-effect to prevent mapping being freed. However, I do not like the solution as it's an unconventional means of preserving a mapping and it's not a context where rcu_read_lock is obviously protecting rcu data.
--- mm/vmscan.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
mm/vmscan.c +12 -2
@@ -1206,6 +1206,7 @@ int __isolate_lru_page(struct page *pageif (PageDirty (page)) {struct address_space *mapping; +bool migrate_dirty;/* ISOLATE_CLEAN means only clean pages */ if (mode &ISOLATE_CLEAN )
@@ -1214,10 +1215,19 @@ int __isolate_lru_page(struct page *page/* * Only pages without mappings or that have a * ->migratepage callback are possible to migrate -* without blocking +* without blocking. However, we can be racing with +* truncation so it's necessary to lock the page +* to stabilise the mapping as truncation holds +* the page lock until after the page is removed +* from the page cache. */ +if (!trylock_page (page)) +return ret; + mapping =page_mapping (page); -if (mapping && !mapping->a_ops->migratepage) + migrate_dirty = mapping && mapping->a_ops->migratepage; +unlock_page (page); +if (!migrate_dirty)return ret; } }
Re: [PATCH 3.16 183/410] mm: pin address_space before dereferencing it while isolating an LRU page
Quoted 1 line · Ben Hutchings
3.16.57-rc1 review patch. If anyone has any objections, please let me know.
Not an objection as such, but if you're including this one, please be sure to add 145e1a71e090575c74969e3daa8136d1e5b99fc8 "mm: fix the NULL mapping case in __isolate_lru_page()"
Thanks,
Hugh
Quoted 96 lines
------------------
From: Mel Gorman <[email protected]>
commit
69d763fc6d3aee787a3e8c8c35092b4f4960fa5dupstream.Minchan Kim asked the following question -- what locks protects
address_spacedestroying when race happens between inode trauncation and__isolate_lru_page? Jan Kara clarified by describing the race as followsCPU1 CPU2
truncate(inode)
__isolate_lru_page()
...truncate_inode_page(mapping, page); delete_from_page_cache(page) spin_lock_irqsave(&mapping->tree_lock, flags); __delete_from_page_cache(page, NULL) page_cache_tree_delete(..) ... mapping = page_mapping(page); page->mapping = NULL; ... spin_unlock_irqrestore(&mapping->tree_lock, flags); page_cache_free_page(mapping, page) put_page(page) if (put_page_testzero(page)) -> false- inode now has no pages and can be freed including embedded
address_spaceif (mapping && !mapping->a_ops->migratepage)- we've dereferenced mapping which is potentially already free.
The race is theoretically possible but unlikely. Before the
delete_from_page_cache,truncate_cleanup_pageis called so the page is likely to be !PageDirty or PageWriteback which gets skipped by the only caller that checks the mappping in__isolate_lru_page. Even if the race occurs, a substantial amount of work has to happen during a tiny window with no preemption but it could potentially be done using a virtual machine to artifically slow one CPU or halt it during the critical window.This patch should eliminate the race with truncation by try-locking the page before derefencing mapping and aborting if the lock was not acquired. There was a suggestion from Huang Ying to use RCU as a side-effect to prevent mapping being freed. However, I do not like the solution as it's an unconventional means of preserving a mapping and it's not a context where
rcu_read_lockis obviously protecting rcu data.Fixes c82449352854 ("mm: compaction: make isolate_lru_page() filter-aware again")Signed-off-by Mel Gorman <[email protected]>Acked-by Minchan Kim <[email protected]>Cc "Huang, Ying" <[email protected]>Cc Jan Kara <[email protected]>Signed-off-by Andrew Morton <[email protected]>Signed-off-by Linus Torvalds <[email protected]>[bwh: Backported to 3.16: adjust context]Signed-off-by Ben Hutchings <[email protected]>--- mm/vmscan.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)mm/vmscan.c +12
-2@@ -1206,6 +1206,7 @@ int __isolate_lru_page(struct page *pageif (PageDirty (page)) {struct address_space *mapping; +bool migrate_dirty;/* ISOLATE_CLEAN means only clean pages */ if (mode &ISOLATE_CLEAN )@@ -1214,10 +1215,19 @@ int __isolate_lru_page(struct page *page/* * Only pages without mappings or that have a * ->migratepage callback are possible to migrate -* without blocking +* without blocking. However, we can be racing with +* truncation so it's necessary to lock the page +* to stabilise the mapping as truncation holds +* the page lock until after the page is removed +* from the page cache. */ +if (!trylock_page (page)) +return ret; + mapping =page_mapping (page); -if (mapping && !mapping->a_ops->migratepage) + migrate_dirty = mapping && mapping->a_ops->migratepage; +unlock_page (page); +if (!migrate_dirty)return ret; } }
Re: [PATCH 3.16 183/410] mm: pin address_space before dereferencing it while isolating an LRU page
Quoted 7 lines · Hugh Dickins
Quoted 1 line · Ben Hutchings
3.16.57-rc1 review patch. If anyone has any objections, please let me know.
Not an objection as such, but if you're including this one, please be sure to add
145e1a71e090575c74969e3daa8136d1e5b99fc8"mm: fix the NULL mapping case in__isolate_lru_page()"
Added, thanks.
Ben.
Quoted 99 lines
Thanks,
HughQuoted 96 lines
------------------
From: Mel Gorman <[email protected]>
commit
69d763fc6d3aee787a3e8c8c35092b4f4960fa5dupstream.Minchan Kim asked the following question -- what locks protects
address_spacedestroying when race happens between inode trauncation and__isolate_lru_page? Jan Kara clarified by describing the race as followsCPU1 CPU2
truncate(inode)
__isolate_lru_page()
...truncate_inode_page(mapping, page); delete_from_page_cache(page) spin_lock_irqsave(&mapping->tree_lock, flags); __delete_from_page_cache(page, NULL) page_cache_tree_delete(..) ... mapping = page_mapping(page); page->mapping = NULL; ... spin_unlock_irqrestore(&mapping->tree_lock, flags); page_cache_free_page(mapping, page) put_page(page) if (put_page_testzero(page)) -> false- inode now has no pages and can be freed including embedded
address_spaceif (mapping && !mapping->a_ops->migratepage)- we've dereferenced mapping which is potentially already free.
The race is theoretically possible but unlikely. Before the
delete_from_page_cache,truncate_cleanup_pageis called so the page is likely to be !PageDirty or PageWriteback which gets skipped by the only caller that checks the mappping in__isolate_lru_page. Even if the race occurs, a substantial amount of work has to happen during a tiny window with no preemption but it could potentially be done using a virtual machine to artifically slow one CPU or halt it during the critical window.This patch should eliminate the race with truncation by try-locking the page before derefencing mapping and aborting if the lock was not acquired. There was a suggestion from Huang Ying to use RCU as a side-effect to prevent mapping being freed. However, I do not like the solution as it's an unconventional means of preserving a mapping and it's not a context where
rcu_read_lockis obviously protecting rcu data.Fixes c82449352854 ("mm: compaction: make isolate_lru_page() filter-aware again")Signed-off-by Mel Gorman <[email protected]>Acked-by Minchan Kim <[email protected]>Cc "Huang, Ying" <[email protected]>Cc Jan Kara <[email protected]>Signed-off-by Andrew Morton <[email protected]>Signed-off-by Linus Torvalds <[email protected]>[bwh: Backported to 3.16: adjust context]Signed-off-by Ben Hutchings <[email protected]>--- mm/vmscan.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)mm/vmscan.c +12
-2@@ -1206,6 +1206,7 @@ int __isolate_lru_page(struct page *pageif (PageDirty (page)) {struct address_space *mapping; +bool migrate_dirty;/* ISOLATE_CLEAN means only clean pages */ if (mode &ISOLATE_CLEAN )@@ -1214,10 +1215,19 @@ int __isolate_lru_page(struct page *page/* * Only pages without mappings or that have a * ->migratepage callback are possible to migrate -* without blocking +* without blocking. However, we can be racing with +* truncation so it's necessary to lock the page +* to stabilise the mapping as truncation holds +* the page lock until after the page is removed +* from the page cache. */ +if (!trylock_page (page)) +return ret; + mapping =page_mapping (page); -if (mapping && !mapping->a_ops->migratepage) + migrate_dirty = mapping && mapping->a_ops->migratepage; +unlock_page (page); +if (!migrate_dirty)return ret; } }
Signature · 3 lines
Ben Hutchings
The generation of random numbers is too important to be left to chance.
- Robert CoveyouPATCH 184/410 KVM: PPC: Book3S PR: Fix svcpu copying with preemption enabled
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Graf <[email protected]>
commit 07ae5389e98c53bb9e9f308fce9c903bc3ee7720 upstream.
When copying between the vcpu and svcpu, we may get scheduled away onto a different host CPU which in turn means our svcpu pointer may change.
That means we need to atomically copy to and from the svcpu with preemption disabled, so that all code around it always sees a coherent state.
--- arch/powerpc/include/asm/kvm_book3s.h | 6 ++---- arch/powerpc/kvm/book3s_interrupts.S | 4 +--- arch/powerpc/kvm/book3s_pr.c | 20 +++++++++----------- 3 files changed, 12 insertions(+), 18 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +2 -4
@@ -190,10 +190,8 @@ extern void kvmppc_hv_entry_trampoline(vextern u32 kvmppc_alignment_dsisr (struct kvm_vcpu *vcpu,unsigned int inst);extern ulong kvmppc_alignment_dar (struct kvm_vcpu *vcpu,unsigned int inst);extern int kvmppc_h_pr (struct kvm_vcpu *vcpu,unsigned long cmd); -extern void kvmppc_copy_to_svcpu (struct kvmppc_book3s_shadow_vcpu *svcpu, -struct kvm_vcpu *vcpu); -extern void kvmppc_copy_from_svcpu (struct kvm_vcpu *vcpu, -struct kvmppc_book3s_shadow_vcpu *svcpu); +extern void kvmppc_copy_to_svcpu (struct kvm_vcpu *vcpu); +extern void kvmppc_copy_from_svcpu (struct kvm_vcpu *vcpu);static inline struct kvmppc_vcpu_book3s *to_book3s (struct kvm_vcpu *vcpu) {
arch/powerpc/kvm/book3s_interrupts.S +1 -3
@@ -96,7 +96,7 @@ kvm_start_entry: kvm_start_lightweight: /* Copy registers into shadow vcpu so we can access them in real mode */ - GET_SHADOW_VCPU(r3) + mr r3, r4 bl FUNC(kvmppc_copy_to_svcpu) nop REST_GPR(4, r1)
@@ -165,9 +165,7 @@ after_sprg3_load: stw r12, VCPU_TRAP(r3) /* Transfer reg values from shadow vcpu back to vcpu struct */ - /* On 64-bit, interrupts are still off at this point */ - GET_SHADOW_VCPU(r4) bl FUNC(kvmppc_copy_from_svcpu) nop
arch/powerpc/kvm/book3s_pr.c +9 -11
@@ -82,7 +82,7 @@ static void kvmppc_core_vcpu_put_pr(stru#ifdef CONFIG_PPC_BOOK3S_64 struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu);if (svcpu->in_use) { -kvmppc_copy_from_svcpu (vcpu, svcpu); +kvmppc_copy_from_svcpu (vcpu); }memcpy (to_book3s (vcpu)->slb_shadow, svcpu->slb,sizeof (svcpu->slb));to_book3s (vcpu)->slb_shadow_max = svcpu->slb_max;
@@ -95,9 +95,10 @@ static void kvmppc_core_vcpu_put_pr(stru }/* Copy data needed by real-mode code from vcpu to shadow vcpu */ -void kvmppc_copy_to_svcpu (struct kvmppc_book3s_shadow_vcpu *svcpu, -struct kvm_vcpu *vcpu) +void kvmppc_copy_to_svcpu (struct kvm_vcpu *vcpu) { +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); + svcpu->gpr[0 ] = vcpu->arch.gpr[0 ]; svcpu->gpr[1 ] = vcpu->arch.gpr[1 ]; svcpu->gpr[2 ] = vcpu->arch.gpr[2 ];
@@ -121,17 +122,14 @@ void kvmppc_copy_to_svcpu(struct kvmppc_ svcpu->shadow_fscr = vcpu->arch.shadow_fscr;#endif svcpu->in_use = true; + +svcpu_put (svcpu); }/* Copy data touched by real-mode code from shadow vcpu back to vcpu */ -void kvmppc_copy_from_svcpu (struct kvm_vcpu *vcpu, -struct kvmppc_book3s_shadow_vcpu *svcpu) +void kvmppc_copy_from_svcpu (struct kvm_vcpu *vcpu) { -/* -* vcpu_put would just call us again because in_use hasn't -* been updated yet. -*/ -preempt_disable (); +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu);/* * Maybe we were already preempted and synced the svcpu from
@@ -169,7 +167,7 @@ void kvmppc_copy_from_svcpu(struct kvm_v svcpu->in_use = false; out: -preempt_enable (); +svcpu_put (svcpu); }static int kvmppc_core_check_requests_pr (struct kvm_vcpu *vcpu)
PATCH 185/410 net: igmp: add a missing rcu locking section
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit e7aadb27a5415e8125834b84a74477bfbee4eff5 upstream.
Newly added igmpv3_get_srcaddr() needs to be called under rcu lock.
Timer callbacks do not ensure this locking.
=============================
WARNING: suspicious RCU usage
4.15.0+ #200 Not tainted
-----------------------------./include/linux/inetdevice.h:216 suspicious rcu_dereference_check() usage!
other info that might help us debug this:
rcu_scheduler_active = 2, debug_locks = 1
3 locks held by syzkaller616973/4074:
#0: (&mm->mmap_sem){++++}, at: [<00000000bfce669e>] __do_page_fault+0x32d/0xc90 arch/x86/mm/fault.c:1355
#1: ((&im->timer)){+.-.}, at: [<00000000619d2f71>] lockdep_copy_map include/linux/lockdep.h:178 [inline]
#1: ((&im->timer)){+.-.}, at: [<00000000619d2f71>] call_timer_fn+0x1c6/0x820 kernel/time/timer.c:1316
#2: (&(&im->lock)->rlock){+.-.}, at: [<000000005f833c5c>] spin_lock_bh include/linux/spinlock.h:315 [inline]
#2: (&(&im->lock)->rlock){+.-.}, at: [<000000005f833c5c>] igmpv3_send_report+0x98/0x5b0 net/ipv4/igmp.c:600stack backtrace: CPU: 0 PID: 4074 Comm: syzkaller616973 Not tainted 4.15.0+ #200 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: <IRQ> __dump_stack lib/dump_stack.c:17 [inline] dump_stack+0x194/0x257 lib/dump_stack.c:53 lockdep_rcu_suspicious+0x123/0x170 kernel/locking/lockdep.c:4592 __in_dev_get_rcu include/linux/inetdevice.h:216 [inline] igmpv3_get_srcaddr net/ipv4/igmp.c:329 [inline] igmpv3_newpack+0xeef/0x12e0 net/ipv4/igmp.c:389 add_grhead.isra.27+0x235/0x300 net/ipv4/igmp.c:432 add_grec+0xbd3/0x1170 net/ipv4/igmp.c:565 igmpv3_send_report+0xd5/0x5b0 net/ipv4/igmp.c:605 igmp_send_report+0xc43/0x1050 net/ipv4/igmp.c:722 igmp_timer_expire+0x322/0x5c0 net/ipv4/igmp.c:831 call_timer_fn+0x228/0x820 kernel/time/timer.c:1326 expire_timers kernel/time/timer.c:1363 [inline] __run_timers+0x7ee/0xb70 kernel/time/timer.c:1666 run_timer_softirq+0x4c/0x70 kernel/time/timer.c:1692 __do_softirq+0x2d7/0xb85 kernel/softirq.c:285 invoke_softirq kernel/softirq.c:365 [inline] irq_exit+0x1cc/0x200 kernel/softirq.c:405 exiting_irq arch/x86/include/asm/apic.h:541 [inline] smp_apic_timer_interrupt+0x16b/0x700 arch/x86/kernel/apic/apic.c:1052 apic_timer_interrupt+0xa9/0xb0 arch/x86/entry/entry_64.S:938
--- net/ipv4/igmp.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv4/igmp.c +4 -0
@@ -388,7 +388,11 @@ static struct sk_buff *igmpv3_newpack(st pip->frag_off =htons (IP_DF ); pip->ttl =1 ; pip->daddr = fl4.daddr; + +rcu_read_lock (); pip->saddr =igmpv3_get_srcaddr (dev, &fl4); +rcu_read_unlock (); + pip->protocol =IPPROTO_IGMP ; pip->tot_len =0 ;/* filled in later */ ip_select_ident (skb,NULL );
PATCH 186/410 Btrfs: fix deadlock in run_delalloc_nocow
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit e89166990f11c3f21e1649d760dd35f9e410321c upstream.
@cur_offset is not set back to what it should be (@cow_start) if btrfs_next_leaf() returns something wrong, and the range [cow_start, cur_offset) remains locked forever.
--- fs/btrfs/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/btrfs/inode.c +4 -1
@@ -1235,8 +1235,11 @@ next_slot: leaf = path->nodes[0 ];if (path->slots[0 ] >=btrfs_header_nritems (leaf)) { ret =btrfs_next_leaf (root, path); -if (ret <0 ) +if (ret <0 ) { +if (cow_start != (u64)-1 ) + cur_offset = cow_start; goto error; + }if (ret >0 )break ; leaf = path->nodes[0 ];
PATCH 187/410 Btrfs: fix crash due to not cleaning up tree log block's dirty bits
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit 1846430c24d66e85cc58286b3319c82cd54debb2 upstream.
In cases that the whole fs flips into readonly status due to failures in critical sections, then log tree's blocks are still dirty, and this leads to a crash during umount time, the crash is about use-after-free,
umount
-> close_ctree
-> stop workers
-> iput(btree_inode)
-> iput_final
-> write_inode_now
-> ...
-> queue job on stop'd workers--- fs/btrfs/tree-log.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/btrfs/tree-log.c +9 -0
@@ -2197,6 +2197,9 @@ static noinline int walk_down_log_tree(sclean_tree_block (trans, root, next);btrfs_wait_tree_block_writeback (next);btrfs_tree_unlock (next); + }else { +if (test_and_clear_bit (EXTENT_BUFFER_DIRTY , &next->bflags)) +clear_extent_buffer_dirty (next); } WARN_ON(root_owner !=
@@ -2275,6 +2278,9 @@ static noinline int walk_up_log_tree(strclean_tree_block (trans, root, next);btrfs_wait_tree_block_writeback (next);btrfs_tree_unlock (next); + }else { +if (test_and_clear_bit (EXTENT_BUFFER_DIRTY , &next->bflags)) +clear_extent_buffer_dirty (next); }WARN_ON (root_owner !=BTRFS_TREE_LOG_OBJECTID );
@@ -2351,6 +2357,9 @@ static int walk_log_tree(struct btrfs_trclean_tree_block (trans, log, next);btrfs_wait_tree_block_writeback (next);btrfs_tree_unlock (next); + }else { +if (test_and_clear_bit (EXTENT_BUFFER_DIRTY , &next->bflags)) +clear_extent_buffer_dirty (next); } WARN_ON(log->root_key.objectid !=
PATCH 188/410 Btrfs: fix extent state leak from tree log
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit 55237a5f2431a72435e3ed39e4306e973c0446b7 upstream.
It's possible that btrfs_sync_log() bails out after one of the two btrfs_write_marked_extents() which convert extent state's state bit into EXTENT_NEED_WAIT from EXTENT_DIRTY/EXTENT_NEW, however only EXTENT_DIRTY and EXTENT_NEW are searched by free_log_tree() so that those extent states with EXTENT_NEED_WAIT lead to memory leak.
--- fs/btrfs/tree-log.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/btrfs/tree-log.c +3 -2
@@ -2731,13 +2731,14 @@ static void free_log_tree(struct btrfs_twhile (1 ) { ret =find_first_extent_bit (&log->dirty_log_pages, -0 , &start, &end,EXTENT_DIRTY |EXTENT_NEW , +0 , &start, &end, +EXTENT_DIRTY |EXTENT_NEW |EXTENT_NEED_WAIT ,NULL );if (ret)break ;clear_extent_bits (&log->dirty_log_pages, start, end, -EXTENT_DIRTY |EXTENT_NEW ,GFP_NOFS ); +EXTENT_DIRTY |EXTENT_NEW |EXTENT_NEED_WAIT ,GFP_NOFS ); }/*
PATCH 189/410 Btrfs: fix use-after-free on root->orphan_block_rsv
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit 1a932ef4e47984dee227834667b5ff5a334e4805 upstream.
I got these from running generic/475,
WARNING: CPU: 0 PID: 26384 at fs/btrfs/inode.c:3326 btrfs_orphan_commit_root+0x1ac/0x2b0 [btrfs] BUG: unable to handle kernel NULL pointer dereference at 0000000000000010 IP: btrfs_block_rsv_release+0x1c/0x70 [btrfs] Call Trace: btrfs_orphan_release_metadata+0x9f/0x200 [btrfs] btrfs_orphan_del+0x10d/0x170 [btrfs] btrfs_setattr+0x500/0x640 [btrfs] notify_change+0x7ae/0x870 do_truncate+0xca/0x130 vfs_truncate+0x2ee/0x3d0 do_sys_truncate+0xaf/0xf0 SyS_truncate+0xe/0x10 entry_SYSCALL_64_fastpath+0x1f/0x96
The race is between btrfs_orphan_commit_root and btrfs_orphan_del,
t1 t2btrfs_orphan_commit_root btrfs_orphan_del
spin_lock
check (&root->orphan_inodes)
root->orphan_block_rsv = NULL;
spin_unlock
atomic_dec(&root->orphan_inodes);
access root->orphan_block_rsvAccessing root->orphan_block_rsv must be done before decreasing root->orphan_inodes.
[bwh: Backported to 3.16: Drop the added comment in a path that's
unreachable here]
--- fs/btrfs/inode.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-)
fs/btrfs/inode.c +16 -13
@@ -3082,12 +3082,17 @@ int btrfs_orphan_add(struct btrfs_trans_if (insert >=1 ) { ret =btrfs_insert_orphan_item (trans, root,btrfs_ino (inode));if (ret) { -atomic_dec (&root->orphan_inodes);if (reserve) {clear_bit (BTRFS_INODE_ORPHAN_META_RESERVED , &BTRFS_I (inode)->runtime_flags);btrfs_orphan_release_metadata (inode); } +/* +* btrfs_orphan_commit_root may race with us and set +* ->orphan_block_rsv to zero, in order to avoid that, +* decrease ->orphan_inodes after everything is done. +*/ +atomic_dec (&root->orphan_inodes);if (ret != -EEXIST ) {clear_bit (BTRFS_INODE_HAS_ORPHAN_ITEM , &BTRFS_I (inode)->runtime_flags);
@@ -3119,28 +3124,26 @@ static int btrfs_orphan_del(struct btrfs {struct btrfs_root *root =BTRFS_I (inode)->root;int delete_item =0 ; -int release_rsv =0 ;int ret =0 ; -spin_lock (&root->orphan_lock);if (test_and_clear_bit (BTRFS_INODE_HAS_ORPHAN_ITEM , &BTRFS_I (inode)->runtime_flags)) delete_item =1 ; +if (delete_item && trans) + ret =btrfs_del_orphan_item (trans, root,btrfs_ino (inode)); +if (test_and_clear_bit (BTRFS_INODE_ORPHAN_META_RESERVED , &BTRFS_I (inode)->runtime_flags)) - release_rsv =1 ; -spin_unlock (&root->orphan_lock); +btrfs_orphan_release_metadata (inode); -if (delete_item) { +/* +* btrfs_orphan_commit_root may race with us and set ->orphan_block_rsv +* to zero, in order to avoid that, decrease ->orphan_inodes after +* everything is done. +*/ +if (delete_item)atomic_dec (&root->orphan_inodes); -if (trans) - ret =btrfs_del_orphan_item (trans, root, -btrfs_ino (inode)); - } - -if (release_rsv) -btrfs_orphan_release_metadata (inode);return ret; }
PATCH 190/410 btrfs: remove spurious WARN_ON(ref->count < 0) in find_parent_nodes
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Zygo Blaxell <[email protected]>
commit c8195a7b1ad5648857ce20ba24f384faed8512bc upstream.
Until v4.14, this warning was very infrequent:
WARNING: CPU: 3 PID: 18172 at fs/btrfs/backref.c:1391 find_parent_nodes+0xc41/0x14e0 Modules linked in: [...] CPU: 3 PID: 18172 Comm: bees Tainted: G D W L 4.11.9-zb64+ #1 Hardware name: System manufacturer System Product Name/M5A78L-M/USB3, BIOS 2101 12/02/2014 Call Trace: dump_stack+0x85/0xc2 __warn+0xd1/0xf0 warn_slowpath_null+0x1d/0x20 find_parent_nodes+0xc41/0x14e0 __btrfs_find_all_roots+0xad/0x120 ? extent_same_check_offsets+0x70/0x70 iterate_extent_inodes+0x168/0x300 iterate_inodes_from_logical+0x87/0xb0 ? iterate_inodes_from_logical+0x87/0xb0 ? extent_same_check_offsets+0x70/0x70 btrfs_ioctl+0x8ac/0x2820 ? lock_acquire+0xc2/0x200 do_vfs_ioctl+0x91/0x700 ? __fget+0x112/0x200 SyS_ioctl+0x79/0x90 entry_SYSCALL_64_fastpath+0x23/0xc6 ? trace_hardirqs_off_caller+0x1f/0x140
Starting with v4.14 (specifically 86d5f9944252 ("btrfs: convert prelimary reference tracking to use rbtrees")) the WARN_ON occurs three orders of magnitude more frequently--almost once per second while running workloads like bees.
Replace the WARN_ON() with a comment rationale for its removal. The rationale is paraphrased from an explanation by Edmund Nadolski <[email protected]> on the linux-btrfs mailing list.
--- fs/btrfs/backref.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/btrfs/backref.c +10 -1
@@ -979,7 +979,16 @@ again:while (!list_empty (&prefs)) { ref = list_first_entry(&prefs, struct __prelim_ref, list); -WARN_ON (ref->count <0 ); +/* +* ref->count < 0 can happen here if there are delayed +* refs with a node->action of BTRFS_DROP_DELAYED_REF. +* prelim_ref_insert() relies on this when merging +* identical refs to keep the overall count correct. +* prelim_ref_insert() will merge only those refs +* which compare identically. Any refs having +* e.g. different offsets would not be merged, +* and would retain their original ref->count < 0. +*/ if (roots && ref->count && ref->root_id && ref->parent ==0 ) {/* no parent == root of tree */ ret =ulist_add (roots, ref->root_id,0 ,GFP_NOFS );
PATCH 191/410 Input: mms114 - fix license module information
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Andi Shyti <[email protected]>
commit 498e7e7ed1fd72c275a682f0903c4a20cc538658 upstream.
The driver has been released with GNU Public License v2 as stated in the header, but the module license information has been tagged as "GPL" (GNU Public License v2 or later).
Fix the module license information so that it matches the one in the header as "GPL v2".
--- drivers/input/touchscreen/mms114.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/touchscreen/mms114.c +1 -1
@@ -592,4 +592,4 @@ module_i2c_driver(mms114_driver);/* Module information */ MODULE_AUTHOR ("Joonyoung Shim <[email protected]>" );MODULE_DESCRIPTION ("MELFAS mms114 Touchscreen driver" ); -MODULE_LICENSE ("GPL" ); +MODULE_LICENSE ("GPL v2" );
Re: [PATCH 3.16 191/410] Input: mms114 - fix license module information
Quoted 1 line · Ben Hutchings
3.16.57-rc1 review patch. If anyone has any objections, please let me know.
Not a hard objection, but rather a curiosity: for this to be pulled into stable what user issue does this fix?
Quoted 32 lines
------------------
From: Andi Shyti <[email protected]>
commit
498e7e7ed1fd72c275a682f0903c4a20cc538658upstream.The driver has been released with GNU Public License v2 as stated in the header, but the module license information has been tagged as "GPL" (GNU Public License v2 or later).
Fix the module license information so that it matches the one in the header as "GPL v2".
Fixes 07b8481d4aff ("Input: add MELFAS mms114 touchscreen driver")Reported-by Marcus Folkesson <[email protected]>Signed-off-by Andi Shyti <[email protected]>Signed-off-by Dmitry Torokhov <[email protected]>Signed-off-by Ben Hutchings <[email protected]>--- drivers/input/touchscreen/mms114.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/input/touchscreen/mms114.c +1
-1@@ -592,4 +592,4 @@ module_i2c_driver(mms114_driver);/* Module information */ MODULE_AUTHOR ("Joonyoung Shim <[email protected]>" );MODULE_DESCRIPTION ("MELFAS mms114 Touchscreen driver" ); -MODULE_LICENSE ("GPL" ); +MODULE_LICENSE ("GPL v2" );
Signature · 1 line
Dmitry
Re: [PATCH 3.16 191/410] Input: mms114 - fix license module information
Quoted 5 lines · Dmitry Torokhov
Quoted 1 line · Ben Hutchings
3.16.57-rc1 review patch. If anyone has any objections, please let me know.
Not a hard objection, but rather a curiosity: for this to be pulled into stable what user issue does this fix?
I start by selecting anything with a 'Cc: stable' or Fixes tag for a commit that's in the stable branch. If it applies cleanly I might not look far beyond that.
This commit doesn't really meet the stable kernel rules, but it's fixing documentation and is low risk so I'll keep it.
Ben.
Quoted 35 lines
Quoted 32 lines
------------------
From: Andi Shyti <[email protected]>
commit
498e7e7ed1fd72c275a682f0903c4a20cc538658upstream.The driver has been released with GNU Public License v2 as stated in the header, but the module license information has been tagged as "GPL" (GNU Public License v2 or later).
Fix the module license information so that it matches the one in the header as "GPL v2".
Fixes 07b8481d4aff ("Input: add MELFAS mms114 touchscreen driver")Reported-by Marcus Folkesson <[email protected]>Signed-off-by Andi Shyti <[email protected]>Signed-off-by Dmitry Torokhov <[email protected]>Signed-off-by Ben Hutchings <[email protected]>--- drivers/input/touchscreen/mms114.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/input/touchscreen/mms114.c +1
-1@@ -592,4 +592,4 @@ module_i2c_driver(mms114_driver);/* Module information */ MODULE_AUTHOR ("Joonyoung Shim <[email protected]>" );MODULE_DESCRIPTION ("MELFAS mms114 Touchscreen driver" ); -MODULE_LICENSE ("GPL" ); +MODULE_LICENSE ("GPL v2" );
Signature · 2 lines
Ben Hutchings When in doubt, use brute force. - Ken Thompson
PATCH 192/410 firmware: dmi_scan: Fix handling of empty DMI strings
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jean Delvare <[email protected]>
commit a7770ae194569e96a93c48aceb304edded9cc648 upstream.
The handling of empty DMI strings looks quite broken to me:
* Strings from 1 to 7 spaces are not considered empty.
* True empty DMI strings (string index set to 0) are not considered empty, and result in allocating a 0-char string.
* Strings with invalid index also result in allocating a 0-char string.
* Strings starting with 8 spaces are all considered empty, even if non-space characters follow (sounds like a weird thing to do, but I have actually seen occurrences of this in DMI tables before.)
* Strings which are considered empty are reported as 8 spaces, instead of being actually empty.
Some of these issues are the result of an off-by-one error in memcmp, the rest is incorrect by design.
So let's get it square: missing strings and strings made of only spaces, regardless of their length, should be treated as empty and no memory should be allocated for them. All other strings are non-empty and should be allocated.
--- drivers/firmware/dmi_scan.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
drivers/firmware/dmi_scan.c +9 -13
@@ -15,7 +15,7 @@* of and an antecedent to, SMBIOS, which stands for System * Management BIOS. See further: http://www.dmtf.org/standards */ -static const char dmi_empty_string[] =" " ; +static const char dmi_empty_string[] ="" ;static u16 __initdata dmi_ver;/*
@@ -36,25 +36,21 @@ static int dmi_memdev_nr;static const char *__init dmi_string_nosave (const struct dmi_header *dm,u8 s) {const u8 *bp = ((u8 *) dm) + dm->length; +const u8 *nsp;if (s) { - s--; -while (s >0 && *bp) { +while (--s >0 && *bp) bp +=strlen (bp) +1 ; - s--; - } -if (*bp !=0 ) { -size_t len =strlen (bp)+1 ; -size_t cmp_len = len >8 ?8 : len; - -if (!memcmp (bp, dmi_empty_string, cmp_len)) -return dmi_empty_string; +/* Strings containing only spaces are considered empty */ + nsp = bp; +while (*nsp ==' ' ) + nsp++; +if (*nsp !='\0' )return bp; - } } -return "" ; +return dmi_empty_string; }static const char *__init dmi_string (const struct dmi_header *dm,u8 s)
PATCH 193/410 MIPS: TXx9: use IS_BUILTIN() for CONFIG_LEDS_CLASS
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Matt Redfearn <[email protected]>
commit 0cde5b44a30f1daaef1c34e08191239dc63271c4 upstream.
When commit b27311e1cace ("MIPS: TXx9: Add RBTX4939 board support") added board support for the RBTX4939, it added a call to led_classdev_register even if the LED class is built as a module. Built-in arch code cannot call module code directly like this. Commit b33b44073734 ("MIPS: TXX9: use IS_ENABLED() macro") subsequently changed the inclusion of this code to a single check that CONFIG_LEDS_CLASS is either builtin or a module, but the same issue remains.
This leads to MIPS allmodconfig builds failing when CONFIG_MACH_TX49XX=y is set:
arch/mips/txx9/rbtx4939/setup.o: In function `rbtx4939_led_probe':
setup.c:(.init.text+0xc0): undefined reference to `of_led_classdev_register'
make: *** [Makefile:999: vmlinux] Error 1
Fix this by using the IS_BUILTIN() macro instead.
Patchwork: https://patchwork.linux-mips.org/patch/18544/
--- arch/mips/txx9/rbtx4939/setup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/mips/txx9/rbtx4939/setup.c +2 -2
@@ -186,7 +186,7 @@ static void __init rbtx4939_update_ioc_p#define RBTX4939_MAX_7SEGLEDS 8 -#if IS_ENABLED(CONFIG_LEDS_CLASS) +#if IS_BUILTIN(CONFIG_LEDS_CLASS) static u8 led_val[RBTX4939_MAX_7SEGLEDS]; struct rbtx4939_led_data { struct led_classdev cdev;
@@ -262,7 +262,7 @@ static inline void rbtx4939_led_setup(vostatic void __rbtx4939_7segled_putc (unsigned int pos,unsigned char val) { -#if IS_ENABLED (CONFIG_LEDS_CLASS ) +#if IS_BUILTIN (CONFIG_LEDS_CLASS )unsigned long flags;local_irq_save (flags);/* bit7: reserved for LED class */
PATCH 194/410 x86/xen: init %gs very early to avoid page faults with stack protector
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Juergen Gross <[email protected]>
commit 4f277295e54c5b7340e48efea3fc5cc21a2872b7 upstream.
When running as Xen pv guest %gs is initialized some time after C code is started. Depending on stack protector usage this might be too late, resulting in page faults.
So setup %gs and MSR_GS_BASE in assembly code already.
---
arch/x86/xen/xen-head.S +15 -0
@@ -8,7 +8,9 @@ #include <asm/boot.h> #include <asm/asm.h> +#include <asm/msr.h> #include <asm/page_types.h> +#include <asm/percpu.h> #include <xen/interface/elfnote.h> #include <xen/interface/features.h>
@@ -42,7 +44,20 @@ ENTRY(startup_xen) #else mov %rsi,xen_start_info mov $init_thread_union+THREAD_SIZE,%rsp + + /* Set up %gs. + * + * The base of %gs always points to the bottom of the irqstack + * union. If the stack protector canary is enabled, it is + * located at %gs:40. Note that, on SMP, the boot cpu uses + * init data section till per cpu areas are set up. + */ + movl $MSR_GS_BASE,%ecx + movq $INIT_PER_CPU_VAR(irq_stack_union),%rax + cdq + wrmsr #endif + jmp xen_start_kernel __FINIT
PATCH 195/410 arm: KVM: Fix SMCCC handling of unimplemented SMC/HVC calls
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
commit 20e8175d246e9f9deb377f2784b3e7dfb2ad3e86 upstream.
KVM doesn't follow the SMCCC when it comes to unimplemented calls, and inject an UNDEF instead of returning an error. Since firmware calls are now used for security mitigation, they are becoming more common, and the undef is counter productive.
Instead, let's follow the SMCCC which states that -1 must be returned to the caller when getting an unknown function number.
--- arch/arm/kvm/handle_exit.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
arch/arm/kvm/handle_exit.c +11 -2
@@ -45,7 +45,7 @@ static int handle_hvc(struct kvm_vcpu *v ret =kvm_psci_call (vcpu);if (ret <0 ) { -kvm_inject_undefined (vcpu); + *vcpu_reg (vcpu,0 ) = ~0UL ;return 1 ; }
@@ -54,7 +54,16 @@ static int handle_hvc(struct kvm_vcpu *vstatic int handle_smc (struct kvm_vcpu *vcpu,struct kvm_run *run) { -kvm_inject_undefined (vcpu); +/* +* "If an SMC instruction executed at Non-secure EL1 is +* trapped to EL2 because HCR_EL2.TSC is 1, the exception is a +* Trap exception, not a Secure Monitor Call exception [...]" +* +* We need to advance the PC after the trap, as it would +* otherwise return to the same address... +*/ + *vcpu_reg (vcpu,0 ) = ~0UL ; +kvm_skip_instr (vcpu,kvm_vcpu_trap_il_is32bit (vcpu));return 1 ; }
PATCH 196/410 arm64: KVM: Increment PC after handling an SMC trap
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
commit f5115e8869e1dfafac0e414b4f1664f3a84a4683 upstream.
When handling an SMC trap, the "preferred return address" is set to that of the SMC, and not the next PC (which is a departure from the behaviour of an SMC that isn't trapped).
Increment PC in the handler, as the guest is otherwise forever stuck...
--- arch/arm64/kvm/handle_exit.c | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm64/kvm/handle_exit.c +9 -0
@@ -43,7 +43,16 @@ static int handle_hvc(struct kvm_vcpu *vstatic int handle_smc (struct kvm_vcpu *vcpu,struct kvm_run *run) { +/* +* "If an SMC instruction executed at Non-secure EL1 is +* trapped to EL2 because HCR_EL2.TSC is 1, the exception is a +* Trap exception, not a Secure Monitor Call exception [...]" +* +* We need to advance the PC after the trap, as it would +* otherwise return to the same address... +*/ *vcpu_reg (vcpu,0 ) = ~0UL ; +kvm_skip_instr (vcpu,kvm_vcpu_trap_il_is32bit (vcpu));return 1 ; }
PATCH 197/410 netfilter: xt_RATEEST: acquire xt_rateest_mutex for hash insert
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Cong Wang <[email protected]>
commit 7dc68e98757a8eccf8ca7a53a29b896f1eef1f76 upstream.
rateest_hash is supposed to be protected by xt_rateest_mutex, and, as suggested by Eric, lookup and insert should be atomic, so we should acquire the xt_rateest_mutex once for both.
So introduce a non-locking helper for internal use and keep the locking one for external.
--- net/netfilter/xt_RATEEST.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
net/netfilter/xt_RATEEST.c +17 -5
@@ -40,23 +40,31 @@ static void xt_rateest_hash_insert(struchlist_add_head (&est->list, &rateest_hash[h]); } -struct xt_rateest *xt_rateest_lookup (const char *name) +static struct xt_rateest *__xt_rateest_lookup (const char *name) {struct xt_rateest *est;unsigned int h; h =xt_rateest_hash (name); -mutex_lock (&xt_rateest_mutex);hlist_for_each_entry (est, &rateest_hash[h], list) {if (strcmp (est->name, name) ==0 ) { est->refcnt++; -mutex_unlock (&xt_rateest_mutex);return est; } } -mutex_unlock (&xt_rateest_mutex); +return NULL ; } + +struct xt_rateest *xt_rateest_lookup (const char *name) +{ +struct xt_rateest *est; + +mutex_lock (&xt_rateest_mutex); + est =__xt_rateest_lookup (name); +mutex_unlock (&xt_rateest_mutex); +return est; +}EXPORT_SYMBOL_GPL (xt_rateest_lookup);void xt_rateest_put (struct xt_rateest *est)
@@ -104,8 +112,10 @@ static int xt_rateest_tg_checkentry(cons rnd_inited = true; } - est =xt_rateest_lookup (info->name); +mutex_lock (&xt_rateest_mutex); + est =__xt_rateest_lookup (info->name);if (est) { +mutex_unlock (&xt_rateest_mutex);/* * If estimator parameters are specified, they must match the * existing estimator.
@@ -143,11 +153,13 @@ static int xt_rateest_tg_checkentry(cons info->est = est;xt_rateest_hash_insert (est); +mutex_unlock (&xt_rateest_mutex);return 0 ; err2:kfree (est); err1: +mutex_unlock (&xt_rateest_mutex);return ret; }
PATCH 198/410 kernel/async.c: revert "async: simplify lowest_in_progress()"
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Rasmus Villemoes <[email protected]>
commit 4f7e988e63e336827f4150de48163bed05d653bd upstream.
This reverts commit 92266d6ef60c ("async: simplify lowest_in_progress()") which was simply wrong: In the case where domain is NULL, we now use the wrong offsetof() in the list_first_entry macro, so we don't actually fetch the ->cookie value, but rather the eight bytes located sizeof(struct list_head) further into the struct async_entry.
On 64 bit, that's the data member, while on 32 bit, that's a u64 built from func and data in some order.
I think the bug happens to be harmless in practice: It obviously only affects callers which pass a NULL domain, and AFAICT the only such caller is
async_synchronize_full() -> async_synchronize_full_domain(NULL) -> async_synchronize_cookie_domain(ASYNC_COOKIE_MAX, NULL)
and the ASYNC_COOKIE_MAX means that in practice we end up waiting for the async_global_pending list to be empty - but it would break if somebody happened to pass (void*)-1 as the data element to async_schedule, and of course also if somebody ever does a async_synchronize_cookie_domain(, NULL) with a "finite" cookie value.
Maybe the "harmless in practice" means this isn't -stable material. But I'm not completely confident my quick git grep'ing is enough, and there might be affected code in one of the earlier kernels that has since been removed, so I'll leave the decision to the stable guys.
--- kernel/async.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
kernel/async.c +12 -8
@@ -84,20 +84,24 @@ static atomic_t entry_count;static async_cookie_t lowest_in_progress (struct async_domain *domain) { -struct list_head *pending; +struct async_entry *first =NULL ;async_cookie_t ret =ASYNC_COOKIE_MAX ;unsigned long flags;spin_lock_irqsave (&async_lock, flags); -if (domain) - pending = &domain->pending; -else - pending = &async_global_pending; +if (domain) { +if (!list_empty (&domain->pending)) + first =list_first_entry (&domain->pending, + struct async_entry, domain_list); + }else { +if (!list_empty (&async_global_pending)) + first =list_first_entry (&async_global_pending, + struct async_entry, global_list); + } -if (!list_empty (pending)) - ret = list_first_entry(pending, struct async_entry, - domain_list)->cookie; +if (first) + ret = first->cookie;spin_unlock_irqrestore (&async_lock, flags);return ret;
PATCH 199/410 pipe: relocate round_pipe_size() above pipe_set_size()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael Kerrisk (man-pages)" <[email protected]>
commit f491bd71118beba608d39ac2d5f1530e1160cd2e upstream.
Patch series "pipe: fix limit handling", v2.
When changing a pipe's capacity with fcntl(F_SETPIPE_SZ), various limits defined by /proc/sys/fs/pipe-* files are checked to see if unprivileged users are exceeding limits on memory consumption.
While documenting and testing the operation of these limits I noticed that, as currently implemented, these checks have a number of problems:
(1) When increasing the pipe capacity, the checks against the limits in /proc/sys/fs/pipe-user-pages-{soft,hard} are made against existing consumption, and exclude the memory required for the increased pipe capacity. The new increase in pipe capacity can then push the total memory used by the user for pipes (possibly far) over a limit. This can also trigger the problem described next.
(2) The limit checks are performed even when the new pipe capacity is less than the existing pipe capacity. This can lead to problems if a user sets a large pipe capacity, and then the limits are lowered, with the result that the user will no longer be able to decrease the pipe capacity.
(3) As currently implemented, accounting and checking against the limits is done as follows:
(a) Test whether the user has exceeded the limit.
(b) Make new pipe buffer allocation.
(c) Account new allocation against the limits.
This is racey. Multiple processes may pass point (a) simultaneously, and then allocate pipe buffers that are accounted for only in step (c). The race means that the user's pipe buffer allocation could be pushed over the limit (by an arbitrary amount, depending on how unlucky we were in the race). [Thanks to Vegard Nossum for spotting this point, which I had missed.]
This patch series addresses these three problems.
This patch (of 8):
This is a minor preparatory patch. After subsequent patches, round_pipe_size() will be called from pipe_set_size(), so place round_pipe_size() above pipe_set_size().
--- fs/pipe.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
fs/pipe.c +12 -12
@@ -994,6 +994,18 @@ const struct file_operations pipefifo_fo };/* +* Currently we rely on the pipe array holding a power-of-2 number +* of pages. +*/ +static inline unsigned int round_pipe_size (unsigned int size) +{ +unsigned long nr_pages; + + nr_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; +return roundup_pow_of_two (nr_pages) <<PAGE_SHIFT ; +} + +/* * Allocate a new array of pipe buffers and copy the info over. Returns the * pipe size if successful, or return -ERROR on error. */
@@ -1044,18 +1056,6 @@ static long pipe_set_size(struct pipe_in }/* -* Currently we rely on the pipe array holding a power-of-2 number -* of pages. -*/ -static inline unsigned int round_pipe_size (unsigned int size) -{ -unsigned long nr_pages; - - nr_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; -return roundup_pow_of_two (nr_pages) <<PAGE_SHIFT ; -} - -/* * This should work even if CONFIG_PROC_FS isn't set, as proc_dointvec_minmax * will return an error. */
PATCH 200/410 pipe: move limit checking logic into pipe_set_size()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael Kerrisk (man-pages)" <[email protected]>
commit d37d41666408102bf0ac8e48d8efdce7b809e5f6 upstream.
This is a preparatory patch for following work. Move the F_SETPIPE_SZ limit-checking logic from pipe_fcntl() into pipe_set_size(). This simplifies the code a little, and allows for reworking required in a later patch that fixes the limit checking in pipe_set_size()
--- fs/pipe.c | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-)
fs/pipe.c +18 -23
@@ -1009,9 +1009,24 @@ static inline unsigned int round_pipe_si* Allocate a new array of pipe buffers and copy the info over. Returns the * pipe size if successful, or return -ERROR on error. */ -static long pipe_set_size (struct pipe_inode_info *pipe,unsigned long nr_pages) +static long pipe_set_size (struct pipe_inode_info *pipe,unsigned long arg) {struct pipe_buffer *bufs; +unsigned int size, nr_pages; + + size =round_pipe_size (arg); + nr_pages = size >>PAGE_SHIFT ; + +if (!nr_pages) +return -EINVAL ; + +if (!capable (CAP_SYS_RESOURCE ) && size > pipe_max_size) +return -EPERM ; + +if ((too_many_pipe_buffers_hard (pipe->user) || +too_many_pipe_buffers_soft (pipe->user)) && + !capable (CAP_SYS_RESOURCE ) && !capable (CAP_SYS_ADMIN )) +return -EPERM ;/* * We can shrink the pipe, if arg >= pipe->nrbufs. Since we don't
@@ -1094,28 +1109,9 @@ long pipe_fcntl(struct file *file, unsig__pipe_lock (pipe);switch (cmd) { -case F_SETPIPE_SZ : { -unsigned int size, nr_pages; - - size =round_pipe_size (arg); - nr_pages = size >>PAGE_SHIFT ; - - ret = -EINVAL ; -if (!nr_pages) - goto out; - -if (!capable (CAP_SYS_RESOURCE ) && size > pipe_max_size) { - ret = -EPERM ; - goto out; - }else if ((too_many_pipe_buffers_hard (pipe->user) || -too_many_pipe_buffers_soft (pipe->user)) && - !capable (CAP_SYS_RESOURCE ) && !capable (CAP_SYS_ADMIN )) { - ret = -EPERM ; - goto out; - } - ret =pipe_set_size (pipe, nr_pages); +case F_SETPIPE_SZ : + ret =pipe_set_size (pipe, arg);break ; - }case F_GETPIPE_SZ : ret = pipe->buffers *PAGE_SIZE ;break ;
@@ -1124,7 +1120,6 @@ long pipe_fcntl(struct file *file, unsigbreak ; } -out:__pipe_unlock (pipe);return ret; }
PATCH 201/410 pipe: refactor argument for account_pipe_buffers()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael Kerrisk (man-pages)" <[email protected]>
commit 3734a13b96ebf039b293d8d37a934fd1bd9e03ab upstream.
This is a preparatory patch for following work. account_pipe_buffers() performs accounting in the 'user_struct'. There is no need to pass a pointer to a 'pipe_inode_info' struct (which is then dereferenced to obtain a pointer to the 'user' field). Instead, pass a pointer directly to the 'user_struct'. This change is needed in preparation for a subsequent patch that the fixes the limit checking in alloc_pipe_info() (and the resulting code is a little more logical).
--- fs/pipe.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/pipe.c +5 -5
@@ -590,10 +590,10 @@ pipe_fasync(int fd, struct file *filp, ireturn retval; } -static void account_pipe_buffers (struct pipe_inode_info *pipe, +static void account_pipe_buffers (struct user_struct *user,unsigned long old,unsigned long new) { -atomic_long_add (new - old, &pipe->user->pipe_bufs); +atomic_long_add (new - old, &user->pipe_bufs); }static bool too_many_pipe_buffers_soft (struct user_struct *user)
@@ -628,7 +628,7 @@ struct pipe_inode_info *alloc_pipe_info( pipe->r_counter = pipe->w_counter =1 ; pipe->buffers = pipe_bufs; pipe->user = user; -account_pipe_buffers (pipe,0 , pipe_bufs); +account_pipe_buffers (user,0 , pipe_bufs);mutex_init (&pipe->mutex);return pipe; }
@@ -643,7 +643,7 @@ void free_pipe_info(struct pipe_inode_in {int i; -account_pipe_buffers (pipe, pipe->buffers,0 ); +account_pipe_buffers (pipe->user, pipe->buffers,0 );free_uid (pipe->user);for (i =0 ; i < pipe->buffers; i++) {struct pipe_buffer *buf = pipe->bufs + i;
@@ -1062,7 +1062,7 @@ static long pipe_set_size(struct pipe_inmemcpy (bufs + head, pipe->bufs, tail *sizeof (struct pipe_buffer )); } -account_pipe_buffers (pipe, pipe->buffers, nr_pages); +account_pipe_buffers (pipe->user, pipe->buffers, nr_pages); pipe->curbuf =0 ;kfree (pipe->bufs); pipe->bufs = bufs;
PATCH 202/410 pipe: fix limit checking in pipe_set_size()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael Kerrisk (man-pages)" <[email protected]>
commit b0b91d18e2e97b741b294af9333824ecc3fadfd8 upstream.
The limit checking in pipe_set_size() (used by fcntl(F_SETPIPE_SZ)) has the following problems:
(1) When increasing the pipe capacity, the checks against the limits in /proc/sys/fs/pipe-user-pages-{soft,hard} are made against existing consumption, and exclude the memory required for the increased pipe capacity. The new increase in pipe capacity can then push the total memory used by the user for pipes (possibly far) over a limit. This can also trigger the problem described next.
(2) The limit checks are performed even when the new pipe capacity is less than the existing pipe capacity. This can lead to problems if a user sets a large pipe capacity, and then the limits are lowered, with the result that the user will no longer be able to decrease the pipe capacity.
(3) As currently implemented, accounting and checking against the limits is done as follows:
(a) Test whether the user has exceeded the limit.
(b) Make new pipe buffer allocation.
(c) Account new allocation against the limits.
This is racey. Multiple processes may pass point (a) simultaneously, and then allocate pipe buffers that are accounted for only in step (c). The race means that the user's pipe buffer allocation could be pushed over the limit (by an arbitrary amount, depending on how unlucky we were in the race). [Thanks to Vegard Nossum for spotting this point, which I had missed.]
This patch addresses the above problems as follows:
* Perform checks against the limits only when increasing a pipe's capacity; an unprivileged user can always decrease a pipe's capacity.
* Alter the checks against limits to include the memory required for the new pipe capacity.
* Re-order the accounting step so that it precedes the buffer allocation. If the accounting step determines that a limit has been reached, revert the accounting and cause the operation to fail.
The program below can be used to demonstrate problems 1 and 2, and the effect of the fix. The program takes one or more command-line arguments. The first argument specifies the number of pipes that the program should create. The remaining arguments are, alternately, pipe capacities that should be set using fcntl(F_SETPIPE_SZ), and sleep intervals (in seconds) between the fcntl() operations. (The sleep intervals allow the possibility to change the limits between fcntl() operations.)
Problem 1
=========
Using the test program on an unpatched kernel, we first set some limits:
# echo 0 > /proc/sys/fs/pipe-user-pages-soft
# echo 1000000000 > /proc/sys/fs/pipe-max-size
# echo 10000 > /proc/sys/fs/pipe-user-pages-hard # 40.96 MBThen show that we can set a pipe with capacity (100MB) that is over the hard limit
# sudo -u mtk ./test_F_SETPIPE_SZ 1 100000000
Initial pipe capacity: 65536
Loop 1: set pipe capacity to 100000000 bytes
F_SETPIPE_SZ returned 134217728Now set the capacity to 100MB twice. The second call fails (which is probably surprising to most users, since it seems like a no-op):
# sudo -u mtk ./test_F_SETPIPE_SZ 1 100000000 0 100000000
Initial pipe capacity: 65536
Loop 1: set pipe capacity to 100000000 bytes
F_SETPIPE_SZ returned 134217728
Loop 2: set pipe capacity to 100000000 bytes
Loop 2, pipe 0: F_SETPIPE_SZ failed: fcntl: Operation not permittedWith a patched kernel, setting a capacity over the limit fails at the first attempt:
# echo 0 > /proc/sys/fs/pipe-user-pages-soft
# echo 1000000000 > /proc/sys/fs/pipe-max-size
# echo 10000 > /proc/sys/fs/pipe-user-pages-hard
# sudo -u mtk ./test_F_SETPIPE_SZ 1 100000000
Initial pipe capacity: 65536
Loop 1: set pipe capacity to 100000000 bytes
Loop 1, pipe 0: F_SETPIPE_SZ failed: fcntl: Operation not permittedThere is a small chance that the change to fix this problem could break user-space, since there are cases where fcntl(F_SETPIPE_SZ) calls that previously succeeded might fail. However, the chances are small, since (a) the pipe-user-pages-{soft,hard} limits are new (in 4.5), and the default soft/hard limits are high/unlimited. Therefore, it seems warranted to make these limits operate more precisely (and behave more like what users probably expect).
Problem 2
=========
Running the test program on an unpatched kernel, we first set some limits:
# getconf PAGESIZE
4096
# echo 0 > /proc/sys/fs/pipe-user-pages-soft
# echo 1000000000 > /proc/sys/fs/pipe-max-size
# echo 10000 > /proc/sys/fs/pipe-user-pages-hard # 40.96 MBNow perform two fcntl(F_SETPIPE_SZ) operations on a single pipe, first setting a pipe capacity (10MB), sleeping for a few seconds, during which time the hard limit is lowered, and then set pipe capacity to a smaller amount (5MB):
# sudo -u mtk ./test_F_SETPIPE_SZ 1 10000000 15 5000000 &
[1] 748
# Initial pipe capacity: 65536
Loop 1: set pipe capacity to 10000000 bytes
F_SETPIPE_SZ returned 16777216
Sleeping 15 seconds # echo 1000 > /proc/sys/fs/pipe-user-pages-hard # 4.096 MB
# Loop 2: set pipe capacity to 5000000 bytes
Loop 2, pipe 0: F_SETPIPE_SZ failed: fcntl: Operation not permittedIn this case, the user should be able to lower the limit.
With a kernel that has the patch below, the second fcntl() succeeds:
# echo 0 > /proc/sys/fs/pipe-user-pages-soft
# echo 1000000000 > /proc/sys/fs/pipe-max-size
# echo 10000 > /proc/sys/fs/pipe-user-pages-hard
# sudo -u mtk ./test_F_SETPIPE_SZ 1 10000000 15 5000000 &
[1] 3215
# Initial pipe capacity: 65536
# Loop 1: set pipe capacity to 10000000 bytes
F_SETPIPE_SZ returned 16777216
Sleeping 15 seconds# echo 1000 > /proc/sys/fs/pipe-user-pages-hard
# Loop 2: set pipe capacity to 5000000 bytes
F_SETPIPE_SZ returned 8388608
8x---8x---8x---8x---8x---8x---8x---8x---8x---8x---8x---8x---8x---8x---
/* test_F_SETPIPE_SZ.c
(C) 2016, Michael Kerrisk; licensed under GNU GPL version 2 or later
Test operation of fcntl(F_SETPIPE_SZ) for setting pipe capacity and interactions with limits defined by /proc/sys/fs/pipe-* files.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
intmain(int argc, char *argv[])
{
int (*pfd)[2];
int npipes;
int pcap, rcap;
int j, p, s, stime, loop;
if (argc < 2) {
fprintf(stderr, "Usage: %s num-pipes "
"[pipe-capacity sleep-time]...\n", argv[0]);
exit(EXIT_FAILURE);
}
npipes = atoi(argv[1]);
pfd = calloc(npipes, sizeof (int [2]));
if (pfd == NULL) {
perror("calloc");
exit(EXIT_FAILURE);
}
for (j = 0; j < npipes; j++) {
if (pipe(pfd[j]) == -1) {
fprintf(stderr, "Loop %d: pipe() failed: ", j);
perror("pipe");
exit(EXIT_FAILURE);
}
}
printf("Initial pipe capacity: %d\n", fcntl(pfd[0][0], F_GETPIPE_SZ));
for (j = 2; j < argc; j += 2 ) {
loop = j / 2;
pcap = atoi(argv[j]);
printf(" Loop %d: set pipe capacity to %d bytes\n", loop, pcap);
for (p = 0; p < npipes; p++) {
s = fcntl(pfd[p][0], F_SETPIPE_SZ, pcap);
if (s == -1) {
fprintf(stderr, " Loop %d, pipe %d: F_SETPIPE_SZ "
"failed: ", loop, p);
perror("fcntl");
exit(EXIT_FAILURE);
}
if (p == 0) {
printf(" F_SETPIPE_SZ returned %d\n", s);
rcap = s;
} else {
if (s != rcap) {
fprintf(stderr, " Loop %d, pipe %d: F_SETPIPE_SZ "
"unexpected return: %d\n", loop, p, s);
exit(EXIT_FAILURE);
}
}
stime = (j + 1 < argc) ? atoi(argv[j + 1]) : 0;
if (stime > 0) {
printf(" Sleeping %d seconds\n", stime);
sleep(stime);
}
}
}
exit(EXIT_SUCCESS);
}8x---8x---8x---8x---8x---8x---8x---8x---8x---8x---8x---8x---8x---8x---
Patch history:
v2
* Switch order of test in 'if' statement to avoid function call (to capability()) in normal path. [This is a fix to a preexisting wart in the code. Thanks to Willy Tarreau]
* Perform (size > pipe_max_size) check before calling account_pipe_buffers(). [Thanks to Vegard Nossum] Quoting Vegard:
The potential problem happens if the user passes a very large number which will overflow pipe->user->pipe_bufs.
On 32-bit, sizeof(int) == sizeof(long), so if they pass arg = INT_MAX then round_pipe_size() returns INT_MAX. Although it's true that the accounting is done in terms of pages and not bytes, so you'd need on the order of (1 << 13) = 8192 processes hitting the limit at the same time in order to make it overflow, which seems a bit unlikely.
(See https://lkml.org/lkml/2016/8/12/215 for another discussion on the limit checking)
--- fs/pipe.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-)
fs/pipe.c +31 -10
@@ -1013,6 +1013,7 @@ static long pipe_set_size(struct pipe_in {struct pipe_buffer *bufs;unsigned int size, nr_pages; +long ret =0 ; size =round_pipe_size (arg); nr_pages = size >>PAGE_SHIFT ;
@@ -1020,13 +1021,26 @@ static long pipe_set_size(struct pipe_inif (!nr_pages)return -EINVAL ; -if (!capable (CAP_SYS_RESOURCE ) && size > pipe_max_size) +/* +* If trying to increase the pipe capacity, check that an +* unprivileged user is not trying to exceed various limits +* (soft limit check here, hard limit check just below). +* Decreasing the pipe capacity is always permitted, even +* if the user is currently over a limit. +*/ +if (nr_pages > pipe->buffers && + size > pipe_max_size && !capable (CAP_SYS_RESOURCE ))return -EPERM ; -if ((too_many_pipe_buffers_hard (pipe->user) || -too_many_pipe_buffers_soft (pipe->user)) && - !capable (CAP_SYS_RESOURCE ) && !capable (CAP_SYS_ADMIN )) -return -EPERM ; +account_pipe_buffers (pipe->user, pipe->buffers, nr_pages); + +if (nr_pages > pipe->buffers && + (too_many_pipe_buffers_hard (pipe->user) || +too_many_pipe_buffers_soft (pipe->user)) && + !capable (CAP_SYS_RESOURCE ) && !capable (CAP_SYS_ADMIN )) { + ret = -EPERM ; + goto out_revert_acct; + }/* * We can shrink the pipe, if arg >= pipe->nrbufs. Since we don't
@@ -1034,12 +1048,16 @@ static long pipe_set_size(struct pipe_in* again like we would do for growing. If the pipe currently * contains more buffers than arg, then return busy. */ -if (nr_pages < pipe->nrbufs) -return -EBUSY ; +if (nr_pages < pipe->nrbufs) { + ret = -EBUSY ; + goto out_revert_acct; + } bufs =kcalloc (nr_pages,sizeof (*bufs),GFP_KERNEL | __GFP_NOWARN); -if (unlikely (!bufs)) -return -ENOMEM ; +if (unlikely (!bufs)) { + ret = -ENOMEM ; + goto out_revert_acct; + }/* * The pipe array wraps around, so just start the new one at zero
@@ -1062,12 +1080,15 @@ static long pipe_set_size(struct pipe_inmemcpy (bufs + head, pipe->bufs, tail *sizeof (struct pipe_buffer )); } -account_pipe_buffers (pipe->user, pipe->buffers, nr_pages); pipe->curbuf =0 ;kfree (pipe->bufs); pipe->bufs = bufs; pipe->buffers = nr_pages;return nr_pages *PAGE_SIZE ; + +out_revert_acct: +account_pipe_buffers (pipe->user, nr_pages, pipe->buffers); +return ret; }/*
PATCH 203/410 pipe: simplify logic in alloc_pipe_info()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael Kerrisk (man-pages)" <[email protected]>
commit 09b4d1990094dd22c27fb0163534db419458569c upstream.
Replace an 'if' block that covers most of the code in this function with a 'goto'. This makes the code a little simpler to read, and also simplifies the next patch (fix limit checking in alloc_pipe_info())
[bwh: Backported to 3.16:
- Don't use GFP_KERNEL_ACCOUNT
- Adjust context]
---
fs/pipe.c +22 -19
@@ -611,31 +611,34 @@ static bool too_many_pipe_buffers_hard(sstruct pipe_inode_info *alloc_pipe_info (void ) {struct pipe_inode_info *pipe; +unsigned long pipe_bufs =PIPE_DEF_BUFFERS ; +struct user_struct *user =get_current_user (); pipe =kzalloc (sizeof (struct pipe_inode_info ),GFP_KERNEL ); -if (pipe) { -unsigned long pipe_bufs =PIPE_DEF_BUFFERS ; -struct user_struct *user =get_current_user (); +if (pipe ==NULL ) + goto out_free_uid; -if (!too_many_pipe_buffers_hard (user)) { -if (too_many_pipe_buffers_soft (user)) - pipe_bufs =1 ; - pipe->bufs =kzalloc (sizeof (struct pipe_buffer ) * pipe_bufs,GFP_KERNEL ); - } +if (!too_many_pipe_buffers_hard (user)) { +if (too_many_pipe_buffers_soft (user)) + pipe_bufs =1 ; + pipe->bufs =kcalloc (pipe_bufs, +sizeof (struct pipe_buffer ), +GFP_KERNEL ); + } -if (pipe->bufs) { -init_waitqueue_head (&pipe->wait); - pipe->r_counter = pipe->w_counter =1 ; - pipe->buffers = pipe_bufs; - pipe->user = user; -account_pipe_buffers (user,0 , pipe_bufs); -mutex_init (&pipe->mutex); -return pipe; - } -free_uid (user); -kfree (pipe); +if (pipe->bufs) { +init_waitqueue_head (&pipe->wait); + pipe->r_counter = pipe->w_counter =1 ; + pipe->buffers = pipe_bufs; + pipe->user = user; +account_pipe_buffers (user,0 , pipe_bufs); +mutex_init (&pipe->mutex); +return pipe; } +kfree (pipe); +out_free_uid: +free_uid (user);return NULL ; }
PATCH 204/410 pipe: fix limit checking in alloc_pipe_info()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael Kerrisk (man-pages)" <[email protected]>
commit a005ca0e6813e1d796a7422a7e31d8b8d6555df1 upstream.
The limit checking in alloc_pipe_info() (used by pipe(2) and when opening a FIFO) has the following problems:
(1) When checking capacity required for the new pipe, the checks against the limit in /proc/sys/fs/pipe-user-pages-{soft,hard} are made against existing consumption, and exclude the memory required for the new pipe capacity. As a consequence: (1) the memory allocation throttling provided by the soft limit does not kick in quite as early as it should, and (2) the user can overrun the hard limit.
(2) As currently implemented, accounting and checking against the limits is done as follows:
(a) Test whether the user has exceeded the limit.
(b) Make new pipe buffer allocation.
(c) Account new allocation against the limits.
This is racey. Multiple processes may pass point (a) simultaneously, and then allocate pipe buffers that are accounted for only in step (c). The race means that the user's pipe buffer allocation could be pushed over the limit (by an arbitrary amount, depending on how unlucky we were in the race). [Thanks to Vegard Nossum for spotting this point, which I had missed.]
This patch addresses the above problems as follows:
* Alter the checks against limits to include the memory required for the new pipe.
* Re-order the accounting step so that it precedes the buffer allocation. If the accounting step determines that a limit has been reached, revert the accounting and cause the operation to fail.
--- fs/pipe.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
fs/pipe.c +13 -7
@@ -618,24 +618,30 @@ struct pipe_inode_info *alloc_pipe_info(if (pipe ==NULL ) goto out_free_uid; -if (!too_many_pipe_buffers_hard (user)) { -if (too_many_pipe_buffers_soft (user)) - pipe_bufs =1 ; - pipe->bufs =kcalloc (pipe_bufs, -sizeof (struct pipe_buffer ), -GFP_KERNEL ); +account_pipe_buffers (user,0 , pipe_bufs); + +if (too_many_pipe_buffers_soft (user)) { +account_pipe_buffers (user, pipe_bufs,1 ); + pipe_bufs =1 ; } +if (too_many_pipe_buffers_hard (user)) + goto out_revert_acct; + + pipe->bufs =kcalloc (pipe_bufs,sizeof (struct pipe_buffer ), +GFP_KERNEL ); +if (pipe->bufs) {init_waitqueue_head (&pipe->wait); pipe->r_counter = pipe->w_counter =1 ; pipe->buffers = pipe_bufs; pipe->user = user; -account_pipe_buffers (user,0 , pipe_bufs);mutex_init (&pipe->mutex);return pipe; } +out_revert_acct: +account_pipe_buffers (user, pipe_bufs,0 );kfree (pipe); out_free_uid:free_uid (user);
PATCH 205/410 pipe: make account_pipe_buffers() return a value, and use it
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael Kerrisk (man-pages)" <[email protected]>
commit 9c87bcf0a31b338dc8a69a5d251a037565a94e13 upstream.
This is an optional patch, to provide a small performance improvement. Alter account_pipe_buffers() so that it returns the new value in user->pipe_bufs. This means that we can refactor too_many_pipe_buffers_soft() and too_many_pipe_buffers_hard() to avoid the costs of repeated use of atomic_long_read() to get the value user->pipe_bufs.
--- fs/pipe.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
fs/pipe.c +18 -18
@@ -590,22 +590,20 @@ pipe_fasync(int fd, struct file *filp, ireturn retval; } -static void account_pipe_buffers (struct user_struct *user, +static unsigned long account_pipe_buffers (struct user_struct *user,unsigned long old,unsigned long new) { -atomic_long_add (new - old, &user->pipe_bufs); +return atomic_long_add_return (new - old, &user->pipe_bufs); } -static bool too_many_pipe_buffers_soft (struct user_struct *user) +static bool too_many_pipe_buffers_soft (unsigned long user_bufs) { -return pipe_user_pages_soft && -atomic_long_read (&user->pipe_bufs) >= pipe_user_pages_soft; +return pipe_user_pages_soft && user_bufs >= pipe_user_pages_soft; } -static bool too_many_pipe_buffers_hard (struct user_struct *user) +static bool too_many_pipe_buffers_hard (unsigned long user_bufs) { -return pipe_user_pages_hard && -atomic_long_read (&user->pipe_bufs) >= pipe_user_pages_hard; +return pipe_user_pages_hard && user_bufs >= pipe_user_pages_hard; }struct pipe_inode_info *alloc_pipe_info (void )
@@ -613,19 +611,20 @@ struct pipe_inode_info *alloc_pipe_info(struct pipe_inode_info *pipe;unsigned long pipe_bufs =PIPE_DEF_BUFFERS ;struct user_struct *user =get_current_user (); +unsigned long user_bufs; pipe =kzalloc (sizeof (struct pipe_inode_info ),GFP_KERNEL );if (pipe ==NULL ) goto out_free_uid; -account_pipe_buffers (user,0 , pipe_bufs); + user_bufs =account_pipe_buffers (user,0 , pipe_bufs); -if (too_many_pipe_buffers_soft (user)) { -account_pipe_buffers (user, pipe_bufs,1 ); +if (too_many_pipe_buffers_soft (user_bufs)) { + user_bufs =account_pipe_buffers (user, pipe_bufs,1 ); pipe_bufs =1 ; } -if (too_many_pipe_buffers_hard (user)) +if (too_many_pipe_buffers_hard (user_bufs)) goto out_revert_acct; pipe->bufs = kcalloc(pipe_bufs, sizeof(struct pipe_buffer),
@@ -641,7 +640,7 @@ struct pipe_inode_info *alloc_pipe_info( } out_revert_acct: -account_pipe_buffers (user, pipe_bufs,0 ); + (void )account_pipe_buffers (user, pipe_bufs,0 );kfree (pipe); out_free_uid:free_uid (user);
@@ -652,7 +651,7 @@ void free_pipe_info(struct pipe_inode_in {int i; -account_pipe_buffers (pipe->user, pipe->buffers,0 ); + (void )account_pipe_buffers (pipe->user, pipe->buffers,0 );free_uid (pipe->user);for (i =0 ; i < pipe->buffers; i++) {struct pipe_buffer *buf = pipe->bufs + i;
@@ -1022,6 +1021,7 @@ static long pipe_set_size(struct pipe_in {struct pipe_buffer *bufs;unsigned int size, nr_pages; +unsigned long user_bufs;long ret =0 ; size =round_pipe_size (arg);
@@ -1041,11 +1041,11 @@ static long pipe_set_size(struct pipe_in size > pipe_max_size && !capable(CAP_SYS_RESOURCE))return -EPERM ; -account_pipe_buffers (pipe->user, pipe->buffers, nr_pages); + user_bufs =account_pipe_buffers (pipe->user, pipe->buffers, nr_pages);if (nr_pages > pipe->buffers && - (too_many_pipe_buffers_hard (pipe->user) || -too_many_pipe_buffers_soft (pipe->user)) && + (too_many_pipe_buffers_hard (user_bufs) || +too_many_pipe_buffers_soft (user_bufs)) && !capable (CAP_SYS_RESOURCE ) && !capable (CAP_SYS_ADMIN )) { ret = -EPERM ; goto out_revert_acct;
@@ -1096,7 +1096,7 @@ static long pipe_set_size(struct pipe_inreturn nr_pages *PAGE_SIZE ; out_revert_acct: -account_pipe_buffers (pipe->user, nr_pages, pipe->buffers); + (void )account_pipe_buffers (pipe->user, nr_pages, pipe->buffers);return ret; }
PATCH 206/410 pipe: cap initial pipe capacity according to pipe-max-size limit
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael Kerrisk (man-pages)" <[email protected]>
commit 086e774a57fba4695f14383c0818994c0b31da7c upstream.
This is a patch that provides behavior that is more consistent, and probably less surprising to users. I consider the change optional, and welcome opinions about whether it should be applied.
By default, pipes are created with a capacity of 64 kiB. However, /proc/sys/fs/pipe-max-size may be set smaller than this value. In this scenario, an unprivileged user could thus create a pipe whose initial capacity exceeds the limit. Therefore, it seems logical to cap the initial pipe capacity according to the value of pipe-max-size.
The test program shown earlier in this patch series can be used to demonstrate the effect of the change brought about with this patch:
# cat /proc/sys/fs/pipe-max-size
1048576
# sudo -u mtk ./test_F_SETPIPE_SZ 1
Initial pipe capacity: 65536
# echo 10000 > /proc/sys/fs/pipe-max-size
# cat /proc/sys/fs/pipe-max-size
16384
# sudo -u mtk ./test_F_SETPIPE_SZ 1
Initial pipe capacity: 16384
# ./test_F_SETPIPE_SZ 1
Initial pipe capacity: 65536The last two executions of 'test_F_SETPIPE_SZ' show that pipe-max-size caps the initial allocation for a new pipe for unprivileged users, but not for privileged users.
--- fs/pipe.c | 3 +++ 1 file changed, 3 insertions(+)
fs/pipe.c +3 -0
@@ -617,6 +617,9 @@ struct pipe_inode_info *alloc_pipe_info(if (pipe ==NULL ) goto out_free_uid; +if (pipe_bufs *PAGE_SIZE > pipe_max_size && !capable (CAP_SYS_RESOURCE )) + pipe_bufs = pipe_max_size >>PAGE_SHIFT ; + user_bufs =account_pipe_buffers (user,0 , pipe_bufs);if (too_many_pipe_buffers_soft (user_bufs)) {
PATCH 207/410 pipe: avoid round_pipe_size() nr_pages overflow on 32-bit
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Joe Lawrence <[email protected]>
commit d3f14c485867cfb2e0c48aa88c41d0ef4bf5209c upstream.
round_pipe_size() contains a right-bit-shift expression which may overflow, which would cause undefined results in a subsequent roundup_pow_of_two() call.
static inline unsigned int round_pipe_size(unsigned int size)
{
unsigned long nr_pages;
nr_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
return roundup_pow_of_two(nr_pages) << PAGE_SHIFT;}
PAGE_SIZE is defined as (1UL << PAGE_SHIFT), so:
- 4 bytes wide on 32-bit (0 to 0xffffffff)
- 8 bytes wide on 64-bit (0 to 0xffffffffffffffff)
That means that 32-bit round_pipe_size(), nr_pages may overflow to 0:
size=0x00000000 nr_pages=0x0 size=0x00000001 nr_pages=0x1 size=0xfffff000 nr_pages=0xfffff size=0xfffff001 nr_pages=0x0 << ! size=0xffffffff nr_pages=0x0 << !
This is bad because roundup_pow_of_two(n) is undefined when n == 0!
64-bit is not a problem as the unsigned int size is 4 bytes wide (similar to 32-bit) and the larger, 8 byte wide unsigned long, is sufficient to handle the largest value of the bit shift expression:
size=0xffffffff nr_pages=100000
Modify round_pipe_size() to return 0 if n == 0 and updates its callers to handle accordingly.
--- fs/pipe.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
fs/pipe.c +15 -2
@@ -1006,13 +1006,19 @@ const struct file_operations pipefifo_fo/* * Currently we rely on the pipe array holding a power-of-2 number -* of pages. +* of pages. Returns 0 on error. */ static inline unsigned int round_pipe_size (unsigned int size) {unsigned long nr_pages; +if (size < pipe_min_size) + size = pipe_min_size; + nr_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; +if (nr_pages ==0 ) +return 0 ; +return roundup_pow_of_two (nr_pages) <<PAGE_SHIFT ; }
@@ -1028,6 +1034,8 @@ static long pipe_set_size(struct pipe_inlong ret =0 ; size =round_pipe_size (arg); +if (size ==0 ) +return -EINVAL ; nr_pages = size >>PAGE_SHIFT ;if (!nr_pages)
@@ -1110,13 +1118,18 @@ out_revert_acct:int pipe_proc_fn (struct ctl_table *table,int write,void __user *buf,size_t *lenp,loff_t *ppos) { +unsigned int rounded_pipe_max_size;int ret; ret =proc_dointvec_minmax (table, write, buf, lenp, ppos);if (ret <0 || !write)return ret; - pipe_max_size =round_pipe_size (pipe_max_size); + rounded_pipe_max_size =round_pipe_size (pipe_max_size); +if (rounded_pipe_max_size ==0 ) +return -EINVAL ; + + pipe_max_size = rounded_pipe_max_size;return ret; }
PATCH 208/410 pipe: add proc_dopipe_max_size() to safely assign pipe_max_size
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Joe Lawrence <[email protected]>
commit 7a8d181949fb2c16be00f8cdb354794a30e46b39 upstream.
pipe_max_size is assigned directly via procfs sysctl:
static struct ctl_table fs_table[] = {
...
{
.procname = "pipe-max-size",
.data = &pipe_max_size,
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = &pipe_proc_fn,
.extra1 = &pipe_min_size,
},
... int pipe_proc_fn(struct ctl_table *table, int write, void __user *buf,
size_t *lenp, loff_t *ppos)
{
...
ret = proc_dointvec_minmax(table, write, buf, lenp, ppos)
...and then later rounded in-place a few statements later:
...
pipe_max_size = round_pipe_size(pipe_max_size);
...This leaves a window of time between initial assignment and rounding that may be visible to other threads. (For example, one thread sets a non-rounded value to pipe_max_size while another reads its value.)
Similar reads of pipe_max_size are potentially racy:
pipe.c :: alloc_pipe_info()
pipe.c :: pipe_set_size()
Add a new proc_dopipe_max_size() that consolidates reading the new value from the user buffer, verifying bounds, and calling round_pipe_size() with a single assignment to pipe_max_size.
[bwh: Backported to 3.16: Continue using int sysctl functions because we don't
have proper unsigned int support]
---
fs/pipe.c +3 -15
@@ -1008,7 +1008,7 @@ const struct file_operations pipefifo_fo* Currently we rely on the pipe array holding a power-of-2 number * of pages. Returns 0 on error. */ -static inline unsigned int round_pipe_size (unsigned int size) +unsigned int round_pipe_size (unsigned int size) {unsigned long nr_pages;
@@ -1112,25 +1112,13 @@ out_revert_acct: }/* -* This should work even if CONFIG_PROC_FS isn't set, as proc_dointvec_minmax +* This should work even if CONFIG_PROC_FS isn't set, as proc_dopipe_max_size * will return an error. */ int pipe_proc_fn (struct ctl_table *table,int write,void __user *buf,size_t *lenp,loff_t *ppos) { -unsigned int rounded_pipe_max_size; -int ret; - - ret =proc_dointvec_minmax (table, write, buf, lenp, ppos); -if (ret <0 || !write) -return ret; - - rounded_pipe_max_size =round_pipe_size (pipe_max_size); -if (rounded_pipe_max_size ==0 ) -return -EINVAL ; - - pipe_max_size = rounded_pipe_max_size; -return ret; +return proc_dopipe_max_size (table, write, buf, lenp, ppos); }/*
include/linux/pipe_fs_i.h +1 -0
@@ -149,5 +149,6 @@ long pipe_fcntl(struct file *, unsignedstruct pipe_inode_info *get_pipe_info (struct file *file);int create_pipe_files (struct file **,int ); +unsigned int round_pipe_size (unsigned int size);#endif
include/linux/sysctl.h +3 -0
@@ -45,6 +45,9 @@ extern int proc_dointvec(struct ctl_tabl void __user *, size_t *, loff_t *);extern int proc_dointvec_minmax (struct ctl_table *,int ,void __user *,size_t *,loff_t *); +extern int proc_dopipe_max_size (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos);extern int proc_dointvec_jiffies (struct ctl_table *,int ,void __user *,size_t *,loff_t *); extern int proc_dointvec_userhz_jiffies(struct ctl_table *, int,
kernel/sysctl.c +49 -0
73 lines not on this page · raw message
PATCH 209/410 sysctl: check for UINT_MAX before unsigned int min/max
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Joe Lawrence <[email protected]>
commit fb910c42ccebf853c29296185c45c11164a56098 upstream.
Mikulas noticed in the existing do_proc_douintvec_minmax_conv() and do_proc_dopipe_max_size_conv() introduced in this patchset, that they inconsistently handle overflow and min/max range inputs:
For example:
0 ... param->min - 1 ---> ERANGE
param->min ... param->max ---> the value is accepted param->max + 1 ... 0x100000000L + param->min - 1 ---> ERANGE 0x100000000L + param->min ... 0x100000000L + param->max ---> EINVAL 0x100000000L + param->max + 1, 0x200000000L + param->min - 1 ---> ERANGE 0x200000000L + param->min ... 0x200000000L + param->max ---> EINVAL 0x200000000L + param->max + 1, 0x300000000L + param->min - 1 ---> ERANGE
In do_proc_do*() routines which store values into unsigned int variables (4 bytes wide for 64-bit builds), first validate that the input unsigned long value (8 bytes wide for 64-bit builds) will fit inside the smaller unsigned int variable. Then check that the unsigned int value falls inside the specified parameter min, max range. Otherwise the unsigned long -> unsigned int conversion drops leading bits from the input value, leading to the inconsistent pattern Mikulas documented above.
[bwh: Backported to 3.16:
- Drop changes in do_proc_douintvec_minmax_conv()
- Adjust context]
---
kernel/sysctl.c +5 -4
@@ -2233,17 +2233,18 @@ static int do_proc_dopipe_max_size_conv(struct do_proc_dopipe_max_size_conv_param *param = data;if (write) { -unsigned int val =round_pipe_size (*lvalp); +unsigned int val; +if (*lvalp >UINT_MAX ) +return -EINVAL ; + + val =round_pipe_size (*lvalp);if (*negp || val ==0 )return -EINVAL ;if (param->min && *param->min > val)return -ERANGE ; -if (*lvalp >UINT_MAX ) -return -EINVAL ; - *valp = val; }else {unsigned int val = *valp;
PATCH 210/410 pipe, sysctl: drop 'min' parameter from pipe-max-size converter
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 4c2e4befb3cc9ce42d506aa537c9ab504723e98c upstream.
Patch series "pipe: buffer limits fixes and cleanups", v2.
This series simplifies the sysctl handler for pipe-max-size and fixes another set of bugs related to the pipe buffer limits:
- The root user wasn't allowed to exceed the limits when creating new pipes.
- There was an off-by-one error when checking the limits, so a limit of N was actually treated as N - 1.
- F_SETPIPE_SZ accepted values over UINT_MAX.
- Reading the pipe buffer limits could be racy.
This patch (of 7):
Before validating the given value against pipe_min_size, do_proc_dopipe_max_size_conv() calls round_pipe_size(), which rounds the value up to pipe_min_size. Therefore, the second check against pipe_min_size is redundant. Remove it.
--- fs/pipe.c | 10 +++------- include/linux/pipe_fs_i.h | 2 +- kernel/sysctl.c | 15 +-------------- 3 files changed, 5 insertions(+), 22 deletions(-)
fs/pipe.c +3 -7
@@ -34,11 +34,6 @@*/ unsigned int pipe_max_size =1048576 ; -/* -* Minimum pipe size, as required by POSIX -*/ -unsigned int pipe_min_size =PAGE_SIZE ; -/* Maximum allocatable pages per user. Hard limit is unset by default, soft * matches default values. */
@@ -1012,8 +1007,9 @@ unsigned int round_pipe_size(unsigned in {unsigned long nr_pages; -if (size < pipe_min_size) - size = pipe_min_size; +/* Minimum pipe size, as required by POSIX */ +if (size <PAGE_SIZE ) + size =PAGE_SIZE ; nr_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ;if (nr_pages ==0 )
include/linux/pipe_fs_i.h +1 -1
@@ -124,7 +124,7 @@ void pipe_lock(struct pipe_inode_info *)void pipe_unlock (struct pipe_inode_info *);void pipe_double_lock (struct pipe_inode_info *,struct pipe_inode_info *); -extern unsigned int pipe_max_size, pipe_min_size; +extern unsigned int pipe_max_size;extern unsigned long pipe_user_pages_hard;extern unsigned long pipe_user_pages_soft;int pipe_proc_fn (struct ctl_table *,int ,void __user *,size_t *,loff_t *);
kernel/sysctl.c +1 -14
@@ -1672,7 +1672,6 @@ static struct ctl_table fs_table[] = { .maxlen = sizeof(int), .mode = 0644, .proc_handler = &pipe_proc_fn, - .extra1 = &pipe_min_size, }, { .procname = "pipe-user-pages-hard",
@@ -2223,15 +2222,9 @@ int proc_dointvec_minmax(struct ctl_tabl do_proc_dointvec_minmax_conv, ¶m); } -struct do_proc_dopipe_max_size_conv_param { -unsigned int *min; -}; -static int do_proc_dopipe_max_size_conv (bool *negp,unsigned long *lvalp,int *valp,int write,void *data) { -struct do_proc_dopipe_max_size_conv_param *param = data; -if (write) {unsigned int val;
@@ -2242,9 +2235,6 @@ static int do_proc_dopipe_max_size_conv(if (*negp || val ==0 )return -EINVAL ; -if (param->min && *param->min > val) -return -ERANGE ; - *valp = val; }else {unsigned int val = *valp;
@@ -2258,11 +2248,8 @@ static int do_proc_dopipe_max_size_conv(int proc_dopipe_max_size (struct ctl_table *table,int write,void __user *buffer,size_t *lenp,loff_t *ppos) { -struct do_proc_dopipe_max_size_conv_param param = { - .min = (unsigned int *) table->extra1, - };return do_proc_dointvec (table, write, buffer, lenp, ppos, - do_proc_dopipe_max_size_conv, ¶m); + do_proc_dopipe_max_size_conv,NULL ); }static void validate_coredump_safety (void )
PATCH 211/410 pipe, sysctl: remove pipe_proc_fn()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 319e0a21bb7823abbb4818fe2724e572bbac77a2 upstream.
pipe_proc_fn() is no longer needed, as it only calls through to proc_dopipe_max_size(). Just put proc_dopipe_max_size() in the ctl_table entry directly, and remove the unneeded EXPORT_SYMBOL() and the ENOSYS stub for it.
(The reason the ENOSYS stub isn't needed is that the pipe-max-size ctl_table entry is located directly in 'kern_table' rather than being registered separately. Therefore, the entry is already only defined when the kernel is built with sysctl support.)
--- fs/pipe.c | 10 ---------- include/linux/pipe_fs_i.h | 1 - include/linux/sysctl.h | 3 --- kernel/sysctl.c | 15 +++++---------- 4 files changed, 5 insertions(+), 24 deletions(-)
fs/pipe.c +0 -10
@@ -1108,16 +1108,6 @@ out_revert_acct: }/* -* This should work even if CONFIG_PROC_FS isn't set, as proc_dopipe_max_size -* will return an error. -*/ -int pipe_proc_fn (struct ctl_table *table,int write,void __user *buf, -size_t *lenp,loff_t *ppos) -{ -return proc_dopipe_max_size (table, write, buf, lenp, ppos); -} - -/* * After the inode slimming patch, i_pipe/i_bdev/i_cdev share the same * location, so checking ->i_pipe is not enough to verify that this is a * pipe.
include/linux/pipe_fs_i.h +0 -1
@@ -127,7 +127,6 @@ void pipe_double_lock(struct pipe_inode_extern unsigned int pipe_max_size;extern unsigned long pipe_user_pages_hard;extern unsigned long pipe_user_pages_soft; -int pipe_proc_fn (struct ctl_table *,int ,void __user *,size_t *,loff_t *);/* Drop the inode semaphore and wait for a pipe event, atomically */
include/linux/sysctl.h +0 -3
@@ -45,9 +45,6 @@ extern int proc_dointvec(struct ctl_tabl void __user *, size_t *, loff_t *);extern int proc_dointvec_minmax (struct ctl_table *,int ,void __user *,size_t *,loff_t *); -extern int proc_dopipe_max_size (struct ctl_table *table,int write, -void __user *buffer,size_t *lenp, -loff_t *ppos);extern int proc_dointvec_jiffies (struct ctl_table *,int ,void __user *,size_t *,loff_t *); extern int proc_dointvec_userhz_jiffies(struct ctl_table *, int,
kernel/sysctl.c +5 -10
@@ -194,6 +194,8 @@ static int proc_dointvec_minmax_coredumpstatic int proc_dostring_coredump (struct ctl_table *table,int write,void __user *buffer,size_t *lenp,loff_t *ppos);#endif +static int proc_dopipe_max_size (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp,loff_t *ppos);#ifdef CONFIG_MAGIC_SYSRQ /* Note: sysrq code uses it's own private copy */
@@ -1671,7 +1673,7 @@ static struct ctl_table fs_table[] = { .data = &pipe_max_size, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = &pipe_proc_fn, + .proc_handler = proc_dopipe_max_size, }, { .procname = "pipe-user-pages-hard",
@@ -2245,8 +2247,8 @@ static int do_proc_dopipe_max_size_conv(return 0 ; } -int proc_dopipe_max_size (struct ctl_table *table,int write, -void __user *buffer,size_t *lenp,loff_t *ppos) +static int proc_dopipe_max_size (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp,loff_t *ppos) {return do_proc_dointvec (table, write, buffer, lenp, ppos, do_proc_dopipe_max_size_conv,NULL );
@@ -2767,12 +2769,6 @@ int proc_dointvec_minmax(struct ctl_tablreturn -ENOSYS ; } -int proc_dopipe_max_size (struct ctl_table *table,int write, -void __user *buffer,size_t *lenp,loff_t *ppos) -{ -return -ENOSYS ; -} -int proc_dointvec_jiffies (struct ctl_table *table,int write,void __user *buffer,size_t *lenp,loff_t *ppos) {
@@ -2814,7 +2810,6 @@ int proc_doulongvec_ms_jiffies_minmax(stEXPORT_SYMBOL (proc_dointvec);EXPORT_SYMBOL (proc_dointvec_jiffies);EXPORT_SYMBOL (proc_dointvec_minmax); -EXPORT_SYMBOL_GPL (proc_dopipe_max_size);EXPORT_SYMBOL (proc_dointvec_userhz_jiffies);EXPORT_SYMBOL (proc_dointvec_ms_jiffies);EXPORT_SYMBOL (proc_dostring);
PATCH 212/410 pipe: actually allow root to exceed the pipe buffer limits
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 85c2dd5473b2718b4b63e74bfeb1ca876868e11f upstream.
pipe-user-pages-hard and pipe-user-pages-soft are only supposed to apply to unprivileged users, as documented in both Documentation/sysctl/fs.txt and the pipe(7) man page.
However, the capabilities are actually only checked when increasing a pipe's size using F_SETPIPE_SZ, not when creating a new pipe. Therefore, if pipe-user-pages-hard has been set, the root user can run into it and be unable to create pipes. Similarly, if pipe-user-pages-soft has been set, the root user can run into it and have their pipes limited to 1 page each.
Fix this by allowing the privileged override in both cases.
--- fs/pipe.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
fs/pipe.c +8 -3
@@ -601,6 +601,11 @@ static bool too_many_pipe_buffers_hard(ureturn pipe_user_pages_hard && user_bufs >= pipe_user_pages_hard; } +static bool is_unprivileged_user (void ) +{ +return !capable (CAP_SYS_RESOURCE ) && !capable (CAP_SYS_ADMIN ); +} +struct pipe_inode_info *alloc_pipe_info (void ) {struct pipe_inode_info *pipe;
@@ -617,12 +622,12 @@ struct pipe_inode_info *alloc_pipe_info( user_bufs =account_pipe_buffers (user,0 , pipe_bufs); -if (too_many_pipe_buffers_soft (user_bufs)) { +if (too_many_pipe_buffers_soft (user_bufs) &&is_unprivileged_user ()) { user_bufs =account_pipe_buffers (user, pipe_bufs,1 ); pipe_bufs =1 ; } -if (too_many_pipe_buffers_hard (user_bufs)) +if (too_many_pipe_buffers_hard (user_bufs) &&is_unprivileged_user ()) goto out_revert_acct; pipe->bufs = kcalloc(pipe_bufs, sizeof(struct pipe_buffer),
@@ -1053,7 +1058,7 @@ static long pipe_set_size(struct pipe_inif (nr_pages > pipe->buffers && (too_many_pipe_buffers_hard (user_bufs) ||too_many_pipe_buffers_soft (user_bufs)) && - !capable (CAP_SYS_RESOURCE ) && !capable (CAP_SYS_ADMIN )) { +is_unprivileged_user ()) { ret = -EPERM ; goto out_revert_acct; }
PATCH 213/410 pipe: fix off-by-one error when checking buffer limits
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 9903a91c763ecdae333a04a9d89d79d2b8966503 upstream.
With pipe-user-pages-hard set to 'N', users were actually only allowed up to 'N - 1' buffers; and likewise for pipe-user-pages-soft.
Fix this to allow up to 'N' buffers, as would be expected.
--- fs/pipe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/pipe.c +2 -2
@@ -593,12 +593,12 @@ static unsigned long account_pipe_bufferstatic bool too_many_pipe_buffers_soft (unsigned long user_bufs) { -return pipe_user_pages_soft && user_bufs >= pipe_user_pages_soft; +return pipe_user_pages_soft && user_bufs > pipe_user_pages_soft; }static bool too_many_pipe_buffers_hard (unsigned long user_bufs) { -return pipe_user_pages_hard && user_bufs >= pipe_user_pages_hard; +return pipe_user_pages_hard && user_bufs > pipe_user_pages_hard; }static bool is_unprivileged_user (void )
PATCH 214/410 pipe: reject F_SETPIPE_SZ with size over UINT_MAX
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 96e99be40e4cff870a83233731121ec0f7f95075 upstream.
A pipe's size is represented as an 'unsigned int'. As expected, writing a value greater than UINT_MAX to /proc/sys/fs/pipe-max-size fails with EINVAL. However, the F_SETPIPE_SZ fcntl silently truncates such values to 32 bits, rather than failing with EINVAL as expected. (It *does* fail with EINVAL for values above (1 << 31) but <= UINT_MAX.)
Fix this by moving the check against UINT_MAX into round_pipe_size() which is called in both cases.
--- fs/pipe.c | 5 ++++- include/linux/pipe_fs_i.h | 2 +- kernel/sysctl.c | 3 --- 3 files changed, 5 insertions(+), 5 deletions(-)
fs/pipe.c +4 -1
@@ -1008,10 +1008,13 @@ const struct file_operations pipefifo_fo* Currently we rely on the pipe array holding a power-of-2 number * of pages. Returns 0 on error. */ -unsigned int round_pipe_size (unsigned int size) +unsigned int round_pipe_size (unsigned long size) {unsigned long nr_pages; +if (size >UINT_MAX ) +return 0 ; +/* Minimum pipe size, as required by POSIX */ if (size <PAGE_SIZE ) size =PAGE_SIZE ;
include/linux/pipe_fs_i.h +1 -1
@@ -148,6 +148,6 @@ long pipe_fcntl(struct file *, unsignedstruct pipe_inode_info *get_pipe_info (struct file *file);int create_pipe_files (struct file **,int ); -unsigned int round_pipe_size (unsigned int size); +unsigned int round_pipe_size (unsigned long size);#endif
kernel/sysctl.c +0 -3
@@ -2230,9 +2230,6 @@ static int do_proc_dopipe_max_size_conv(if (write) {unsigned int val; -if (*lvalp >UINT_MAX ) -return -EINVAL ; - val =round_pipe_size (*lvalp);if (*negp || val ==0 )return -EINVAL ;
PATCH 215/410 pipe: simplify round_pipe_size()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit c4fed5a91fadc8a277b1eda474317b501651dd3e upstream.
round_pipe_size() calculates the number of pages the requested size corresponds to, then rounds the page count up to the next power of 2.
However, it also rounds everything < PAGE_SIZE up to PAGE_SIZE. Therefore, there's no need to actually translate the size into a page count; we just need to round the size up to the next power of 2.
We do need to verify the size isn't greater than (1 << 31), since on 32-bit systems roundup_pow_of_two() would be undefined in that case. But that can just be combined with the UINT_MAX check which we need anyway now.
Finally, update pipe_set_size() to not redundantly check the return value of round_pipe_size() for the "invalid size" case twice.
--- fs/pipe.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
fs/pipe.c +3 -11
@@ -1010,20 +1010,14 @@ const struct file_operations pipefifo_fo*/ unsigned int round_pipe_size (unsigned long size) { -unsigned long nr_pages; - -if (size >UINT_MAX ) +if (size > (1U <<31 ))return 0 ;/* Minimum pipe size, as required by POSIX */ if (size <PAGE_SIZE ) - size =PAGE_SIZE ; - - nr_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; -if (nr_pages ==0 ) -return 0 ; +return PAGE_SIZE ; -return roundup_pow_of_two (nr_pages) <<PAGE_SHIFT ; +return roundup_pow_of_two (size); }/*
@@ -1038,8 +1032,6 @@ static long pipe_set_size(struct pipe_inlong ret =0 ; size =round_pipe_size (arg); -if (size ==0 ) -return -EINVAL ; nr_pages = size >>PAGE_SHIFT ;if (!nr_pages)
PATCH 216/410 pipe: read buffer limits atomically
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit f7340761812fc10313e6fcc115e0bc4f7a799112 upstream.
The pipe buffer limits are accessed without any locking, and may be changed at any time by the sysctl handlers. In theory this could cause problems for expressions like the following:
pipe_user_pages_hard && user_bufs > pipe_user_pages_hard
... since the assembly code might reference the 'pipe_user_pages_hard' memory location multiple times, and if the admin removes the limit by setting it to 0, there is a very brief window where processes could incorrectly observe the limit to be exceeded.
Fix this by loading the limits with READ_ONCE() prior to use.
[bwh: Backported to 3.16:
- Use ACCESS_ONCE() instead of READ_ONCE()
- Adjust context]
--- fs/pipe.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
fs/pipe.c +9 -4
@@ -593,12 +593,16 @@ static unsigned long account_pipe_bufferstatic bool too_many_pipe_buffers_soft (unsigned long user_bufs) { -return pipe_user_pages_soft && user_bufs > pipe_user_pages_soft; +unsigned long soft_limit =ACCESS_ONCE (pipe_user_pages_soft); + +return soft_limit && user_bufs > soft_limit; }static bool too_many_pipe_buffers_hard (unsigned long user_bufs) { -return pipe_user_pages_hard && user_bufs > pipe_user_pages_hard; +unsigned long hard_limit =ACCESS_ONCE (pipe_user_pages_hard); + +return hard_limit && user_bufs > hard_limit; }static bool is_unprivileged_user (void )
@@ -612,13 +616,14 @@ struct pipe_inode_info *alloc_pipe_info(unsigned long pipe_bufs =PIPE_DEF_BUFFERS ;struct user_struct *user =get_current_user ();unsigned long user_bufs; +unsigned int max_size =ACCESS_ONCE (pipe_max_size); pipe =kzalloc (sizeof (struct pipe_inode_info ),GFP_KERNEL );if (pipe ==NULL ) goto out_free_uid; -if (pipe_bufs *PAGE_SIZE > pipe_max_size && !capable (CAP_SYS_RESOURCE )) - pipe_bufs = pipe_max_size >>PAGE_SHIFT ; +if (pipe_bufs *PAGE_SIZE > max_size && !capable (CAP_SYS_RESOURCE )) + pipe_bufs = max_size >>PAGE_SHIFT ; user_bufs =account_pipe_buffers (user,0 , pipe_bufs);
PATCH 217/410 cifs: silence compiler warnings showing up with gcc-8.0.0
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
commit ade7db991b47ab3016a414468164f4966bd08202 upstream.
This bug was fixed before, but came up again with the latest compiler in another function:
fs/cifs/cifssmb.c: In function 'CIFSSMBSetEA':fs/cifs/cifssmb.c:6362:3: error: 'strncpy' offset 8 is out of the bounds [0, 4] [-Werror=array-bounds]
strncpy(parm_data->list[0].name, ea_name, name_len);
Let's apply the same fix that was used for the other instances.
--- fs/cifs/cifssmb.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/cifs/cifssmb.c +1 -3
@@ -6366,9 +6366,7 @@ SetEARetry: pSMB->InformationLevel =cpu_to_le16 (SMB_SET_FILE_EA ); - parm_data = - (struct fealist *) (((char *) &pSMB->hdr.Protocol) + - offset); + parm_data = (void *)pSMB + offsetof(struct smb_hdr , Protocol) + offset; pSMB->ParameterOffset =cpu_to_le16 (param_offset); pSMB->DataOffset =cpu_to_le16 (offset); pSMB->SetupCount =1 ;
PATCH 218/410 crypto: caam - fix endless loop when DECO acquire fails
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Horia Geantă <[email protected]>
commit 225ece3e7dad4cfc44cca38ce7a3a80f255ea8f1 upstream.
In case DECO0 cannot be acquired - i.e. run_descriptor_deco0() fails with -ENODEV, caam_probe() enters an endless loop:
run_descriptor_deco0
ret -ENODEV -> instantiate_rng -ENODEV, overwritten by -EAGAIN ret -EAGAIN -> caam_probe -EAGAIN results in endless loop
It turns out the error path in instantiate_rng() is incorrect, the checks are done in the wrong order.
--- drivers/crypto/caam/ctrl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/crypto/caam/ctrl.c +6 -2
@@ -196,12 +196,16 @@ static int instantiate_rng(struct device* without any error (HW optimizations for later * CAAM eras), then try again. */ +if (ret) +break ; + rdsta_val =rd_reg32 (&topregs->ctrl.r4tst[0 ].rdsta) &RDSTA_IFMASK ; -if (status || !(rdsta_val & (1 << sh_idx))) +if (status || !(rdsta_val & (1 << sh_idx))) { ret = -EAGAIN ; -if (ret)break ; + } +dev_info (ctrldev,"Instantiated RNG4 SH%d\n" , sh_idx);/* Clear the contents before recreating the descriptor */
PATCH 219/410 powerpc/numa: Invalidate numa_cpu_lookup_table on cpu remove
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nathan Fontenot <[email protected]>
commit 1d9a090783bef19fe8cdec878620d22f05191316 upstream.
When DLPAR removing a CPU, the unmapping of the cpu from a node in unmap_cpu_from_node() should also invalidate the CPUs entry in the numa_cpu_lookup_table. There is not a guarantee that on a subsequent DLPAR add of the CPU the associativity will be the same and thus could be in a different node. Invalidating the entry in the numa_cpu_lookup_table causes the associativity to be read from the device tree at the time of the add.
The current behavior of not invalidating the CPUs entry in the numa_cpu_lookup_table can result in scenarios where the the topology layout of CPUs in the partition does not match the device tree or the topology reported by the HMC.
This bug looks like it was introduced in 2004 in the commit titled "ppc64: cpu hotplug notifier for numa", which is 6b15e4e87e32 in the linux-fullhist tree. Hence tag it for all stable releases.
--- arch/powerpc/include/asm/topology.h | 5 +++++ arch/powerpc/mm/numa.c | 5 ----- arch/powerpc/platforms/pseries/hotplug-cpu.c | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/topology.h +5 -0
@@ -44,6 +44,11 @@ extern void __init dump_numa_cpu_topologextern int sysfs_add_device_to_node (struct device *dev,int nid);extern void sysfs_remove_device_from_node (struct device *dev,int nid); +static inline void update_numa_cpu_lookup_table (unsigned int cpu,int node) +{ + numa_cpu_lookup_table[cpu] = node; +} +static inline int early_cpu_to_node (int cpu) {int nid;
arch/powerpc/mm/numa.c +0 -5
@@ -162,11 +162,6 @@ static void reset_numa_cpu_lookup_table( numa_cpu_lookup_table[cpu] =-1 ; } -static void update_numa_cpu_lookup_table (unsigned int cpu,int node) -{ - numa_cpu_lookup_table[cpu] = node; -} -static void map_cpu_to_node (int cpu,int node) {update_numa_cpu_lookup_table (cpu, node);
arch/powerpc/platforms/pseries/hotplug-cpu.c +2 -0
@@ -31,6 +31,7 @@#include <asm/vdso_datapage.h> #include <asm/xics.h> #include <asm/plpar_wrappers.h> +#include <asm/topology.h> #include "offline_states.h"
@@ -328,6 +329,7 @@ static void pseries_remove_processor(strBUG_ON (cpu_online (cpu));set_cpu_present (cpu, false);set_hard_smp_processor_id (cpu,-1 ); +update_numa_cpu_lookup_table (cpu,-1 );break ; }if (cpu >= nr_cpu_ids)
PATCH 220/410 netlink: ensure to loop over all netns in genlmsg_multicast_allns()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nicolas Dichtel <[email protected]>
commit cb9f7a9a5c96a773bbc9c70660dc600cfff82f82 upstream.
Nowadays, nlmsg_multicast() returns only 0 or -ESRCH but this was not the case when commit 134e63756d5f was pushed.
However, there was no reason to stop the loop if a netns does not have listeners.
Returns -ESRCH only if there was no listeners in all netns.
To avoid having the same problem in the future, I didn't take the assumption that nlmsg_multicast() returns only 0 or -ESRCH.
--- net/netlink/genetlink.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
net/netlink/genetlink.c +10 -2
@@ -1042,6 +1042,7 @@ static int genlmsg_mcast(struct sk_buff {struct sk_buff *tmp;struct net *net, *prev =NULL ; +bool delivered = false;int err;for_each_net_rcu (net) {
@@ -1053,14 +1054,21 @@ static int genlmsg_mcast(struct sk_buff } err =nlmsg_multicast (prev->genl_sock, tmp, portid, group, flags); -if (err) +if (!err) + delivered = true; +else if (err != -ESRCH ) goto error; } prev = net; } -return nlmsg_multicast (prev->genl_sock, skb, portid, group, flags); + err =nlmsg_multicast (prev->genl_sock, skb, portid, group, flags); +if (!err) + delivered = true; +else if (err != -ESRCH ) + goto error; +return delivered ?0 : -ESRCH ; error:kfree_skb (skb);return err;
PATCH 221/410 netlink: avoid a double skb free in genlmsg_mcast()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nicolas Dichtel <[email protected]>
commit 02a2385f37a7c6594c9d89b64c4a1451276f08eb upstream.
nlmsg_multicast() consumes always the skb, thus the original skb must be freed only when this function is called with a clone.
--- net/netlink/genetlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netlink/genetlink.c +1 -1
@@ -1067,7 +1067,7 @@ static int genlmsg_mcast(struct sk_buffif (!err) delivered = true;else if (err != -ESRCH ) - goto error; +return err;return delivered ?0 : -ESRCH ; error:kfree_skb (skb);
PATCH 222/410 9p/trans_virtio: discard zero-length reply
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kurz <[email protected]>
commit 26d99834f89e76514076d9cd06f61e56e6a509b8 upstream.
When a 9p request is successfully flushed, the server is expected to just mark it as used without sending a 9p reply (ie, without writing data into the buffer). In this case, virtqueue_get_buf() will return len == 0 and we must not report a REQ_STATUS_RCVD status to the client, otherwise the client will erroneously assume the request has not been flushed.
--- net/9p/trans_virtio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/9p/trans_virtio.c +2 -1
@@ -164,7 +164,8 @@ static void req_done(struct virtqueue *vp9_debug (P9_DEBUG_TRANS ,": rc %p\n" , rc);p9_debug (P9_DEBUG_TRANS ,": lookup tag %d\n" , rc->tag); req =p9_tag_lookup (chan->client, rc->tag); -p9_client_cb (chan->client, req,REQ_STATUS_RCVD ); +if (len) +p9_client_cb (chan->client, req,REQ_STATUS_RCVD ); } }
PATCH 223/410 s390/qeth: fix SETIP command handling
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Julian Wiedmann <[email protected]>
commit 1c5b2216fbb973a9410e0b06389740b5c1289171 upstream.
send_control_data() applies some special handling to SETIP v4 IPA commands. But current code parses *all* command types for the SETIP command code. Limit the command code check to IPA commands.
--- drivers/s390/net/qeth_core.h | 5 +++++ drivers/s390/net/qeth_core_main.c | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-)
drivers/s390/net/qeth_core.h +5 -0
@@ -593,6 +593,11 @@ struct qeth_cmd_buffer {void (*callback) (struct qeth_channel *,struct qeth_cmd_buffer *); }; +static inline struct qeth_ipa_cmd *__ipa_cmd (struct qeth_cmd_buffer *iob) +{ +return (struct qeth_ipa_cmd *)(iob->data +IPA_PDU_HEADER_SIZE ); +} +/** * definition of a qeth channel, used for read and write */
drivers/s390/net/qeth_core_main.c +8 -6
@@ -2025,7 +2025,7 @@ int qeth_send_control_data(struct qeth_cunsigned long flags;struct qeth_reply *reply =NULL ;unsigned long timeout, event_timeout; -struct qeth_ipa_cmd *cmd; +struct qeth_ipa_cmd *cmd =NULL ;QETH_CARD_TEXT (card,2 ,"sendctl" );
@@ -2052,10 +2052,13 @@ int qeth_send_control_data(struct qeth_cwhile (atomic_cmpxchg (&card->write.irq_pending,0 ,1 )) ;qeth_prepare_control_data (card, len, iob); -if (IS_IPA (iob->data)) +if (IS_IPA (iob->data)) { + cmd =__ipa_cmd (iob); event_timeout =QETH_IPA_TIMEOUT ; -else + }else { event_timeout =QETH_TIMEOUT ; + } + timeout = jiffies + event_timeout;QETH_CARD_TEXT (card,6 ,"noirqpnd" );
@@ -2080,9 +2083,8 @@ int qeth_send_control_data(struct qeth_c/* we have only one long running ipassist, since we can ensure process context of this command we can sleep */ - cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE ); -if ((cmd->hdr.command ==IPA_CMD_SETIP ) && - (cmd->hdr.prot_version ==QETH_PROT_IPV4 )) { +if (cmd && cmd->hdr.command ==IPA_CMD_SETIP && + cmd->hdr.prot_version ==QETH_PROT_IPV4 ) {if (!wait_event_timeout (reply->wait_q,atomic_read (&reply->received), event_timeout)) goto time_err;
PATCH 224/410 Input: matrix_keypad - fix race when disabling interrupts
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Bo <[email protected]>
commit ea4f7bd2aca9f68470e9aac0fc9432fd180b1fe7 upstream.
If matrix_keypad_stop() is executing and the keypad interrupt is triggered, disable_row_irqs() may be called by both matrix_keypad_interrupt() and matrix_keypad_stop() at the same time, causing interrupts to be disabled twice and the keypad being "stuck" after resuming.
Take lock when setting keypad->stopped to ensure that ISR will not race with matrix_keypad_stop() disabling interrupts.
--- drivers/input/keyboard/matrix_keypad.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/input/keyboard/matrix_keypad.c +3 -1
@@ -216,8 +216,10 @@ static void matrix_keypad_stop(struct in {struct matrix_keypad *keypad =input_get_drvdata (dev); +spin_lock_irq (&keypad->lock); keypad->stopped = true; -mb (); +spin_unlock_irq (&keypad->lock); +flush_work (&keypad->work.work);/* * matrix_keypad_scan() will leave IRQs enabled;
PATCH 225/410 ALSA: usb-audio: add implicit fb quirk for Behringer UFX1204
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Lassi Ylikojola <[email protected]>
commit 5e35dc0338d85ccebacf3f77eca1e5dea73155e8 upstream.
Add quirk to ensure a sync endpoint is properly configured. This patch is a fix for same symptoms on Behringer UFX1204 as patch from Albertto Aquirre on Dec 8 2016 for Axe-Fx II.
--- sound/usb/pcm.c | 9 +++++++++ 1 file changed, 9 insertions(+)
sound/usb/pcm.c +9 -0
@@ -348,6 +348,15 @@ static int set_sync_ep_implicit_fb_quirk alts = &iface->altsetting[1 ]; goto add_sync_ep; +case USB_ID (0x1397 ,0x0002 ): + ep =0x81 ; + iface =usb_ifnum_to_if (dev,1 ); + +if (!iface || iface->num_altsetting ==0 ) +return -EINVAL ; + + alts = &iface->altsetting[1 ]; + goto add_sync_ep; } if (attr == USB_ENDPOINT_SYNC_ASYNC && altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC &&
PATCH 226/410 usb: dwc3: gadget: Set maxpacket size for ep0 IN
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Thinh Nguyen <[email protected]>
commit 6180026341e852a250e1f97ebdcf71684a3c81b9 upstream.
There are 2 control endpoint structures for DWC3. However, the driver only updates the OUT direction control endpoint structure during ConnectDone event. DWC3 driver needs to update the endpoint max packet size for control IN endpoint as well. If the max packet size is not properly set, then the driver will incorrectly calculate the data transfer size and fail to send ZLP for HS/FS 3-stage control read transfer.
The fix is simply to update the max packet size for the ep0 IN direction during ConnectDone event.
--- drivers/usb/dwc3/gadget.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/dwc3/gadget.c +2 -0
@@ -2436,6 +2436,8 @@ static void dwc3_gadget_conndone_interrubreak ; } + dwc->eps[1 ]->endpoint.maxpacket = dwc->gadget.ep0->maxpacket; +/* Enable USB2 LPM Capability */ if ((dwc->revision > DWC3_REVISION_194A)
PATCH 227/410 bridge: check brport attr show in brport_show
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
commit 1b12580af1d0677c3c3a19e35bfe5d59b03f737f upstream.
Now br_sysfs_if file flush doesn't have attr show. To read it will cause kernel panic after users chmod u+r this file.
Xiong found this issue when running the commands:
ip link add br0 type bridge
ip link add type veth
ip link set veth0 master br0
chmod u+r /sys/devices/virtual/net/veth0/brport/flush timeout 3 cat /sys/devices/virtual/net/veth0/brport/flush
kernel crashed with NULL a pointer dereference call trace.
This patch is to fix it by return -EINVAL when brport_attr->show is null, just the same as the check for brport_attr->store in brport_store().
--- net/bridge/br_sysfs_if.c | 3 +++ 1 file changed, 3 insertions(+)
net/bridge/br_sysfs_if.c +3 -0
@@ -225,6 +225,9 @@ static ssize_t brport_show(struct kobjecstruct brport_attribute *brport_attr =to_brport_attr (attr);struct net_bridge_port *p =to_brport (kobj); +if (!brport_attr->show) +return -EINVAL ; +return brport_attr->show (p, buf); }
PATCH 228/410 libata: fix length validation of ATAPI-relayed SCSI commands
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 058f58e235cbe03e923b30ea7c49995a46a8725f upstream.
syzkaller reported a crash in ata_bmdma_fill_sg() when writing to /dev/sg1. The immediate cause was that the ATA command's scatterlist was not DMA-mapped, which causes 'pi - 1' to underflow, resulting in a write to 'qc->ap->bmdma_prd[0xffffffff]'.
Strangely though, the flag ATA_QCFLAG_DMAMAP was set in qc->flags. The root cause is that when __ata_scsi_queuecmd() is preparing to relay a SCSI command to an ATAPI device, it doesn't correctly validate the CDB length before copying it into the 16-byte buffer 'cdb' in 'struct ata_queued_cmd'. Namely, it validates the fixed CDB length expected based on the SCSI opcode but not the actual CDB length, which can be larger due to the use of the SG_NEXT_CMD_LEN ioctl. Since 'flags' is the next member in ata_queued_cmd, a buffer overflow corrupts it.
Fix it by requiring that the actual CDB length be <= 16 (ATAPI_CDB_LEN).
[Really it seems the length should be required to be <= dev->cdb_len, but the current behavior seems to have been intentionally introduced by commit 607126c2a21c ("libata-scsi: be tolerant of 12-byte ATAPI commands in 16-byte CDBs") to work around a userspace bug in mplayer. Probably the workaround is no longer needed (mplayer was fixed in 2007), but continuing to allow lengths to up 16 appears harmless for now.]
Here's a reproducer that works in QEMU when /dev/sg1 refers to the CD-ROM drive that qemu-system-x86_64 creates by default:
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#define SG_NEXT_CMD_LEN 0x2283
int main()
{
char buf[53] = { [36] = 0x7e, [52] = 0x02 };
int fd = open("/dev/sg1", O_RDWR);
ioctl(fd, SG_NEXT_CMD_LEN, &(int){ 17 });
write(fd, buf, sizeof(buf));
}The crash was:
BUG: unable to handle kernel paging request at ffff8cb97db37ffc
IP: ata_bmdma_fill_sg drivers/ata/libata-sff.c:2623 [inline]
IP: ata_bmdma_qc_prep+0xa4/0xc0 drivers/ata/libata-sff.c:2727
PGD fb6c067 P4D fb6c067 PUD 0
Oops: 0002 [#1] SMP
CPU: 1 PID: 150 Comm: syz_ata_bmdma_q Not tainted 4.15.0-next-20180202 #99
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-20171110_100015-anatol 04/01/2014
[...]
Call Trace:
ata_qc_issue+0x100/0x1d0 drivers/ata/libata-core.c:5421
ata_scsi_translate+0xc9/0x1a0 drivers/ata/libata-scsi.c:2024
__ata_scsi_queuecmd drivers/ata/libata-scsi.c:4326 [inline]
ata_scsi_queuecmd+0x8c/0x210 drivers/ata/libata-scsi.c:4375
scsi_dispatch_cmd+0xa2/0xe0 drivers/scsi/scsi_lib.c:1727
scsi_request_fn+0x24c/0x530 drivers/scsi/scsi_lib.c:1865
__blk_run_queue_uncond block/blk-core.c:412 [inline]
__blk_run_queue+0x3a/0x60 block/blk-core.c:432
blk_execute_rq_nowait+0x93/0xc0 block/blk-exec.c:78
sg_common_write.isra.7+0x272/0x5a0 drivers/scsi/sg.c:806
sg_write+0x1ef/0x340 drivers/scsi/sg.c:677
__vfs_write+0x31/0x160 fs/read_write.c:480
vfs_write+0xa7/0x160 fs/read_write.c:544
SYSC_write fs/read_write.c:589 [inline]
SyS_write+0x4d/0xc0 fs/read_write.c:581
do_syscall_64+0x5e/0x110 arch/x86/entry/common.c:287
entry_SYSCALL_64_after_hwframe+0x21/0x86--- drivers/ata/libata-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/ata/libata-scsi.c +3 -1
@@ -3435,7 +3435,9 @@ static inline int __ata_scsi_queuecmd(stif (likely ((scsi_op !=ATA_16 ) || !atapi_passthru16)) {/* relay SCSI command to ATAPI device */ int len =COMMAND_SIZE (scsi_op); -if (unlikely (len > scmd->cmd_len || len > dev->cdb_len)) +if (unlikely (len > scmd->cmd_len || + len > dev->cdb_len || + scmd->cmd_len >ATAPI_CDB_LEN )) goto bad_cdb_len; xlat_func = atapi_xlat;
PATCH 229/410 libata: remove WARN() for DMA or PIO command without data
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 9173e5e80729c8434b8d27531527c5245f4a5594 upstream.
syzkaller hit a WARN() in ata_qc_issue() when writing to /dev/sg0. This happened because it issued a READ_6 command with no data buffer.
Just remove the WARN(), as it doesn't appear indicate a kernel bug. The expected behavior is to fail the command, which the code does.
Here's a reproducer that works in QEMU when /dev/sg0 refers to a disk of the default type ("82371SB PIIX3 IDE"):
#include <fcntl.h>
#include <unistd.h>
int main()
{
char buf[42] = { [36] = 0x8 /* READ_6 */ };
write(open("/dev/sg0", O_RDWR), buf, sizeof(buf));
}--- drivers/ata/libata-core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/ata/libata-core.c +1 -2
@@ -5139,8 +5139,7 @@ void ata_qc_issue(struct ata_queued_cmd* We guarantee to LLDs that they will have at least one * non-zero sg if the command is a data command. */ -if (WARN_ON_ONCE (ata_is_data (prot) && - (!qc->sg || !qc->n_elem || !qc->nbytes))) +if (ata_is_data (prot) && (!qc->sg || !qc->n_elem || !qc->nbytes)) goto sys_err; if (ata_is_dma(prot) || (ata_is_pio(prot) &&
PATCH 230/410 xfrm_user: uncoditionally validate esn replay attribute struct
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit d97ca5d714a5334aecadadf696875da40f1fbf3e upstream.
The sanity test added in ecd7918745234 can be bypassed, validation only occurs if XFRM_STATE_ESN flag is set, but rest of code doesn't care and just checks if the attribute itself is present.
So always validate. Alternative is to reject if we have the attribute without the flag but that would change abi.
--- net/xfrm/xfrm_user.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
net/xfrm/xfrm_user.c +8 -13
@@ -120,22 +120,17 @@ static inline int verify_replay(struct xstruct nlattr *rt = attrs[XFRMA_REPLAY_ESN_VAL ];struct xfrm_replay_state_esn *rs; -if (p->flags &XFRM_STATE_ESN ) { -if (!rt) -return -EINVAL ; - - rs =nla_data (rt); +if (!rt) +return (p->flags &XFRM_STATE_ESN ) ? -EINVAL :0 ; -if (rs->bmp_len >XFRMA_REPLAY_ESN_MAX /sizeof (rs->bmp[0 ]) /8 ) -return -EINVAL ; + rs =nla_data (rt); -if (nla_len (rt) <xfrm_replay_state_esn_len (rs) && -nla_len (rt) !=sizeof (*rs)) -return -EINVAL ; - } +if (rs->bmp_len >XFRMA_REPLAY_ESN_MAX /sizeof (rs->bmp[0 ]) /8 ) +return -EINVAL ; -if (!rt) -return 0 ; +if (nla_len (rt) <xfrm_replay_state_esn_len (rs) && +nla_len (rt) !=sizeof (*rs)) +return -EINVAL ;/* As only ESP and AH support ESN feature. */ if ((p->id.proto !=IPPROTO_ESP ) && (p->id.proto !=IPPROTO_AH ))
PATCH 231/410 ARM: mvebu: Fix broken PL310_ERRATA_753970 selects
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ulf Magnusson <[email protected]>
commit 8aa36a8dcde3183d84db7b0d622ffddcebb61077 upstream.
The MACH_ARMADA_375 and MACH_ARMADA_38X boards select ARM_ERRATA_753970, but it was renamed to PL310_ERRATA_753970 by commit fa0ce4035d48 ("ARM:
7162/1: errata: tidy up Kconfig options for PL310 errata workarounds").
Fix the selects to use the new name.
Discovered with the
https://github.com/ulfalizer/Kconfiglib/blob/master/examples/list_undefined.py
script.
PL310 errata workarounds"
--- arch/arm/mach-mvebu/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-mvebu/Kconfig +2 -2
@@ -33,7 +33,7 @@ config MACH_ARMADA_370 config MACH_ARMADA_375 bool "Marvell Armada 375 boards" if ARCH_MULTI_V7 select ARM_ERRATA_720789 - select ARM_ERRATA_753970 + select PL310_ERRATA_753970 select ARM_GIC select ARMADA_375_CLK select HAVE_ARM_SCU
@@ -48,7 +48,7 @@ config MACH_ARMADA_375 config MACH_ARMADA_38X bool "Marvell Armada 380/385 boards" if ARCH_MULTI_V7 select ARM_ERRATA_720789 - select ARM_ERRATA_753970 + select PL310_ERRATA_753970 select ARM_GIC select ARMADA_38X_CLK select HAVE_ARM_SCU
PATCH 232/410 ALSA: hda/realtek: PCI quirk for Fujitsu U7x7
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan-Marek Glogowski <[email protected]>
commit fdcc968a3b290407bcba9d4c90e2fba6d8d928f1 upstream.
These laptops have a combined jack to attach headsets, the U727 on the left, the U757 on the right, but a headsets microphone doesn't work. Using hdajacksensetest I found that pin 0x19 changed the present state when plugging the headset, in addition to 0x21, but didn't have the correct configuration (shown as "Not connected").
So this sets the configuration to the same values as the headphone pin 0x21 except for the device type microphone, which makes it work correctly. With the patch the configured pins for U727 are
Pin 0x12 (Internal Mic, Mobile-In): present = No Pin 0x14 (Internal Speaker): present = No Pin 0x19 (Black Mic, Left side): present = No Pin 0x1d (Internal Aux): present = No
Pin 0x21 (Black Headphone, Left side): present = No
--- sound/pci/hda/patch_realtek.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
sound/pci/hda/patch_realtek.c +19 -0
@@ -3289,6 +3289,19 @@ static void alc269_fixup_pincfg_no_hp_to spec->parse_flags =HDA_PINCFG_NO_HP_FIXUP ; } +static void alc269_fixup_pincfg_U7x7_headset_mic (struct hda_codec *codec, +const struct hda_fixup *fix, +int action) +{ +unsigned int cfg_headphone =snd_hda_codec_get_pincfg (codec,0x21 ); +unsigned int cfg_headset_mic =snd_hda_codec_get_pincfg (codec,0x19 ); + +if (cfg_headphone && cfg_headset_mic ==0x411111f0 ) +snd_hda_codec_set_pincfg (codec,0x19 , + (cfg_headphone & ~AC_DEFCFG_DEVICE ) | + (AC_JACK_MIC_IN <<AC_DEFCFG_DEVICE_SHIFT )); +} +static void alc269_fixup_hweq (struct hda_codec *codec,const struct hda_fixup *fix,int action) {
@@ -4292,6 +4305,7 @@ enum {ALC269_FIXUP_LIFEBOOK_EXTMIC ,ALC269_FIXUP_LIFEBOOK_HP_PIN ,ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT , + ALC255_FIXUP_LIFEBOOK_U7x7_HEADSET_MIC,ALC269_FIXUP_AMIC ,ALC269_FIXUP_DMIC , ALC269VB_FIXUP_AMIC,
@@ -4456,6 +4470,10 @@ static const struct hda_fixup alc269_fix .type = HDA_FIXUP_FUNC, .v.func = alc269_fixup_pincfg_no_hp_to_lineout, }, + [ALC255_FIXUP_LIFEBOOK_U7x7_HEADSET_MIC] = { + .type = HDA_FIXUP_FUNC, + .v.func = alc269_fixup_pincfg_U7x7_headset_mic, + }, [ALC269_FIXUP_AMIC] = { .type = HDA_FIXUP_PINS, .v.pins = (const struct hda_pintbl []) {
@@ -4996,6 +5014,7 @@ static const struct snd_pci_quirk alc269SND_PCI_QUIRK (0x10cf ,0x159f ,"Lifebook E780" ,ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT ),SND_PCI_QUIRK (0x10cf ,0x15dc ,"Lifebook T731" ,ALC269_FIXUP_LIFEBOOK_HP_PIN ),SND_PCI_QUIRK (0x10cf ,0x1757 ,"Lifebook E752" ,ALC269_FIXUP_LIFEBOOK_HP_PIN ), +SND_PCI_QUIRK (0x10cf ,0x1629 ,"Lifebook U7x7" , ALC255_FIXUP_LIFEBOOK_U7x7_HEADSET_MIC),SND_PCI_QUIRK (0x10cf ,0x1845 ,"Lifebook U904" ,ALC269_FIXUP_LIFEBOOK_EXTMIC ),SND_PCI_QUIRK (0x17aa ,0x20f2 ,"Thinkpad SL410/510" ,ALC269_FIXUP_SKU_IGNORE ), SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
PATCH 233/410 net: fix race on decreasing number of TX queues
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
commit ac5b70198adc25c73fba28de4f78adcee8f6be0b upstream.
netif_set_real_num_tx_queues() can be called when netdev is up. That usually happens when user requests change of number of channels/rings with ethtool -L. The procedure for changing the number of queues involves resetting the qdiscs and setting dev->num_tx_queues to the new value. When the new value is lower than the old one, extra care has to be taken to ensure ordering of accesses to the number of queues vs qdisc reset.
Currently the queues are reset before new dev->num_tx_queues is assigned, leaving a window of time where packets can be enqueued onto the queues going down, leading to a likely crash in the drivers, since most drivers don't check if TX skbs are assigned to an active queue.
--- net/core/dev.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
net/core/dev.c +9 -2
@@ -2084,8 +2084,11 @@ EXPORT_SYMBOL(netif_set_xps_queue);*/ int netif_set_real_num_tx_queues (struct net_device *dev,unsigned int txq) { +bool disabling;int rc; + disabling = txq < dev->real_num_tx_queues; +if (txq <1 || txq > dev->num_tx_queues)return -EINVAL ;
@@ -2101,15 +2104,19 @@ int netif_set_real_num_tx_queues(structif (dev->num_tc)netif_setup_tc (dev, txq); -if (txq < dev->real_num_tx_queues) { + dev->real_num_tx_queues = txq; + +if (disabling) { +synchronize_net ();qdisc_reset_all_tx_gt (dev, txq);#ifdef CONFIG_XPS netif_reset_xps_queues_gt (dev, txq);#endif } + }else { + dev->real_num_tx_queues = txq; } - dev->real_num_tx_queues = txq;return 0 ; }EXPORT_SYMBOL (netif_set_real_num_tx_queues);
PATCH 234/410 netfilter: drop outermost socket lock in getsockopt()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
commit 01ea306f2ac2baff98d472da719193e738759d93 upstream.
The Syzbot reported a possible deadlock in the netfilter area caused by rtnl lock, xt lock and socket lock being acquired with a different order on different code paths, leading to the following backtrace:
======================================================
WARNING: possible circular locking dependency detected 4.15.0+ #301 Not tainted
------------------------------------------------------
syzkaller233489/4179 is trying to acquire lock:
(rtnl_mutex){+.+.}, at: [<0000000048e996fd>] rtnl_lock+0x17/0x20net/core/rtnetlink.c:74
but task is already holding lock:
(&xt[i].mutex){+.+.}, at: [<00000000328553a2>]xt_find_table_lock+0x3e/0x3e0 net/netfilter/x_tables.c:1041
which lock already depends on the new lock.
===
Since commit 3f34cfae1230 ("netfilter: on sockopt() acquire sock lock only in the required scope"), we already acquire the socket lock in the innermost scope, where needed. In such commit I forgot to remove the outer-most socket lock from the getsockopt() path, this commit addresses the issues dropping it now.
v1 -> v2: fix bad subj, added relavant 'fixes' tag
--- net/ipv4/ip_sockglue.c | 7 +------ net/ipv6/ipv6_sockglue.c | 10 ++-------- 2 files changed, 3 insertions(+), 14 deletions(-)
net/ipv4/ip_sockglue.c +1 -6
@@ -1391,10 +1391,7 @@ int ip_getsockopt(struct sock *sk, int lif (get_user (len, optlen))return -EFAULT ; -lock_sock (sk); - err =nf_getsockopt (sk,PF_INET , optname, optval, - &len); -release_sock (sk); + err =nf_getsockopt (sk,PF_INET , optname, optval, &len);if (err >=0 ) err =put_user (len, optlen);return err;
@@ -1426,9 +1423,7 @@ int compat_ip_getsockopt(struct sock *skif (get_user (len, optlen))return -EFAULT ; -lock_sock (sk); err =compat_nf_getsockopt (sk,PF_INET , optname, optval, &len); -release_sock (sk);if (err >=0 ) err =put_user (len, optlen);return err;
net/ipv6/ipv6_sockglue.c +2 -8
@@ -1309,10 +1309,7 @@ int ipv6_getsockopt(struct sock *sk, intif (get_user (len, optlen))return -EFAULT ; -lock_sock (sk); - err =nf_getsockopt (sk,PF_INET6 , optname, optval, - &len); -release_sock (sk); + err =nf_getsockopt (sk,PF_INET6 , optname, optval, &len);if (err >=0 ) err =put_user (len, optlen); }
@@ -1352,10 +1349,7 @@ int compat_ipv6_getsockopt(struct sock *if (get_user (len, optlen))return -EFAULT ; -lock_sock (sk); - err =compat_nf_getsockopt (sk,PF_INET6 , - optname, optval, &len); -release_sock (sk); + err =compat_nf_getsockopt (sk,PF_INET6 , optname, optval, &len);if (err >=0 ) err =put_user (len, optlen); }
PATCH 235/410 netfilter: ipt_CLUSTERIP: fix a refcount bug in clusterip_config_find_get()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Cong Wang <[email protected]>
commit db93a3632b0f8773a3899e04a3a3e0aa7a26eb46 upstream.
In clusterip_config_find_get() we hold RCU read lock so it could run concurrently with clusterip_config_entry_put(), as a result, the refcnt could go back to 1 from 0, which leads to a double list_del()... Just replace refcount_inc() with refcount_inc_not_zero(), as for c->refcount.
--- net/ipv4/netfilter/ipt_CLUSTERIP.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/ipv4/netfilter/ipt_CLUSTERIP.c +6 -2
@@ -147,8 +147,12 @@ clusterip_config_find_get(struct net *neif (c) {if (unlikely (!atomic_inc_not_zero (&c->refcount))) c =NULL ; -else if (entry) -atomic_inc (&c->entries); +else if (entry) { +if (unlikely (!atomic_inc_not_zero (&c->entries))) { +clusterip_config_put (c); + c =NULL ; + } + } }rcu_read_unlock_bh ();
PATCH 236/410 netfilter: x_tables: fix missing timer initialization in xt_LED
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
commit 10414014bc085aac9f787a5890b33b5605fbcfc4 upstream.
syzbot reported that xt_LED may try to use the ledinternal->timer without previously initializing it:
------------[ cut here ]------------
kernel BUG at kernel/time/timer.c:958!
invalid opcode: 0000 [#1] SMP KASAN
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in:
CPU: 1 PID: 1826 Comm: kworker/1:2 Not tainted 4.15.0+ #306
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Workqueue: ipv6_addrconf addrconf_dad_work
RIP: 0010:__mod_timer kernel/time/timer.c:958 [inline]
RIP: 0010:mod_timer+0x7d6/0x13c0 kernel/time/timer.c:1102
RSP: 0018:ffff8801d24fe9f8 EFLAGS: 00010293
RAX: ffff8801d25246c0 RBX: ffff8801aec6cb50 RCX: ffffffff816052c6
RDX: 0000000000000000 RSI: 00000000fffbd14b RDI: ffff8801aec6cb68
RBP: ffff8801d24fec98 R08: 0000000000000000 R09: 1ffff1003a49fd6c
R10: ffff8801d24feb28 R11: 0000000000000005 R12: dffffc0000000000
R13: ffff8801d24fec70 R14: 00000000fffbd14b R15: ffff8801af608f90
FS: 0000000000000000(0000) GS:ffff8801db500000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00000000206d6fd0 CR3: 0000000006a22001 CR4: 00000000001606e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
led_tg+0x1db/0x2e0 net/netfilter/xt_LED.c:75
ip6t_do_table+0xc2a/0x1a30 net/ipv6/netfilter/ip6_tables.c:365
ip6table_raw_hook+0x65/0x80 net/ipv6/netfilter/ip6table_raw.c:42
nf_hook_entry_hookfn include/linux/netfilter.h:120 [inline]
nf_hook_slow+0xba/0x1a0 net/netfilter/core.c:483
nf_hook.constprop.27+0x3f6/0x830 include/linux/netfilter.h:243
NF_HOOK include/linux/netfilter.h:286 [inline]
ndisc_send_skb+0xa51/0x1370 net/ipv6/ndisc.c:491
ndisc_send_ns+0x38a/0x870 net/ipv6/ndisc.c:633
addrconf_dad_work+0xb9e/0x1320 net/ipv6/addrconf.c:4008
process_one_work+0xbbf/0x1af0 kernel/workqueue.c:2113
worker_thread+0x223/0x1990 kernel/workqueue.c:2247
kthread+0x33c/0x400 kernel/kthread.c:238
ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:429
Code: 85 2a 0b 00 00 4d 8b 3c 24 4d 85 ff 75 9f 4c 8b bd 60 fd ff ff e8 bb
57 10 00 65 ff 0d 94 9a a1 7e e9 d9 fc ff ff e8 aa 57 10 00 <0f> 0b e8 a3
57 10 00 e9 14 fb ff ff e8 99 57 10 00 4c 89 bd 70
RIP: __mod_timer kernel/time/timer.c:958 [inline] RSP: ffff8801d24fe9f8
RIP: mod_timer+0x7d6/0x13c0 kernel/time/timer.c:1102 RSP: ffff8801d24fe9f8
---[ end trace f661ab06f5dd8b3d ]---The ledinternal struct can be shared between several different xt_LED targets, but the related timer is currently initialized only if the first target requires it. Fix it by unconditionally initializing the timer struct.
v1 -> v2: call del_timer_sync() unconditionally, too.
---
net/netfilter/xt_LED.c +6 -6
@@ -139,10 +139,11 @@ static int led_tg_check(const struct xt_ goto exit_alloc; } -/* See if we need to set up a timer */ -if (ledinfo->delay >0 ) -setup_timer (&ledinternal->timer, led_timeout_callback, - (unsigned long )ledinternal); +/* Since the letinternal timer can be shared between multiple targets, +* always set it up, even if the current target does not need it +*/ +setup_timer (&ledinternal->timer, led_timeout_callback, + (unsigned long )ledinternal);list_add_tail (&ledinternal->list, &xt_led_triggers);
@@ -179,8 +180,7 @@ static void led_tg_destroy(const structlist_del (&ledinternal->list); -if (ledinfo->delay >0 ) -del_timer_sync (&ledinternal->timer); +del_timer_sync (&ledinternal->timer);led_trigger_unregister (&ledinternal->netfilter_led_trigger);
PATCH 237/410 netfilter: nat: cope with negative port range
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
commit db57ccf0f2f4624b4c4758379f8165277504fbd7 upstream.
syzbot reported a division by 0 bug in the netfilter nat code:
divide error: 0000 [#1] SMP KASAN
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in: CPU: 1 PID: 4168 Comm: syzkaller034710 Not tainted 4.16.0-rc1+ #309 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:nf_nat_l4proto_unique_tuple+0x291/0x530 net/netfilter/nf_nat_proto_common.c:88 RSP: 0018:ffff8801b2466778 EFLAGS: 00010246 RAX: 000000000000f153 RBX: ffff8801b2466dd8 RCX: ffff8801b2466c7c RDX: 0000000000000000 RSI: ffff8801b2466c58 RDI: ffff8801db5293ac RBP: ffff8801b24667d8 R08: ffff8801b8ba6dc0 R09: ffffffff88af5900 R10: ffff8801b24666f0 R11: 0000000000000000 R12: 000000002990f153 R13: 0000000000000001 R14: 0000000000000000 R15: ffff8801b2466c7c FS: 00000000017e3880(0000) GS:ffff8801db500000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000208fdfe4 CR3: 00000001b5340002 CR4: 00000000001606e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: dccp_unique_tuple+0x40/0x50 net/netfilter/nf_nat_proto_dccp.c:30 get_unique_tuple+0xc28/0x1c10 net/netfilter/nf_nat_core.c:362 nf_nat_setup_info+0x1c2/0xe00 net/netfilter/nf_nat_core.c:406 nf_nat_redirect_ipv6+0x306/0x730 net/netfilter/nf_nat_redirect.c:124 redirect_tg6+0x7f/0xb0 net/netfilter/xt_REDIRECT.c:34 ip6t_do_table+0xc2a/0x1a30 net/ipv6/netfilter/ip6_tables.c:365 ip6table_nat_do_chain+0x65/0x80 net/ipv6/netfilter/ip6table_nat.c:41 nf_nat_ipv6_fn+0x594/0xa80 net/ipv6/netfilter/nf_nat_l3proto_ipv6.c:302 nf_nat_ipv6_local_fn+0x33/0x5d0 net/ipv6/netfilter/nf_nat_l3proto_ipv6.c:407 ip6table_nat_local_fn+0x2c/0x40 net/ipv6/netfilter/ip6table_nat.c:69 nf_hook_entry_hookfn include/linux/netfilter.h:120 [inline] nf_hook_slow+0xba/0x1a0 net/netfilter/core.c:483 nf_hook include/linux/netfilter.h:243 [inline] NF_HOOK include/linux/netfilter.h:286 [inline] ip6_xmit+0x10ec/0x2260 net/ipv6/ip6_output.c:277 inet6_csk_xmit+0x2fc/0x580 net/ipv6/inet6_connection_sock.c:139 dccp_transmit_skb+0x9ac/0x10f0 net/dccp/output.c:142 dccp_connect+0x369/0x670 net/dccp/output.c:564 dccp_v6_connect+0xe17/0x1bf0 net/dccp/ipv6.c:946 __inet_stream_connect+0x2d4/0xf00 net/ipv4/af_inet.c:620 inet_stream_connect+0x58/0xa0 net/ipv4/af_inet.c:684 SYSC_connect+0x213/0x4a0 net/socket.c:1639 SyS_connect+0x24/0x30 net/socket.c:1620 do_syscall_64+0x282/0x940 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x26/0x9b RIP: 0033:0x441c69 RSP: 002b:00007ffe50cc0be8 EFLAGS: 00000217 ORIG_RAX: 000000000000002a RAX: ffffffffffffffda RBX: ffffffffffffffff RCX: 0000000000441c69 RDX: 000000000000001c RSI: 00000000208fdfe4 RDI: 0000000000000003 RBP: 00000000006cc018 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000538 R11: 0000000000000217 R12: 0000000000403590 R13: 0000000000403620 R14: 0000000000000000 R15: 0000000000000000 Code: 48 89 f0 83 e0 07 83 c0 01 38 d0 7c 08 84 d2 0f 85 46 02 00 00 48 8b 45 c8 44 0f b7 20 e8 88 97 04 fd 31 d2 41 0f b7 c4 4c 89 f9 <41> f7 f6 48 c1 e9 03 48 b8 00 00 00 00 00 fc ff df 0f b6 0c 01 RIP: nf_nat_l4proto_unique_tuple+0x291/0x530
net/netfilter/nf_nat_proto_common.c:88 RSP: ffff8801b2466778
The problem is that currently we don't have any check on the configured port range. A port range == -1 triggers the bug, while other negative values may require a very long time to complete the following loop.
This commit addresses the issue swapping the two ends on negative ranges. The check is performed in nf_nat_l4proto_unique_tuple() since the nft nat loads the port values from nft registers at runtime.
v1 -> v2: use the correct 'Fixes' tag
v2 -> v3: update commit message, drop unneeded READ_ONCE()
--- net/netfilter/nf_nat_proto_common.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/netfilter/nf_nat_proto_common.c +5 -2
@@ -41,7 +41,7 @@ void nf_nat_l4proto_unique_tuple(const sconst struct nf_conn *ct, u16 *rover) { - unsigned int range_size, min, i; + unsigned int range_size, min, max, i;__be16 *portptr;u_int16_t off;
@@ -71,7 +71,10 @@ void nf_nat_l4proto_unique_tuple(const s } }else { min =ntohs (range->min_proto.all); - range_size =ntohs (range->max_proto.all) - min +1 ; + max =ntohs (range->max_proto.all); +if (unlikely (max < min)) +swap (max, min); + range_size = max - min +1 ; }if (range->flags &NF_NAT_RANGE_PROTO_RANDOM ) {
PATCH 238/410 powerpc/pseries: Add empty update_numa_cpu_lookup_table() for NUMA=n
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Corentin Labbe <[email protected]>
commit c1e150ceb61e4a585bad156da15c33bfe89f5858 upstream.
When CONFIG_NUMA is not set, the build fails with:
arch/powerpc/platforms/pseries/hotplug-cpu.c:335:4:
error: déclaration implicite de la fonction « update_numa_cpu_lookup_table »
So we have to add update_numa_cpu_lookup_table() as an empty function when CONFIG_NUMA is not set.
--- arch/powerpc/include/asm/topology.h | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/include/asm/topology.h +3 -0
@@ -76,6 +76,9 @@ static inline void sysfs_remove_device_f int nid) { } + +static inline void update_numa_cpu_lookup_table (unsigned int cpu,int node) {} +#endif /* CONFIG_NUMA */ #if defined(CONFIG_NUMA ) && defined(CONFIG_PPC_SPLPAR )
PATCH 239/410 x86/speculation: Add <asm/msr-index.h> dependency
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
commit ea00f301285ea2f07393678cd2b6057878320c9d upstream.
Joe Konno reported a compile failure resulting from using an MSR without inclusion of <asm/msr-index.h>, and while the current code builds fine (by accident) this needs fixing for future patches.
--- arch/x86/include/asm/nospec-branch.h | 1 + 1 file changed, 1 insertion(+)
arch/x86/include/asm/nospec-branch.h +1 -0
@@ -6,6 +6,7 @@#include <asm/alternative.h> #include <asm/alternative-asm.h> #include <asm/cpufeature.h> +#include <asm/msr-index.h> /* * Fill the CPU return stack buffer.
PATCH 240/410 crypto: s5p-sss - Fix kernel Oops in AES-ECB mode
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Kamil Konieczny <[email protected]>
commit c927b080c67e3e97193c81fc1d27f4251bf4e036 upstream.
In AES-ECB mode crypt is done with key only, so any use of IV can cause kernel Oops. Use IV only in AES-CBC and AES-CTR.
--- drivers/crypto/s5p-sss.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/crypto/s5p-sss.c +9 -3
@@ -426,15 +426,21 @@ static void s5p_aes_crypt_start(struct suint32_t aes_control;int err;unsigned long flags; +u8 *iv; aes_control =SSS_AES_KEY_CHANGE_MODE ;if (mode &FLAGS_AES_DECRYPT ) aes_control |=SSS_AES_MODE_DECRYPT ; -if ((mode &FLAGS_AES_MODE_MASK ) ==FLAGS_AES_CBC ) +if ((mode &FLAGS_AES_MODE_MASK ) ==FLAGS_AES_CBC ) { aes_control |=SSS_AES_CHAIN_MODE_CBC ; -else if ((mode &FLAGS_AES_MODE_MASK ) ==FLAGS_AES_CTR ) + iv = req->info; + }else if ((mode &FLAGS_AES_MODE_MASK ) ==FLAGS_AES_CTR ) { aes_control |=SSS_AES_CHAIN_MODE_CTR ; + iv = req->info; + }else { + iv =NULL ;/* AES_ECB */ + }if (dev->ctx->keylen ==AES_KEYSIZE_192 ) aes_control |=SSS_AES_KEY_SIZE_192 ;
@@ -465,7 +471,7 @@ static void s5p_aes_crypt_start(struct s goto outdata_error;SSS_AES_WRITE (dev,AES_CONTROL , aes_control); -s5p_set_aes (dev, dev->ctx->aes_key, req->info, dev->ctx->keylen); +s5p_set_aes (dev, dev->ctx->aes_key, iv, dev->ctx->keylen);s5p_set_dma_indata (dev, req->src);s5p_set_dma_outdata (dev, req->dst);
PATCH 241/410 usbip: keep usbip_device sockfd state in sync with tcp_socket
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Shuah Khan <[email protected]>
commit 009f41aed4b3e11e6dc1e3c07377a10c20f1a5ed upstream.
Keep usbip_device sockfd state in sync with tcp_socket. When tcp_socket is reset to null, reset sockfd to -1 to keep it in sync.
--- drivers/staging/usbip/stub_dev.c | 3 +++ drivers/staging/usbip/vhci_hcd.c | 2 ++ 2 files changed, 5 insertions(+)
drivers/staging/usbip/stub_dev.c +3 -0
@@ -114,6 +114,7 @@ static ssize_t store_sockfd(struct devic goto err; sdev->ud.tcp_socket = socket; + sdev->ud.sockfd = sockfd;spin_unlock_irq (&sdev->ud.lock);
@@ -213,6 +214,7 @@ static void stub_shutdown_connection(strif (ud->tcp_socket) {sockfd_put (ud->tcp_socket); ud->tcp_socket =NULL ; + ud->sockfd =-1 ; }/* 3. free used data */
@@ -307,6 +309,7 @@ static struct stub_device *stub_device_a sdev->ud.status =SDEV_ST_AVAILABLE ;spin_lock_init (&sdev->ud.lock); sdev->ud.tcp_socket =NULL ; + sdev->ud.sockfd =-1 ;INIT_LIST_HEAD (&sdev->priv_init);INIT_LIST_HEAD (&sdev->priv_tx);
drivers/staging/usbip/vhci_hcd.c +2 -0
@@ -786,6 +786,7 @@ static void vhci_shutdown_connection(strif (vdev->ud.tcp_socket) {sockfd_put (vdev->ud.tcp_socket); vdev->ud.tcp_socket =NULL ; + vdev->ud.sockfd =-1 ; }pr_info ("release socket\n" );
@@ -833,6 +834,7 @@ static void vhci_device_reset(struct usbif (ud->tcp_socket) {sockfd_put (ud->tcp_socket); ud->tcp_socket =NULL ; + ud->sockfd =-1 ; } ud->status =VDEV_ST_NULL ;
PATCH 242/410 usb: ldusb: add PIDs for new CASSY devices supported by this driver
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Karsten Koop <[email protected]>
commit 52ad2bd8918158266fc88a05f95429b56b6a33c5 upstream.
This patch adds support for new CASSY devices to the ldusb driver. The PIDs are also added to the ignore list in hid-quirks.
--- drivers/hid/hid-core.c | 3 +++ drivers/hid/hid-ids.h | 3 +++ drivers/usb/misc/ldusb.c | 6 ++++++ 3 files changed, 12 insertions(+)
drivers/hid/hid-core.c +3 -0
@@ -2309,6 +2309,9 @@ static const struct hid_device_id hid_ig { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) }, { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) }, { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERANALYSERCASSY) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CONVERTERCONTROLLERCASSY) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETESTCASSY) }, { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) }, { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) }, { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
drivers/hid/hid-ids.h +3 -0
@@ -582,6 +582,9 @@#define USB_DEVICE_ID_LD_MICROCASSYTIME 0x1033#define USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE 0x1035#define USB_DEVICE_ID_LD_MICROCASSYPH 0x1038 +#define USB_DEVICE_ID_LD_POWERANALYSERCASSY 0x1040 +#define USB_DEVICE_ID_LD_CONVERTERCONTROLLERCASSY 0x1042 +#define USB_DEVICE_ID_LD_MACHINETESTCASSY 0x1043#define USB_DEVICE_ID_LD_JWM 0x1080#define USB_DEVICE_ID_LD_DMMP 0x1081#define USB_DEVICE_ID_LD_UMIP 0x1090
drivers/usb/misc/ldusb.c +6 -0
@@ -46,6 +46,9 @@#define USB_DEVICE_ID_LD_MICROCASSYTIME 0x1033/* USB Product ID of Micro-CASSY Time (reserved) */ #define USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE 0x1035/* USB Product ID of Micro-CASSY Temperature */ #define USB_DEVICE_ID_LD_MICROCASSYPH 0x1038/* USB Product ID of Micro-CASSY pH */ +#define USB_DEVICE_ID_LD_POWERANALYSERCASSY 0x1040/* USB Product ID of Power Analyser CASSY */ +#define USB_DEVICE_ID_LD_CONVERTERCONTROLLERCASSY 0x1042/* USB Product ID of Converter Controller CASSY */ +#define USB_DEVICE_ID_LD_MACHINETESTCASSY 0x1043/* USB Product ID of Machine Test CASSY */ #define USB_DEVICE_ID_LD_JWM 0x1080/* USB Product ID of Joule and Wattmeter */ #define USB_DEVICE_ID_LD_DMMP 0x1081/* USB Product ID of Digital Multimeter P (reserved) */ #define USB_DEVICE_ID_LD_UMIP 0x1090/* USB Product ID of UMI P */
@@ -94,6 +97,9 @@ static const struct usb_device_id ld_usb { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) }, { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) }, { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) }, + { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERANALYSERCASSY) }, + { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CONVERTERCONTROLLERCASSY) }, + { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETESTCASSY) }, { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) }, { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) }, { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
PATCH 243/410 usb: ohci: Proper handling of ed_rm_list to handle race condition between usb_kill_urb() and finish_unlinks()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: AMAN DEEP <[email protected]>
commit 46408ea558df13b110e0866b99624384a33bdeba upstream.
There is a race condition between finish_unlinks->finish_urb() function and usb_kill_urb() in ohci controller case. The finish_urb calls spin_unlock(&ohci->lock) before usb_hcd_giveback_urb() function call, then if during this time, usb_kill_urb is called for another endpoint, then new ed will be added to ed_rm_list at beginning for unlink, and ed_rm_list will point to newly added.
When finish_urb() is completed in finish_unlinks() and ed->td_list becomes empty as in below code (in finish_unlinks() function):
if (list_empty(&ed->td_list)) {
*last = ed->ed_next;
ed->ed_next = NULL;
} else if (ohci->rh_state == OHCI_RH_RUNNING) {
*last = ed->ed_next;
ed->ed_next = NULL;
ed_schedule(ohci, ed);
}The *last = ed->ed_next will make ed_rm_list to point to ed->ed_next and previously added ed by usb_kill_urb will be left unreferenced by ed_rm_list. This causes usb_kill_urb() hang forever waiting for finish_unlink to remove added ed from ed_rm_list.
The main reason for hang in this race condtion is addition and removal of ed from ed_rm_list in the beginning during usb_kill_urb and later last* is modified in finish_unlinks().
As suggested by Alan Stern, the solution for proper handling of ohci->ed_rm_list is to remove ed from the ed_rm_list before finishing any URBs. Then at the end, we can add ed back to the list if necessary.
This properly handle the updated ohci->ed_rm_list in usb_kill_urb().
--- drivers/usb/host/ohci-q.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/usb/host/ohci-q.c +10 -7
@@ -966,6 +966,8 @@ skip_ed:* have modified this list. normally it's just prepending * entries (which we'd ignore), but paranoia won't hurt. */ + *last = ed->ed_next; + ed->ed_next =NULL ; modified =0 ;/* unlink urbs as requested, but rescan the list after
@@ -1024,20 +1026,21 @@ rescan_this: goto rescan_this;/* -* If no TDs are queued, take ED off the ed_rm_list. +* If no TDs are queued, ED is now idle. * Otherwise, if the HC is running, reschedule. -* If not, leave it on the list for further dequeues. +* If the HC isn't running, add ED back to the +* start of the list for later processing. */ if (list_empty (&ed->td_list)) { - *last = ed->ed_next; - ed->ed_next =NULL ; ed->state =ED_IDLE ; }else if (ohci->rh_state ==OHCI_RH_RUNNING ) { - *last = ed->ed_next; - ed->ed_next =NULL ;ed_schedule (ohci, ed); }else { - last = &ed->ed_next; + ed->ed_next = ohci->ed_rm_list; + ohci->ed_rm_list = ed; +/* Don't loop on the same ED */ +if (last == &ohci->ed_rm_list) + last = &ed->ed_next; }if (modified)
PATCH 244/410 Add delay-init quirk for Corsair K70 RGB keyboards
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jack Stocker <[email protected]>
commit 7a1646d922577b5b48c0d222e03831141664bb59 upstream.
Following on from this patch: https://lkml.org/lkml/2017/11/3/516,
Corsair K70 RGB keyboards also require the DELAY_INIT quirk to start correctly at boot.
Device ids found here:
usb 3-3: New USB device found, idVendor=1b1c, idProduct=1b13 usb 3-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3 usb 3-3: Product: Corsair K70 RGB Gaming Keyboard
--- drivers/usb/core/quirks.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/core/quirks.c +3 -0
@@ -222,6 +222,9 @@ static const struct usb_device_id usb_qu { USB_DEVICE(0x1a0a, 0x0200), .driver_info = USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL }, + /* Corsair K70 RGB */ + { USB_DEVICE(0x1b1c, 0x1b13), .driver_info = USB_QUIRK_DELAY_INIT }, + /* Corsair Strafe RGB */ { USB_DEVICE(0x1b1c, 0x1b20), .driver_info = USB_QUIRK_DELAY_INIT },
PATCH 245/410 IB/ipoib: Do not warn if IPoIB debugfs doesn't exist
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Alaa Hleihel <[email protected]>
commit 14fa91e0fef8e4d6feb8b1fa2a807828e0abe815 upstream.
netdev_wait_allrefs() could rebroadcast NETDEV_UNREGISTER event multiple times until all refs are gone, which will result in calling ipoib_delete_debug_files multiple times and printing a warning.
Remove the WARN_ONCE since checks of NULL pointers before calling debugfs_remove are not needed.
--- drivers/infiniband/ulp/ipoib/ipoib_fs.c | 2 -- 1 file changed, 2 deletions(-)
drivers/infiniband/ulp/ipoib/ipoib_fs.c +0 -2
@@ -281,8 +281,6 @@ void ipoib_delete_debug_files(struct net {struct ipoib_dev_priv *priv =netdev_priv (dev); -WARN_ONCE (!priv->mcg_dentry,"null mcg debug file\n" ); -WARN_ONCE (!priv->path_dentry,"null path debug file\n" );debugfs_remove (priv->mcg_dentry);debugfs_remove (priv->path_dentry); priv->mcg_dentry = priv->path_dentry =NULL ;
PATCH 246/410 binder: check for binder_thread allocation failure in binder_poll()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit f88982679f54f75daa5b8eff3da72508f1e7422f upstream.
If the kzalloc() in binder_get_thread() fails, binder_poll() dereferences the resulting NULL pointer.
Fix it by returning POLLERR if the memory allocation failed.
This bug was found by syzkaller using fault injection.
[bwh: Backported to 3.16:
- Drop the binder global lock before returning
- Adjust filename]
---
drivers/staging/android/binder.c +4 -0
@@ -2572,6 +2572,10 @@ static unsigned int binder_poll(struct fbinder_lock (__func__); thread =binder_get_thread (proc); +if (!thread) { +binder_unlock (__func__); +return POLLERR ; + } wait_for_proc_work = thread->transaction_stack ==NULL &&list_empty (&thread->todo) && thread->return_error ==BR_OK ;
PATCH 247/410 binder: replace "%p" with "%pK"
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Todd Kjos <[email protected]>
commit 8ca86f1639ec5890d400fff9211aca22d0a392eb upstream.
The format specifier "%p" can leak kernel addresses. Use "%pK" instead. There were 4 remaining cases in binder.c.
--- drivers/staging/android/binder.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/android/binder.c +4 -4
@@ -1242,7 +1242,7 @@ static void binder_transaction_buffer_reint debug_id = buffer->debug_id;binder_debug (BINDER_DEBUG_TRANSACTION , -"%d buffer release %d, size %zd-%zd, failed at %p\n" , +"%d buffer release %d, size %zd-%zd, failed at %pK\n" , proc->pid, buffer->debug_id, buffer->data_size, buffer->offsets_size, failed_at);
@@ -2059,7 +2059,7 @@ static int binder_thread_write(struct bi } }binder_debug (BINDER_DEBUG_DEAD_BINDER , -"%d:%d BC_DEAD_BINDER_DONE %016llx found %p\n" , +"%d:%d BC_DEAD_BINDER_DONE %016llx found %pK\n" , proc->pid, thread->pid, (u64 )cookie, death);if (death ==NULL ) {
@@ -3162,7 +3162,7 @@ static void print_binder_transaction(str struct binder_transaction *t) { seq_printf(m, - "%s %d: %p from %d:%d to %d:%d code %x flags %x pri %ld r%d", + "%s %d: %pK from %d:%d to %d:%d code %x flags %x pri %ld r%d", prefix, t->debug_id, t, t->from ? t->from->proc->pid : 0, t->from ? t->from->pid : 0,
@@ -3176,7 +3176,7 @@ static void print_binder_transaction(strif (t->buffer->target_node)seq_printf (m," node %d" , t->buffer->target_node->debug_id); -seq_printf (m," size %zd:%zd data %p\n" , +seq_printf (m," size %zd:%zd data %pK\n" , t->buffer->data_size, t->buffer->offsets_size, t->buffer->data); }
PATCH 248/410 staging: android: ashmem: Fix a race condition in pin ioctls
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ben Hutchings <[email protected]>
commit ce8a3a9e76d0193e2e8d74a06d275b3c324ca652 upstream.
ashmem_pin_unpin() reads asma->file and asma->size before taking the ashmem_mutex, so it can race with other operations that modify them.
Build-tested only.
--- drivers/staging/android/ashmem.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
drivers/staging/android/ashmem.c +11 -8
@@ -703,30 +703,32 @@ static int ashmem_pin_unpin(struct ashmesize_t pgstart, pgend;int ret = -EINVAL ; +mutex_lock (&ashmem_mutex); +if (unlikely (!asma->file)) -return -EINVAL ; + goto out_unlock; -if (unlikely (copy_from_user (&pin, p,sizeof (pin)))) -return -EFAULT ; +if (unlikely (copy_from_user (&pin, p,sizeof (pin)))) { + ret = -EFAULT ; + goto out_unlock; + }/* per custom, you can pass zero for len to mean "everything onward" */ if (!pin.len) pin.len =PAGE_ALIGN (asma->size) - pin.offset;if (unlikely ((pin.offset | pin.len) & ~PAGE_MASK )) -return -EINVAL ; + goto out_unlock;if (unlikely (((__u32) -1 ) - pin.offset < pin.len)) -return -EINVAL ; + goto out_unlock;if (unlikely (PAGE_ALIGN (asma->size) < pin.offset + pin.len)) -return -EINVAL ; + goto out_unlock; pgstart = pin.offset /PAGE_SIZE ; pgend = pgstart + (pin.len /PAGE_SIZE ) -1 ; -mutex_lock (&ashmem_mutex); -switch (cmd) {case ASHMEM_PIN : ret =ashmem_pin (asma, pgstart, pgend);
@@ -739,6 +741,7 @@ static int ashmem_pin_unpin(struct ashmebreak ; } +out_unlock:mutex_unlock (&ashmem_mutex);return ret;
PATCH 249/410 staging: android: ashmem: Fix possible deadlock in ashmem_ioctl
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Yisheng Xie <[email protected]>
commit 740a5759bf222332fbb5eda42f89aa25ba38f9b2 upstream.
ashmem_mutex may create a chain of dependencies like:
CPU0 CPU1
mmap syscall ioctl syscall
-> mmap_sem (acquired) -> ashmem_ioctl
-> ashmem_mmap -> ashmem_mutex (acquired)
-> ashmem_mutex (try to acquire) -> copy_from_user
-> mmap_sem (try to acquire)There is a lock odering problem between mmap_sem and ashmem_mutex causing a lockdep splat[1] during a syzcaller test. This patch fixes the problem by move copy_from_user out of ashmem_mutex.
[1] https://www.spinics.net/lists/kernel/msg2733200.html
--- drivers/staging/android/ashmem.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/android/ashmem.c +3 -5
@@ -703,16 +703,14 @@ static int ashmem_pin_unpin(struct ashmesize_t pgstart, pgend;int ret = -EINVAL ; +if (unlikely (copy_from_user (&pin, p,sizeof (pin)))) +return -EFAULT ; +mutex_lock (&ashmem_mutex);if (unlikely (!asma->file)) goto out_unlock; -if (unlikely (copy_from_user (&pin, p,sizeof (pin)))) { - ret = -EFAULT ; - goto out_unlock; - } -/* per custom, you can pass zero for len to mean "everything onward" */ if (!pin.len) pin.len =PAGE_ALIGN (asma->size) - pin.offset;
PATCH 250/410 mm: hide a #warning for COMPILE_TEST
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
commit af27d9403f5b80685b79c88425086edccecaf711 upstream.
We get a warning about some slow configurations in randconfig kernels:
mm/memory.c:83:2: error: #warning Unfortunate NUMA and NUMA Balancing config, growing page-frame for last_cpupid. [-Werror=cpp]
The warning is reasonable by itself, but gets in the way of randconfig build testing, so I'm hiding it whenever CONFIG_COMPILE_TEST is set.
The warning was added in 2013 in commit 75980e97dacc ("mm: fold page->_last_nid into page->flags where possible").
--- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory.c +1 -1
@@ -71,7 +71,7 @@#include "internal.h" -#ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS +#if defined(LAST_CPUPID_NOT_IN_PAGE_FLAGS ) && !defined(CONFIG_COMPILE_TEST )#warning Unfortunate NUMA and NUMA Balancing config, growing page-frame for last_cpupid.#endif
PATCH 251/410 NFC: llcp: Limit size of SDP URI
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Kees Cook <[email protected]>
commit fe9c842695e26d8116b61b80bfb905356f07834b upstream.
The tlv_len is u8, so we need to limit the size of the SDP URI. Enforce this both in the NLA policy and in the code that performs the allocation and copy, to avoid writing past the end of the allocated buffer.
--- net/nfc/llcp_commands.c | 4 ++++ net/nfc/netlink.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)
net/nfc/llcp_commands.c +4 -0
@@ -149,6 +149,10 @@ struct nfc_llcp_sdp_tlv *nfc_llcp_build_pr_debug ("uri: %s, len: %zu\n" , uri, uri_len); +/* sdreq->tlv_len is u8, takes uri_len, + 3 for header, + 1 for NULL */ +if (WARN_ON_ONCE (uri_len >U8_MAX -4 )) +return NULL ; + sdreq =kzalloc (sizeof (struct nfc_llcp_sdp_tlv ),GFP_KERNEL );if (sdreq ==NULL )return NULL ;
net/nfc/netlink.c +2 -1
@@ -60,7 +60,8 @@ static const struct nla_policy nfc_genl_ };static const struct nla_policy nfc_sdp_genl_policy[NFC_SDP_ATTR_MAX +1 ] = { - [NFC_SDP_ATTR_URI ] = { .type =NLA_STRING }, + [NFC_SDP_ATTR_URI ] = { .type =NLA_STRING , + .len =U8_MAX -4 }, [NFC_SDP_ATTR_SAP ] = { .type =NLA_U8 }, };
PATCH 252/410 dn_getsockoptdecnet: move nf_{get/set}sockopt outside sock lock
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
commit dfec091439bb2acf763497cfc58f2bdfc67c56b7 upstream.
After commit 3f34cfae1238 ("netfilter: on sockopt() acquire sock lock only in the required scope"), the caller of nf_{get/set}sockopt() must not hold any lock, but, in such changeset, I forgot to cope with DECnet.
This commit addresses the issue moving the nf call outside the lock, in the dn_{get,set}sockopt() with the same schema currently used by ipv4 and ipv6. Also moves the unhandled sockopts of the end of the main switch statements, to improve code readability.
--- net/decnet/af_decnet.c | 62 ++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 29 deletions(-)
net/decnet/af_decnet.c +33 -29
@@ -1336,6 +1336,12 @@ static int dn_setsockopt(struct socket *lock_sock (sk); err =__dn_setsockopt (sock, level, optname, optval, optlen,0 );release_sock (sk); +#ifdef CONFIG_NETFILTER +/* we need to exclude all possible ENOPROTOOPTs except default case */ +if (err == -ENOPROTOOPT && optname !=DSO_LINKINFO && + optname !=DSO_STREAM && optname !=DSO_SEQPACKET ) + err =nf_setsockopt (sk, PF_DECnet, optname, optval, optlen); +#endif return err; }
@@ -1443,15 +1449,6 @@ static int __dn_setsockopt(struct socketdn_nsp_send_disc (sk,0x38 ,0 , sk->sk_allocation);break ; -default : -#ifdef CONFIG_NETFILTER -return nf_setsockopt (sk, PF_DECnet, optname, optval, optlen); -#endif -case DSO_LINKINFO : -case DSO_STREAM : -case DSO_SEQPACKET : -return -ENOPROTOOPT ; -case DSO_MAXWINDOW :if (optlen !=sizeof (unsigned long ))return -EINVAL ;
@@ -1499,6 +1496,12 @@ static int __dn_setsockopt(struct socketreturn -EINVAL ; scp->info_loc = u.info;break ; + +case DSO_LINKINFO : +case DSO_STREAM : +case DSO_SEQPACKET : +default : +return -ENOPROTOOPT ; }return 0 ;
@@ -1512,6 +1515,20 @@ static int dn_getsockopt(struct socket *lock_sock (sk); err =__dn_getsockopt (sock, level, optname, optval, optlen,0 );release_sock (sk); +#ifdef CONFIG_NETFILTER +if (err == -ENOPROTOOPT && optname !=DSO_STREAM && + optname !=DSO_SEQPACKET && optname !=DSO_CONACCEPT && + optname !=DSO_CONREJECT ) { +int len; + +if (get_user (len, optlen)) +return -EFAULT ; + + err =nf_getsockopt (sk, PF_DECnet, optname, optval, &len); +if (err >=0 ) + err =put_user (len, optlen); + } +#endif return err; }
@@ -1577,26 +1594,6 @@ static int __dn_getsockopt(struct socket r_data = &link;break ; -default : -#ifdef CONFIG_NETFILTER - { -int ret, len; - -if (get_user (len, optlen)) -return -EFAULT ; - - ret =nf_getsockopt (sk, PF_DECnet, optname, optval, &len); -if (ret >=0 ) - ret =put_user (len, optlen); -return ret; - } -#endif -case DSO_STREAM : -case DSO_SEQPACKET : -case DSO_CONACCEPT : -case DSO_CONREJECT : -return -ENOPROTOOPT ; -case DSO_MAXWINDOW :if (r_len >sizeof (unsigned long )) r_len =sizeof (unsigned long );
@@ -1628,6 +1625,13 @@ static int __dn_getsockopt(struct socket r_len =sizeof (unsigned char ); r_data = &scp->info_rem;break ; + +case DSO_STREAM : +case DSO_SEQPACKET : +case DSO_CONACCEPT : +case DSO_CONREJECT : +default : +return -ENOPROTOOPT ; }if (r_data) {
PATCH 253/410 udplite: fix partial checksum initialization
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Kodanev <[email protected]>
commit 15f35d49c93f4fa9875235e7bf3e3783d2dd7a1b upstream.
Since UDP-Lite is always using checksum, the following path is triggered when calculating pseudo header for it:
udp4_csum_init() or udp6_csum_init()
skb_checksum_init_zero_check()
__skb_checksum_validate_complete()
The problem can appear if skb->len is less than CHECKSUM_BREAK. In this particular case __skb_checksum_validate_complete() also invokes __skb_checksum_complete(skb). If UDP-Lite is using partial checksum that covers only part of a packet, the function will return bad checksum and the packet will be dropped.
It can be fixed if we skip skb_checksum_init_zero_check() and only set the required pseudo header checksum for UDP-Lite with partial checksum before udp4_csum_init()/udp6_csum_init() functions return.
--- include/net/udplite.h | 1 + net/ipv4/udp.c | 5 +++++ net/ipv6/ip6_checksum.c | 5 +++++ 3 files changed, 11 insertions(+)
include/net/udplite.h +1 -0
@@ -61,6 +61,7 @@ static inline int udplite_checksum_init(UDP_SKB_CB (skb)->cscov = cscov;if (skb->ip_summed ==CHECKSUM_COMPLETE ) skb->ip_summed =CHECKSUM_NONE ; + skb->csum_valid =0 ; }return 0 ;
net/ipv4/udp.c +5 -0
@@ -1729,6 +1729,11 @@ static inline int udp4_csum_init(struct err =udplite_checksum_init (skb, uh);if (err)return err; + +if (UDP_SKB_CB (skb)->partial_cov) { + skb->csum =inet_compute_pseudo (skb, proto); +return 0 ; + } } return skb_checksum_init_zero_check(skb, proto, uh->check,
net/ipv6/ip6_checksum.c +5 -0
@@ -73,6 +73,11 @@ int udp6_csum_init(struct sk_buff *skb, err =udplite_checksum_init (skb, uh);if (err)return err; + +if (UDP_SKB_CB (skb)->partial_cov) { + skb->csum =ip6_compute_pseudo (skb, proto); +return 0 ; + } }/* To support RFC 6936 (allow zero checksum in UDP/IPV6 for tunnels)
PATCH 254/410 workqueue: Allow retrieval of current task's work struct
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Wunner <[email protected]>
commit 27d4ee03078aba88c5e07dcc4917e8d01d046f38 upstream.
Introduce a helper to retrieve the current task's work struct if it is a workqueue worker.
This allows us to fix a long-standing deadlock in several DRM drivers wherein the ->runtime_suspend callback waits for a specific worker to finish and that worker in turn calls a function which waits for runtime suspend to finish. That function is invoked from multiple call sites and waiting for runtime suspend to finish is the correct thing to do except if it's executing in the context of the worker.
--- include/linux/workqueue.h | 1 + kernel/workqueue.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)
include/linux/workqueue.h +1 -0
@@ -455,6 +455,7 @@ extern bool cancel_delayed_work_sync(strextern void workqueue_set_max_active (struct workqueue_struct *wq,int max_active); +extern struct work_struct *current_work (void );extern bool current_is_workqueue_rescuer (void );extern bool workqueue_congested (int cpu,struct workqueue_struct *wq);extern unsigned int work_busy (struct work_struct *work);
kernel/workqueue.c +16 -0
@@ -4369,6 +4369,22 @@ void workqueue_set_max_active(struct worEXPORT_SYMBOL_GPL (workqueue_set_max_active);/** +* current_work - retrieve %current task's work struct +* +* Determine if %current task is a workqueue worker and what it's working on. +* Useful to find out the context that the %current task is running in. +* +* Return: work struct if %current task is a workqueue worker, %NULL otherwise. +*/ +struct work_struct *current_work (void ) +{ +struct worker *worker =current_wq_worker (); + +return worker ? worker->current_work :NULL ; +} +EXPORT_SYMBOL (current_work); + +/** * current_is_workqueue_rescuer - is %current workqueue rescuer? * * Determine whether %current is a workqueue rescuer. Can be used from
PATCH 255/410 drm: Allow determining if current task is output poll worker
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Wunner <[email protected]>
commit 25c058ccaf2ebbc3e250ec1e199e161f91fe27d4 upstream.
Introduce a helper to determine if the current task is an output poll worker.
This allows us to fix a long-standing deadlock in several DRM drivers wherein the ->runtime_suspend callback waits for the output poll worker to finish and the worker in turn calls a ->detect callback which waits for runtime suspend to finish. The ->detect callback is invoked from multiple call sites and waiting for runtime suspend to finish is the correct thing to do except if it's executing in the context of the worker.
v2: Expand kerneldoc to specifically mention deadlock between
output poll worker and autosuspend worker as use case. (Lyude)
--- drivers/gpu/drm/drm_probe_helper.c | 20 ++++++++++++++++++++ include/drm/drm_crtc_helper.h | 1 + 2 files changed, 21 insertions(+)
drivers/gpu/drm/drm_probe_helper.c +20 -0
@@ -303,6 +303,26 @@ static void output_poll_execute(struct w }/** +* drm_kms_helper_is_poll_worker - is %current task an output poll worker? +* +* Determine if %current task is an output poll worker. This can be used +* to select distinct code paths for output polling versus other contexts. +* +* One use case is to avoid a deadlock between the output poll worker and +* the autosuspend worker wherein the latter waits for polling to finish +* upon calling drm_kms_helper_poll_disable(), while the former waits for +* runtime suspend to finish upon calling pm_runtime_get_sync() in a +* connector ->detect hook. +*/ +bool drm_kms_helper_is_poll_worker (void ) +{ +struct work_struct *work =current_work (); + +return work && work->func == output_poll_execute; +} +EXPORT_SYMBOL (drm_kms_helper_is_poll_worker); + +/** * drm_kms_helper_poll_disable - disable output polling * @dev: drm_device *
include/drm/drm_crtc_helper.h +1 -0
@@ -176,5 +176,6 @@ extern void drm_kms_helper_hotplug_eventextern void drm_kms_helper_poll_disable (struct drm_device *dev);extern void drm_kms_helper_poll_enable (struct drm_device *dev); +bool drm_kms_helper_is_poll_worker (void );#endif
PATCH 256/410 drm/nouveau: Fix deadlock on runtime suspend
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Wunner <[email protected]>
commit d61a5c1063515e855bedb1b81e20e50b0ac3541e upstream.
nouveau's ->runtime_suspend hook calls drm_kms_helper_poll_disable(), which waits for the output poll worker to finish if it's running.
The output poll worker meanwhile calls pm_runtime_get_sync() in nouveau_connector_detect() which waits for the ongoing suspend to finish, causing a deadlock.
Fix by not acquiring a runtime PM ref if nouveau_connector_detect() is called in the output poll worker's context. This is safe because the poll worker is only enabled while runtime active and we know that ->runtime_suspend waits for it to finish.
Other contexts calling nouveau_connector_detect() do require a runtime PM ref, these comprise:
status_store() drm sysfs interface
->fill_modes drm callback
drm_fb_helper_probe_connector_modes()
drm_mode_getconnector()
nouveau_connector_hotplug()
nouveau_display_hpd_work()
nv17_tv_set_property()
Stack trace for posterity:
INFO: task kworker/0:1:58 blocked for more than 120 seconds. Workqueue: events output_poll_execute [drm_kms_helper] Call Trace: schedule+0x28/0x80 rpm_resume+0x107/0x6e0 __pm_runtime_resume+0x47/0x70 nouveau_connector_detect+0x7e/0x4a0 [nouveau] nouveau_connector_detect_lvds+0x132/0x180 [nouveau] drm_helper_probe_detect_ctx+0x85/0xd0 [drm_kms_helper] output_poll_execute+0x11e/0x1c0 [drm_kms_helper] process_one_work+0x184/0x380 worker_thread+0x2e/0x390 INFO: task kworker/0:2:252 blocked for more than 120 seconds. Workqueue: pm pm_runtime_work Call Trace: schedule+0x28/0x80 schedule_timeout+0x1e3/0x370 wait_for_completion+0x123/0x190 flush_work+0x142/0x1c0 nouveau_pmops_runtime_suspend+0x7e/0xd0 [nouveau] pci_pm_runtime_suspend+0x5c/0x180 vga_switcheroo_runtime_suspend+0x1e/0xa0 __rpm_callback+0xc1/0x200 rpm_callback+0x1f/0x70 rpm_suspend+0x13c/0x640 pm_runtime_work+0x6e/0x90 process_one_work+0x184/0x380 worker_thread+0x2e/0x390
Bugzilla: https://bugs.archlinux.org/task/53497
Bugzilla: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=870523
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=70388#c33
--- drivers/gpu/drm/nouveau/nouveau_connector.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/gpu/drm/nouveau/nouveau_connector.c +13 -5
@@ -256,9 +256,15 @@ nouveau_connector_detect(struct drm_conn nv_connector->edid =NULL ; } - ret =pm_runtime_get_sync (connector->dev->dev); -if (ret <0 && ret != -EACCES ) -return conn_status; +/* Outputs are only polled while runtime active, so acquiring a +* runtime PM ref here is unnecessary (and would deadlock upon +* runtime suspend because it waits for polling to finish). +*/ +if (!drm_kms_helper_is_poll_worker ()) { + ret =pm_runtime_get_sync (connector->dev->dev); +if (ret <0 && ret != -EACCES ) +return conn_status; + } nv_encoder =nouveau_connector_ddc_detect (connector);if (nv_encoder && (i2c = nv_encoder->i2c) !=NULL ) {
@@ -326,8 +332,10 @@ detect_analog: out: -pm_runtime_mark_last_busy (connector->dev->dev); -pm_runtime_put_autosuspend (connector->dev->dev); +if (!drm_kms_helper_is_poll_worker ()) { +pm_runtime_mark_last_busy (connector->dev->dev); +pm_runtime_put_autosuspend (connector->dev->dev); + }return conn_status; }
PATCH 257/410 drm/radeon: Fix deadlock on runtime suspend
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Wunner <[email protected]>
commit 15734feff2bdac24aa3266c437cffa42851990e3 upstream.
radeon's ->runtime_suspend hook calls drm_kms_helper_poll_disable(), which waits for the output poll worker to finish if it's running.
The output poll worker meanwhile calls pm_runtime_get_sync() in radeon's ->detect hooks, which waits for the ongoing suspend to finish, causing a deadlock.
Fix by not acquiring a runtime PM ref if the ->detect hooks are called in the output poll worker's context. This is safe because the poll worker is only enabled while runtime active and we know that ->runtime_suspend waits for it to finish.
Stack trace for posterity:
INFO: task kworker/0:3:31847 blocked for more than 120 seconds Workqueue: events output_poll_execute [drm_kms_helper] Call Trace: schedule+0x3c/0x90 rpm_resume+0x1e2/0x690 __pm_runtime_resume+0x3f/0x60 radeon_lvds_detect+0x39/0xf0 [radeon] output_poll_execute+0xda/0x1e0 [drm_kms_helper] process_one_work+0x14b/0x440 worker_thread+0x48/0x4a0 INFO: task kworker/2:0:10493 blocked for more than 120 seconds. Workqueue: pm pm_runtime_work Call Trace: schedule+0x3c/0x90 schedule_timeout+0x1b3/0x240 wait_for_common+0xc2/0x180 wait_for_completion+0x1d/0x20 flush_work+0xfc/0x1a0 __cancel_work_timer+0xa5/0x1d0 cancel_delayed_work_sync+0x13/0x20 drm_kms_helper_poll_disable+0x1f/0x30 [drm_kms_helper] radeon_pmops_runtime_suspend+0x3d/0xa0 [radeon] pci_pm_runtime_suspend+0x61/0x1a0 vga_switcheroo_runtime_suspend+0x21/0x70 __rpm_callback+0x32/0x70 rpm_callback+0x24/0x80 rpm_suspend+0x12b/0x640 pm_runtime_work+0x6f/0xb0 process_one_work+0x14b/0x440 worker_thread+0x48/0x4a0
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=94147
--- drivers/gpu/drm/radeon/radeon_connectors.c | 74 ++++++++++++++-------- 1 file changed, 49 insertions(+), 25 deletions(-)
drivers/gpu/drm/radeon/radeon_connectors.c +49 -25
@@ -707,9 +707,11 @@ radeon_lvds_detect(struct drm_connectorenum drm_connector_status ret = connector_status_disconnected;int r; - r =pm_runtime_get_sync (connector->dev->dev); -if (r <0 ) -return connector_status_disconnected; +if (!drm_kms_helper_is_poll_worker ()) { + r =pm_runtime_get_sync (connector->dev->dev); +if (r <0 ) +return connector_status_disconnected; + }if (encoder) {struct radeon_encoder *radeon_encoder =to_radeon_encoder (encoder);
@@ -739,8 +741,12 @@ radeon_lvds_detect(struct drm_connector/* check acpi lid status ??? */ radeon_connector_update_scratch_regs (connector, ret); -pm_runtime_mark_last_busy (connector->dev->dev); -pm_runtime_put_autosuspend (connector->dev->dev); + +if (!drm_kms_helper_is_poll_worker ()) { +pm_runtime_mark_last_busy (connector->dev->dev); +pm_runtime_put_autosuspend (connector->dev->dev); + } +return ret; }
@@ -842,9 +848,11 @@ radeon_vga_detect(struct drm_connector *enum drm_connector_status ret = connector_status_disconnected;int r; - r =pm_runtime_get_sync (connector->dev->dev); -if (r <0 ) -return connector_status_disconnected; +if (!drm_kms_helper_is_poll_worker ()) { + r =pm_runtime_get_sync (connector->dev->dev); +if (r <0 ) +return connector_status_disconnected; + } encoder =radeon_best_single_encoder (connector);if (!encoder)
@@ -913,8 +921,10 @@ radeon_vga_detect(struct drm_connector *radeon_connector_update_scratch_regs (connector, ret); out: -pm_runtime_mark_last_busy (connector->dev->dev); -pm_runtime_put_autosuspend (connector->dev->dev); +if (!drm_kms_helper_is_poll_worker ()) { +pm_runtime_mark_last_busy (connector->dev->dev); +pm_runtime_put_autosuspend (connector->dev->dev); + }return ret; }
@@ -977,9 +987,11 @@ radeon_tv_detect(struct drm_connector *cif (!radeon_connector->dac_load_detect)return ret; - r =pm_runtime_get_sync (connector->dev->dev); -if (r <0 ) -return connector_status_disconnected; +if (!drm_kms_helper_is_poll_worker ()) { + r =pm_runtime_get_sync (connector->dev->dev); +if (r <0 ) +return connector_status_disconnected; + } encoder =radeon_best_single_encoder (connector);if (!encoder)
@@ -991,8 +1003,12 @@ radeon_tv_detect(struct drm_connector *cif (ret == connector_status_connected) ret =radeon_connector_analog_encoder_conflict_solve (connector, encoder, ret, false);radeon_connector_update_scratch_regs (connector, ret); -pm_runtime_mark_last_busy (connector->dev->dev); -pm_runtime_put_autosuspend (connector->dev->dev); + +if (!drm_kms_helper_is_poll_worker ()) { +pm_runtime_mark_last_busy (connector->dev->dev); +pm_runtime_put_autosuspend (connector->dev->dev); + } +return ret; }
@@ -1064,9 +1080,11 @@ radeon_dvi_detect(struct drm_connector *enum drm_connector_status ret = connector_status_disconnected;bool dret = false, broken_edid = false; - r =pm_runtime_get_sync (connector->dev->dev); -if (r <0 ) -return connector_status_disconnected; +if (!drm_kms_helper_is_poll_worker ()) { + r =pm_runtime_get_sync (connector->dev->dev); +if (r <0 ) +return connector_status_disconnected; + }if (!force &&radeon_check_hpd_status_unchanged (connector)) { ret = connector->status;
@@ -1225,8 +1243,10 @@ out:radeon_connector_update_scratch_regs (connector, ret); exit: -pm_runtime_mark_last_busy (connector->dev->dev); -pm_runtime_put_autosuspend (connector->dev->dev); +if (!drm_kms_helper_is_poll_worker ()) { +pm_runtime_mark_last_busy (connector->dev->dev); +pm_runtime_put_autosuspend (connector->dev->dev); + }return ret; }
@@ -1480,9 +1500,11 @@ radeon_dp_detect(struct drm_connector *cstruct drm_encoder *encoder =radeon_best_single_encoder (connector);int r; - r =pm_runtime_get_sync (connector->dev->dev); -if (r <0 ) -return connector_status_disconnected; +if (!drm_kms_helper_is_poll_worker ()) { + r =pm_runtime_get_sync (connector->dev->dev); +if (r <0 ) +return connector_status_disconnected; + }if (!force &&radeon_check_hpd_status_unchanged (connector)) { ret = connector->status;
@@ -1557,8 +1579,10 @@ radeon_dp_detect(struct drm_connector *cradeon_connector_update_scratch_regs (connector, ret); out: -pm_runtime_mark_last_busy (connector->dev->dev); -pm_runtime_put_autosuspend (connector->dev->dev); +if (!drm_kms_helper_is_poll_worker ()) { +pm_runtime_mark_last_busy (connector->dev->dev); +pm_runtime_put_autosuspend (connector->dev->dev); + }return ret; }
PATCH 258/410 nospec: Allow index argument to have const-qualified type
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Rasmus Villemoes <[email protected]>
commit b98c6a160a057d5686a8c54c79cc6c8c94a7d0c8 upstream.
The last expression in a statement expression need not be a bare variable, quoting gcc docs
The last thing in the compound statement should be an expression followed by a semicolon; the value of this subexpression serves as the value of the entire construct.
and we already use that in e.g. the min/max macros which end with a ternary expression.
This way, we can allow index to have const-qualified type, which will in some cases avoid the need for introducing a local copy of index of non-const qualified type. That, in turn, can prevent readers not familiar with the internals of array_index_nospec from wondering about the seemingly redundant extra variable, and I think that's worthwhile considering how confusing the whole _nospec business is.
The expression _i&_mask has type unsigned long (since that is the type of _mask, and the BUILD_BUG_ONs guarantee that _i will get promoted to that), so in order not to change the type of the whole expression, add a cast back to typeof(_i).
--- include/linux/nospec.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/nospec.h +1 -2
@@ -53,7 +53,6 @@ static inline unsigned long array_index_BUILD_BUG_ON (sizeof (_i) >sizeof (long )); \BUILD_BUG_ON (sizeof (_s) >sizeof (long )); \ \ - _i &= _mask; \ - _i; \ + (typeof (_i)) (_i & _mask); \ })#endif /* _LINUX_NOSPEC_H */
PATCH 259/410 iio: adis_lib: Initialize trigger before requesting interrupt
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Lars-Peter Clausen <[email protected]>
commit f027e0b3a774e10302207e91d304bbf99e3a8b36 upstream.
The adis_probe_trigger() creates a new IIO trigger and requests an interrupt associated with the trigger. The interrupt uses the generic iio_trigger_generic_data_rdy_poll() function as its interrupt handler.
Currently the driver initializes some fields of the trigger structure after the interrupt has been requested. But an interrupt can fire as soon as it has been requested. This opens up a race condition.
iio_trigger_generic_data_rdy_poll() will access the trigger data structure and dereference the ops field. If the ops field is not yet initialized this will result in a NULL pointer deref.
It is not expected that the device generates an interrupt at this point, so typically this issue did not surface unless e.g. due to a hardware misconfiguration (wrong interrupt number, wrong polarity, etc.).
But some newer devices from the ADIS family start to generate periodic interrupts in their power-on reset configuration and unfortunately the interrupt can not be masked in the device. This makes the race condition much more visible and the following crash has been observed occasionally when booting a system using the ADIS16460.
Unable to handle kernel NULL pointer dereference at virtual address 00000008 pgd = c0004000 [00000008] *pgd=00000000 Internal error: Oops: 5 [#1] PREEMPT SMP ARM Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.9.0-04126-gf9739f0-dirty #257 Hardware name: Xilinx Zynq Platform task: ef04f640 task.stack: ef050000 PC is at iio_trigger_notify_done+0x30/0x68 LR is at iio_trigger_generic_data_rdy_poll+0x18/0x20 pc : [<c042d868>] lr : [<c042d924>] psr: 60000193 sp : ef051bb8 ip : 00000000 fp : ef106400 r10: c081d80a r9 : ef3bfa00 r8 : 00000087 r7 : ef051bec r6 : 00000000 r5 : ef3bfa00 r4 : ee92ab00 r3 : 00000000 r2 : 00000000 r1 : 00000000 r0 : ee97e400 Flags: nZCv IRQs off FIQs on Mode SVC_32 ISA ARM Segment none Control: 18c5387d Table: 0000404a DAC: 00000051 Process swapper/0 (pid: 1, stack limit = 0xef050210) [<c042d868>] (iio_trigger_notify_done) from [<c0065b10>] (__handle_irq_event_percpu+0x88/0x118) [<c0065b10>] (__handle_irq_event_percpu) from [<c0065bbc>] (handle_irq_event_percpu+0x1c/0x58) [<c0065bbc>] (handle_irq_event_percpu) from [<c0065c30>] (handle_irq_event+0x38/0x5c) [<c0065c30>] (handle_irq_event) from [<c0068e28>] (handle_level_irq+0xa4/0x130) [<c0068e28>] (handle_level_irq) from [<c0064e74>] (generic_handle_irq+0x24/0x34) [<c0064e74>] (generic_handle_irq) from [<c021ab7c>] (zynq_gpio_irqhandler+0xb8/0x13c) [<c021ab7c>] (zynq_gpio_irqhandler) from [<c0064e74>] (generic_handle_irq+0x24/0x34) [<c0064e74>] (generic_handle_irq) from [<c0065370>] (__handle_domain_irq+0x5c/0xb4) [<c0065370>] (__handle_domain_irq) from [<c000940c>] (gic_handle_irq+0x48/0x8c) [<c000940c>] (gic_handle_irq) from [<c0013e8c>] (__irq_svc+0x6c/0xa8)
To fix this make sure that the trigger is fully initialized before requesting the interrupt.
--- drivers/iio/imu/adis_trigger.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iio/imu/adis_trigger.c +4 -3
@@ -47,6 +47,10 @@ int adis_probe_trigger(struct adis *adisif (adis->trig ==NULL )return -ENOMEM ; + adis->trig->dev.parent = &adis->spi->dev; + adis->trig->ops = &adis_trigger_ops; +iio_trigger_set_drvdata (adis->trig, adis); + ret = request_irq(adis->spi->irq, &iio_trigger_generic_data_rdy_poll, IRQF_TRIGGER_RISING,
@@ -55,9 +59,6 @@ int adis_probe_trigger(struct adis *adisif (ret) goto error_free_trig; - adis->trig->dev.parent = &adis->spi->dev; - adis->trig->ops = &adis_trigger_ops; -iio_trigger_set_drvdata (adis->trig, adis); ret =iio_trigger_register (adis->trig); indio_dev->trig =iio_trigger_get (adis->trig);
PATCH 260/410 iio: buffer: check if a buffer has been set up when poll is called
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Stefan Windfeldt-Prytz <[email protected]>
commit 4cd140bda6494543f1c1b0ccceceaa44b676eef6 upstream.
If no iio buffer has been set up and poll is called return 0. Without this check there will be a null pointer dereference when calling poll on a iio driver without an iio buffer.
--- drivers/iio/industrialio-buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/industrialio-buffer.c +1 -1
@@ -95,7 +95,7 @@ unsigned int iio_buffer_poll(struct filestruct iio_dev *indio_dev = filp->private_data;struct iio_buffer *rb = indio_dev->buffer; -if (!indio_dev->info) +if (!indio_dev->info || rb ==NULL )return 0 ;poll_wait (filp, &rb->pollq, wait);
PATCH 261/410 libata: Apply NOLPM quirk to Crucial MX100 512GB SSDs
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit 9c7be59fc519af9081c46c48f06f2b8fadf55ad8 upstream.
Various people have reported the Crucial MX100 512GB model not working with LPM set to min_power. I've now received a report that it also does not work with the new med_power_with_dipm level.
It does work with medium_power, but that has no measurable power-savings and given the amount of people being bitten by the other levels not working, this commit just disables LPM altogether.
Note all reporters of this have either the 512GB model (max capacity), or are not specifying their SSD's size. So for now this quirk assumes this is a problem with the 512GB model only.
---
drivers/ata/libata-core.c +4 -0
@@ -4224,6 +4224,10 @@ static const struct ata_blacklist_entry { "PIONEER DVD-RW DVR-212D", NULL, ATA_HORKAGE_NOSETXFER }, { "PIONEER DVD-RW DVR-216D", NULL, ATA_HORKAGE_NOSETXFER }, +/* The 512GB version of the MX100 has both queued TRIM and LPM issues */ + { "Crucial_CT512MX100*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | + ATA_HORKAGE_NOLPM, }, + /* devices that don't properly handle queued TRIM commands */ { "Micron_M500_*", NULL, ATA_HORKAGE_NO_NCQ_TRIM, }, { "Crucial_CT*M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM, },
PATCH 262/410 ASoC: rt5651: Fix regcache sync errors on resume
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit 2d30e9494f1ea320aaaad0cff9ddd92c87eac355 upstream.
The ALC5651 does not like multi-write accesses, avoid them. This fixes:
rt5651 i2c-10EC5651:00: Unable to sync registers 0x27-0x28. -121
Errors on resume (and all registers after the registers in the error not being synced).
--- sound/soc/codecs/rt5651.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/codecs/rt5651.c +1 -0
@@ -1732,6 +1732,7 @@ static const struct regmap_config rt5651 .num_reg_defaults = ARRAY_SIZE(rt5651_reg), .ranges = rt5651_ranges, .num_ranges = ARRAY_SIZE(rt5651_ranges), + .use_single_rw = true, };static const struct i2c_device_id rt5651_i2c_id[] = {
PATCH 263/410 cfg80211: fix cfg80211_beacon_dup
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
commit bee92d06157fc39d5d7836a061c7d41289a55797 upstream.
gcc-8 warns about some obviously incorrect code:
net/mac80211/cfg.c: In function 'cfg80211_beacon_dup':net/mac80211/cfg.c:2896:3: error: 'memcpy' source argument is the same as destination [-Werror=restrict]
=46romthe context, I conclude that we want to copy from beacon into new_beacon, as we do in the rest of the function.
--- net/mac80211/cfg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac80211/cfg.c +1 -1
@@ -3054,7 +3054,7 @@ cfg80211_beacon_dup(struct cfg80211_beac }if (beacon->probe_resp_len) { new_beacon->probe_resp_len = beacon->probe_resp_len; - beacon->probe_resp = pos; + new_beacon->probe_resp = pos;memcpy (pos, beacon->probe_resp, beacon->probe_resp_len); pos += beacon->probe_resp_len; }
PATCH 264/410 drm/edid: Add 6 bpc quirk for CPT panel in Asus UX303LA
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Kai-Heng Feng <[email protected]>
commit 06998a756a3865817b87a129a7e5d5bb66dc1ec3 upstream.
Similar to commit e10aec652f31 ("drm/edid: Add 6 bpc quirk for display AEO model 0."), the EDID reports "DFP 1.x compliant TMDS" but it support 6bpc instead of 8 bpc.
Hence, use 6 bpc quirk for this panel.
--- drivers/gpu/drm/drm_edid.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_edid.c +3 -0
@@ -105,6 +105,9 @@ static struct edid_quirk {/* AEO model 0 reports 8 bpc, but is a 6 bpc panel */ { "AEO", 0, EDID_QUIRK_FORCE_6BPC }, +/* CPT panel of Asus UX303LA reports 8 bpc, but is a 6 bpc panel */ + { "CPT", 0x17df, EDID_QUIRK_FORCE_6BPC }, +/* Belinea 10 15 55 */ { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 }, { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
PATCH 265/410 arm64: remove __die()'s stack dump
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mark Rutland <[email protected]>
commit c5bc503cbeee8586395aa541d2b53c69c3dd6930 upstream.
Our __die() implementation tries to dump the stack memory, in addition to a backtrace, which is problematic.
For contemporary 16K stacks, this can be a lot of data, which can take a long time to dump, and can push other useful context out of the kernel's printk ringbuffer (and/or a user's scrollback buffer on an attached console).
Additionally, the code implicitly assumes that the SP is on the task's stack, and tries to dump everything between the SP and the highest task stack address. When the SP points at an IRQ stack (or is corrupted), this makes the kernel attempt to dump vast amounts of VA space. With vmap'd stacks, this may result in erroneous accesses to peripherals.
This patch removes the memory dump, leaving us to rely on the backtrace, and other means of dumping stack memory such as kdump.
--- arch/arm64/kernel/traps.c | 2 -- 1 file changed, 2 deletions(-)
arch/arm64/kernel/traps.c +0 -2
@@ -206,8 +206,6 @@ static int __die(const char *str, int er TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), thread + 1);if (!user_mode (regs) ||in_interrupt ()) { -dump_mem (KERN_EMERG ,"Stack: " , regs->sp, -THREAD_SIZE + (unsigned long )task_stack_page (tsk));dump_backtrace (regs, tsk);dump_instr (KERN_EMERG , regs); }
PATCH 266/410 arm64: traps: Don't print stack or raw PC/LR values in backtraces
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
commit a25ffd3a6302a67814280274d8f1aa4ae2ea4b59 upstream.
Printing raw pointer values in backtraces has potential security implications and are of questionable value anyway.
This patch follows x86's lead and removes the "Exception stack:" dump from kernel backtraces, as well as converting PC/LR values to symbols such as "sysrq_handle_crash+0x20/0x30".
[bwh: Backported to 3.16:
- Deleted code in dump_mem() and dump_backtrace_entry() is a bit different
- Leave dump_backtrace() unchanged, since it doesn't use dump_mem()]
---
arch/arm64/kernel/process.c +3 -5
@@ -198,11 +198,9 @@ void __show_regs(struct pt_regs *regs) }show_regs_print_info (KERN_DEFAULT ); -print_symbol ("PC is at %s\n" ,instruction_pointer (regs)); -print_symbol ("LR is at %s\n" , lr); -printk ("pc : [<%016llx>] lr : [<%016llx>] pstate: %08llx\n" , - regs->pc, lr, regs->pstate); -printk ("sp : %016llx\n" , sp); +print_symbol ("pc : %s\n" , regs->pc); +print_symbol ("lr : %s\n" , lr); +printk ("sp : %016llx pstate : %08llx\n" , sp, regs->pstate);for (i = top_reg; i >=0 ; i--) {printk ("x%-2d: %016llx " , i, regs->regs[i]);if (i %2 ==0 )
arch/arm64/kernel/traps.c +1 -45
54 lines not on this page · raw message
PATCH 267/410 arm64: do not use print_symbol()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Sergey Senozhatsky <[email protected]>
commit 4ef7963843d3243260aa335dfb9cb2fede06aacf upstream.
print_symbol() is a very old API that has been obsoleted by %pS format specifier in a normal printk() call.
Replace print_symbol() with a direct printk("%pS") call.
To: Andrew Morton <[email protected]>
To: Russell King <[email protected]>
To: Catalin Marinas <[email protected]>
To: Mark Salter <[email protected]>
To: Tony Luck <[email protected]>
To: David Howells <[email protected]>
To: Yoshinori Sato <[email protected]>
To: Guan Xuetao <[email protected]>
To: Borislav Petkov <[email protected]>
To: Greg Kroah-Hartman <[email protected]>
To: Thomas Gleixner <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Vineet Gupta <[email protected]>
To: Fengguang Wu <[email protected]>
--- arch/arm64/kernel/process.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm64/kernel/process.c +2 -3
@@ -31,7 +31,6 @@#include <linux/delay.h> #include <linux/reboot.h> #include <linux/interrupt.h> -#include <linux/kallsyms.h> #include <linux/init.h> #include <linux/cpu.h> #include <linux/elfcore.h>
@@ -198,8 +197,8 @@ void __show_regs(struct pt_regs *regs) }show_regs_print_info (KERN_DEFAULT ); -print_symbol ("pc : %s\n" , regs->pc); -print_symbol ("lr : %s\n" , lr); +printk ("pc : %pS\n" , (void *)regs->pc); +printk ("lr : %pS\n" , (void *)lr);printk ("sp : %016llx pstate : %08llx\n" , sp, regs->pstate);for (i = top_reg; i >=0 ; i--) {printk ("x%-2d: %016llx " , i, regs->regs[i]);
PATCH 268/410 arm64: Disable unhandled signal log messages by default
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Michael Weiser <[email protected]>
commit 5ee39a71fd89ab7240c5339d04161c44a8e03269 upstream.
aarch64 unhandled signal kernel messages are very verbose, suggesting them to be more of a debugging aid:
sigsegv[33]: unhandled level 2 translation fault (11) at 0x00000000, esr 0x92000046, in sigsegv[400000+71000]
CPU: 1 PID: 33 Comm: sigsegv Tainted: G W 4.15.0-rc3+ #3 Hardware name: linux,dummy-virt (DT) pstate: 60000000 (nZCv daif -PAN -UAO) pc : 0x4003f4 lr : 0x4006bc
sp : 0000fffffe94a060
x29: 0000fffffe94a070 x28: 0000000000000000
x27: 0000000000000000 x26: 0000000000000000
x25: 0000000000000000 x24: 00000000004001b0
x23: 0000000000486ac8 x22: 00000000004001c8
x21: 0000000000000000 x20: 0000000000400be8
x19: 0000000000400b30 x18: 0000000000484728
x17: 000000000865ffc8 x16: 000000000000270f
x15: 00000000000000b0 x14: 0000000000000002
x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0008000020008008 x9 : 000000000000000f x8 : ffffffffffffffff x7 : 0004000000000000 x6 : ffffffffffffffff x5 : 0000000000000000 x4 : 0000000000000000 x3 : 00000000004003e4 x2 : 0000fffffe94a1e8 x1 : 000000000000000a x0 : 0000000000000000
Disable them by default, so they can be enabled using /proc/sys/debug/exception-trace.
--- arch/arm64/kernel/traps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/traps.c +1 -1
@@ -45,7 +45,7 @@ static const char *handler[]= { "Error" }; -int show_unhandled_signals =1 ; +int show_unhandled_signals =0 ;static void dump_backtrace_entry (unsigned long where,unsigned long stack) {
PATCH 269/410 arm64: Remove unimplemented syscall log message
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Michael Weiser <[email protected]>
commit 1962682d2b2fbe6cfa995a85c53c069fadda473e upstream.
Stop printing a (ratelimited) kernel message for each instance of an unimplemented syscall being called. Userland making an unimplemented syscall is not necessarily misbehaviour and to be expected with a current userland running on an older kernel. Also, the current message looks scary to users but does not actually indicate a real problem nor help them narrow down the cause. Just rely on sys_ni_syscall() to return -ENOSYS.
--- arch/arm64/kernel/traps.c | 8 -------- 1 file changed, 8 deletions(-)
arch/arm64/kernel/traps.c +0 -8
@@ -251,14 +251,6 @@ asmlinkage long do_ni_syscall(struct pt_ }#endif -if (show_unhandled_signals &&printk_ratelimit ()) { -pr_info ("%s[%d]: syscall %d\n" , current->comm, -task_pid_nr (current), (int )regs->syscallno); -dump_instr ("" , regs); -if (user_mode (regs)) -__show_regs (regs); - } -return sys_ni_syscall (); }
PATCH 270/410 arm64: __show_regs: Only resolve kernel symbols when running at EL1
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
commit a06f818a70de21b4b3b4186816094208fc7accf9 upstream.
__show_regs pretty prints PC and LR by attempting to map them to kernel function names to improve the utility of crash reports. Unfortunately, this mapping is applied even when the pt_regs corresponds to user mode, resulting in a KASLR oracle.
Avoid this issue by only looking up the function symbols when the register state indicates that we're actually running at EL1.
--- arch/arm64/kernel/process.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
arch/arm64/kernel/process.c +9 -2
@@ -197,8 +197,15 @@ void __show_regs(struct pt_regs *regs) }show_regs_print_info (KERN_DEFAULT ); -printk ("pc : %pS\n" , (void *)regs->pc); -printk ("lr : %pS\n" , (void *)lr); + +if (!user_mode (regs)) { +printk ("pc : %pS\n" , (void *)regs->pc); +printk ("lr : %pS\n" , (void *)lr); + }else { +printk ("pc : %016llx\n" , regs->pc); +printk ("lr : %016llx\n" , lr); + } +printk ("sp : %016llx pstate : %08llx\n" , sp, regs->pstate);for (i = top_reg; i >=0 ; i--) {printk ("x%-2d: %016llx " , i, regs->regs[i]);
PATCH 271/410 netfilter: IDLETIMER: be syzkaller friendly
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit cfc2c740533368b96e2be5e0a4e8c3cace7d9814 upstream.
We had one report from syzkaller [1]
First issue is that INIT_WORK() should be done before mod_timer() or we risk timer being fired too soon, even with a 1 second timer.
Second issue is that we need to reject too big info->timeout to avoid overflows in msecs_to_jiffies(info->timeout * 1000), or risk looping, if result after overflow is 0.
[1]
WARNING: CPU: 1 PID: 5129 at kernel/workqueue.c:1444 __queue_work+0xdf4/0x1230 kernel/workqueue.c:1444 Kernel panic - not syncing: panic_on_warn set ... CPU: 1 PID: 5129 Comm: syzkaller159866 Not tainted 4.16.0-rc1+ #230 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: <IRQ> __dump_stack lib/dump_stack.c:17 [inline] dump_stack+0x194/0x257 lib/dump_stack.c:53 panic+0x1e4/0x41c kernel/panic.c:183 __warn+0x1dc/0x200 kernel/panic.c:547 report_bug+0x211/0x2d0 lib/bug.c:184 fixup_bug.part.11+0x37/0x80 arch/x86/kernel/traps.c:178 fixup_bug arch/x86/kernel/traps.c:247 [inline] do_error_trap+0x2d7/0x3e0 arch/x86/kernel/traps.c:296 do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:315 invalid_op+0x22/0x40 arch/x86/entry/entry_64.S:988 RIP: 0010:__queue_work+0xdf4/0x1230 kernel/workqueue.c:1444 RSP: 0018:ffff8801db507538 EFLAGS: 00010006 RAX: ffff8801aeb46080 RBX: ffff8801db530200 RCX: ffffffff81481404 RDX: 0000000000000100 RSI: ffffffff86b42640 RDI: 0000000000000082 RBP: ffff8801db507758 R08: 1ffff1003b6a0de5 R09: 000000000000000c R10: ffff8801db5073f0 R11: 0000000000000020 R12: 1ffff1003b6a0eb6 R13: ffff8801b1067ae0 R14: 00000000000001f8 R15: dffffc0000000000 queue_work_on+0x16a/0x1c0 kernel/workqueue.c:1488 queue_work include/linux/workqueue.h:488 [inline] schedule_work include/linux/workqueue.h:546 [inline] idletimer_tg_expired+0x44/0x60 net/netfilter/xt_IDLETIMER.c:116 call_timer_fn+0x228/0x820 kernel/time/timer.c:1326 expire_timers kernel/time/timer.c:1363 [inline] __run_timers+0x7ee/0xb70 kernel/time/timer.c:1666 run_timer_softirq+0x4c/0x70 kernel/time/timer.c:1692 __do_softirq+0x2d7/0xb85 kernel/softirq.c:285 invoke_softirq kernel/softirq.c:365 [inline] irq_exit+0x1cc/0x200 kernel/softirq.c:405 exiting_irq arch/x86/include/asm/apic.h:541 [inline] smp_apic_timer_interrupt+0x16b/0x700 arch/x86/kernel/apic/apic.c:1052 apic_timer_interrupt+0xa9/0xb0 arch/x86/entry/entry_64.S:829 </IRQ> RIP: 0010:arch_local_irq_restore arch/x86/include/asm/paravirt.h:777 [inline] RIP: 0010:__raw_spin_unlock_irqrestore include/linux/spinlock_api_smp.h:160 [inline] RIP: 0010:_raw_spin_unlock_irqrestore+0x5e/0xba kernel/locking/spinlock.c:184 RSP: 0018:ffff8801c20173c8 EFLAGS: 00000282 ORIG_RAX: ffffffffffffff12 RAX: dffffc0000000000 RBX: 0000000000000282 RCX: 0000000000000006 RDX: 1ffffffff0d592cd RSI: 1ffff10035d68d23 RDI: 0000000000000282 RBP: ffff8801c20173d8 R08: 1ffff10038402e47 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000000 R12: ffffffff8820e5c8 R13: ffff8801b1067ad8 R14: ffff8801aea7c268 R15: ffff8801aea7c278 __debug_object_init+0x235/0x1040 lib/debugobjects.c:378 debug_object_init+0x17/0x20 lib/debugobjects.c:391 __init_work+0x2b/0x60 kernel/workqueue.c:506 idletimer_tg_create net/netfilter/xt_IDLETIMER.c:152 [inline] idletimer_tg_checkentry+0x691/0xb00 net/netfilter/xt_IDLETIMER.c:213 xt_check_target+0x22c/0x7d0 net/netfilter/x_tables.c:850 check_target net/ipv6/netfilter/ip6_tables.c:533 [inline] find_check_entry.isra.7+0x935/0xcf0 net/ipv6/netfilter/ip6_tables.c:575 translate_table+0xf52/0x1690 net/ipv6/netfilter/ip6_tables.c:744 do_replace net/ipv6/netfilter/ip6_tables.c:1160 [inline] do_ip6t_set_ctl+0x370/0x5f0 net/ipv6/netfilter/ip6_tables.c:1686 nf_sockopt net/netfilter/nf_sockopt.c:106 [inline] nf_setsockopt+0x67/0xc0 net/netfilter/nf_sockopt.c:115 ipv6_setsockopt+0x10b/0x130 net/ipv6/ipv6_sockglue.c:927 udpv6_setsockopt+0x45/0x80 net/ipv6/udp.c:1422 sock_common_setsockopt+0x95/0xd0 net/core/sock.c:2976 SYSC_setsockopt net/socket.c:1850 [inline] SyS_setsockopt+0x189/0x360 net/socket.c:1829 do_syscall_64+0x282/0x940 arch/x86/entry/common.c:287
--- net/netfilter/xt_IDLETIMER.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/netfilter/xt_IDLETIMER.c +6 -3
@@ -146,11 +146,11 @@ static int idletimer_tg_create(struct id (unsigned long) info->timer); info->timer->refcnt =1 ; +INIT_WORK (&info->timer->work, idletimer_tg_work); +mod_timer (&info->timer->timer,msecs_to_jiffies (info->timeout *1000 ) + jiffies); -INIT_WORK (&info->timer->work, idletimer_tg_work); -return 0 ; out_free_attr:
@@ -191,7 +191,10 @@ static int idletimer_tg_checkentry(constpr_debug ("timeout value is zero\n" );return -EINVAL ; } - +if (info->timeout >=INT_MAX /1000 ) { +pr_debug ("timeout value is too big\n" ); +return -EINVAL ; + }if (info->label[0 ] =='\0' ||strnlen (info->label,MAX_IDLETIMER_LABEL_SIZE ) ==MAX_IDLETIMER_LABEL_SIZE ) {
PATCH 272/410 md raid10: fix NULL deference in handle_write_completed()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Yufen Yu <[email protected]>
commit 01a69cab01c184d3786af09e9339311123d63d22 upstream.
In the case of 'recover', an r10bio with R10BIO_WriteError & R10BIO_IsRecover will be progressed by handle_write_completed(). This function traverses all r10bio->devs[copies].
If devs[m].repl_bio != NULL, it thinks conf->mirrors[dev].replacement is also not NULL. However, this is not always true.
When there is an rdev of raid10 has replacement, then each r10bio ->devs[m].repl_bio != NULL in conf->r10buf_pool. However, in 'recover', even if corresponded replacement is NULL, it doesn't clear r10bio ->devs[m].repl_bio, resulting in replacement NULL deference.
This bug was introduced when replacement support for raid10 was added in Linux 3.3.
As NeilBrown suggested:
Elsewhere the determination of "is this device part of the resync/recovery" is made by resting bio->bi_end_io. If this is end_sync_write, then we tried to write here. If it is NULL, then we didn't try to write.
--- drivers/md/raid10.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/md/raid10.c +4 -2
@@ -2746,7 +2746,8 @@ static void handle_write_completed(strucfor (m =0 ; m < conf->copies; m++) {int dev = r10_bio->devs[m].devnum; rdev = conf->mirrors[dev].rdev; -if (r10_bio->devs[m].bio ==NULL ) +if (r10_bio->devs[m].bio ==NULL || + r10_bio->devs[m].bio->bi_end_io ==NULL )continue ;if (test_bit (BIO_UPTODATE , &r10_bio->devs[m].bio->bi_flags)) {
@@ -2762,7 +2763,8 @@ static void handle_write_completed(strucmd_error (conf->mddev, rdev); } rdev = conf->mirrors[dev].replacement; -if (r10_bio->devs[m].repl_bio ==NULL ) +if (r10_bio->devs[m].repl_bio ==NULL || + r10_bio->devs[m].repl_bio->bi_end_io ==NULL )continue ;if (test_bit (BIO_UPTODATE , &r10_bio->devs[m].repl_bio->bi_flags)) {
PATCH 273/410 x86/mm: Fix {pmd,pud}_{set,clear}_flags()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Beulich <[email protected]>
commit 842cef9113c2120f74f645111ded1e020193d84c upstream.
Just like pte_{set,clear}_flags() their PMD and PUD counterparts should not do any address translation. This was outright wrong under Xen (causing a dead boot with no useful output on "suitable" systems), and produced needlessly more complicated code (even if just slightly) when paravirt was enabled.
[bwh: Backported to 3.16:
- There aren't any pud_{set,clear}_flags() functions
- There's no p4d level]
---
arch/x86/include/asm/pgtable.h +2 -2
@@ -263,14 +263,14 @@ static inline pmd_t pmd_set_flags(pmd_t {pmdval_t v =native_pmd_val (pmd); -return __pmd (v | set); +return native_make_pmd (v | set); }static inline pmd_t pmd_clear_flags (pmd_t pmd,pmdval_t clear) {pmdval_t v =native_pmd_val (pmd); -return __pmd (v & ~clear); +return native_make_pmd (v & ~clear); }static inline pmd_t pmd_mkold (pmd_t pmd)
arch/x86/include/asm/pgtable_types.h +5 -0
@@ -321,6 +321,11 @@ static inline pmdval_t native_pmd_val(pm#else #include <asm-generic/pgtable-nopmd.h> +static inline pmd_t native_make_pmd (pmdval_t val) +{ +return (pmd_t ) { .pud.pgd =native_make_pgd (val) }; +} +static inline pmdval_t native_pmd_val (pmd_t pmd) {return native_pgd_val (pmd.pud.pgd);
PATCH 274/410 libata: disable LPM for Crucial BX100 SSD 500GB drive
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Kai-Heng Feng <[email protected]>
commit b17e5729a630d8326a48ec34ef02e6b4464a6aef upstream.
After Laptop Mode Tools starts to use min_power for LPM, a user found out Crucial BX100 SSD can't get mounted.
Crucial BX100 SSD 500GB drive don't work well with min_power. This also happens to med_power_with_dipm.
So let's disable LPM for Crucial BX100 SSD 500GB drive.
--- drivers/ata/libata-core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/ata/libata-core.c +3 -0
@@ -4224,6 +4224,9 @@ static const struct ata_blacklist_entry { "PIONEER DVD-RW DVR-212D", NULL, ATA_HORKAGE_NOSETXFER }, { "PIONEER DVD-RW DVR-216D", NULL, ATA_HORKAGE_NOSETXFER }, +/* Crucial BX100 SSD 500GB has broken LPM support */ + { "CT500BX100SSD1", "MU02", ATA_HORKAGE_NOLPM }, +/* The 512GB version of the MX100 has both queued TRIM and LPM issues */ { "Crucial_CT512MX100*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | ATA_HORKAGE_NOLPM, },
PATCH 275/410 x86/oprofile: Fix bogus GCC-8 warning in nmi_setup()
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
commit 85c615eb52222bc5fab6c7190d146bc59fac289e upstream.
GCC-8 shows a warning for the x86 oprofile code that copies per-CPU data from CPU 0 to all other CPUs, which when building a non-SMP kernel turns into a memcpy() with identical source and destination pointers:
arch/x86/oprofile/nmi_int.c: In function 'mux_clone':
arch/x86/oprofile/nmi_int.c:285:2: error: 'memcpy' source argument is the same as destination [-Werror=restrict]
memcpy(per_cpu(cpu_msrs, cpu).multiplex,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
per_cpu(cpu_msrs, 0).multiplex,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sizeof(struct op_msr) * model->num_virt_counters);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ arch/x86/oprofile/nmi_int.c: In function 'nmi_setup':
arch/x86/oprofile/nmi_int.c:466:3: error: 'memcpy' source argument is the same as destination [-Werror=restrict] arch/x86/oprofile/nmi_int.c:470:3: error: 'memcpy' source argument is the same as destination [-Werror=restrict]
I have analyzed a number of such warnings now: some are valid and the GCC warning is welcome. Others turned out to be false-positives, and GCC was changed to not warn about those any more. This is a corner case that is a false-positive but the GCC developers feel it's better to keep warning about it.
In this case, it seems best to work around it by telling GCC a little more clearly that this code path is never hit with an IS_ENABLED() configuration check.
--- arch/x86/oprofile/nmi_int.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/oprofile/nmi_int.c +1 -1
@@ -471,7 +471,7 @@ static int nmi_setup(void) goto fail;for_each_possible_cpu (cpu) { -if (!cpu) +if (!IS_ENABLED (CONFIG_SMP ) || !cpu)continue ; memcpy(per_cpu(cpu_msrs, cpu).counters,
PATCH 276/410 kernel/relay.c: limit kmalloc size to KMALLOC_MAX_SIZE
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: David Rientjes <[email protected]>
commit 88913bd8ea2a75d7e460a4bed5f75e1c32660d7e upstream.
chan->n_subbufs is set by the user and relay_create_buf() does a kmalloc() of chan->n_subbufs * sizeof(size_t *).
kmalloc_slab() will generate a warning when this fails if chan->subbufs * sizeof(size_t *) > KMALLOC_MAX_SIZE.
Limit chan->n_subbufs to the maximum allowed kmalloc() size.
--- kernel/relay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/relay.c +1 -1
@@ -166,7 +166,7 @@ static struct rchan_buf *relay_create_bu {struct rchan_buf *buf; -if (chan->n_subbufs >UINT_MAX /sizeof (size_t *)) +if (chan->n_subbufs >KMALLOC_MAX_SIZE /sizeof (size_t *))return NULL ; buf =kzalloc (sizeof (struct rchan_buf ),GFP_KERNEL );
PATCH 277/410 regulatory: add NUL to request alpha2
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
commit 657308f73e674e86b60509a430a46e569bf02846 upstream.
Similar to the ancient commit a5fe8e7695dc ("regulatory: add NUL to alpha2"), add another byte to alpha2 in the request struct so that when we use nla_put_string(), we don't overrun anything.
--- include/net/regulatory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/regulatory.h +1 -1
@@ -78,7 +78,7 @@ struct regulatory_request {int wiphy_idx;enum nl80211_reg_initiator initiator;enum nl80211_user_reg_hint_type user_reg_hint_type; -char alpha2[2 ]; +char alpha2[3 ];enum nl80211_dfs_regions dfs_region;bool intersect;bool processed;
PATCH 278/410 drm/radeon: insist on 32-bit DMA for Cedar on PPC64/PPC64LE
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ben Crocker <[email protected]>
commit 2c83029cda55a5e7665c7c6326909427d6a01350 upstream.
In radeon_device_init, set the need_dma32 flag for Cedar chips (e.g. FirePro 2270). This fixes, or at least works around, a bug on PowerPC exposed by last year's commits
8e3f1b1d8255105f31556aacf8aeb6071b00d469 (Russell Currey)
and
253fd51e2f533552ae35a0c661705da6c4842c1b (Alistair Popple)
which enabled the 64-bit DMA iommu bypass.
This caused the device to freeze, in some cases unrecoverably, and is the subject of several bug reports internal to Red Hat.
--- drivers/gpu/drm/radeon/radeon_device.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/radeon/radeon_device.c +4 -0
@@ -1339,6 +1339,10 @@ int radeon_device_init(struct radeon_devif ((rdev->flags &RADEON_IS_PCI ) && (rdev->family <=CHIP_RS740 )) rdev->need_dma32 = true; +#ifdef CONFIG_PPC64 +if (rdev->family ==CHIP_CEDAR ) + rdev->need_dma32 = true; +#endif dma_bits = rdev->need_dma32 ?32 :40 ; r =pci_set_dma_mask (rdev->pdev,DMA_BIT_MASK (dma_bits));
PATCH 279/410 KVM: mmu: Fix overlap between public and private memslots
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Wanpeng Li <[email protected]>
commit b28676bb8ae4569cced423dc2a88f7cb319d5379 upstream.
Reported by syzkaller:
pte_list_remove: ffff9714eb1f8078 0->BUG
------------[ cut here ]------------
kernel BUG at arch/x86/kvm/mmu.c:1157!
invalid opcode: 0000 [#1] SMP
RIP: 0010:pte_list_remove+0x11b/0x120 [kvm]
Call Trace:
drop_spte+0x83/0xb0 [kvm]
mmu_page_zap_pte+0xcc/0xe0 [kvm]
kvm_mmu_prepare_zap_page+0x81/0x4a0 [kvm]
kvm_mmu_invalidate_zap_all_pages+0x159/0x220 [kvm]
kvm_arch_flush_shadow_all+0xe/0x10 [kvm]
kvm_mmu_notifier_release+0x6c/0xa0 [kvm]
? kvm_mmu_notifier_release+0x5/0xa0 [kvm]
__mmu_notifier_release+0x79/0x110
? __mmu_notifier_release+0x5/0x110
exit_mmap+0x15a/0x170
? do_exit+0x281/0xcb0
mmput+0x66/0x160
do_exit+0x2c9/0xcb0
? __context_tracking_exit.part.5+0x4a/0x150
do_group_exit+0x50/0xd0
SyS_exit_group+0x14/0x20
do_syscall_64+0x73/0x1f0
entry_SYSCALL64_slow_path+0x25/0x25The reason is that when creates new memslot, there is no guarantee for new memslot not overlap with private memslots. This can be triggered by the following program:
#include <fcntl.h> #include <pthread.h> #include <setjmp.h> #include <signal.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/types.h> #include <unistd.h> #include <linux/kvm.h> long r[16];
int main()
{
void *p = valloc(0x4000);
r[2] = open("/dev/kvm", 0);
r[3] = ioctl(r[2], KVM_CREATE_VM, 0x0ul);
uint64_t addr = 0xf000;
ioctl(r[3], KVM_SET_IDENTITY_MAP_ADDR, &addr);
r[6] = ioctl(r[3], KVM_CREATE_VCPU, 0x0ul);
ioctl(r[3], KVM_SET_TSS_ADDR, 0x0ul);
ioctl(r[6], KVM_RUN, 0);
ioctl(r[6], KVM_RUN, 0);
struct kvm_userspace_memory_region mr = {
.slot = 0,
.flags = KVM_MEM_LOG_DIRTY_PAGES,
.guest_phys_addr = 0xf000,
.memory_size = 0x4000,
.userspace_addr = (uintptr_t) p
};
ioctl(r[3], KVM_SET_USER_MEMORY_REGION, &mr);
return 0;}
This patch fixes the bug by not adding a new memslot even if it overlaps with private memslots.
--- virt/kvm/kvm_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
virt/kvm/kvm_main.c +1 -2
@@ -837,8 +837,7 @@ int __kvm_set_memory_region(struct kvm */* Check for overlaps */ r = -EEXIST ;kvm_for_each_memslot (slot, kvm->memslots) { -if ((slot->id >=KVM_USER_MEM_SLOTS ) || - (slot->id == mem->slot)) +if (slot->id == mem->slot)continue ;if (!((base_gfn + npages <= slot->base_gfn) || (base_gfn >= slot->base_gfn + slot->npages)))
PATCH 280/410 lock_parent() needs to recheck if dentry got __dentry_kill'ed under it
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
commit 3b821409632ab778d46e807516b457dfa72736ed upstream.
In case when dentry passed to lock_parent() is protected from freeing only by the fact that it's on a shrink list and trylock of parent fails, we could get hit by __dentry_kill() (and subsequent dentry_kill(parent)) between unlocking dentry and locking presumed parent. We need to recheck that dentry is alive once we lock both it and parent *and* postpone rcu_read_unlock() until after that point. Otherwise we could return a pointer to struct dentry that already is rcu-scheduled for freeing, with ->d_lock held on it; caller's subsequent attempt to unlock it can end up with memory corruption.
--- fs/dcache.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
fs/dcache.c +8 -3
@@ -590,11 +590,16 @@ again:spin_unlock (&parent->d_lock); goto again; } -rcu_read_unlock (); -if (parent != dentry) +if (parent != dentry) {spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED ); -else +if (unlikely (dentry->d_lockref.count <0 )) { +spin_unlock (&parent->d_lock); + parent =NULL ; + } + }else { parent =NULL ; + } +rcu_read_unlock ();return parent; }
PATCH 281/410 ALSA: usb-audio: Add a quirck for B&W PX headphones
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Erik Veijola <[email protected]>
commit 240a8af929c7c57dcde28682725b29cf8474e8e5 upstream.
The capture interface doesn't work and the playback interface only supports 48 kHz sampling rate even though it advertises more rates.
--- sound/usb/quirks-table.h | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
sound/usb/quirks-table.h +47 -0
@@ -3266,4 +3266,51 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge } }, +{ +/* +* Bower's & Wilkins PX headphones only support the 48 kHz sample rate +* even though it advertises more. The capture interface doesn't work +* even on windows. +*/ + USB_DEVICE(0x19b5, 0x0021), + .driver_info = (unsigned long ) &(const struct snd_usb_audio_quirk ) { + .ifnum =QUIRK_ANY_INTERFACE , + .type =QUIRK_COMPOSITE , + .data = (const struct snd_usb_audio_quirk []) { + { + .ifnum =0 , + .type =QUIRK_AUDIO_STANDARD_MIXER , + }, +/* Capture */ + { + .ifnum =1 , + .type =QUIRK_IGNORE_INTERFACE , + }, +/* Playback */ + { + .ifnum =2 , + .type =QUIRK_AUDIO_FIXED_ENDPOINT , + .data = &(const struct audioformat ) { + .formats =SNDRV_PCM_FMTBIT_S16_LE , + .channels =2 , + .iface =2 , + .altsetting =1 , + .altset_idx =1 , + .attributes =UAC_EP_CS_ATTR_FILL_MAX | +UAC_EP_CS_ATTR_SAMPLE_RATE , + .endpoint =0x03 , + .ep_attr =USB_ENDPOINT_XFER_ISOC , + .rates =SNDRV_PCM_RATE_48000 , + .rate_min =48000 , + .rate_max =48000 , + .nr_rates =1 , + .rate_table = (unsigned int []) { +48000 + } + } + }, + } + } +}, + #undef USB_DEVICE_VENDOR_SPEC
PATCH 282/410 batman-adv: fix packet checksum in receive path
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Schiffer <[email protected]>
commit abd6360591d3f8259f41c34e31ac4826dfe621b8 upstream.
eth_type_trans() internally calls skb_pull(), which does not adjust the skb checksum; skb_postpull_rcsum() is necessary to avoid log spam of the form "bat0: hw csum failure" when packets with CHECKSUM_COMPLETE are received.
Note that in usual setups, packets don't reach batman-adv with CHECKSUM_COMPLETE (I assume NICs bail out of checksumming when they see batadv's ethtype?), which is why the log messages do not occur on every system using batman-adv. I could reproduce this issue by stacking batman-adv on top of a VXLAN interface.
--- net/batman-adv/soft-interface.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
net/batman-adv/soft-interface.c +1 -7
@@ -401,13 +401,7 @@ void batadv_interface_rx(struct net_devi/* skb->dev & skb->pkt_type are set here */ skb->protocol =eth_type_trans (skb, soft_iface); - -/* should not be necessary anymore as we use skb_pull_rcsum() -* TODO: please verify this and remove this TODO -* -- Dec 21st 2009, Simon Wunderlich -*/ - -/* skb->ip_summed = CHECKSUM_UNNECESSARY; */ +skb_postpull_rcsum (skb,eth_hdr (skb),ETH_HLEN );batadv_inc_counter (bat_priv,BATADV_CNT_RX ); batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES,
PATCH 283/410 batman-adv: invalidate checksum on fragment reassembly
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Schiffer <[email protected]>
commit 3bf2a09da956b43ecfaa630a2ef9a477f991a46a upstream.
A more sophisticated implementation could try to combine fragment checksums when all fragments have CHECKSUM_COMPLETE and are split at even offsets. For now, we just set ip_summed to CHECKSUM_NONE to avoid "hw csum failure" warnings in the kernel log when fragmented frames are received. In consequence, skb_pull_rcsum() can be replaced with skb_pull().
Note that in usual setups, packets don't reach batman-adv with CHECKSUM_COMPLETE (I assume NICs bail out of checksumming when they see batadv's ethtype?), which is why the log messages do not occur on every system using batman-adv. I could reproduce this issue by stacking batman-adv on top of a VXLAN interface.
--- net/batman-adv/fragmentation.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/batman-adv/fragmentation.c +2 -1
@@ -262,7 +262,8 @@ batadv_frag_merge_packets(struct hlist_h/* Move the existing MAC header to just before the payload. (Override * the fragment header.) */ -skb_pull_rcsum (skb_out, hdr_size); +skb_pull (skb_out, hdr_size); + skb_out->ip_summed =CHECKSUM_NONE ;memmove (skb_out->data -ETH_HLEN ,skb_mac_header (skb_out),ETH_HLEN );skb_set_mac_header (skb_out, -ETH_HLEN );skb_reset_network_header (skb_out);
PATCH 284/410 netfilter: ipv6: fix use-after-free Write in nf_nat_ipv6_manip_pkt
In reply to Ben Hutchings3.16.57-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit b078556aecd791b0e5cb3a59f4c3a14273b52121 upstream.
l4proto->manip_pkt() can cause reallocation of skb head so pointer to the ipv6 header must be reloaded.
--- net/ipv6/netfilter/nf_nat_l3proto_ipv6.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c +4 -0
@@ -99,6 +99,10 @@ static bool nf_nat_ipv6_manip_pkt(struct !l4proto->manip_pkt(skb, &nf_nat_l3proto_ipv6, iphdroff, hdroff, target, maniptype))return false; + +/* must reload, offset might have changed */ + ipv6h = (void *)skb->data + iphdroff; + manip_addr:if (maniptype ==NF_NAT_MANIP_SRC ) ipv6h->saddr = target->src.u3.in6;