6.6.160-rc1 review
Subsystems (12)
Greg Kroah-Hartman
maintainerPATCH 1362/1674 usb: gadget: f_midi: Annotate struct f_midi with __counted_by
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kees Cook <[email protected]>
[ Upstream commit 182717026e2c8e6cc3b5757f601c3fee15f64ecb ]
Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
As found with Coccinelle[1], add __counted_by for struct f_midi. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier.
[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
Stable-dep-of: 7e07d3e4c389 ("usb: gadget: f_midi: initialize work in f_midi_alloc()")
--- drivers/usb/gadget/function/f_midi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/f_midi.c +2 -2
@@ -99,7 +99,7 @@ struct f_midi {unsigned int in_last_port;unsigned char free_ref; -struct gmidi_in_port in_ports_array[/* in_ports */ ]; + struct gmidi_in_port in_ports_array[] __counted_by(in_ports); };static inline struct f_midi *func_to_midi (struct usb_function *f)
@@ -1359,6 +1359,7 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi) status = -ENOMEM ; goto setup_fail; } + midi->in_ports = opts->in_ports;for (i =0 ; i < opts->in_ports; i++) midi->in_ports_array[i].cable = i;
@@ -1369,7 +1370,6 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi) status = -ENOMEM ; goto midi_free; } - midi->in_ports = opts->in_ports; midi->out_ports = opts->out_ports; midi->index = opts->index; midi->buflen = opts->buflen;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1363/1674 usb: gadget: f_midi: initialize work in f_midi_alloc()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeffin Philip <[email protected]>
[ Upstream commit 7e07d3e4c389217d7d7171d80edf2e23ac70f1ea ]
f_midi_alloc initializes free_ref to 1 and it can only be incremented when a sound card is registered via f_midi_register_card(). f_midi_register_card() is only called in f_midi_bind() which actually performs INIT_WORK. If f_midi_bind() is never run, work is not initialized and the if condition in f_midi_free becomes true, this results in a warning later in __flush_work as work->func = 0. Fix this by moving INIT_WORK from f_midi_bind() to f_midi_alloc().
--- drivers/usb/gadget/function/f_midi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/function/f_midi.c +1 -1
@@ -877,7 +877,6 @@ static int f_midi_bind(struct usb_configuration *c, struct usb_function *f)int status, n, jack =1 , i =0 , endpoint_descriptor_index =0 ; midi->gadget = cdev->gadget; -INIT_WORK (&midi->work, f_midi_in_work); status =f_midi_register_card (midi);if (status <0 ) goto fail_register;
@@ -1370,6 +1369,7 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi) status = -ENOMEM ; goto midi_free; } +INIT_WORK (&midi->work, f_midi_in_work); midi->out_ports = opts->out_ports; midi->index = opts->index; midi->buflen = opts->buflen;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1364/1674 usb: dwc3: gadget: Reinitiate stream for all host NoStream behavior
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thinh Nguyen <[email protected]>
[ Upstream commit dcfe437492e27d54f3ac491aed024da760f5c43c ]
There are too many different host behaviors when it comes to NoStream handling, and not everyone follows the USB and xHCI spec. The DWC3 driver attempts to do some guess work to interop with different hosts, but it can't cover everything. Let's keep it simple and treat every host the same: just retry on NoStream after a 100ms of no response delay. Note that some hosts cannot handle frequent retries. This may affect performance on certain defective hosts, but NoStream is a rare occurrence and interoperability is more important.
Stable-dep-of: b58e6200450d ("usb: dwc3: clear forceRM when issuing EndTransfer")
--- drivers/usb/dwc3/core.h | 3 +- drivers/usb/dwc3/gadget.c | 109 ++++++++++++++++++++------------------ 2 files changed, 59 insertions(+), 53 deletions(-)
drivers/usb/dwc3/core.h +2 -1
@@ -727,6 +727,7 @@ struct dwc3_event_buffer {*/ struct dwc3_ep {struct usb_ep endpoint; +struct delayed_work nostream_work;struct list_head cancelled_list;struct list_head pending_list;struct list_head started_list;
@@ -749,7 +750,7 @@ struct dwc3_ep {#define DWC3_EP_WAIT_TRANSFER_COMPLETE BIT(7)#define DWC3_EP_IGNORE_NEXT_NOSTREAM BIT(8)#define DWC3_EP_FORCE_RESTART_STREAM BIT(9) -#define DWC3_EP_FIRST_STREAM_PRIMED BIT(10) +#define DWC3_EP_STREAM_PRIMED BIT(10)#define DWC3_EP_PENDING_CLEAR_STALL BIT(11)#define DWC3_EP_TXFIFO_RESIZED BIT(12)#define DWC3_EP_DELAY_STOP BIT(13)
drivers/usb/dwc3/gadget.c +57 -52
143 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1365/1674 usb: dwc3: clear forceRM when issuing EndTransfer
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Elson Serrao <[email protected]>
[ Upstream commit b58e6200450d350314db0ecda7d6d1bde3281e80 ]
The forceRM bit of the DEPCMD register controls the behavior of the EndTransfer command used to stop an active transfer. Older DWC3 programming guide revisions recommended setting forceRM=1 when issuing EndTransfer. Newer programming guide revisions recommend issuing EndTransfer with forceRM cleared.
With forceRM=1 on DWC_usb31 v2.00a and v2.10a controllers, a transfer aborted through the ep_dequeue path was observed to remain active after EndTransfer completion. A subsequent StartTransfer issued on the same endpoint triggered writes associated with the aborted transfer. This resulted in an SMMU fault because the transfer buffer had already been unmapped during EndTransfer command-completion cleanup.
Using forceRM=0 eliminates the issue. Although older DWC3 programming guide revisions recommended setting forceRM=1, no issues are known from using forceRM=0. Clear forceRM when issuing EndTransfer to provide consistent EndTransfer behavior and align with newer programming guide recommendations.
--- drivers/usb/dwc3/ep0.c | 2 +- drivers/usb/dwc3/gadget.c | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-)
drivers/usb/dwc3/ep0.c +1 -1
@@ -313,7 +313,7 @@ void dwc3_ep0_out_start(struct dwc3 *dwc) dwc3_ep->flags &= ~DWC3_EP_DELAY_STOP ;if (dwc->connected) -dwc3_stop_active_transfer (dwc3_ep, true, true); +dwc3_stop_active_transfer (dwc3_ep, false, true);else dwc3_remove_requests (dwc, dwc3_ep, -ESHUTDOWN ); }
drivers/usb/dwc3/gadget.c +13 -8
@@ -993,7 +993,7 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, unsigned int action)* controller to generate an ERDY to initiate the * stream. */ -dwc3_stop_active_transfer (dep, true, true); +dwc3_stop_active_transfer (dep, false, true);/* * All stream eps will reinitiate stream on NoStream
@@ -1021,7 +1021,7 @@ void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status) {struct dwc3_request *req; -dwc3_stop_active_transfer (dep, true, false); +dwc3_stop_active_transfer (dep, false, false);/* If endxfer is delayed, avoid unmapping requests */ if (dep->flags &DWC3_EP_DELAY_STOP )
@@ -1715,7 +1715,7 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep)if (ret == -EAGAIN )return ret; -dwc3_stop_active_transfer (dep, true, true); +dwc3_stop_active_transfer (dep, false, true);list_for_each_entry_safe (req, tmp, &dep->started_list, list)dwc3_gadget_move_cancelled_request (req,DWC3_REQUEST_STATUS_DEQUEUED );
@@ -1752,6 +1752,11 @@ static int __dwc3_gadget_get_frame(struct dwc3 *dwc)* the controller won't update the TRB progress on command * completion. It also won't clear the HWO bit in the TRB. * The command will also not complete immediately in that case. +* +* Older programming guide revisions recommended setting ForceRM to 1 +* when ending a transfer. Newer programming guide revisions now +* recommend keeping ForceRM cleared, and TRBs are properly updated +* on command completion. */ static int __dwc3_stop_active_transfer (struct dwc3_ep *dep,bool force,bool interrupt) {
@@ -1877,7 +1882,7 @@ static int dwc3_gadget_start_isoc_quirk(struct dwc3_ep *dep)* to wait for the next XferNotReady to test the command again */ if (cmd_status ==0 ) { -dwc3_stop_active_transfer (dep, true, true); +dwc3_stop_active_transfer (dep, false, true);return 0 ; } }
@@ -2164,7 +2169,7 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep,struct dwc3_request *t;/* wait until it is processed */ -dwc3_stop_active_transfer (dep, true, true); +dwc3_stop_active_transfer (dep, false, true);/* * Remove any started request if the transfer is
@@ -2241,7 +2246,7 @@ int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol)return 0 ; } -dwc3_stop_active_transfer (dep, true, true); +dwc3_stop_active_transfer (dep, false, true);list_for_each_entry_safe (req, tmp, &dep->started_list, list)dwc3_gadget_move_cancelled_request (req,DWC3_REQUEST_STATUS_STALLED );
@@ -3398,7 +3403,7 @@ static void dwc3_nostream_work(struct work_struct *work)dwc3_send_gadget_generic_command (dwc, cmd, dep->number); }else { dep->flags |=DWC3_EP_DELAY_START ; -dwc3_stop_active_transfer (dep, true, true); +dwc3_stop_active_transfer (dep, false, true);spin_unlock_irqrestore (&dwc->lock, flags);return ; }
@@ -3742,7 +3747,7 @@ static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep,if (usb_endpoint_xfer_isoc (dep->endpoint.desc) &&list_empty (&dep->started_list) && (list_empty (&dep->pending_list) || status == -EXDEV )) -dwc3_stop_active_transfer (dep, true, true); +dwc3_stop_active_transfer (dep, false, true);else if (dwc3_gadget_ep_should_continue (dep))if (__dwc3_gadget_kick_transfer (dep) ==0 ) no_started_trb = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1366/1674 NFSD: Prevent client use-after-free during blocked-lock reaping
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 9026932ac8be4d0ae01db47f23619a98cc57b671 ]
A bare lock owner -- its only remaining reference a blocked lock on nn->blocked_locks_lru -- holds a raw pointer to its nfs4_client but no reference keeping the client alive. When the per-net laundromat reaps such a lock, freeing the nbl drops the owner reference held through flc_owner, and the final nfs4_put_stateowner() takes the client's cl_lock. Because the laundromat detaches the nbl first, __destroy_client() no longer finds it, so a concurrent force_expire_client() can free the client before nfs4_put_stateowner() runs, dereferencing cl_lock in freed memory.
Pin the client with cl_rpc_users before dropping nn->blocked_locks_lock, and skip clients already expiring, whose blocked locks __destroy_client() frees while holding an owner reference. Take nn->client_lock outside nn->blocked_locks_lock. Every other site holds nn->blocked_locks_lock as a leaf, acquiring no further lock, so placing nn->client_lock outside it cannot form a lock-order cycle.
--- fs/nfsd/nfs4state.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
fs/nfsd/nfs4state.c +24 -3
@@ -329,6 +329,16 @@ free_blocked_lock(struct nfsd4_blocked_lock *nbl)kref_put (&nbl->nbl_kref, free_nbl); } +/* A blocked lock's fl_owner is its nfs4_lockowner. */ +static struct nfs4_client * +nbl_client (struct nfsd4_blocked_lock *nbl) +{ +struct nfs4_lockowner *lo; + + lo = (struct nfs4_lockowner *)nbl->nbl_lock.fl_owner; +return lo->lo_owner.so_client; +} +static void remove_blocked_locks (struct nfs4_lockowner *lo) {
@@ -6392,22 +6402,33 @@ nfs4_laundromat(struct nfsd_net *nn)* indefinitely once the lock does become free. */ BUG_ON (!list_empty (&reaplist)); +spin_lock (&nn->client_lock);spin_lock (&nn->blocked_locks_lock); -while (!list_empty (&nn->blocked_locks_lru)) { - nbl =list_first_entry (&nn->blocked_locks_lru, - struct nfsd4_blocked_lock, nbl_lru); +list_for_each_safe (pos, next, &nn->blocked_locks_lru) { + nbl = list_entry(pos, struct nfsd4_blocked_lock, nbl_lru);if (!state_expired (<, nbl->nbl_time))break ; + clp =nbl_client (nbl); +if (is_client_expired (clp)) +continue ; +atomic_inc (&clp->cl_rpc_users);list_move (&nbl->nbl_lru, &reaplist);list_del_init (&nbl->nbl_list); }spin_unlock (&nn->blocked_locks_lock); +spin_unlock (&nn->client_lock);while (!list_empty (&reaplist)) { nbl =list_first_entry (&reaplist, struct nfsd4_blocked_lock, nbl_lru); + clp =nbl_client (nbl);list_del_init (&nbl->nbl_lru);free_blocked_lock (nbl); +if (atomic_dec_and_lock (&clp->cl_rpc_users, &nn->client_lock)) { +if (is_client_expired (clp)) +wake_up_all (&expiry_wq); +spin_unlock (&nn->client_lock); + } }#ifdef CONFIG_NFSD_V4_2_INTER_SSC /* service the server-to-server copy delayed unmount list */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1367/1674 NFSD: Prevent client use-after-free during close_lru reaping
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 2330b788d732f43668b965b3105b37ceb276dfea ]
An nfs4_openowner left on nn->close_lru after its final CLOSE keeps its last closed stateid in oo_last_closed_stid, holding only a raw pointer to its nfs4_client. The laundromat reaps timed-out entries, drops nn->client_lock, and calls nfs4_put_stid(), which dereferences the client through cl_lock. Nothing pins the client across that window, so a concurrent force_expire_client() can free it and nfs4_put_stid() reads freed memory. __destroy_client() hits the same race, walking clp->cl_openowners without cl_lock.
Pin the client with cl_rpc_users before dropping client_lock, and skip clients already expiring. __destroy_client() then cleans up its own close_lru entries through release_last_closed_stateid(), so teardown no longer races the laundromat.
--- fs/nfsd/nfs4state.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/nfsd/nfs4state.c +7 -0
@@ -6382,11 +6382,18 @@ nfs4_laundromat(struct nfsd_net *nn)if (!state_expired (<, oo->oo_time))break ;list_del_init (&oo->oo_close_lru); + clp = oo->oo_owner.so_client; +if (is_client_expired (clp)) +continue ; stp = oo->oo_last_closed_stid; oo->oo_last_closed_stid =NULL ; +atomic_inc (&clp->cl_rpc_users);spin_unlock (&nn->client_lock);nfs4_put_stid (&stp->st_stid);spin_lock (&nn->client_lock); +if (atomic_dec_and_test (&clp->cl_rpc_users) && +is_client_expired (clp)) +wake_up_all (&expiry_wq); }spin_unlock (&nn->client_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1368/1674 HID: sony: clean up device list on probe failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
[ Upstream commit 7c65699a3a311198a07659a614fe64d45924839e ]
sony_input_configured() adds some controllers to sony_device_list before HID core registers their input devices. input_register_device() can fail after the callback returns successfully. sony_probe() then observes that HID_CLAIMED_INPUT is clear and unwinds, but only stops the HID hardware. The devres-managed sony_sc is freed while its list node remains linked, so the next matching controller traverses freed memory.
Initialize the list node and device ID to inactive states. Make list removal idempotent and run the driver-private cleanup on every probe failure path. This also makes a second cleanup safe when sony_input_configured() already unwound a partial initialization before sony_probe() handles the missing input claim.
Found by 0sec (https://0sec.ai) using automated source analysis; verified against the HID input registration and probe unwind paths.
--- drivers/hid/hid-sony.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
drivers/hid/hid-sony.c +16 -17
@@ -1745,13 +1745,10 @@ static int sony_check_add_dev_list(struct sony_sc *sc)static void sony_remove_dev_list (struct sony_sc *sc) { -unsigned long flags; +guard (spinlock_irqsave)(&sony_dev_list_lock); -if (sc->list_node.next) { -spin_lock_irqsave (&sony_dev_list_lock, flags); -list_del (&(sc->list_node)); -spin_unlock_irqrestore (&sony_dev_list_lock, flags); - } +if (!list_empty (&sc->list_node)) +list_del_init (&sc->list_node); }static int sony_get_bt_devaddr (struct sony_sc *sc)
@@ -1889,6 +1886,13 @@ static inline void sony_cancel_work_sync(struct sony_sc *sc) } } +static void sony_cleanup (struct sony_sc *sc) +{ +sony_cancel_work_sync (sc); +sony_remove_dev_list (sc); +sony_release_device_id (sc); +} +static int sony_input_configured (struct hid_device *hdev,struct hid_input *hidinput) {
@@ -2049,9 +2053,7 @@ static int sony_input_configured(struct hid_device *hdev, err_close:hid_hw_close (hdev); err_stop: -sony_cancel_work_sync (sc); -sony_remove_dev_list (sc); -sony_release_device_id (sc); +sony_cleanup (sc);return ret; }
@@ -2077,6 +2079,8 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) }spin_lock_init (&sc->lock); +INIT_LIST_HEAD (&sc->list_node); + sc->device_id =-1 ; sc->quirks = quirks;hid_set_drvdata (hdev, sc);
@@ -2105,6 +2109,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) ret =hid_hw_start (hdev, connect_mask);if (ret) {hid_err (hdev,"hw start failed\n" ); +sony_cleanup (sc);return ret; }
@@ -2156,7 +2161,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) err:usb_free_urb (sc->ghl_urb); - +sony_cleanup (sc);hid_hw_stop (hdev);return ret; }
@@ -2173,13 +2178,7 @@ static void sony_remove(struct hid_device *hdev) }hid_hw_close (hdev); - -sony_cancel_work_sync (sc); - -sony_remove_dev_list (sc); - -sony_release_device_id (sc); - +sony_cleanup (sc);hid_hw_stop (hdev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1369/1674 netfilter: nf_tables: skip double clone set expressions on element insert
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit 43559058d21e0493aa220ac167e0279334dea5f9 ]
Both the dynset and newsetelem path clone the existing set expressions when setting set element expressions if no override expressions are provided. This results in a double clone, once to clone the template set expressions then another clone on the new element. Add a flag to annotate if userspace provides a override expression (ie. expression of the same type of the set but different configuration), otherwise borrow the existing expression from the set. Add conditionals to release expression iif they represent an override. Use this new override_exprs flag to dump the dynset expression override to userspace.
This simplifies the existing logic and it also fixes a bug with the connlimit expression which results in a module refcount imbalance WARNING splat when resorting on the default set expressions.
--- include/net/netfilter/nf_tables.h | 2 -- net/netfilter/nf_tables_api.c | 56 ++++++++++--------------------- net/netfilter/nft_dynset.c | 25 ++++++++------ 3 files changed, 33 insertions(+), 50 deletions(-)
include/net/netfilter/nf_tables.h +0 -2
@@ -855,8 +855,6 @@ void *nft_set_elem_init(const struct nft_set *set,const struct nft_set_ext_tmpl *tmpl, const u32 *key, const u32 *key_end, const u32 *data, u64 timeout, u64 expiration, gfp_t gfp); -int nft_set_elem_expr_clone (const struct nft_ctx *ctx,struct nft_set *set, -struct nft_expr *expr_array[]);void nft_set_elem_expr_destroy (const struct nft_ctx *ctx,struct nft_set_elem_expr *elem_expr); void nft_set_elem_destroy(const struct nft_set *set, void *elem,
net/netfilter/nf_tables_api.c +18 -38
114 lines not on this page · raw message
net/netfilter/nft_dynset.c +15 -10
@@ -19,7 +19,8 @@ struct nft_dynset {u8 sreg_key;u8 sreg_data;bool invert; -bool expr; + bool expr:1, + override_exprs:1;u8 num_exprs;u64 timeout;struct nft_expr *expr_array[NFT_SET_EXPR_MAX ];
@@ -254,6 +255,7 @@ static int nft_dynset_init(const struct nft_ctx *ctx, priv->num_exprs++; priv->expr_array[0 ] = dynset_expr; + priv->override_exprs = true; if (set->num_exprs > 1 || (set->num_exprs == 1 &&
@@ -286,6 +288,7 @@ static int nft_dynset_init(const struct nft_ctx *ctx, } priv->expr_array[i] = dynset_expr; priv->num_exprs++; + priv->override_exprs = true;if (set->num_exprs) {if (i >= set->num_exprs) {
@@ -304,9 +307,8 @@ static int nft_dynset_init(const struct nft_ctx *ctx, goto err_expr_free; } }else if (set->num_exprs >0 ) { - err =nft_set_elem_expr_clone (ctx, set, priv->expr_array); -if (err <0 ) -return err; +for (i =0 ; i < set->num_exprs; i++) + priv->expr_array[i] = set->exprs[i]; priv->num_exprs = set->num_exprs; }
@@ -339,8 +341,10 @@ static int nft_dynset_init(const struct nft_ctx *ctx,return 0 ; err_expr_free: -for (i =0 ; i < priv->num_exprs; i++) -nft_expr_destroy (ctx, priv->expr_array[i]); +if (priv->override_exprs) { +for (i =0 ; i < priv->num_exprs; i++) +nft_expr_destroy (ctx, priv->expr_array[i]); + }return err; }
@@ -367,9 +371,10 @@ static void nft_dynset_destroy(const struct nft_ctx *ctx,struct nft_dynset *priv =nft_expr_priv (expr);int i; -for (i =0 ; i < priv->num_exprs; i++) -nft_expr_destroy (ctx, priv->expr_array[i]); - +if (priv->override_exprs) { +for (i =0 ; i < priv->num_exprs; i++) +nft_expr_destroy (ctx, priv->expr_array[i]); + }nf_tables_destroy_set (ctx, priv->set); }
@@ -393,7 +398,7 @@ static int nft_dynset_dump(struct sk_buff *skb, nf_jiffies64_to_msecs(priv->timeout), NFTA_DYNSET_PAD)) goto nla_put_failure; -if (priv->set->num_exprs ==0 ) { +if (priv->set->num_exprs ==0 || priv->override_exprs) {if (priv->num_exprs ==1 ) {if (nft_expr_dump (skb,NFTA_DYNSET_EXPR , priv->expr_array[0 ], reset))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1370/1674 net_sched: sch_fq: struct sched_data reorg
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 54ff8ad69c6e93c0767451ae170b41c000e565dd ]
q->flows can be often modified, and q->timer_slack is read mostly.
Exchange the two fields, so that cache line countaining quantum, initial_quantum, and other critical parameters stay clean (read-mostly).
Move q->watchdog next to q->stat_throttled
Add comments explaining how the structure is split in three different parts.
pahole output before the patch:
struct fq_sched_data {
struct fq_flow_head new_flows; /* 0 0x10 */
struct fq_flow_head old_flows; /* 0x10 0x10 */
struct rb_root delayed; /* 0x20 0x8 */
u64 time_next_delayed_flow; /* 0x28 0x8 */
u64 ktime_cache; /* 0x30 0x8 */
unsigned long unthrottle_latency_ns; /* 0x38 0x8 */
/* --- cacheline 1 boundary (64 bytes) --- */
struct fq_flow internal __attribute__((__aligned__(64))); /* 0x40 0x80 */
/* XXX last struct has 16 bytes of padding */
/* --- cacheline 3 boundary (192 bytes) --- */
u32 quantum; /* 0xc0 0x4 */
u32 initial_quantum; /* 0xc4 0x4 */
u32 flow_refill_delay; /* 0xc8 0x4 */
u32 flow_plimit; /* 0xcc 0x4 */
unsigned long flow_max_rate; /* 0xd0 0x8 */
u64 ce_threshold; /* 0xd8 0x8 */
u64 horizon; /* 0xe0 0x8 */
u32 orphan_mask; /* 0xe8 0x4 */
u32 low_rate_threshold; /* 0xec 0x4 */
struct rb_root * fq_root; /* 0xf0 0x8 */
u8 rate_enable; /* 0xf8 0x1 */
u8 fq_trees_log; /* 0xf9 0x1 */
u8 horizon_drop; /* 0xfa 0x1 */
/* XXX 1 byte hole, try to pack */<bad> u32 flows; /* 0xfc 0x4 */
/* --- cacheline 4 boundary (256 bytes) --- */ u32 inactive_flows; /* 0x100 0x4 */ u32 throttled_flows; /* 0x104 0x4 */ u64 stat_gc_flows; /* 0x108 0x8 */ u64 stat_internal_packets; /* 0x110 0x8 */ u64 stat_throttled; /* 0x118 0x8 */ u64 stat_ce_mark; /* 0x120 0x8 */ u64 stat_horizon_drops; /* 0x128 0x8 */ u64 stat_horizon_caps; /* 0x130 0x8 */ u64 stat_flows_plimit; /* 0x138 0x8 */ /* --- cacheline 5 boundary (320 bytes) --- */ u64 stat_pkts_too_long; /* 0x140 0x8 */ u64 stat_allocation_errors; /* 0x148 0x8 */
<bad> u32 timer_slack; /* 0x150 0x4 */
/* XXX 4 bytes hole, try to pack */ struct qdisc_watchdog watchdog; /* 0x158 0x48 */ /* size: 448, cachelines: 7, members: 34 */ /* sum members: 411, holes: 2, sum holes: 5 */ /* padding: 32 */ /* paddings: 1, sum paddings: 16 */ /* forced alignments: 1 */ };
pahole output after the patch:
struct fq_sched_data {
struct fq_flow_head new_flows; /* 0 0x10 */
struct fq_flow_head old_flows; /* 0x10 0x10 */
struct rb_root delayed; /* 0x20 0x8 */
u64 time_next_delayed_flow; /* 0x28 0x8 */
u64 ktime_cache; /* 0x30 0x8 */
unsigned long unthrottle_latency_ns; /* 0x38 0x8 */
/* --- cacheline 1 boundary (64 bytes) --- */
struct fq_flow internal __attribute__((__aligned__(64))); /* 0x40 0x80 */
/* XXX last struct has 16 bytes of padding */
/* --- cacheline 3 boundary (192 bytes) --- */
u32 quantum; /* 0xc0 0x4 */
u32 initial_quantum; /* 0xc4 0x4 */
u32 flow_refill_delay; /* 0xc8 0x4 */
u32 flow_plimit; /* 0xcc 0x4 */
unsigned long flow_max_rate; /* 0xd0 0x8 */
u64 ce_threshold; /* 0xd8 0x8 */
u64 horizon; /* 0xe0 0x8 */
u32 orphan_mask; /* 0xe8 0x4 */
u32 low_rate_threshold; /* 0xec 0x4 */
struct rb_root * fq_root; /* 0xf0 0x8 */
u8 rate_enable; /* 0xf8 0x1 */
u8 fq_trees_log; /* 0xf9 0x1 */
u8 horizon_drop; /* 0xfa 0x1 */
/* XXX 1 byte hole, try to pack */<good> u32 timer_slack; /* 0xfc 0x4 */
/* --- cacheline 4 boundary (256 bytes) --- */ <good> u32 flows; /* 0x100 0x4 */ u32 inactive_flows; /* 0x104 0x4 */ u32 throttled_flows; /* 0x108 0x4 */
/* XXX 4 bytes hole, try to pack */ u64 stat_throttled; /* 0x110 0x8 */ <better> struct qdisc_watchdog watchdog; /* 0x118 0x48 */ /* --- cacheline 5 boundary (320 bytes) was 32 bytes ago --- */ u64 stat_gc_flows; /* 0x160 0x8 */ u64 stat_internal_packets; /* 0x168 0x8 */ u64 stat_ce_mark; /* 0x170 0x8 */ u64 stat_horizon_drops; /* 0x178 0x8 */ /* --- cacheline 6 boundary (384 bytes) --- */ u64 stat_horizon_caps; /* 0x180 0x8 */ u64 stat_flows_plimit; /* 0x188 0x8 */ u64 stat_pkts_too_long; /* 0x190 0x8 */ u64 stat_allocation_errors; /* 0x198 0x8 */ /* Force padding: */ u64 :64; u64 :64; u64 :64; u64 :64; /* size: 448, cachelines: 7, members: 34 */ /* sum members: 411, holes: 2, sum holes: 5 */ /* padding: 32 */ /* paddings: 1, sum paddings: 16 */ /* forced alignments: 1 */ };
Stable-dep-of: 709f34f7c28d ("net/sched: fq: add overflow bounds to quantum and initial quantum")
--- net/sched/sch_fq.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
net/sched/sch_fq.c +12 -4
@@ -104,6 +104,9 @@ struct fq_sched_data {unsigned long unthrottle_latency_ns;struct fq_flow internal;/* for non classified or high prio packets */ + +/* Read mostly cache line */ +u32 quantum;u32 initial_quantum;u32 flow_refill_delay;
@@ -117,22 +120,27 @@ struct fq_sched_data {u8 rate_enable;u8 fq_trees_log;u8 horizon_drop; +u32 timer_slack;/* hrtimer slack in ns */ + +/* Read/Write fields. */ +u32 flows;u32 inactive_flows;u32 throttled_flows; +u64 stat_throttled; +struct qdisc_watchdog watchdog;u64 stat_gc_flows; + +/* Seldom used fields. */ +u64 stat_internal_packets; -u64 stat_throttled;u64 stat_ce_mark;u64 stat_horizon_drops;u64 stat_horizon_caps;u64 stat_flows_plimit;u64 stat_pkts_too_long;u64 stat_allocation_errors; - -u32 timer_slack;/* hrtimer slack in ns */ -struct qdisc_watchdog watchdog; };/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1371/1674 net_sched: sch_fq: change how @inactive is tracked
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit ee9af4e14d166c34ec78896bb1ba545249445df0 ]
Currently, when one fq qdisc has no more packets to send, it can still have some flows stored in its RR lists (q->new_flows & q->old_flows)
This was a design choice, but what is a bit disturbing is that the inactive_flows counter does not include the count of empty flows in RR lists.
As next patch needs to know better if there are active flows, this change makes inactive_flows exact.
Before the patch, following command on an empty qdisc could have returned:
lpaa17:~# tc -s -d qd sh dev eth1 | grep inactive flows 1322 (inactive 1316 throttled 0) flows 1330 (inactive 1325 throttled 0) flows 1193 (inactive 1190 throttled 0) flows 1208 (inactive 1202 throttled 0)
After the patch, we now have:
lpaa17:~# tc -s -d qd sh dev eth1 | grep inactive flows 1322 (inactive 1322 throttled 0) flows 1330 (inactive 1330 throttled 0) flows 1193 (inactive 1193 throttled 0) flows 1208 (inactive 1208 throttled 0)
Stable-dep-of: 709f34f7c28d ("net/sched: fq: add overflow bounds to quantum and initial quantum")
--- net/sched/sch_fq.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
net/sched/sch_fq.c +7 -5
@@ -125,7 +125,7 @@ struct fq_sched_data {/* Read/Write fields. */ u32 flows; -u32 inactive_flows; +u32 inactive_flows;/* Flows with no packet to send. */ u32 throttled_flows;u64 stat_throttled;
@@ -402,9 +402,12 @@ static void fq_erase_head(struct Qdisc *sch, struct fq_flow *flow,static void fq_dequeue_skb (struct Qdisc *sch,struct fq_flow *flow,struct sk_buff *skb) { +struct fq_sched_data *q =qdisc_priv (sch); +fq_erase_head (sch, flow, skb);skb_mark_not_on_list (skb); - flow->qlen--; +if (--flow->qlen ==0 ) + q->inactive_flows++;qdisc_qstats_backlog_dec (sch, skb); sch->q.qlen--; }
@@ -484,13 +487,13 @@ static int fq_enqueue(struct sk_buff *skb, struct Qdisc *sch,return qdisc_drop (skb, sch, to_free); } - f->qlen++; +if (f->qlen++ ==0 ) + q->inactive_flows--;qdisc_qstats_backlog_inc (sch, skb);if (fq_flow_is_detached (f)) {fq_flow_add_tail (&q->new_flows, f);if (time_after (jiffies, f->age + q->flow_refill_delay)) f->credit =max_t (u32, f->credit, q->quantum); - q->inactive_flows--; }/* Note: this overwrites f->age */
@@ -597,7 +600,6 @@ static struct sk_buff *fq_dequeue(struct Qdisc *sch)fq_flow_add_tail (&q->old_flows, f); }else {fq_flow_set_detached (f); - q->inactive_flows++; } goto begin; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1372/1674 net_sched: export pfifo_fast prio2band[]
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 5579ee462dfe768297563a6083e21df52c3ad856 ]
pfifo_fast prio2band[] is renamed to sch_default_prio2band[] and exported because we want to share it in FQ.
Stable-dep-of: 709f34f7c28d ("net/sched: fq: add overflow bounds to quantum and initial quantum")
--- include/net/sch_generic.h | 1 + net/sched/sch_generic.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-)
include/net/sch_generic.h +1 -0
@@ -595,6 +595,7 @@ static inline void sch_tree_unlock(struct Qdisc *q)extern struct Qdisc noop_qdisc;extern struct Qdisc_ops noop_qdisc_ops;extern struct Qdisc_ops pfifo_fast_ops; +extern const u8 sch_default_prio2band[TC_PRIO_MAX +1 ];extern struct Qdisc_ops mq_qdisc_ops;extern struct Qdisc_ops noqueue_qdisc_ops;extern const struct Qdisc_ops *default_qdisc_ops;
net/sched/sch_generic.c +5 -4
@@ -727,9 +727,10 @@ struct Qdisc_ops noqueue_qdisc_ops __read_mostly = { .owner = THIS_MODULE, }; -static const u8 prio2band[TC_PRIO_MAX +1 ] = { -1 ,2 ,2 ,2 ,1 ,2 ,0 ,0 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 +const u8 sch_default_prio2band[TC_PRIO_MAX +1 ] = { +1 ,2 ,2 ,2 ,1 ,2 ,0 ,0 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 }; +EXPORT_SYMBOL (sch_default_prio2band);/* 3-band FIFO queue: old style, but should be a bit faster than generic prio+fifo combination.
@@ -754,7 +755,7 @@ static inline struct skb_array *band2list(struct pfifo_fast_priv *priv,static int pfifo_fast_enqueue (struct sk_buff *skb,struct Qdisc *qdisc,struct sk_buff **to_free) { -int band = prio2band[skb->priority &TC_PRIO_MAX ]; +int band = sch_default_prio2band[skb->priority &TC_PRIO_MAX ];struct pfifo_fast_priv *priv =qdisc_priv (qdisc);struct skb_array *q =band2list (priv, band);unsigned int pkt_len =qdisc_pkt_len (skb);
@@ -863,7 +864,7 @@ static int pfifo_fast_dump(struct Qdisc *qdisc, struct sk_buff *skb) {struct tc_prio_qopt opt = { .bands =PFIFO_FAST_BANDS }; -memcpy (&opt.priomap, prio2band,TC_PRIO_MAX +1 ); +memcpy (&opt.priomap, sch_default_prio2band,TC_PRIO_MAX +1 );if (nla_put (skb,TCA_OPTIONS ,sizeof (opt), &opt)) goto nla_put_failure;return skb->len;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1373/1674 net/sched: fq: add overflow bounds to quantum and initial quantum
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 709f34f7c28dc4dd6c40343d101850f11e172312 ]
fq_init() computes quantum = 2 * psched_mtu() and initial_quantum = 10 * psched_mtu() with no overflow check. A device with a huge MTU (e.g. dummy with max_mtu == 0 accepting MTU 2147483634) makes psched_mtu() return 0x80000000; the 2 * and 10 * multiplications wrap to 0 in 32-bit arithmetic, so q->quantum == 0. Then in fq_dequeue() the credit-refill loop adds 0 to f->credit (which stays <= 0) and goto begin loops forever under the qdisc lock, creating a soft lockup.
Clamp psched_mtu() to [1, 1 << 20] before multiplying so the product cannot wrap, then cap the result at 1 << 20, matching the bound already enforced on TCA_FQ_QUANTUM in fq_change().
Conditions to recreate the bug: a device whose MTU (plus hard_header_len) is large enough that 2 * psched_mtu() wraps (e.g. a dummy device with max_mtu == 0 accepting MTU 2147483634). Requires CAP_NET_ADMIN in a user namespace.
--- net/sched/sch_fq.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/sched/sch_fq.c +4 -2
@@ -940,12 +940,14 @@ static int fq_init(struct Qdisc *sch, struct nlattr *opt, struct netlink_ext_ack *extack) {struct fq_sched_data *q =qdisc_priv (sch); +u32 mtu;int err; sch->limit =10000 ; q->flow_plimit =100 ; - q->quantum =2 *psched_mtu (qdisc_dev (sch)); - q->initial_quantum =10 *psched_mtu (qdisc_dev (sch)); + mtu =clamp_t (u32,psched_mtu (qdisc_dev (sch)),1 ,1 <<20 ); + q->quantum =min_t (u32,2 * mtu,1 <<20 ); + q->initial_quantum =min_t (u32,10 * mtu,1 <<20 ); q->flow_refill_delay =msecs_to_jiffies (40 ); q->flow_max_rate = ~0UL ; q->time_next_delayed_flow = ~0ULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1374/1674 net/sched: act_ife: Only operate on Ethernet frames
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Victor Nogueira <[email protected]>
[ Upstream commit 5b483f7791b079bb97d411f1066652ff659207ff ]
act_ife encapsulates/decapsulates the original Ethernet header and uses skb->dev->hard_header_len as the length of that header. That is only correct for Ethernet devices: on a device where hard_header_len does not match the L2 header that was actually pulled (PPP reports PPP_HDRLEN while nothing is stripped on ingress), the ingress skb_push()/skb_pull() use the wrong length and can hit skb_under_panic when headroom is tight.
IFE is Ethernet-only by design - it builds an outer ethhdr, rewrites h_source/h_dest/h_proto, and calls eth_type_trans() on decode - so instead of trying to make the offsets work for arbitrary link types, simply drop packets that do not carry an Ethernet header.
Checking skb->dev->type alone is not enough. We have to cater for a corner case where mirred can redirect an skb from a non-Ethernet device to an Ethernet one, and skb->dev then says nothing about the framing the skb actually has: an skb redirected from ppp0 reaches the target's ingress hook with mac_len 0 and no Ethernet header at all. So at ingress also require mac_len to be ETH_HLEN. On egress mac_len is not maintained, so the device type is all we have; a bogus redirect there yields a malformed frame rather than an out-of-bounds push, and it would be malformed with or without IFE.
That corner case is not theoretical - redirecting from ppp0 into a veth that has an ife encode action on its ingress hook panics without this patch:
skbuff: skb_under_panic: len:98 put:14 head:ffff88800e410000
data:ffff88800e40fff5 tail:0x57 end:0x640 dev:veth3 kernel BUG at net/core/skbuff.c:214! Call Trace: skb_push (net/core/skbuff.c:224 net/core/skbuff.c:2657) tcf_ife_act (net/sched/act_ife.c:829 net/sched/act_ife.c:874) tc_run (net/core/dev.c:4463) netif_receive_skb (net/core/dev.c:6463 net/core/dev.c:6522) tcf_mirred_to_dev (net/sched/act_mirred.c:248 net/sched/act_mirred.c:328) tcf_mirred_act (net/sched/act_mirred.c:489) tc_run (net/core/dev.c:4463) process_backlog (net/core/dev.c:6728)
With Ethernet framing guaranteed, use ETH_HLEN instead of hard_header_len.
--- net/ife/ife.c | 14 +++++++------- net/sched/act_ife.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 11 deletions(-)
net/ife/ife.c +7 -7
@@ -37,7 +37,7 @@ void *ife_encode(struct sk_buff *skb, u16 metalen)* where ORIGDATA = original ethernet header ... */ int hdrm = metalen +IFE_METAHDRLEN ; -int total_push = hdrm + skb->dev->hard_header_len; +int total_push = hdrm +ETH_HLEN ;struct ifeheadr *ifehdr;struct ethhdr *iethh;/* inner ether header */ int skboff =0 ;
@@ -50,9 +50,9 @@ void *ife_encode(struct sk_buff *skb, u16 metalen) iethh = (struct ethhdr *) skb->data;__skb_push (skb, total_push); -memcpy (skb->data, iethh, skb->dev->hard_header_len); +memcpy (skb->data, iethh,ETH_HLEN );skb_reset_mac_header (skb); - skboff += skb->dev->hard_header_len; + skboff +=ETH_HLEN ;/* total metadata length */ ifehdr = (struct ifeheadr *) (skb->data + skboff);
@@ -69,12 +69,12 @@ void *ife_decode(struct sk_buff *skb, u16 *metalen)int total_pull;u16 ifehdrln; -if (!pskb_may_pull (skb, skb->dev->hard_header_len +IFE_METAHDRLEN )) +if (!pskb_may_pull (skb,ETH_HLEN +IFE_METAHDRLEN ))return NULL ; - ifehdr = (struct ifeheadr *) (skb->data + skb->dev->hard_header_len); + ifehdr = (struct ifeheadr *)(skb->data +ETH_HLEN ); ifehdrln =ntohs (ifehdr->metalen); - total_pull = skb->dev->hard_header_len + ifehdrln; + total_pull =ETH_HLEN + ifehdrln;if (unlikely (ifehdrln <2 ))return NULL ;
@@ -82,7 +82,7 @@ void *ife_decode(struct sk_buff *skb, u16 *metalen)if (unlikely (!pskb_may_pull (skb, total_pull +ETH_HLEN )))return NULL ; - ifehdr = (struct ifeheadr *)(skb->data + skb->dev->hard_header_len); + ifehdr = (struct ifeheadr *)(skb->data +ETH_HLEN );skb_set_mac_header (skb, total_pull);__skb_pull (skb, total_pull); *metalen = ifehdrln -IFE_METAHDRLEN ;
net/sched/act_ife.c +28 -4
@@ -28,6 +28,7 @@#include <uapi/linux/tc_act/tc_ife.h> #include <net/tc_act/tc_ife.h> #include <linux/etherdevice.h> +#include <linux/if_arp.h> #include <net/ife.h> #include <net/tc_wrapper.h>
@@ -723,7 +724,7 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a,tcf_lastuse_update (&ife->tcf_tm);if (skb_at_tc_ingress (skb)) -skb_push (skb, skb->dev->hard_header_len); +skb_push (skb,ETH_HLEN ); tlv_data =ife_decode (skb, &metalen);if (unlikely (!tlv_data)) {
@@ -795,7 +796,7 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a,where ORIGDATA = original ethernet header ... */ u16 metalen =ife_get_sz (skb, p); -int hdrm = metalen + skb->dev->hard_header_len +IFE_METAHDRLEN ; +int hdrm = metalen +ETH_HLEN +IFE_METAHDRLEN ;unsigned int skboff =0 ;int new_len = skb->len + hdrm;bool exceed_mtu = false;
@@ -826,7 +827,7 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a, }if (skb_at_tc_ingress (skb)) -skb_push (skb, skb->dev->hard_header_len); +skb_push (skb,ETH_HLEN ); ife_meta =ife_encode (skb, metalen);if (!ife_meta)
@@ -856,11 +857,27 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a, oethh->h_proto =htons (p->eth_type);if (skb_at_tc_ingress (skb)) -skb_pull (skb, skb->dev->hard_header_len); +skb_pull (skb,ETH_HLEN );return action; } +/* IFE encapsulates the original Ethernet header and, on decode, expects to +* find one, so it can only ever work on skbs that carry one. Loopback carries +* Ethernet header as well, so it qualifies here. +* At ingress, also verify that the L2 header about to be pushed back really +* is an Ethernet header because the skb could've been redirected with mirred +* from a non-Ethernet device. +*/ +static bool tcf_ife_is_eth_skb (const struct sk_buff *skb) +{ +if (skb->dev->type !=ARPHRD_ETHER && + skb->dev->type !=ARPHRD_LOOPBACK ) +return false; + +return !skb_at_tc_ingress (skb) || skb->mac_len ==ETH_HLEN ; +} + TC_INDIRECT_SCOPE int tcf_ife_act(struct sk_buff *skb,const struct tc_action *a,struct tcf_result *res)
@@ -869,6 +886,13 @@ TC_INDIRECT_SCOPE int tcf_ife_act(struct sk_buff *skb,struct tcf_ife_params *p;int ret; +if (unlikely (!tcf_ife_is_eth_skb (skb))) { +bstats_update (this_cpu_ptr (ife->common.cpu_bstats), skb); +tcf_lastuse_update (&ife->tcf_tm); +qstats_drop_inc (this_cpu_ptr (ife->common.cpu_qstats)); +return TC_ACT_SHOT ; + } + p =rcu_dereference_bh (ife->params);if (p->flags &IFE_ENCODE ) { ret =tcf_ife_encode (skb, a, res, p);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1375/1674 octeontx2-vf: fix workqueue and netdev race in probe/remove
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anshumali Gaur <[email protected]>
[ Upstream commit 3ba97ff4f873481d370bee7f7dfb87f8296af9be ]
Initialize the VF workqueue before register_netdev() so ndo_set_rx_mode does not queue work on a NULL workqueue. Unregister the netdev before destroying the workqueue, and add proper probe error cleanup.
--- .../ethernet/marvell/octeontx2/nic/otx2_vf.c | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +13 -7
@@ -685,16 +685,16 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)snprintf (netdev->name,sizeof (netdev->name),"lbk%d" , n); } + err =otx2_wq_init (vf); +if (err) + goto err_ptp_destroy; + err =register_netdev (netdev);if (err) {dev_err (dev,"Failed to register netdevice\n" ); - goto err_ptp_destroy; + goto err_wq_destroy; } - err =otx2_wq_init (vf); -if (err) - goto err_unreg_netdev; -otx2vf_set_ethtool_ops (netdev); err =otx2vf_mcam_flow_init (vf);
@@ -722,6 +722,10 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)otx2_shutdown_tc (vf); err_unreg_netdev:unregister_netdev (netdev); +err_wq_destroy: +cancel_work_sync (&vf->reset_task); +cancel_work_sync (&vf->rx_mode_work); +destroy_workqueue (vf->otx2_wq); err_ptp_destroy:otx2_ptp_destroy (vf); err_detach_rsrc:
@@ -769,11 +773,13 @@ static void otx2vf_remove(struct pci_dev *pdev) }#endif -cancel_work_sync (&vf->reset_task);otx2_unregister_dl (vf);unregister_netdev (netdev); -if (vf->otx2_wq) +if (vf->otx2_wq) { +cancel_work_sync (&vf->reset_task); +cancel_work_sync (&vf->rx_mode_work);destroy_workqueue (vf->otx2_wq); + }otx2_ptp_destroy (vf);otx2_mcam_flow_del (vf);otx2_shutdown_tc (vf);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1376/1674 Bluetooth: do not leak an hci_conn when a second LE connect is rejected
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Radek Podgorny <[email protected]>
[ Upstream commit 7e1e4047200fd7519f9bdfe8a001437715e618b4 ]
create_le_conn_complete() decides whether the failed connection is still pending by comparing it against hci_lookup_le_connect(), which returns the first LE connection in BT_CONNECT. That is the same connection only while at most one is pending.
Two can be pending. Connections created on the passive scan path sit in BT_CONNECT with HCI_CONN_SCANNING set and are invisible to hci_lookup_le_connect() until hci_le_create_conn_sync() clears the flag when their command is issued, so the -EBUSY guard in hci_connect_le() does not prevent a second connection from being queued while the first is still on the scan path. Whenever two connections are in BT_CONNECT at once, the lookup may return one connection while create_le_conn_complete() is reporting the failure of the other; the early exit then drops the error and hci_conn_failed() never runs on the connection that failed.
The controller also rejects a second HCI_OP_LE_CREATE_CONN issued while another connection creation is still outstanding, per Core Spec Vol 4, Part E. The spec calls for Command Disallowed there; the bcm43438 observed here answers with an LMP/LL error code instead, which bt_to_errno() maps to the -EPROTO (-71) in the log below.
The leaked connection stays in BT_CONNECT forever, and because hci_connect_le() refuses to dial while hci_lookup_le_connect() finds anything, every subsequent attempt to reach any peer fails with -EBUSY and no command reaches the controller at all.
Seen on a bcm43438 with two BLE peers polled on the same interval (state 5 is BT_CONNECT; both handles are UNSET ones, allocated from the ida above HCI_CONN_HANDLE_MAX):
Bluetooth: hci1: Opcode 0x2013 failed: -71
# hcitool con
< LE 14:9C:EF:03:68:81 handle 3840 state 5 lm CENTRAL
< LE C4:D3:6A:8C:B5:38 handle 3841 state 5 lm CENTRALA btmon capture across the next ten minutes of connect attempts contains no HCI_OP_LE_CREATE_CONN at all; outgoing LE connections do not recover until the adapter is reset. With this change the same scenario fails the rejected connection cleanly and further connects to both peers go through.
Ask about the connection itself instead of about the device.
--- net/bluetooth/hci_sync.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/bluetooth/hci_sync.c +7 -2
@@ -7154,8 +7154,13 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) goto unlock; } -/* Check if connection is still pending */ -if (conn !=hci_lookup_le_connect (hdev)) +/* Check if this connection is still pending. +* +* hci_lookup_le_connect() returns only the first LE connection +* in BT_CONNECT, which is not necessarily this one when two are +* pending at once, so ask the connection itself. +*/ +if (conn->state !=BT_CONNECT ) goto unlock;/* Flush to make sure we send create conn cancel command if needed */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1377/1674 Bluetooth: L2CAP: access chan->conn safely in get/setsockopt
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
[ Upstream commit ca2c4c26498643f421d35ffe258fafbd3ed461c3 ]
Since commit b66774b48dd9 ("Bluetooth: L2CAP: Fix UAF in channel timeout by holding conn ref") l2cap_chan::conn has held reference and remains non-NULL also after the corresponding hci_conn is deleted. In this state accessing various
fields eg. hci_conn::hdev is invalid, which leads to KASAN crash in l2cap_sock_setsockopt() access of conn->hcon->hdev.
Check l2cap_chan::conn.hcon corresponds to an alive hci_conn before trying to use it in l2cap_sock.c. Hold l2cap_chan_lock() in getsockopt/setsockopt to ensure it stays alive, and to avoid data races in l2cap_chan fields.
--- net/bluetooth/l2cap_sock.c | 57 ++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 11 deletions(-)
net/bluetooth/l2cap_sock.c +46 -11
@@ -437,11 +437,26 @@ static int l2cap_get_mode(struct l2cap_chan *chan)return -EINVAL ; } +static struct l2cap_conn *l2cap_chan_conn (struct l2cap_chan *chan) +{ +lockdep_assert_held (&chan->lock); + +/* l2cap_conn_del() sets FLAG_DEL while holding chan->lock before +* conn->hcon is deleted. If not set and conn is non-NULL, conn->hcon +* remains alive during this chan->lock critical section. +*/ +if (test_bit (FLAG_DEL , &chan->flags)) +return NULL ; + +return chan->conn; +} +static int l2cap_sock_getsockopt_old (struct socket *sock,int optname,char __user *optval,int __user *optlen) {struct sock *sk = sock->sk;struct l2cap_chan *chan =l2cap_pi (sk)->chan; +struct l2cap_conn *conn;struct l2cap_options opts;struct l2cap_conninfo cinfo;int err =0 ;
@@ -453,6 +468,7 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname,if (get_user (len, optlen))return -EFAULT ; +l2cap_chan_lock (chan);lock_sock (sk);switch (optname) {
@@ -538,9 +554,15 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname,break ; } + conn =l2cap_chan_conn (chan); +if (!conn) { + err = -ENOTCONN ; +break ; + } +memset (&cinfo,0 ,sizeof (cinfo)); - cinfo.hci_handle = chan->conn->hcon->handle; -memcpy (cinfo.dev_class, chan->conn->hcon->dev_class,3 ); + cinfo.hci_handle = conn->hcon->handle; +memcpy (cinfo.dev_class, conn->hcon->dev_class,3 ); len =min (len,sizeof (cinfo));if (copy_to_user (optval, (char *) &cinfo, len))
@@ -554,6 +576,8 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, }release_sock (sk); +l2cap_chan_unlock (chan); +return err; }
@@ -562,6 +586,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, {struct sock *sk = sock->sk;struct l2cap_chan *chan =l2cap_pi (sk)->chan; +struct l2cap_conn *conn;struct bt_security sec;struct bt_power pwr;u32 phys;
@@ -578,6 +603,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,if (get_user (len, optlen))return -EFAULT ; +l2cap_chan_lock (chan);lock_sock (sk);switch (optname) {
@@ -589,12 +615,14 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,break ; } + conn =l2cap_chan_conn (chan); +memset (&sec,0 ,sizeof (sec)); -if (chan->conn) { - sec.level = chan->conn->hcon->sec_level; +if (conn) { + sec.level = conn->hcon->sec_level;if (sk->sk_state ==BT_CONNECTED ) - sec.key_size = chan->conn->hcon->enc_key_size; + sec.key_size = conn->hcon->enc_key_size; }else { sec.level = chan->sec_level; }
@@ -670,12 +698,14 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,break ;case BT_PHY : -if (sk->sk_state !=BT_CONNECTED ) { + conn =l2cap_chan_conn (chan); + +if (sk->sk_state !=BT_CONNECTED || !conn) { err = -ENOTCONN ;break ; } - phys =hci_conn_get_phy (chan->conn->hcon); + phys =hci_conn_get_phy (conn->hcon);if (put_user (phys, (u32 __user *) optval)) err = -EFAULT ;
@@ -708,6 +738,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, }release_sock (sk); +l2cap_chan_unlock (chan);return err; }
@@ -738,6 +769,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,BT_DBG ("sk %p" , sk); +l2cap_chan_lock (chan);lock_sock (sk);switch (optname) {
@@ -838,6 +870,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, }release_sock (sk); +l2cap_chan_unlock (chan);return err; }
@@ -901,6 +934,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,if (level !=SOL_BLUETOOTH )return -ENOPROTOOPT ; +l2cap_chan_lock (chan);lock_sock (sk);switch (optname) {
@@ -926,11 +960,10 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, chan->sec_level = sec.level; -if (!chan->conn) + conn =l2cap_chan_conn (chan); +if (!conn)break ; - conn = chan->conn; -/* change security for LE channels */ if (chan->scid ==L2CAP_CID_ATT ) {if (smp_conn_security (conn->hcon, sec.level)) {
@@ -985,7 +1018,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, }if (opt ==BT_FLUSHABLE_OFF ) { - conn = chan->conn; + conn =l2cap_chan_conn (chan); +/* proceed further only when we have l2cap_conn and No Flush support in the LM */ if (!conn || !lmp_no_flush_capable (conn->hcon->hdev)) {
@@ -1108,6 +1142,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, }release_sock (sk); +l2cap_chan_unlock (chan);return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1378/1674 Drivers: hv: vmbus: Skip VMBus module cleanup for non-nested root partition
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Kelley <[email protected]>
[ Upstream commit cee0d90bceae1dee3bcc70f8d6b2ceb5b87deb42 ]
The VMBus module initialization function, hv_acpi_init(), currently does nothing when running in the root partition and root is not nested in another VM. But the initialization function reports success, so the VMBus module is indeed loaded. VMBus functionality is not actually needed, but the VMBus module must be loaded so that hv_vmbus_exists() can answer correctly. Furthermore, the mshv_root dependency on the VMBus module is needed as described in the commit message for 840b740a35bf ("mshv: Add conditional VMBus dependency").
Loading the VMBus module without actually initializing it causes failures if the module should later be unloaded. The module unload code tries to clean up things that were never initialized, resulting in memory faults and a panic.
Fix this by having VMBus module exit function perform the same check for non-nested root partition, and do nothing in such a case, just like hv_acpi_init().
In the long run, the code that manages the Hyper-V provided SynIC should be refactored to better coordinate the requirements of root partition scenarios and normal VM scenarios, and to hopefully remove the hv_vmbus_exists() dependnecy between mshv_root and VMBus modules. Preventing the current unload failure scenario is an expediency until such a refactoring is done.
--- drivers/hv/vmbus_drv.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/hv/vmbus_drv.c +15 -0
@@ -2640,6 +2640,13 @@ static int __init hv_acpi_init(void)return -ENODEV ;if (hv_root_partition && !hv_nested) +/* +* A non-nested root partition does not need VMBus client +* functionality. However, the mshv_root module may have +* a dependency on the VMBus module as described in +* commit 840b740a35bf. Return success so the module +* loads even though no VMBus initialization is done. +*/ return 0 ;/*
@@ -2688,6 +2695,14 @@ static void __exit vmbus_exit(void) {int cpu; +if (hv_root_partition && !hv_nested) +/* +* If a non-nested root partition loaded the VMBus module, +* hv_acpi_init() did not do any VMBus initialization. +* There's nothing to clean up, so just return. +*/ +return ; +unregister_syscore_ops (&hv_synic_syscore_ops);hv_remove_kexec_handler ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1379/1674 net/sched: account classifier filter allocations to memcg
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 1beb81947eb486716af80db7a584f9e9fef7e003 ]
Allocations in the tc classifier *_change() paths (filter objects, per-CPU counters, and per-filter aux data) use plain GFP_KERNEL without __GFP_ACCOUNT, allowing unprivileged users to pin kernel memory outside memcg charging. The shared tcf_exts_init_ex() action array allocation in cls_api.c was also uncharged; this patch closes it along with the per-classifier filter-object/percpu/aux allocations that remain unaccounted.
Add GFP_KERNEL_ACCOUNT to:
- the shared tcf_exts_init_ex() action array (cls_api.c), common to every filter of every classifier (32 pointers, 256 bytes);
- the filter-object, per-CPU-counter, and per-filter aux allocations in cls_basic, cls_bpf, cls_cgroup, cls_flow, cls_flower, cls_fw, cls_matchall, cls_route and cls_u32;
- the u32_init_knode() replace-path knode allocation (cls_u32.c), which allocates the same struct tc_u_knode + sel.keys on every replace of an existing knode and was missed by the create-path-only conversion.
Also fix the cls_basic error path: basic_change() inserts fnew into the IDR before allocating the per-CPU counter. If alloc_percpu() fails the errout path kfree'd fnew without idr_remove, leaving a dangling pointer in the IDR. With GFP_KERNEL_ACCOUNT the percpu alloc becomes failable on demand (memcg at memory.max), making the dead path attacker-reachable and burning the handle permanently. Add the idr_remove on the percpu failure path, matching the basic_set_parms failure-path pattern.
Note: [email protected] provided a poc for basic_cls, but it was easy to extend to the other classifiers.
Conditions to recreate the bug:
- CONFIG_NET_SCHED, CONFIG_NET_CLS_* (the classifier being used), CONFIG_NET_CLS_ACT, CONFIG_MEMCG, CONFIG_USER_NS, CONFIG_NET_NS.
- Unprivileged user in a fresh user+network namespace (unshare -Urn), or root with CAP_NET_ADMIN.
- Create a large number of tc filters (e.g. tc filter add dev lo ingress ... <classifier> ...) while watching a memcg-limited cgroup:
system slab grows far faster than memory.current, pinning kernel memory outside memcg charging.
--- net/sched/cls_api.c | 2 +- net/sched/cls_basic.c | 6 ++++-- net/sched/cls_bpf.c | 6 +++--- net/sched/cls_cgroup.c | 2 +- net/sched/cls_flow.c | 2 +- net/sched/cls_flower.c | 4 ++-- net/sched/cls_fw.c | 4 ++-- net/sched/cls_matchall.c | 4 ++-- net/sched/cls_route.c | 4 ++-- net/sched/cls_u32.c | 11 ++++++----- 10 files changed, 24 insertions(+), 21 deletions(-)
net/sched/cls_api.c +1 -1
@@ -3356,7 +3356,7 @@ int tcf_exts_init_ex(struct tcf_exts *exts, struct net *net, int action,*/ exts->net = net; exts->actions =kcalloc (TCA_ACT_MAX_PRIO ,sizeof (struct tc_action *), -GFP_KERNEL ); +GFP_KERNEL_ACCOUNT );if (!exts->actions)return -ENOMEM ;#endif
net/sched/cls_basic.c +4 -2
@@ -193,7 +193,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,return -EINVAL ; } - fnew =kzalloc (sizeof (*fnew),GFP_KERNEL ); + fnew =kzalloc (sizeof (*fnew),GFP_KERNEL_ACCOUNT );if (!fnew)return -ENOBUFS ;
@@ -212,9 +212,11 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,if (err) goto errout; fnew->handle = handle; - fnew->pf = alloc_percpu(struct tc_basic_pcnt); + fnew->pf = alloc_percpu_gfp(struct tc_basic_pcnt, GFP_KERNEL_ACCOUNT);if (!fnew->pf) { err = -ENOMEM ; +if (!fold) +idr_remove (&head->handle_idr, fnew->handle); goto errout; }
net/sched/cls_bpf.c +3 -3
@@ -352,7 +352,7 @@ static int cls_bpf_prog_from_ops(struct nlattr **tb, struct cls_bpf_prog *prog)if (bpf_size !=nla_len (tb[TCA_BPF_OPS ]))return -EINVAL ; - bpf_ops =kmemdup (nla_data (tb[TCA_BPF_OPS ]), bpf_size,GFP_KERNEL ); + bpf_ops =kmemdup (nla_data (tb[TCA_BPF_OPS ]), bpf_size,GFP_KERNEL_ACCOUNT );if (bpf_ops ==NULL )return -ENOMEM ;
@@ -403,7 +403,7 @@ static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog, }if (tb[TCA_BPF_NAME ]) { - name =nla_memdup (tb[TCA_BPF_NAME ],GFP_KERNEL ); + name =nla_memdup (tb[TCA_BPF_NAME ],GFP_KERNEL_ACCOUNT );if (!name) {bpf_prog_put (fp);return -ENOMEM ;
@@ -443,7 +443,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,if (ret <0 )return ret; - prog =kzalloc (sizeof (*prog),GFP_KERNEL ); + prog =kzalloc (sizeof (*prog),GFP_KERNEL_ACCOUNT );if (!prog)return -ENOBUFS ;
net/sched/cls_cgroup.c +1 -1
@@ -95,7 +95,7 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,if (head && handle != head->handle)return -ENOENT ; - new =kzalloc (sizeof (*head),GFP_KERNEL ); + new =kzalloc (sizeof (*head),GFP_KERNEL_ACCOUNT );if (!new)return -ENOBUFS ;
net/sched/cls_flow.c +1 -1
@@ -438,7 +438,7 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,return -EOPNOTSUPP ; } - fnew =kzalloc (sizeof (*fnew),GFP_KERNEL ); + fnew =kzalloc (sizeof (*fnew),GFP_KERNEL_ACCOUNT );if (!fnew)return -ENOBUFS ;
net/sched/cls_flower.c +2 -2
@@ -2109,7 +2109,7 @@ static struct fl_flow_mask *fl_create_new_mask(struct cls_fl_head *head,struct fl_flow_mask *newmask;int err; - newmask =kzalloc (sizeof (*newmask),GFP_KERNEL ); + newmask =kzalloc (sizeof (*newmask),GFP_KERNEL_ACCOUNT );if (!newmask)return ERR_PTR (-ENOMEM );
@@ -2269,7 +2269,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, goto errout_tb; } - fnew =kzalloc (sizeof (*fnew),GFP_KERNEL ); + fnew =kzalloc (sizeof (*fnew),GFP_KERNEL_ACCOUNT );if (!fnew) { err = -ENOBUFS ; goto errout_tb;
net/sched/cls_fw.c +2 -2
@@ -276,7 +276,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,if (f->id != handle && handle)return -EINVAL ; - fnew =kzalloc (sizeof (struct fw_filter ),GFP_KERNEL ); + fnew =kzalloc (sizeof (struct fw_filter ),GFP_KERNEL_ACCOUNT );if (!fnew)return -ENOBUFS ;
@@ -330,7 +330,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,rcu_assign_pointer (tp->root, head); } - f =kzalloc (sizeof (struct fw_filter ),GFP_KERNEL ); + f =kzalloc (sizeof (struct fw_filter ),GFP_KERNEL_ACCOUNT );if (f ==NULL )return -ENOBUFS ;
net/sched/cls_matchall.c +2 -2
@@ -189,7 +189,7 @@ static int mall_change(struct net *net, struct sk_buff *in_skb,return -EINVAL ; } - new =kzalloc (sizeof (*new),GFP_KERNEL ); + new =kzalloc (sizeof (*new),GFP_KERNEL_ACCOUNT );if (!new)return -ENOBUFS ;
@@ -201,7 +201,7 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, handle =1 ; new->handle = handle; new->flags = userflags; - new->pf = alloc_percpu(struct tc_matchall_pcnt); + new->pf = alloc_percpu_gfp(struct tc_matchall_pcnt, GFP_KERNEL_ACCOUNT);if (!new->pf) { err = -ENOMEM ; goto err_alloc_percpu;
net/sched/cls_route.c +2 -2
@@ -455,7 +455,7 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp, h1 =to_hash (nhandle); b =rtnl_dereference (head->table[h1]);if (!b) { - b =kzalloc (sizeof (struct route4_bucket ),GFP_KERNEL ); + b =kzalloc (sizeof (struct route4_bucket ),GFP_KERNEL_ACCOUNT );if (b ==NULL )return -ENOBUFS ;
@@ -530,7 +530,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,return -EINVAL ; err = -ENOBUFS ; - f =kzalloc (sizeof (struct route4_filter ),GFP_KERNEL ); + f =kzalloc (sizeof (struct route4_filter ),GFP_KERNEL_ACCOUNT );if (!f) goto errout;
net/sched/cls_u32.c +6 -5
@@ -841,7 +841,7 @@ static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp,struct tc_u32_sel *s = &n->sel;struct tc_u_knode *new; - new =kzalloc (struct_size (new, sel.keys, s->nkeys),GFP_KERNEL ); + new =kzalloc (struct_size (new, sel.keys, s->nkeys),GFP_KERNEL_ACCOUNT );if (!new)return NULL ;
@@ -1139,15 +1139,16 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, goto erridr; } - n =kzalloc (struct_size (n, sel.keys, s->nkeys),GFP_KERNEL ); + n =kzalloc (struct_size (n, sel.keys, s->nkeys),GFP_KERNEL_ACCOUNT );if (n ==NULL ) { err = -ENOBUFS ; goto erridr; }#ifdef CONFIG_CLS_U32_PERF - n->pf =__alloc_percpu (struct_size (n->pf, kcnts, s->nkeys), - __alignof__(struct tc_u32_pcnt )); + n->pf =__alloc_percpu_gfp (struct_size (n->pf, kcnts, s->nkeys), + __alignof__(struct tc_u32_pcnt ), +GFP_KERNEL_ACCOUNT );if (!n->pf) { err = -ENOBUFS ; goto errfree;
@@ -1169,7 +1170,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, goto errout;#ifdef CONFIG_CLS_U32_MARK - n->pcpu_success =alloc_percpu (u32); + n->pcpu_success =alloc_percpu_gfp (u32,GFP_KERNEL_ACCOUNT );if (!n->pcpu_success) { err = -ENOMEM ; goto errout;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1380/1674 NFSv4.1: zero referring call lists before decoding
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 8fa4804fe62ca4155a2d8fc2789d630376cbf2fc ]
decode_cb_sequence_args() allocates csa_rclists with kmalloc_objs(), so each referring_call_list starts uninitialized. decode_rc_list() assigns rcl_refcalls only when rcl_nrefcalls is nonzero. A valid list with zero referring calls therefore leaves the pointer uninitialized, and nfs4_callback_sequence() later passes stale slab contents to kfree().
Allocate csa_rclists with kzalloc_objs() so every rcl_refcalls member is NULL from the beginning, including valid empty referring call lists.
--- fs/nfs/callback_xdr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/nfs/callback_xdr.c +3 -3
@@ -419,9 +419,9 @@ static __be32 decode_cb_sequence_args(struct svc_rqst *rqstp, args->csa_nrclists =ntohl (*p++); args->csa_rclists =NULL ;if (args->csa_nrclists) { - args->csa_rclists =kmalloc_array (args->csa_nrclists, -sizeof (*args->csa_rclists), -GFP_KERNEL ); + args->csa_rclists =kcalloc (args->csa_nrclists, +sizeof (*args->csa_rclists), +GFP_KERNEL );if (unlikely (args->csa_rclists ==NULL ))return htonl (NFS4ERR_RESOURCE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1381/1674 vxlan: fix reading neigh ha
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikolay Aleksandrov <[email protected]>
[ Upstream commit b824059a673b2283e78c7aae2c7d257aad7f0e1d ]
Currently arp/neigh_reduce read neigh ha directly which can lead to partial reads while the neigh is being updated. Use neigh_ha_snapshot to take a stable snapshot of the address similar to route_shortcircuit which already does the right thing.
--- drivers/net/vxlan/vxlan_core.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/net/vxlan/vxlan_core.c +13 -7
@@ -1899,6 +1899,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (n) {struct vxlan_rdst *rdst =NULL ; +u8 ha[ETH_ALEN ]__aligned(2) ;struct vxlan_fdb *f;struct sk_buff *reply;
@@ -1907,7 +1908,9 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) goto out; } - f =vxlan_find_mac (vxlan, n->ha, vni); +neigh_ha_snapshot (ha, n, n->dev); + + f =vxlan_find_mac (vxlan, ha, vni);if (f) rdst =first_remote_rcu (f);if (rdst &&vxlan_addr_any (&rdst->remote_ip)) {
@@ -1917,7 +1920,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) } reply =arp_create (ARPOP_REPLY ,ETH_P_ARP , sip, dev, tip, sha, - n->ha, sha); + ha, sha);neigh_release (n);
@@ -1950,7 +1953,8 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)#if IS_ENABLED (CONFIG_IPV6 )static struct sk_buff *vxlan_na_create (struct sk_buff *request, -struct neighbour *n,bool isrouter) +struct neighbour *n,u8 *ha, +bool isrouter) {struct net_device *dev = request->dev;struct sk_buff *reply;
@@ -1998,7 +2002,7 @@ static struct sk_buff *vxlan_na_create(struct sk_buff *request,/* Ethernet header */ ether_addr_copy (eth_hdr (reply)->h_dest, daddr); -ether_addr_copy (eth_hdr (reply)->h_source, n->ha); +ether_addr_copy (eth_hdr (reply)->h_source, ha);eth_hdr (reply)->h_proto =htons (ETH_P_IPV6 ); reply->protocol =htons (ETH_P_IPV6 );
@@ -2027,7 +2031,7 @@ static struct sk_buff *vxlan_na_create(struct sk_buff *request, na->icmph.icmp6_override =1 ; na->icmph.icmp6_solicited =1 ; na->target = ns->target; -ether_addr_copy (&na->opt[2 ], n->ha); +ether_addr_copy (&na->opt[2 ], ha); na->opt[0 ] =ND_OPT_TARGET_LL_ADDR ; na->opt[1 ] = na_olen >>3 ;
@@ -2070,6 +2074,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (n) {struct vxlan_rdst *rdst =NULL ; +u8 ha[ETH_ALEN ]__aligned(2) ;struct vxlan_fdb *f;struct sk_buff *reply;
@@ -2078,7 +2083,8 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) goto out; } - f =vxlan_find_mac (vxlan, n->ha, vni); +neigh_ha_snapshot (ha, n, n->dev); + f =vxlan_find_mac (vxlan, ha, vni);if (f) rdst =first_remote_rcu (f);if (rdst &&vxlan_addr_any (&rdst->remote_ip)) {
@@ -2087,7 +2093,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) goto out; } - reply =vxlan_na_create (skb, n, + reply =vxlan_na_create (skb, n, ha, !!(f ? f->flags &NTF_ROUTER :0 ));neigh_release (n);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1382/1674 net: bridge: arp/nd proxy: fix reading neigh ha
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikolay Aleksandrov <[email protected]>
[ Upstream commit 57549ab9079122991dfa0f8248ca00e101e8e69b ]
Currently neigh ha address is read directly, but that can result in torn/partial reads if the neigh is being updated. Use neigh_ha_snapshot to take a stable snapshot of the address.
--- net/bridge/br_arp_nd_proxy.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
net/bridge/br_arp_nd_proxy.c +14 -10
@@ -191,13 +191,15 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, n =neigh_lookup (&arp_tbl, &tip, vlandev);if (n) {struct net_bridge_fdb_entry *f; +u8 ha[ETH_ALEN ]__aligned(2) ;if (!(READ_ONCE (n->nud_state) &NUD_VALID )) {neigh_release (n);return ; } - f =br_fdb_find_rcu (br, n->ha, vid); +neigh_ha_snapshot (ha, n, n->dev); + f =br_fdb_find_rcu (br, ha, vid);if (f) {const struct net_bridge_port *dst =READ_ONCE (f->dst);bool replied = false;
@@ -207,10 +209,10 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, br_is_neigh_suppress_enabled(dst, vid)) {if (!vid)br_arp_send (br, p, skb->dev, sip, tip, - sha, n->ha, sha,0 ,0 ); + sha, ha, sha,0 ,0 );else br_arp_send (br, p, skb->dev, sip, tip, - sha, n->ha, sha, + sha, ha, sha, skb->vlan_proto,skb_vlan_tag_get (skb)); replied = true;
@@ -248,7 +250,7 @@ struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb, struct nd_msg *msg) }static void br_nd_send (struct net_bridge *br,struct net_bridge_port *p, -struct sk_buff *request,struct neighbour *n, +struct sk_buff *request,struct neighbour *n,u8 *ha,__be16 vlan_proto,u16 vlan_tci) {struct net_device *dev = request->dev;
@@ -306,7 +308,7 @@ static void br_nd_send(struct net_bridge *br, struct net_bridge_port *p,ipv6_eth_mc_map (&in6addr_linklocal_allnodes,eth_hdr (reply)->h_dest); else ether_addr_copy(eth_hdr(reply)->h_dest, daddr); -ether_addr_copy (eth_hdr (reply)->h_source, n->ha); +ether_addr_copy (eth_hdr (reply)->h_source, ha);eth_hdr (reply)->h_proto =htons (ETH_P_IPV6 ); reply->protocol =htons (ETH_P_IPV6 );
@@ -336,7 +338,7 @@ static void br_nd_send(struct net_bridge *br, struct net_bridge_port *p, na->icmph.icmp6_override =1 ; na->icmph.icmp6_solicited = dad ?0 :1 ; na->target = ns->target; -ether_addr_copy (&na->opt[2 ], n->ha); +ether_addr_copy (&na->opt[2 ], ha); na->opt[0 ] =ND_OPT_TARGET_LL_ADDR ; na->opt[1 ] = na_olen >>3 ;
@@ -365,7 +367,7 @@ static void br_nd_send(struct net_bridge *br, struct net_bridge_port *p,__vlan_hwaccel_put_tag (reply, vlan_proto, vlan_tci);netdev_dbg (dev,"nd send dev %s dst %pI6 dst_hw %pM src %pI6 src_hw %pM\n" , - dev->name, &pip6->daddr, daddr, &pip6->saddr, n->ha); + dev->name, &pip6->daddr, daddr, &pip6->saddr, ha);if (p) {dev_queue_xmit (reply);
@@ -462,24 +464,26 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, n =neigh_lookup (ipv6_stub->nd_tbl, &msg->target, vlandev);if (n) {struct net_bridge_fdb_entry *f; +u8 ha[ETH_ALEN ]__aligned(2) ;if (!(READ_ONCE (n->nud_state) &NUD_VALID )) {neigh_release (n);return ; } - f =br_fdb_find_rcu (br, n->ha, vid); +neigh_ha_snapshot (ha, n, n->dev); + f =br_fdb_find_rcu (br, ha, vid);if (f) {const struct net_bridge_port *dst =READ_ONCE (f->dst);bool replied = false;if (br_is_neigh_suppress_enabled (dst, vid)) {if (vid !=0 ) -br_nd_send (br, p, skb, n, +br_nd_send (br, p, skb, n, ha, skb->vlan_proto,skb_vlan_tag_get (skb));else -br_nd_send (br, p, skb, n,0 ,0 ); +br_nd_send (br, p, skb, n, ha,0 ,0 ); replied = true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1383/1674 net_sched: sch_fifo: implement lockless __fifo_dump()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 01daf66b791e1ddd1a4aae2a65ea65fa1d4a96ef ]
Instead of relying on RTNL, __fifo_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() ones in __fifo_init().
Also add missing READ_ONCE(sh->limit) in bfifo_enqueue(), pfifo_enqueue() and pfifo_tail_enqueue().
Stable-dep-of: 4c660ee8c809 ("net: sched: fix 32-bit backlog wrap in gred, bfifo and plug enqueue")
--- net/sched/sch_fifo.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
net/sched/sch_fifo.c +9 -7
@@ -19,7 +19,8 @@static int bfifo_enqueue (struct sk_buff *skb,struct Qdisc *sch,struct sk_buff **to_free) { -if (likely (sch->qstats.backlog +qdisc_pkt_len (skb) <= sch->limit)) +if (likely (sch->qstats.backlog +qdisc_pkt_len (skb) <= +READ_ONCE (sch->limit)))return qdisc_enqueue_tail (skb, sch);return qdisc_drop (skb, sch, to_free);
@@ -28,7 +29,7 @@ static int bfifo_enqueue(struct sk_buff *skb, struct Qdisc *sch,static int pfifo_enqueue (struct sk_buff *skb,struct Qdisc *sch,struct sk_buff **to_free) { -if (likely (sch->q.qlen < sch->limit)) +if (likely (sch->q.qlen <READ_ONCE (sch->limit)))return qdisc_enqueue_tail (skb, sch);return qdisc_drop (skb, sch, to_free);
@@ -38,11 +39,12 @@ static int pfifo_tail_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free) {unsigned int prev_backlog; +u32 limit =READ_ONCE (sch->limit); -if (unlikely (sch->limit ==0 )) +if (unlikely (limit ==0 ))return qdisc_drop (skb, sch, to_free); -if (likely (sch->q.qlen < sch->limit)) +if (likely (sch->q.qlen < limit))return qdisc_enqueue_tail (skb, sch); prev_backlog = sch->qstats.backlog;
@@ -108,14 +110,14 @@ static int __fifo_init(struct Qdisc *sch, struct nlattr *opt,if (is_bfifo) limit *=psched_mtu (qdisc_dev (sch)); - sch->limit = limit; +WRITE_ONCE (sch->limit, limit); }else {struct tc_fifo_qopt *ctl =nla_data (opt);if (nla_len (opt) <sizeof (*ctl))return -EINVAL ; - sch->limit = ctl->limit; +WRITE_ONCE (sch->limit, ctl->limit); }if (is_bfifo)
@@ -157,7 +159,7 @@ static void fifo_destroy(struct Qdisc *sch)static int __fifo_dump (struct Qdisc *sch,struct sk_buff *skb) { -struct tc_fifo_qopt opt = { .limit = sch->limit }; +struct tc_fifo_qopt opt = { .limit =READ_ONCE (sch->limit) };if (nla_put (skb,TCA_OPTIONS ,sizeof (opt), &opt)) goto nla_put_failure;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1384/1674 net: sched: fix 32-bit backlog wrap in gred, bfifo and plug enqueue
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 4c660ee8c809637909f4f7eb1017f7b9401c75c4 ]
gred_enqueue(), bfifo_enqueue() and plug_enqueue() admit a packet when the current backlog plus the packet length fits within the queue limit:
sch->qstats.backlog + qdisc_pkt_len(skb) <= sch->limit (gred default VQ) gred_backlog+qdisc_pkt_len(skb) <= q->limit (gred configured VQ) sch->qstats.backlog + qdisc_pkt_len(skb) <= sch->limit (bfifo)
sch->qstats.backlog + skb->len <= q->limit (plug)
sch->qstats.backlog and q->backlog are u32, and qdisc_pkt_len()/skb->len are unsigned int, so all sums are computed in 32 bits and wrap at 2^32. Once the true backlog exceeds 4 GiB the wrapped sum becomes small and admission keeps succeeding, so the queue grows without bound and the kernel can be driven to OOM.
Promote the sums to u64 so admission stops once the true backlog exceeds the limit. The limit is u32, so the bounded queue stays below 2^32 and the stored u32 backlog never wraps.
The bug can only be reproduced as root (albeit with ridiculous setup):
attach a gred (or bfifo/plug) qdisc with a limit near 4 GiB, leaving the default VQ unconfigured (for gred), and drive >4 GiB of queued traffic (e.g. via a size table / stab to inflate qdisc_pkt_len, or sustained high-rate traffic). The u32 backlog+len sum wraps at 2^32, admission keeps succeeding, and the queue grows unboundedly to OOM.
--- net/sched/sch_fifo.c | 2 +- net/sched/sch_gred.c | 4 ++-- net/sched/sch_plug.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
net/sched/sch_fifo.c +1 -1
@@ -19,7 +19,7 @@static int bfifo_enqueue (struct sk_buff *skb,struct Qdisc *sch,struct sk_buff **to_free) { -if (likely (sch->qstats.backlog +qdisc_pkt_len (skb) <= +if (likely ((u64 )sch->qstats.backlog +qdisc_pkt_len (skb) <=READ_ONCE (sch->limit)))return qdisc_enqueue_tail (skb, sch);
net/sched/sch_gred.c +2 -2
@@ -179,7 +179,7 @@ static int gred_enqueue(struct sk_buff *skb, struct Qdisc *sch,* if no default DP has been configured. This * allows for DP flows to be left untouched. */ -if (likely (sch->qstats.backlog +qdisc_pkt_len (skb) <= +if (likely ((u64 )sch->qstats.backlog +qdisc_pkt_len (skb) <= sch->limit))return qdisc_enqueue_tail (skb, sch);else
@@ -244,7 +244,7 @@ static int gred_enqueue(struct sk_buff *skb, struct Qdisc *sch,break ; } -if (gred_backlog (t, q, sch) +qdisc_pkt_len (skb) <= q->limit) { +if ((u64 )gred_backlog (t, q, sch) +qdisc_pkt_len (skb) <= q->limit) { q->backlog +=qdisc_pkt_len (skb);return qdisc_enqueue_tail (skb, sch); }
net/sched/sch_plug.c +1 -1
@@ -89,7 +89,7 @@ static int plug_enqueue(struct sk_buff *skb, struct Qdisc *sch, {struct plug_sched_data *q =qdisc_priv (sch); -if (likely (sch->qstats.backlog + skb->len <= q->limit)) { +if (likely ((u64 )sch->qstats.backlog + skb->len <= q->limit)) {if (!q->unplug_indefinite) q->pkts_current_epoch++;return qdisc_enqueue_tail (skb, sch);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1385/1674 ip6mr: do not clone dst in ip6mr_cache_report()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 235b42b5860189eb8c27c36435ad932cae65a734 ]
IPv6 input attaches a non-refcounted (NOREF) dst to skbs under RCU. When an ingress multicast packet misses MFC lookup, ip6mr_cache_unresolved() places the skb onto the unresolved queue, escaping the receive-side RCU grace period.
If the underlying route is deleted and freed, and the MFC queue is later resolved with a wrong parent interface, ip6_mr_forward() invokes ip6mr_cache_report(..., MRT6MSG_WRONGMIF), which executes dst_clone(skb_dst(pkt)) on the freed dst entry, triggering a slab use-after-free.
Report packets queued to mroute6_sk (a raw socket) and netlink notifications do not require an attached dst entry.
Fix this by:
1. Removing dst_clone() in ip6mr_cache_report() and ensuring report skbs do not hold a dst.
2. Dropping skb_dst before queuing unresolved skbs in ip6mr_cache_unresolved(), matching the fact that multicast forwarding resolves outgoing routes anew via ip6_route_output().
--- net/ipv6/ip6mr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv6/ip6mr.c +2 -1
@@ -1128,7 +1128,6 @@ static int ip6mr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt, msg->im6_src =ipv6_hdr (pkt)->saddr; msg->im6_dst =ipv6_hdr (pkt)->daddr; -skb_dst_set (skb,dst_clone (skb_dst (pkt))); skb->ip_summed =CHECKSUM_UNNECESSARY ; }
@@ -1138,6 +1137,7 @@ static int ip6mr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt,return -EINVAL ; } +skb_dst_drop (skb);mrt6msg_netlink_event (mrt, skb);/* Deliver to user space multicast routing algorithms */
@@ -1217,6 +1217,7 @@ static int ip6mr_cache_unresolved(struct mr_table *mrt, mifi_t mifi, skb->dev = dev; skb->skb_iif = dev->ifindex; } +skb_dst_drop (skb);skb_queue_tail (&c->_c.mfc_un.unres.unresolved, skb); err =0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1386/1674 net: qlcnic: validate unified ROM sections before loading
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 5e8076e4e4124dae75a3e080ddc20404700d7585 ]
The unified ROM parser reads directory, product, and data-descriptor fields from the firmware file. Existing validation forms table and data ends with unchecked additions and multiplications. Malformed values can wrap before they are compared with the firmware size. The parser also dereferences typed pointers at firmware-controlled offsets.
Valid descriptor extents alone are insufficient for the consumers. The loader reads a fixed-size bootloader regardless of its declared size, the version parser assumes a 17-byte tail, and a partial final firmware word is read as a full u64. A truncated image can therefore make the driver read beyond the firmware allocation during validation or loading.
Replace the pointer-returning parser with bounded range helpers. Validate table entry sizes, descriptor indices, section ranges, the fixed bootloader load length, and the version tail before exposing any section. Read all file fields with unaligned little-endian accessors and assemble a partial final word from only the bytes that remain. Apply the same range checks to the legacy image before reading its fixed fields.
--- .../net/ethernet/qlogic/qlcnic/qlcnic_init.c | 445 ++++++++++-------- 1 file changed, 248 insertions(+), 197 deletions(-)
drivers/net/ethernet/qlogic/qlcnic/qlcnic_init.c +248 -197
@@ -6,6 +6,7 @@#include "qlcnic.h" #include "qlcnic_hw.h" +#include <asm/unaligned.h> struct crb_addr_pair {u32 addr;
@@ -740,159 +741,212 @@ qlcnic_has_mn(struct qlcnic_adapter *adapter)return 0 ; } -static -struct uni_table_desc *qlcnic_get_table_desc (const u8 *unirom,int section) -{ -u32 i, entries; -struct uni_table_desc *directory = (struct uni_table_desc *) &unirom[0 ]; - entries =le32_to_cpu (directory->num_entries); - -for (i =0 ; i < entries; i++) { +#define FILEHEADER_SIZE (14 * 4) +#define QLCNIC_UNI_DIR_TYPE_OFF (8 * sizeof(__le32)) +#define QLCNIC_UNI_DIR_ENTRY_MIN_SIZE (9 * sizeof(__le32)) +#define QLCNIC_UNI_PRODUCT_ENTRY_MIN_SIZE \ + ((QLCNIC_UNI_FIRMWARE_IDX_OFF + 1) * sizeof(__le32)) +#define QLCNIC_UNI_VERSION_TAIL_SIZE 17 +#define QLCNIC_UNI_BOOTLD_SIZE \ + (QLCNIC_IMAGE_START - QLCNIC_BOOTLD_START) + +struct qlcnic_uni_data { +u32 offset; +u32 size; +}; -u32 offs =le32_to_cpu (directory->findex) + - i *le32_to_cpu (directory->entry_size); -u32 tab_type =le32_to_cpu (*((__le32 *)&unirom[offs] +8 )); +static bool qlcnic_rom_range_valid (size_t size,size_t offset,size_t len) +{ +return offset <= size && len <= size - offset; +} -if (tab_type == section) -return (struct uni_table_desc *) &unirom[offs]; - } +static bool qlcnic_rom_table_valid (size_t size,u32 offset,u32 entries, +u32 entry_size,u32 min_entry_size) +{ +if (entry_size < min_entry_size || offset > size) +return false; -return NULL ; +return entries <= (size - offset) / entry_size; } -#define FILEHEADER_SIZE (14 * 4) - -static int -qlcnic_validate_header (struct qlcnic_adapter *adapter) +static int qlcnic_get_directory (struct qlcnic_adapter *adapter, +size_t *offset,u32 *entries,u32 *entry_size) { -const u8 *unirom = adapter->fw->data; -struct uni_table_desc *directory = (struct uni_table_desc *) &unirom[0 ]; -u32 entries, entry_size, tab_size, fw_file_size; - - fw_file_size = adapter->fw->size; +const struct firmware *fw = adapter->fw; +const u8 *directory = fw->data; -if (fw_file_size <FILEHEADER_SIZE ) +if (fw->size <FILEHEADER_SIZE )return -EINVAL ; - entries =le32_to_cpu (directory->num_entries); - entry_size =le32_to_cpu (directory->entry_size); - tab_size =le32_to_cpu (directory->findex) + (entries * entry_size); + *offset =get_unaligned_le32 (directory + + offsetof(struct uni_table_desc , findex)); + *entries =get_unaligned_le32 (directory + + offsetof(struct uni_table_desc , num_entries)); + *entry_size =get_unaligned_le32 (directory + + offsetof(struct uni_table_desc , entry_size)); -if (fw_file_size < tab_size) +if (!qlcnic_rom_table_valid (fw->size, *offset, *entries, *entry_size, +QLCNIC_UNI_DIR_ENTRY_MIN_SIZE ))return -EINVAL ;return 0 ; } -static int -qlcnic_validate_bootld (struct qlcnic_adapter *adapter) +static int qlcnic_get_table_desc (struct qlcnic_adapter *adapter,int section, +size_t *desc_offset) { -struct uni_table_desc *tab_desc; -struct uni_data_desc *descr; -u32 offs, tab_size, data_size, idx;const u8 *unirom = adapter->fw->data; -__le32 temp; - - temp = *((__le32 *)&unirom[adapter->file_prd_off] + -QLCNIC_UNI_BOOTLD_IDX_OFF ); - idx =le32_to_cpu (temp); - tab_desc =qlcnic_get_table_desc (unirom,QLCNIC_UNI_DIR_SECT_BOOTLD ); - -if (!tab_desc) -return -EINVAL ; - - tab_size =le32_to_cpu (tab_desc->findex) + -le32_to_cpu (tab_desc->entry_size) * (idx +1 ); - -if (adapter->fw->size < tab_size) -return -EINVAL ; +size_t directory_offset; +u32 entries, entry_size; +size_t i; +int ret; - offs =le32_to_cpu (tab_desc->findex) + -le32_to_cpu (tab_desc->entry_size) * idx; - descr = (struct uni_data_desc *)&unirom[offs]; + ret =qlcnic_get_directory (adapter, &directory_offset, &entries, + &entry_size); +if (ret) +return ret; - data_size =le32_to_cpu (descr->findex) +le32_to_cpu (descr->size); +for (i =0 ; i < entries; i++) { +size_t offset = directory_offset + i * entry_size; +u32 table_type; -if (adapter->fw->size < data_size) -return -EINVAL ; + table_type =get_unaligned_le32 (unirom + offset + +QLCNIC_UNI_DIR_TYPE_OFF ); +if (table_type == section) { + *desc_offset = offset; +return 0 ; + } + } -return 0 ; +return -ENOENT ; }static int -qlcnic_validate_fw (struct qlcnic_adapter *adapter) +qlcnic_validate_header (struct qlcnic_adapter *adapter) { -struct uni_table_desc *tab_desc; -struct uni_data_desc *descr; -const u8 *unirom = adapter->fw->data; -u32 offs, tab_size, data_size, idx; -__le32 temp; +u32 entries, entry_size; +size_t offset; + +return qlcnic_get_directory (adapter, &offset, &entries, &entry_size); +} - temp = *((__le32 *)&unirom[adapter->file_prd_off] + -QLCNIC_UNI_FIRMWARE_IDX_OFF ); - idx =le32_to_cpu (temp); - tab_desc =qlcnic_get_table_desc (unirom,QLCNIC_UNI_DIR_SECT_FW ); +static int qlcnic_get_data_desc (struct qlcnic_adapter *adapter,u32 section, +u32 index_offset,struct qlcnic_uni_data *data) +{ +size_t table_desc_offset, table_offset, desc_offset; +const struct firmware *fw = adapter->fw; +const u8 *unirom = fw->data; +size_t product_index_offset; +u32 entries, entry_size, idx; +int ret; -if (!tab_desc) + product_index_offset = adapter->file_prd_off + + (size_t )index_offset *sizeof (__le32); +if (!qlcnic_rom_range_valid (fw->size, product_index_offset, +sizeof (__le32)))return -EINVAL ; - tab_size =le32_to_cpu (tab_desc->findex) + -le32_to_cpu (tab_desc->entry_size) * (idx +1 ); + idx =get_unaligned_le32 (unirom + product_index_offset); + ret =qlcnic_get_table_desc (adapter, section, &table_desc_offset); +if (ret) +return ret; -if (adapter->fw->size < tab_size) + table_offset =get_unaligned_le32 (unirom + table_desc_offset + + offsetof(struct uni_table_desc , findex)); + entries =get_unaligned_le32 (unirom + table_desc_offset + + offsetof(struct uni_table_desc , num_entries)); + entry_size =get_unaligned_le32 (unirom + table_desc_offset + + offsetof(struct uni_table_desc , entry_size)); +if (!qlcnic_rom_table_valid (fw->size, table_offset, entries, + entry_size,sizeof (struct uni_data_desc )) || + idx >= entries)return -EINVAL ; - offs =le32_to_cpu (tab_desc->findex) + -le32_to_cpu (tab_desc->entry_size) * idx; - descr = (struct uni_data_desc *)&unirom[offs]; - data_size =le32_to_cpu (descr->findex) +le32_to_cpu (descr->size); + desc_offset = table_offset + (size_t )idx * entry_size; + data->offset =get_unaligned_le32 (unirom + desc_offset + + offsetof(struct uni_data_desc , findex)); + data->size =get_unaligned_le32 (unirom + desc_offset + + offsetof(struct uni_data_desc , size)); -if (adapter->fw->size < data_size) +if (!qlcnic_rom_range_valid (fw->size, data->offset, data->size))return -EINVAL ;return 0 ; } +static int qlcnic_validate_bootld (struct qlcnic_adapter *adapter) +{ +struct qlcnic_uni_data data; +int ret; + + ret =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_BOOTLD , +QLCNIC_UNI_BOOTLD_IDX_OFF , &data); +if (ret) +return ret; + +return data.size <QLCNIC_UNI_BOOTLD_SIZE ? -EINVAL :0 ; +} + +static int qlcnic_validate_fw (struct qlcnic_adapter *adapter) +{ +struct qlcnic_uni_data data; +int ret; + + ret =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_FW , +QLCNIC_UNI_FIRMWARE_IDX_OFF , &data); +if (ret) +return ret; + +return data.size <QLCNIC_UNI_VERSION_TAIL_SIZE ? -EINVAL :0 ; +} +static int qlcnic_validate_product_offs (struct qlcnic_adapter *adapter) { -struct uni_table_desc *ptab_descr; +size_t table_desc_offset, table_offset;const u8 *unirom = adapter->fw->data;int mn_present =qlcnic_has_mn (adapter); -u32 entries, entry_size, tab_size, i; -__le32 temp; - - ptab_descr =qlcnic_get_table_desc (unirom, -QLCNIC_UNI_DIR_SECT_PRODUCT_TBL ); -if (!ptab_descr) -return -EINVAL ; +u32 entries, entry_size; +size_t i; +int ret; - entries =le32_to_cpu (ptab_descr->num_entries); - entry_size =le32_to_cpu (ptab_descr->entry_size); - tab_size =le32_to_cpu (ptab_descr->findex) + (entries * entry_size); + ret =qlcnic_get_table_desc (adapter,QLCNIC_UNI_DIR_SECT_PRODUCT_TBL , + &table_desc_offset); +if (ret) +return ret; -if (adapter->fw->size < tab_size) + table_offset =get_unaligned_le32 (unirom + table_desc_offset + + offsetof(struct uni_table_desc , findex)); + entries =get_unaligned_le32 (unirom + table_desc_offset + + offsetof(struct uni_table_desc , num_entries)); + entry_size =get_unaligned_le32 (unirom + table_desc_offset + + offsetof(struct uni_table_desc , entry_size)); +if (!qlcnic_rom_table_valid (adapter->fw->size, table_offset, entries, + entry_size, +QLCNIC_UNI_PRODUCT_ENTRY_MIN_SIZE ))return -EINVAL ; nomn:for (i =0 ; i < entries; i++) { - -u32 flags, file_chiprev, offs; +size_t offset = table_offset + i * entry_size;u8 chiprev = adapter->ahw->revision_id; +u32 flags, file_chiprev;u32 flagbit; - offs =le32_to_cpu (ptab_descr->findex) + - i *le32_to_cpu (ptab_descr->entry_size); - temp = *((__le32 *)&unirom[offs] +QLCNIC_UNI_FLAGS_OFF ); - flags =le32_to_cpu (temp); - temp = *((__le32 *)&unirom[offs] +QLCNIC_UNI_CHIP_REV_OFF ); - file_chiprev =le32_to_cpu (temp); + flags =get_unaligned_le32 (unirom + offset + +QLCNIC_UNI_FLAGS_OFF *sizeof (__le32)); + file_chiprev =get_unaligned_le32 (unirom + offset + +QLCNIC_UNI_CHIP_REV_OFF * +sizeof (__le32)); flagbit = mn_present ?1 :2 ;if ((chiprev == file_chiprev) && ((1ULL << flagbit) & flags)) { - adapter->file_prd_off = offs; +if (offset >U32_MAX ) +return -EINVAL ; + + adapter->file_prd_off = offset;return 0 ; } }
@@ -933,93 +987,81 @@ qlcnic_validate_unified_romimage(struct qlcnic_adapter *adapter)return 0 ; } -static -struct uni_data_desc *qlcnic_get_data_desc (struct qlcnic_adapter *adapter, -u32 section,u32 idx_offset) -{ -const u8 *unirom = adapter->fw->data; -struct uni_table_desc *tab_desc; -u32 offs, idx; -__le32 temp; - - temp = *((__le32 *)&unirom[adapter->file_prd_off] + idx_offset); - idx =le32_to_cpu (temp); - - tab_desc =qlcnic_get_table_desc (unirom, section); - -if (tab_desc ==NULL ) -return NULL ; - - offs =le32_to_cpu (tab_desc->findex) + -le32_to_cpu (tab_desc->entry_size) * idx; - -return (struct uni_data_desc *)&unirom[offs]; -} - -static u8 * -qlcnic_get_bootld_offs (struct qlcnic_adapter *adapter) +static int qlcnic_get_bootld_data (struct qlcnic_adapter *adapter, +const u8 **bootld) {u32 offs =QLCNIC_BOOTLD_START ; -struct uni_data_desc *data_desc; - - data_desc =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_BOOTLD , -QLCNIC_UNI_BOOTLD_IDX_OFF ); +struct qlcnic_uni_data data; +int ret; -if (adapter->ahw->fw_type ==QLCNIC_UNIFIED_ROMIMAGE ) - offs =le32_to_cpu (data_desc->findex); +if (adapter->ahw->fw_type ==QLCNIC_UNIFIED_ROMIMAGE ) { + ret =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_BOOTLD , +QLCNIC_UNI_BOOTLD_IDX_OFF , &data); +if (ret || data.size <QLCNIC_UNI_BOOTLD_SIZE ) +return -EINVAL ; + offs = data.offset; + }else if (!qlcnic_rom_range_valid (adapter->fw->size, offs, +QLCNIC_UNI_BOOTLD_SIZE )) { +return -EINVAL ; + } -return (u8 *)&adapter->fw->data[offs]; + *bootld = adapter->fw->data + offs; +return 0 ; } -static u8 * -qlcnic_get_fw_offs (struct qlcnic_adapter *adapter) +static int qlcnic_get_fw_data (struct qlcnic_adapter *adapter, +const u8 **image,u32 *image_size) {u32 offs =QLCNIC_IMAGE_START ; -struct uni_data_desc *data_desc; - - data_desc =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_FW , -QLCNIC_UNI_FIRMWARE_IDX_OFF ); -if (adapter->ahw->fw_type ==QLCNIC_UNIFIED_ROMIMAGE ) - offs =le32_to_cpu (data_desc->findex); - -return (u8 *)&adapter->fw->data[offs]; -} +struct qlcnic_uni_data data; +int ret; -static u32 qlcnic_get_fw_size (struct qlcnic_adapter *adapter) -{ -struct uni_data_desc *data_desc; -const u8 *unirom = adapter->fw->data; +if (adapter->ahw->fw_type ==QLCNIC_UNIFIED_ROMIMAGE ) { + ret =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_FW , +QLCNIC_UNI_FIRMWARE_IDX_OFF , &data); +if (ret) +return ret; + offs = data.offset; + *image_size = data.size; + }else { +if (!qlcnic_rom_range_valid (adapter->fw->size, +QLCNIC_FW_SIZE_OFFSET , +sizeof (__le32))) +return -EINVAL ; + *image_size =get_unaligned_le32 (adapter->fw->data + +QLCNIC_FW_SIZE_OFFSET ); + } - data_desc =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_FW , -QLCNIC_UNI_FIRMWARE_IDX_OFF ); +if (!qlcnic_rom_range_valid (adapter->fw->size, offs, *image_size)) +return -EINVAL ; -if (adapter->ahw->fw_type ==QLCNIC_UNIFIED_ROMIMAGE ) -return le32_to_cpu (data_desc->size); -else -return le32_to_cpu (*(__le32 *)&unirom[QLCNIC_FW_SIZE_OFFSET ]); + *image = adapter->fw->data + offs; +return 0 ; }static u32 qlcnic_get_fw_version (struct qlcnic_adapter *adapter) { -struct uni_data_desc *fw_data_desc; +char ver_str[QLCNIC_UNI_VERSION_TAIL_SIZE +1 ];const struct firmware *fw = adapter->fw; +struct qlcnic_uni_data data;u32 major, minor, sub; -__le32 version_offset; -const u8 *ver_str;int i, ret; -if (adapter->ahw->fw_type !=QLCNIC_UNIFIED_ROMIMAGE ) { - version_offset = *(__le32 *)&fw->data[QLCNIC_FW_VERSION_OFFSET ]; -return le32_to_cpu (version_offset); - } +if (adapter->ahw->fw_type !=QLCNIC_UNIFIED_ROMIMAGE ) +return get_unaligned_le32 (fw->data +QLCNIC_FW_VERSION_OFFSET ); + + ret =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_FW , +QLCNIC_UNI_FIRMWARE_IDX_OFF , &data); +if (ret || data.size <QLCNIC_UNI_VERSION_TAIL_SIZE ) +return 0 ; - fw_data_desc =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_FW , -QLCNIC_UNI_FIRMWARE_IDX_OFF ); - ver_str = fw->data +le32_to_cpu (fw_data_desc->findex) + -le32_to_cpu (fw_data_desc->size) -17 ; +memcpy (ver_str, fw->data + data.offset + data.size - +QLCNIC_UNI_VERSION_TAIL_SIZE , +QLCNIC_UNI_VERSION_TAIL_SIZE ); + ver_str[QLCNIC_UNI_VERSION_TAIL_SIZE ] ='\0' ;for (i =0 ; i <12 ; i++) { -if (!strncmp (&ver_str[i],"REV=" ,4 )) { +if (!strncmp (ver_str + i,"REV=" ,4 )) { ret =sscanf (&ver_str[i+4 ],"%u.%u.%u " , &major, &minor, &sub);if (ret !=3 )
@@ -1034,18 +1076,15 @@ static u32 qlcnic_get_fw_version(struct qlcnic_adapter *adapter)static u32 qlcnic_get_bios_version (struct qlcnic_adapter *adapter) { -const struct firmware *fw = adapter->fw;u32 bios_ver, prd_off = adapter->file_prd_off; -u8 *version_offset; -__le32 temp; +const struct firmware *fw = adapter->fw; -if (adapter->ahw->fw_type !=QLCNIC_UNIFIED_ROMIMAGE ) { - version_offset = (u8 *)&fw->data[QLCNIC_BIOS_VERSION_OFFSET ]; -return le32_to_cpu (*(__le32 *)version_offset); - } +if (adapter->ahw->fw_type !=QLCNIC_UNIFIED_ROMIMAGE ) +return get_unaligned_le32 (fw->data +QLCNIC_BIOS_VERSION_OFFSET ); - temp = *((__le32 *)(&fw->data[prd_off]) +QLCNIC_UNI_BIOS_VERSION_OFF ); - bios_ver =le32_to_cpu (temp); + bios_ver =get_unaligned_le32 (fw->data + prd_off + +QLCNIC_UNI_BIOS_VERSION_OFF * +sizeof (__le32));return (bios_ver <<16 ) + ((bios_ver >>8 ) &0xff00 ) + (bios_ver >>24 ); }
@@ -1106,24 +1145,26 @@ static const char *fw_name[] = {int qlcnic_load_firmware (struct qlcnic_adapter *adapter) { -__le64 *ptr64; -u32 i, flashaddr, size;const struct firmware *fw = adapter->fw;struct pci_dev *pdev = adapter->pdev; +const u8 *bootld, *image; +u32 i, flashaddr, image_size; +int ret;dev_info (&pdev->dev,"loading firmware from %s\n" , fw_name[adapter->ahw->fw_type]);if (fw) { +u32 words, remainder;u64 data; - size = (QLCNIC_IMAGE_START -QLCNIC_BOOTLD_START ) /8 ; - - ptr64 = (__le64 *)qlcnic_get_bootld_offs (adapter); + ret =qlcnic_get_bootld_data (adapter, &bootld); +if (ret) +return ret; flashaddr =QLCNIC_BOOTLD_START ; -for (i =0 ; i < size; i++) { - data =le64_to_cpu (ptr64[i]); +for (i =0 ; i <QLCNIC_UNI_BOOTLD_SIZE /sizeof (u64); i++) { + data =get_unaligned_le64 (bootld + i *sizeof (u64));if (qlcnic_pci_mem_write_2M (adapter, flashaddr, data))return -EIO ;
@@ -1131,13 +1172,15 @@ qlcnic_load_firmware(struct qlcnic_adapter *adapter) flashaddr +=8 ; } - size =qlcnic_get_fw_size (adapter) /8 ; - - ptr64 = (__le64 *)qlcnic_get_fw_offs (adapter); + ret =qlcnic_get_fw_data (adapter, &image, &image_size); +if (ret) +return ret; + words = image_size /sizeof (u64); + remainder = image_size %sizeof (u64); flashaddr =QLCNIC_IMAGE_START ; -for (i =0 ; i < size; i++) { - data =le64_to_cpu (ptr64[i]); +for (i =0 ; i < words; i++) { + data =get_unaligned_le64 (image + i *sizeof (u64));if (qlcnic_pci_mem_write_2M (adapter, flashaddr, data))
@@ -1146,9 +1189,11 @@ qlcnic_load_firmware(struct qlcnic_adapter *adapter) flashaddr +=8 ; } - size =qlcnic_get_fw_size (adapter) %8 ; -if (size) { - data =le64_to_cpu (ptr64[i]); +if (remainder) { +__le64 tail =0 ; + +memcpy (&tail, image + words *sizeof (u64), remainder); + data =le64_to_cpu (tail);if (qlcnic_pci_mem_write_2M (adapter, flashaddr, data))
@@ -1156,10 +1201,9 @@ qlcnic_load_firmware(struct qlcnic_adapter *adapter) } }else { -u64 data; -u32 hi, lo; -int ret;struct qlcnic_flt_entry bootld_entry; +u32 hi, lo, size; +u64 data; ret =qlcnic_get_flt_entry (adapter,QLCNIC_BOOTLD_REGION , &bootld_entry);
@@ -1200,26 +1244,33 @@ qlcnic_load_firmware(struct qlcnic_adapter *adapter)static int qlcnic_validate_firmware (struct qlcnic_adapter *adapter) { -u32 val; -u32 ver, bios, min_size; -struct pci_dev *pdev = adapter->pdev;const struct firmware *fw = adapter->fw; +struct pci_dev *pdev = adapter->pdev;u8 fw_type = adapter->ahw->fw_type; +u32 ver, bios, min_size; +const u8 *data; +u32 data_size; +u32 val; + +if (fw_type ==QLCNIC_UNIFIED_ROMIMAGE ) + min_size =QLCNIC_UNI_FW_MIN_SIZE ; +else + min_size =QLCNIC_FW_MIN_SIZE ; + +if (fw->size < min_size) +return -EINVAL ;if (fw_type ==QLCNIC_UNIFIED_ROMIMAGE ) {if (qlcnic_validate_unified_romimage (adapter))return -EINVAL ; - - min_size =QLCNIC_UNI_FW_MIN_SIZE ; }else { - val =le32_to_cpu (*(__le32 *)&fw->data[QLCNIC_FW_MAGIC_OFFSET ]); + val =get_unaligned_le32 (fw->data +QLCNIC_FW_MAGIC_OFFSET );if (val !=QLCNIC_BDINFO_MAGIC )return -EINVAL ; - - min_size =QLCNIC_FW_MIN_SIZE ; } -if (fw->size < min_size) +if (qlcnic_get_bootld_data (adapter, &data) || +qlcnic_get_fw_data (adapter, &data, &data_size))return -EINVAL ; val =qlcnic_get_fw_version (adapter);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1387/1674 ALSA: mtpav: shut down output timer before card teardown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit c73cb5b7c159246dd572277c668851a56e516019 ]
snd_mtpav_output_timer() rearms chip->timer while holding chip->spinlock and accesses the card-private mtpav state.
snd_mtpav_free() currently takes the same lock and calls timer_delete() when the timer is active. This only removes a pending timer; it does not wait for a callback that is already running and does not prevent the callback from rearming the timer.
A callback running on another CPU can therefore continue after snd_mtpav_free() releases the lock and access the card-private state while the card is being torn down. It can also rearm the timer after timer_delete() has returned.
Call timer_shutdown_sync() without holding chip->spinlock. This waits for any running callback to finish and prevents further rearming before the card-private mtpav state is released.
--- sound/drivers/mtpav.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
sound/drivers/mtpav.c +1 -5
@@ -663,12 +663,8 @@ static int snd_mtpav_get_RAWMIDI(struct mtpav *mcard)static void snd_mtpav_free (struct snd_card *card) {struct mtpav *crd = card->private_data; -unsigned long flags; -spin_lock_irqsave (&crd->spinlock, flags); -if (crd->istimer >0 ) -snd_mtpav_remove_output_timer (crd); -spin_unlock_irqrestore (&crd->spinlock, flags); +timer_shutdown_sync (&crd->timer); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1388/1674 net: add missing ref_tracker_dir_exit() to alloc_netdev_mqs()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tetsuo Handa <[email protected]>
[ Upstream commit 0b1c2af8a22c35cb099c735c2f63ea3ba757557d ]
sashiko is reporting that trying to read /sys/kernel/debug/ref_tracker/* causes use-afer-free crash when either alloc_percpu() or dev_addr_init() in alloc_netdev_mqs() failed, for commit 4d92b95ff2f9 ("net: add net device refcount tracker infrastructure") added ref_tracker_dir_exit() to only free_netdev() path.
--- net/core/dev.c | 1 + 1 file changed, 1 insertion(+)
net/core/dev.c +1 -0
@@ -11040,6 +11040,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,free_percpu (dev->pcpu_refcnt); free_dev:#endif +ref_tracker_dir_exit (&dev->refcnt_tracker);netdev_freemem (dev);return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1389/1674 vsock: dont check the listeners sk_err in vsock_accept()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nguyen Dinh Phi <[email protected]>
[ Upstream commit b8c899cf5e7be29840a172c183dedd8d3e7a0287 ]
Syzbot reported an issue which can be reproduced with these steps:
r0 = socket(AF_VSOCK, SOCK_STREAM, 0)
bind(r0, {VMADDR_CID_ANY, PORT})
connect(r0, {VMADDR_CID_LOCAL, PORT}) -> -1, EPROTO (self-connect)
listen(r0, backlog) -> 0
r1 = socket(AF_VSOCK, SOCK_STREAM, 0)
connect(r1, {VMADDR_CID_LOCAL, PORT}) -> 0
accept(r0) -> -1, EPROTO (stale sk_err)Basically, it creates a socket (r0) and triggers a self-connect after binding it. This self-connect fails with EPROTO because it loops back to r0 while the socket is still in the TCP_SYN_SENT state, causing it to be incorrectly dispatched to the connecting-client path. The unexpected packet type encountered there sets sk_err to EPROTO.
After that, it invokes a listen() call on the same socket. This listen() call succeeds because the kernel's listening path never inspects or clears sk_err. Then, a new socket (r1) is created as a normal client and connects to r0. However, vsock_accept() rejects this incoming connection because the listener's sk_err still holds the EPROTO error from the earlier failed self-connect.
This rejection causes the child socket created for r1's connection to never be freed on virtio or hyperv transports; only the VMCI transport implements pending_work to revisit and clean up a rejected socket.
For a non-blocking connect(), vsock_connect() may return -EINPROGRESS immediately, and vsock_connect_timeout() can later set sk->sk_err asynchronously.
Since no vsock transport ever sets sk_err on a socket while it is in TCP_LISTEN state, checking it in vsock_accept() serves no purpose and only carries forward errors left behind by earlier, unrelated connection attempts on the same socket. Remove the checks so accept() no longer rejects valid incoming connections because of a stale error, which also avoids the resource leak described above.
--- net/vmw_vsock/af_vsock.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
net/vmw_vsock/af_vsock.c +1 -5
@@ -1649,8 +1649,7 @@ static int vsock_accept(struct socket *sock, struct socket *newsock, int flags, timeout =sock_rcvtimeo (listener, flags &O_NONBLOCK );prepare_to_wait (sk_sleep (listener), &wait,TASK_INTERRUPTIBLE ); -while ((connected =vsock_dequeue_accept (listener)) ==NULL && - listener->sk_err ==0 ) { +while ((connected =vsock_dequeue_accept (listener)) ==NULL ) {release_sock (listener); timeout =schedule_timeout (timeout);finish_wait (sk_sleep (listener), &wait);
@@ -1668,9 +1667,6 @@ static int vsock_accept(struct socket *sock, struct socket *newsock, int flags, }finish_wait (sk_sleep (listener), &wait); -if (listener->sk_err) - err = -listener->sk_err; -if (connected) {sk_acceptq_removed (listener);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1390/1674 filelock: add some new helper functions
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit 75cabec0111b7ccb140d917cc9c481e845cc3498 ]
In later patches we're going to embed some common fields into a new structure inside struct file_lock. Smooth the transition by adding some new helper functions, and converting the core file locking code to use them.
Stable-dep-of: 468e458ffde9 ("NFSv4: Fix incorrect argument passed to nfs4_delete_lease() in nfs4_add_lease()")
--- fs/locks.c | 18 ++++++++-------- include/linux/filelock.h | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 9 deletions(-)
fs/locks.c +9 -9
@@ -675,7 +675,7 @@ static void __locks_wake_up_blocks(struct file_lock *blocker)if (waiter->fl_lmops && waiter->fl_lmops->lm_notify) waiter->fl_lmops->lm_notify (waiter);else -wake_up (&waiter->fl_wait); +locks_wake_up (waiter);/* * The setting of fl_blocker to NULL marks the "done"
@@ -842,9 +842,9 @@ locks_delete_lock_ctx(struct file_lock *fl, struct list_head *dispose)static bool locks_conflict (struct file_lock *caller_fl,struct file_lock *sys_fl) { -if (sys_fl->fl_type ==F_WRLCK ) +if (lock_is_write (sys_fl))return true; -if (caller_fl->fl_type ==F_WRLCK ) +if (lock_is_write (caller_fl))return true;return false; }
@@ -875,7 +875,7 @@ static bool posix_test_locks_conflict(struct file_lock *caller_fl, struct file_lock *sys_fl) {/* F_UNLCK checks any locks on the same fd. */ -if (caller_fl->fl_type ==F_UNLCK ) { +if (lock_is_unlock (caller_fl)) {if (!posix_same_owner (caller_fl, sys_fl))return false;return locks_overlap (caller_fl, sys_fl);
@@ -1056,7 +1056,7 @@ static int flock_lock_inode(struct inode *inode, struct file_lock *request)break ; } -if (request->fl_type ==F_UNLCK ) { +if (lock_is_unlock (request)) {if ((request->fl_flags &FL_EXISTS ) && !found) error = -ENOENT ; goto out;
@@ -1108,7 +1108,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request, ctx =locks_get_lock_context (inode, request->fl_type);if (!ctx) -return (request->fl_type ==F_UNLCK ) ?0 : -ENOMEM ; +return lock_is_unlock (request) ?0 : -ENOMEM ;/* * We may need two file_lock structures for this operation,
@@ -1229,7 +1229,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,continue ;if (fl->fl_start > request->fl_end)break ; -if (request->fl_type ==F_UNLCK ) +if (lock_is_unlock (request)) added = true;if (fl->fl_start < request->fl_start) left = fl;
@@ -1280,7 +1280,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request, error =0 ;if (!added) { -if (request->fl_type ==F_UNLCK ) { +if (lock_is_unlock (request)) {if (request->fl_flags &FL_EXISTS ) error = -ENOENT ; goto out;
@@ -1609,7 +1609,7 @@ void lease_get_mtime(struct inode *inode, struct timespec64 *time)spin_lock (&ctx->flc_lock); fl =list_first_entry_or_null (&ctx->flc_lease, struct file_lock, fl_list); -if (fl && (fl->fl_type ==F_WRLCK )) +if (fl &&lock_is_write (fl)) has_lease = true;spin_unlock (&ctx->flc_lock); }
include/linux/filelock.h +44 -0
56 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1391/1674 NFSv4: Fix incorrect argument passed to nfs4_delete_lease() in nfs4_add_lease()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhansong Gao <[email protected]>
[ Upstream commit 468e458ffde907ba19acd2102ca1fbb8f6fbede2 ]
When nfs4_add_lease() races with a delegation return, it calls nfs4_delete_lease() to clean up. Previously, it passed priv, which can legitimately be NULL. Passing a NULL priv eventually leads to a NULL pointer dereference in generic_setlease().
--- fs/nfs/nfs4proc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/nfs/nfs4proc.c +3 -1
@@ -7635,6 +7635,7 @@ static int nfs4_add_lease(struct file *file, int arg, struct file_lock **lease, {struct inode *inode =file_inode (file);fmode_t type = arg ==F_RDLCK ?FMODE_READ :FMODE_WRITE ; +fl_owner_t owner = (*lease)->c.flc_owner;int ret;/* No delegation, no lease */
@@ -7644,7 +7645,8 @@ static int nfs4_add_lease(struct file *file, int arg, struct file_lock **lease,if (ret ||nfs4_have_delegation (inode, type))return ret;/* We raced with a delegation return */ -nfs4_delete_lease (file, priv); +dprintk ("%s: raced with a delegation return\n" , __func__); +nfs4_delete_lease (file, &owner);return -EAGAIN ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1392/1674 NFSv4/flexfiles: fix NULL dereference for NFSv4.0 data servers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeuk Kim <[email protected]>
[ Upstream commit 2b03ebbf8d5e8f6af4ecd6c65375232dd1ec32cc ]
flexfiles accepts NFSv4.0 data servers, but two NFSv4 code paths assume the data server client has a session. Unlike NFSv4.1+, an NFSv4.0 client has no session (clp->cl_session is NULL; it uses clp->cl_slot_tbl), so I/O to a v4.0 flexfiles DS oopses:
- nfs4_init_ds_session() dereferences clp->cl_session->session_state while seeding the DS lease. It also only seeds cl_lease_time when NFS4_SESSION_INITING is set; without a session that never happens, so cl_lease_time stays 0 and nfs4_renew_state() busy-loops, requeuing every 5 seconds. Seed the lease whenever there is no session and return before touching session state.
- ff_layout_async_handle_error_v4() dereferences
clp->cl_session->fc_slot_table on every DS I/O error. Fall back to the
v4.0 transport slot table (clp->cl_slot_tbl) when there is no session.--- fs/nfs/flexfilelayout/flexfilelayout.c | 3 ++- fs/nfs/nfs4session.c | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +2 -1
@@ -1127,7 +1127,8 @@ static int ff_layout_async_handle_error_v4(struct rpc_task *task,struct pnfs_layout_hdr *lo = lseg->pls_layout;struct inode *inode = lo->plh_inode;struct nfs4_deviceid_node *devid =FF_LAYOUT_DEVID_NODE (lseg, idx); -struct nfs4_slot_table *tbl = &clp->cl_session->fc_slot_table; +struct nfs4_slot_table *tbl =nfs4_has_session (clp) ? + &clp->cl_session->fc_slot_table : clp->cl_slot_tbl;switch (op_status) {case NFS4_OK :
fs/nfs/nfs4session.c +11 -5
@@ -634,16 +634,22 @@ int nfs4_init_ds_session(struct nfs_client *clp, unsigned long lease_time)int ret;spin_lock (&clp->cl_lock); -if (test_and_clear_bit (NFS4_SESSION_INITING , &session->session_state)) { -/* -* Do not set NFS_CS_CHECK_LEASE_TIME instead set the -* DS lease to be equal to the MDS lease. -*/ +/* +* Do not set NFS_CS_CHECK_LEASE_TIME instead set the +* DS lease to be equal to the MDS lease. +* +* A v4.0 DS has no session, so seed the lease every time. +*/ +if (!session || +test_and_clear_bit (NFS4_SESSION_INITING , &session->session_state)) { clp->cl_lease_time = lease_time; clp->cl_last_renewal = jiffies; }spin_unlock (&clp->cl_lock); +if (!session) +return 0 ; + ret =nfs41_check_session_ready (clp);if (ret)return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1393/1674 pnfs/blocklayout: Fix device leaks on parse failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: ZhangGuoDong <[email protected]>
[ Upstream commit c056f817e4200fb18079d5052c273a22f191ff0a ]
bl_parse_concat() and bl_parse_stripe() allocate a child device array and then parse each child in turn. If parsing a child fails, the failed child is not counted in nr_children and the parent may be left with a children array that bl_free_device() will not release when nr_children is zero.
Release the failed child and the already parsed children before returning the error. Also make bl_free_device() release the child array whenever the children pointer is set, so that partially initialised concat or stripe devices are cleaned up correctly.
bl_parse_scsi() can also fail after assigning d->bdev_file and dropping the file reference. Clear the pointer after fput() so that an outer cleanup path does not put it again.
--- fs/nfs/blocklayout/dev.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
fs/nfs/blocklayout/dev.c +15 -4
@@ -16,12 +16,14 @@static void bl_free_device (struct pnfs_block_dev *dev) { -if (dev->nr_children) { +if (dev->children) {int i;for (i =0 ; i < dev->nr_children; i++)bl_free_device (&dev->children[i]);kfree (dev->children); + dev->children =NULL ; + dev->nr_children =0 ; }else {if (dev->pr_registered) { const struct pr_ops *ops =
@@ -34,8 +36,10 @@ bl_free_device(struct pnfs_block_dev *dev)pr_err ("failed to unregister PR key.\n" ); } -if (dev->bdev) +if (dev->bdev) {blkdev_put (dev->bdev,NULL ); + dev->bdev =NULL ; + } } }
@@ -377,6 +381,7 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d, out_blkdev_put:blkdev_put (d->bdev,NULL ); + d->bdev =NULL ;return error; }
@@ -412,8 +417,11 @@ bl_parse_concat(struct nfs_server *server, struct pnfs_block_dev *d,for (i =0 ; i < v->concat.volumes_count; i++) { ret =bl_parse_deviceid (server, &d->children[i], volumes, v->concat.volumes[i], gfp_mask); -if (ret) +if (ret) { +bl_free_device (&d->children[i]); +bl_free_device (d);return ret; + } d->nr_children++; d->children[i].start += len;
@@ -441,8 +449,11 @@ bl_parse_stripe(struct nfs_server *server, struct pnfs_block_dev *d,for (i =0 ; i < v->stripe.volumes_count; i++) { ret =bl_parse_deviceid (server, &d->children[i], volumes, v->stripe.volumes[i], gfp_mask); -if (ret) +if (ret) { +bl_free_device (&d->children[i]); +bl_free_device (d);return ret; + } d->nr_children++; len += d->children[i].len;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1394/1674 smb/server: fix session leak in ksmbd_session_register()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ze Tan <[email protected]>
[ Upstream commit 99b25b046e47e4904373cfeb445c5483f1633d88 ]
See the procedure below:
smb2_sess_setup
ksmbd_smb2_session_create
__session_create
atomic_set(&sess->refcnt, 2)
hash_add(sessions_table, &sess->hlist, sess->id)
ksmbd_session_register
xa_store(&conn->sessions, sess->id, sess) // fail
ksmbd_user_session_put
atomic_dec(&sess->refcnt) // refcnt is 1, session is not freedRemove the session from sessions_table and drop its table reference if xa_store() fails.
--- fs/smb/server/mgmt/user_session.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
fs/smb/server/mgmt/user_session.c +11 -1
@@ -212,10 +212,20 @@ static void ksmbd_expire_session(struct ksmbd_conn *conn)int ksmbd_session_register (struct ksmbd_conn *conn,struct ksmbd_session *sess) { +int ret; + sess->dialect = conn->dialect;memcpy (sess->ClientGUID, conn->ClientGUID,SMB2_CLIENT_GUID_SIZE );ksmbd_expire_session (conn); -return xa_err (xa_store (&conn->sessions, sess->id, sess,GFP_KERNEL )); + ret =xa_err (xa_store (&conn->sessions, sess->id, sess,GFP_KERNEL )); +if (ret) { +down_write (&sessions_table_lock); +hash_del (&sess->hlist); +up_write (&sessions_table_lock); +ksmbd_user_session_put (sess); + } + +return ret; }static int ksmbd_chann_del (struct ksmbd_conn *conn,struct ksmbd_session *sess)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1395/1674 ksmbd: scope session state changes to bound connections
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit c50e628122aed077695669e25b842e778511a43d ]
ksmbd_all_conn_set_status() treats every connection whose transient binding flag is set as belonging to the target SessionId. A logoff or session replacement can consequently move an unrelated connection to NEED_RECONNECT or NEED_SETUP.
Pass the target session itself and select connections using either the connection-local session xarray or the session's permanent channel list. Use the same association test while waiting for requests to drain.
Serialize session-wide status changes under request_lock and do not overwrite EXITING or RELEASING. Protect the shutdown transition with the same lock so a concurrent session update cannot revive a closing connection.
--- fs/smb/server/connection.c | 35 ++++++++++++++++++++++++++----- fs/smb/server/connection.h | 7 +++++-- fs/smb/server/mgmt/user_session.c | 8 +++---- fs/smb/server/smb2pdu.c | 6 ++---- 4 files changed, 41 insertions(+), 15 deletions(-)
fs/smb/server/connection.c +30 -5
@@ -242,15 +242,37 @@ void ksmbd_conn_unlock(struct ksmbd_conn *conn)mutex_unlock (&conn->srv_mutex); } -void ksmbd_all_conn_set_status (u64 sess_id,u32 status) +static bool ksmbd_session_is_bound_to_conn (struct ksmbd_session *sess, +struct ksmbd_conn *conn) +{ +bool found; + +rcu_read_lock (); + found =xa_load (&conn->sessions, sess->id) == sess; +rcu_read_unlock (); +if (found) +return true; + +down_read (&sess->chann_lock); + found =xa_load (&sess->ksmbd_chann_list, (long )conn); +up_read (&sess->chann_lock); +return found; +} + +void ksmbd_all_conn_set_status (struct ksmbd_session *sess,u32 status) {struct ksmbd_conn *conn;int bkt;down_read (&conn_list_lock);hash_for_each (conn_list, bkt, conn, hlist) { -if (conn->binding ||xa_load (&conn->sessions, sess_id)) -WRITE_ONCE (conn->status, status); +if (ksmbd_session_is_bound_to_conn (sess, conn)) { +spin_lock (&conn->request_lock); +if (!ksmbd_conn_exiting (conn) && + !ksmbd_conn_releasing (conn)) +WRITE_ONCE (conn->status, status); +spin_unlock (&conn->request_lock); + } }up_read (&conn_list_lock); }
@@ -276,7 +298,8 @@ void ksmbd_conn_wait_idle(struct ksmbd_conn *conn)wait_event (conn->req_running_q,atomic_read (&conn->req_running) <2 ); } -int ksmbd_conn_wait_idle_sess_id (struct ksmbd_conn *curr_conn,u64 sess_id) +int ksmbd_conn_wait_idle_sess (struct ksmbd_conn *curr_conn, +struct ksmbd_session *sess) {struct ksmbd_conn *conn;int rc, retry_count =0 , max_timeout =120 ;
@@ -288,7 +311,7 @@ int ksmbd_conn_wait_idle_sess_id(struct ksmbd_conn *curr_conn, u64 sess_id)down_read (&conn_list_lock);hash_for_each (conn_list, bkt, conn, hlist) { -if (conn->binding ||xa_load (&conn->sessions, sess_id)) { +if (ksmbd_session_is_bound_to_conn (sess, conn)) { rcount = (conn == curr_conn) ?2 :1 ;if (atomic_read (&conn->req_running) >= rcount) { rc = wait_event_timeout(conn->req_running_q,
@@ -589,7 +612,9 @@ static void stop_sessions(void)down_read (&conn_list_lock);hash_for_each (conn_list, bkt, conn, hlist) { t = conn->transport; +spin_lock (&conn->request_lock);ksmbd_conn_set_exiting (conn); +spin_unlock (&conn->request_lock);if (t->ops->shutdown) {up_read (&conn_list_lock); t->ops->shutdown (t);
fs/smb/server/connection.h +5 -2
@@ -20,6 +20,8 @@#include "smb_common.h" #include "ksmbd_work.h" +struct ksmbd_session ; +#define KSMBD_SOCKET_BACKLOG 16enum {
@@ -160,7 +162,8 @@ extern struct rw_semaphore conn_list_lock;bool ksmbd_conn_alive (struct ksmbd_conn *conn);void ksmbd_conn_wait_idle (struct ksmbd_conn *conn); -int ksmbd_conn_wait_idle_sess_id (struct ksmbd_conn *curr_conn,u64 sess_id); +int ksmbd_conn_wait_idle_sess (struct ksmbd_conn *curr_conn, +struct ksmbd_session *sess);struct ksmbd_conn *ksmbd_conn_alloc (void );void ksmbd_conn_free (struct ksmbd_conn *conn);struct ksmbd_conn *ksmbd_conn_get (struct ksmbd_conn *conn);
@@ -265,5 +268,5 @@ static inline void ksmbd_conn_set_releasing(struct ksmbd_conn *conn) WRITE_ONCE(conn->status, KSMBD_SESS_RELEASING); } -void ksmbd_all_conn_set_status (u64 sess_id,u32 status); +void ksmbd_all_conn_set_status (struct ksmbd_session *sess,u32 status);#endif /* __CONNECTION_H__ */
fs/smb/server/mgmt/user_session.c +4 -4
@@ -412,16 +412,16 @@ void destroy_previous_session(struct ksmbd_conn *conn, memcmp(user->passkey, prev_user->passkey, user->passkey_sz)) goto out; -ksmbd_all_conn_set_status (id,KSMBD_SESS_NEED_RECONNECT ); - err =ksmbd_conn_wait_idle_sess_id (conn, id); +ksmbd_all_conn_set_status (prev_sess,KSMBD_SESS_NEED_RECONNECT ); + err =ksmbd_conn_wait_idle_sess (conn, prev_sess);if (err) { -ksmbd_all_conn_set_status (id,KSMBD_SESS_NEED_SETUP ); +ksmbd_all_conn_set_status (prev_sess,KSMBD_SESS_NEED_SETUP ); goto out; }ksmbd_destroy_file_table (prev_sess); prev_sess->state =SMB2_SESSION_EXPIRED ; -ksmbd_all_conn_set_status (id,KSMBD_SESS_NEED_SETUP ); +ksmbd_all_conn_set_status (prev_sess,KSMBD_SESS_NEED_SETUP );ksmbd_launch_ksmbd_durable_scavenger (); out:up_write (&conn->session_lock);
fs/smb/server/smb2pdu.c +2 -4
@@ -2246,7 +2246,6 @@ int smb2_session_logoff(struct ksmbd_work *work)struct ksmbd_session *sess = work->sess;struct smb2_logoff_req *req;struct smb2_logoff_rsp *rsp; -u64 sess_id;int err;WORK_BUFFERS (work, req, rsp);
@@ -2260,8 +2259,7 @@ int smb2_session_logoff(struct ksmbd_work *work)smb2_set_err_rsp (work);return -ENOENT ; } - sess_id =le64_to_cpu (req->hdr.SessionId); -ksmbd_all_conn_set_status (sess_id,KSMBD_SESS_NEED_RECONNECT ); +ksmbd_all_conn_set_status (sess,KSMBD_SESS_NEED_RECONNECT );ksmbd_conn_unlock (conn);ksmbd_close_session_fds (work);
@@ -2278,7 +2276,7 @@ int smb2_session_logoff(struct ksmbd_work *work) sess->state =SMB2_SESSION_EXPIRED ;up_write (&conn->session_lock); -ksmbd_all_conn_set_status (sess_id,KSMBD_SESS_NEED_SETUP ); +ksmbd_all_conn_set_status (sess,KSMBD_SESS_NEED_SETUP ); rsp->StructureSize =cpu_to_le16 (4 ); err =ksmbd_iov_pin_rsp (work, rsp,sizeof (struct smb2_logoff_rsp ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1396/1674 ksmbd: detach blocked lock requests before freeing
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 215e8816b1ac25176d911abb8704390413ccee4b ]
A file_lock retained by ksmbd for byte-range lock bookkeeping can still be part of the VFS blocked-request graph. In particular, the VFS can chain a new waiter below an already blocked request through flc_blocked_requests. The ksmbd_file reference count does not cover that graph.
Both __ksmbd_close_fd() and the cross-request unlock path free these retained file_lock objects directly. If a dependent waiter is still attached, locks_release_private() hits BUG_ON(!list_empty(&flc->flc_blocked_requests)). The same lifetime mismatch can leave a freed ksmbd_lock reachable through its request-local llist.
Detach the file_lock from the blocked-request graph before freeing it in the close, cross-request unlock, and rollback paths. locks_delete_block() also wakes requests chained below the object. Remove llist when a completed lock is published so a globally visible ksmbd_lock no longer points into the submitting worker's stack.
--- fs/smb/server/smb2pdu.c | 14 ++++++++++---- fs/smb/server/vfs_cache.c | 8 +++++--- 2 files changed, 15 insertions(+), 7 deletions(-)
fs/smb/server/smb2pdu.c +10 -4
@@ -7506,6 +7506,12 @@ static void smb2_remove_blocked_lock(void **argv)wake_up (&flock->fl_wait); } +static void smb2_free_lock (struct file_lock *flock) +{ +ksmbd_vfs_posix_lock_unblock (flock); +locks_free_lock (flock); +} +static inline bool lock_defer_pending (struct file_lock *fl) {/* check pending lock waiters */
@@ -7659,14 +7665,14 @@ int smb2_lock(struct ksmbd_work *work) cmp_lock->end == smb_lock->end && !lock_defer_pending(cmp_lock->fl)) { nolock =0 ; -list_del (&cmp_lock->flist); -list_del (&cmp_lock->clist); +list_del_init (&cmp_lock->flist); +list_del_init (&cmp_lock->clist); cmp_lock->conn =NULL ;spin_unlock (&conn->llist_lock);up_read (&conn_list_lock);ksmbd_conn_put (conn); -locks_free_lock (cmp_lock->fl); +smb2_free_lock (cmp_lock->fl);kfree (cmp_lock); goto out_check_cl; }
@@ -7864,7 +7870,7 @@ int smb2_lock(struct ksmbd_work *work)spin_unlock (&conn->llist_lock);ksmbd_conn_put (conn); -locks_free_lock (smb_lock->fl); +smb2_free_lock (smb_lock->fl);if (rlock)locks_free_lock (rlock);kfree (smb_lock);
fs/smb/server/vfs_cache.c +5 -3
@@ -388,8 +388,9 @@ static void __ksmbd_close_fd(struct ksmbd_file_table *ft, struct ksmbd_file *fp)if (!IS_ERR_OR_NULL (filp))fput (filp); -/* because the reference count of fp is 0, it is guaranteed that -* there are not accesses to fp->lock_list. +/* +* The zero fp reference count serializes access to fp->lock_list, but +* the VFS may still have blocked requests chained below these locks. */ list_for_each_entry_safe (smb_lock, tmp_lock, &fp->lock_list, flist) {struct ksmbd_conn *conn = smb_lock->conn;
@@ -402,7 +403,8 @@ static void __ksmbd_close_fd(struct ksmbd_file_table *ft, struct ksmbd_file *fp)ksmbd_conn_put (conn); } -list_del (&smb_lock->flist); +list_del_init (&smb_lock->flist); +ksmbd_vfs_posix_lock_unblock (smb_lock->fl);locks_free_lock (smb_lock->fl);kfree (smb_lock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1397/1674 ksmbd: safely discard unregistered deferred locks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 054bcca4cd9f00719b01f7108b51a2168fb94f15 ]
When vfs_lock_file() defers a lock, smb2_lock() puts its ksmbd_lock on rollback_list before allocating and registering the asynchronous work. If either operation fails, rollback assumes that smb_lock->conn is initialized and dereferences NULL. The deferred file_lock also remains linked into the VFS blocked-lock state while it is freed.
Keep the lock off rollback_list until async setup succeeds. On setup failures, explicitly unblock and wake the deferred lock before freeing it and its ksmbd wrapper.
--- fs/smb/server/smb2pdu.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +12 -1
@@ -7512,6 +7512,13 @@ static void smb2_free_lock(struct file_lock *flock)locks_free_lock (flock); } +static void smb2_free_blocked_lock (struct file_lock *flock) +{ +ksmbd_vfs_posix_lock_unblock (flock); +locks_wake_up (flock); +locks_free_lock (flock); +} +static inline bool lock_defer_pending (struct file_lock *fl) {/* check pending lock waiters */
@@ -7754,11 +7761,12 @@ int smb2_lock(struct ksmbd_work *work)ksmbd_debug (SMB ,"would have to wait for getting lock\n" ); -list_add (&smb_lock->llist, &rollback_list); argv =kmalloc (sizeof (void *),GFP_KERNEL );if (!argv) { err = -ENOMEM ; +smb2_free_blocked_lock (flock); +kfree (smb_lock); goto out; } argv[0 ] = flock;
@@ -7769,8 +7777,11 @@ int smb2_lock(struct ksmbd_work *work)if (rc) {kfree (argv); err = -ENOMEM ; +smb2_free_blocked_lock (flock); +kfree (smb_lock); goto out; } +list_add (&smb_lock->llist, &rollback_list);spin_lock (&fp->f_lock);list_add (&work->fp_entry, &fp->blocked_works);spin_unlock (&fp->f_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1398/1674 erofs: fix interlaced ztailpacking pclusters
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gao Xiang <[email protected]>
[ Upstream commit 862427ebb81d1f6abbf74d799790e1694b37b187 ]
On-disk sizes of interlaced pclusters should be block-aligned, and ztailpacking interlaced pclusters should be invalid at all.
Currently, mkfs.erofs won't generate any interlaced pcluster with ztailpacking enabled, so this doesn't affect any existing valid filesystems.
However, crafted images can contain invalid interlaced ztailpacking pclusters, resulting in an out-of-bounds read from a kmap'd page and copying irrelevant kernel memory into userspace-visible page cache.
--- fs/erofs/zmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/erofs/zmap.c +2 -1
@@ -559,7 +559,8 @@ static int z_erofs_do_map_blocks(struct inode *inode, err = -EFSCORRUPTED ; goto unmap_out; } - afmt = vi->z_advise &Z_EROFS_ADVISE_INTERLACED_PCLUSTER ? + afmt = (vi->z_advise &Z_EROFS_ADVISE_INTERLACED_PCLUSTER ) && + !(map->m_flags &EROFS_MAP_META ) ?Z_EROFS_COMPRESSION_INTERLACED :Z_EROFS_COMPRESSION_SHIFTED ; }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1399/1674 ksmbd: defer publishing granted locks to prevent UAF/double-free race
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilan Dudnik <[email protected]>
[ Upstream commit 29f74f0f2e6df3b393b7b66e810136d0c64e3c59 ]
In smb2_lock(), mid-batch granted locks are published to connection-wide (conn->lock_list) and file-wide (fp->lock_list) lists immediately upon vfs_lock_file() success, while also remaining tracked on the stack-local rollback_list.
If a subsequent element in the same SMB2_LOCK request array fails validation or execution, the thread jumps to out: and walks rollback_list to undo previously granted locks. However, because the granted lock was already published to conn->lock_list, a concurrent UNLOCK request on the same connection can find the lock object and kfree() it before the rollback loop executes.
When the granting thread subsequently walks rollback_list, it dereferences and frees the already-freed ksmbd_lock structure, resulting in a Use-After-Free and Double-Free (on both ksmbd_lock and struct file_lock).
Fix this by deferring the publication of granted locks to conn->lock_list and fp->lock_list until after the entire array of lock elements has been processed without error. Mid-batch grants remain tracked exclusively on the request-local rollback_list until the whole batch succeeds, eliminating the race window.
--- fs/smb/server/smb2pdu.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-)
fs/smb/server/smb2pdu.c +15 -17
@@ -7814,16 +7814,10 @@ int smb2_lock(struct ksmbd_work *work) rsp->hdr.Status =STATUS_RANGE_NOT_LOCKED ;kfree (smb_lock); - goto out2; +/* rollback_list may still hold earlier grants */ + goto out; }else if (!rc) {list_add (&smb_lock->llist, &rollback_list); - smb_lock->conn =ksmbd_conn_get (work->conn); -spin_lock (&work->conn->llist_lock); -list_add_tail (&smb_lock->clist, - &work->conn->lock_list); -list_add_tail (&smb_lock->flist, - &fp->lock_list); -spin_unlock (&work->conn->llist_lock);ksmbd_debug (SMB ,"successful in taking lock\n" ); }else {locks_free_lock (flock);
@@ -7845,6 +7839,19 @@ int smb2_lock(struct ksmbd_work *work)if (err) goto out; +/* publish only once the whole batch has committed */ +if (!list_empty (&rollback_list)) { +spin_lock (&work->conn->llist_lock); +list_for_each_entry (smb_lock, &rollback_list, llist) { + smb_lock->conn =ksmbd_conn_get (work->conn); +list_add_tail (&smb_lock->clist, + &work->conn->lock_list); +list_add_tail (&smb_lock->flist, + &fp->lock_list); + } +spin_unlock (&work->conn->llist_lock); + } +ksmbd_fd_put (work, fp);return 0 ;
@@ -7872,15 +7879,6 @@ int smb2_lock(struct ksmbd_work *work) }list_del (&smb_lock->llist); - conn = smb_lock->conn; -spin_lock (&conn->llist_lock); -if (!list_empty (&smb_lock->flist)) -list_del (&smb_lock->flist); -list_del (&smb_lock->clist); - smb_lock->conn =NULL ; -spin_unlock (&conn->llist_lock); -ksmbd_conn_put (conn); -smb2_free_lock (smb_lock->fl);if (rlock)locks_free_lock (rlock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1400/1674 smb/server: fix null-ptr-deref in ksmbd_ipc_tree_connect_request()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: ZhangGuoDong <[email protected]>
[ Upstream commit d2ccf905f47d2344270749f4dfa905afcd3edeb0 ]
See the procedure below:
ksmbd_tree_conn_connect
ksmbd_share_config_get
share->name = kstrdup() // fail
if (!test_share_config_flag(share, KSMBD_SHARE_FLAG_PIPE)) // false
// do not check `share->name`
ksmbd_ipc_tree_connect_request
strlen(share->name) // null-ptr-deref--- fs/smb/server/mgmt/share_config.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/smb/server/mgmt/share_config.c +6 -1
@@ -161,6 +161,11 @@ static struct ksmbd_share_config *share_config_request(struct ksmbd_work *work,atomic_set (&share->refcount,1 );INIT_LIST_HEAD (&share->veto_list); share->name =kstrdup (name,GFP_KERNEL ); +if (!share->name) { +kill_share (share); + share =NULL ; + goto out; + }if (!test_share_config_flag (share,KSMBD_SHARE_FLAG_PIPE )) {size_t path_len;
@@ -217,7 +222,7 @@ static struct ksmbd_share_config *share_config_request(struct ksmbd_work *work, share->path =NULL ; } } -if (ret || !share->name) { +if (ret) {kill_share (share); share =NULL ; goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1401/1674 ksmbd: serialize oplock close with pending break ownership
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit b0148dc5625dbfd50596ac63c7487c12e8a8ab03 ]
close may abort an in-flight oplock break while another breaker already holds an opinfo reference. Releasing pending_break wakes that waiter, but without serializing the close transition with bit acquisition it can become a new break owner through the test_and_set_bit() fast path. It can then overwrite OPLOCK_CLOSING with OPLOCK_ACK_WAIT and continue a break for a dying opinfo.
Make OPLOCK_CLOSING terminal once the opinfo is removed from the inode list. Serialize that transition, pending_break acquisition, and OPLOCK_ACK_WAIT setup with an opinfo state lock. A breaker which loses the race releases its ownership and returns -ENOENT. Explicitly wake pending_break waiters during close so they can observe the terminal state.
Also prevent ACK and timeout paths from replacing OPLOCK_CLOSING with OPLOCK_STATE_NONE.
--- fs/smb/server/oplock.c | 83 +++++++++++++++++++++++++++++++++-------- fs/smb/server/oplock.h | 1 + fs/smb/server/smb2pdu.c | 12 ++++-- 3 files changed, 78 insertions(+), 18 deletions(-)
fs/smb/server/oplock.c +68 -15
@@ -56,6 +56,7 @@ static struct oplock_info *alloc_opinfo(struct ksmbd_work *work, opinfo->conn =ksmbd_conn_get (work->conn); opinfo->level =SMB2_OPLOCK_LEVEL_NONE ; opinfo->op_state =OPLOCK_STATE_NONE ; +spin_lock_init (&opinfo->state_lock); opinfo->pending_break =0 ; opinfo->fid = id; opinfo->Tid = Tid;
@@ -424,14 +425,23 @@ void close_id_del_oplock(struct ksmbd_file *fp)opinfo_del (opinfo);rcu_assign_pointer (fp->f_opinfo,NULL ); -if (opinfo->op_state ==OPLOCK_ACK_WAIT ) { - opinfo->op_state =OPLOCK_CLOSING ; -wake_up_interruptible_all (&opinfo->oplock_q); -if (opinfo->is_lease) { -atomic_set (&opinfo->breaking_cnt,0 ); -wake_up_interruptible_all (&opinfo->oplock_brk); - } - } +spin_lock (&opinfo->state_lock); +if (opinfo->op_state ==OPLOCK_ACK_WAIT && opinfo->is_lease) +atomic_set (&opinfo->breaking_cnt,0 ); +/* +* An opinfo that has been removed from the inode list is terminal. Keep +* this transition and releasing pending_break under state_lock. a breaker +* takes the same lock before it acquires pending_break or sets ACK_WAIT. +*/ + opinfo->op_state =OPLOCK_CLOSING ; +clear_bit_unlock (0 , &opinfo->pending_break); +spin_unlock (&opinfo->state_lock); +wake_up_interruptible_all (&opinfo->oplock_q); +if (opinfo->is_lease) +wake_up_interruptible_all (&opinfo->oplock_brk); +/* memory barrier is needed for wake_up_bit() */ +smp_mb__after_atomic (); +wake_up_bit (&opinfo->pending_break,0 );opinfo_count_dec (fp);atomic_dec (&opinfo->refcount);
@@ -610,10 +620,16 @@ static void wait_for_break_ack(struct oplock_info *opinfo)/* is this a timeout ? */ if (!rc) { +spin_lock (&opinfo->state_lock); +if (opinfo->op_state ==OPLOCK_CLOSING ) { +spin_unlock (&opinfo->state_lock); +return ; + }if (opinfo->is_lease) opinfo->o_lease->state =SMB2_LEASE_NONE_LE ; opinfo->level =SMB2_OPLOCK_LEVEL_NONE ; opinfo->op_state =OPLOCK_STATE_NONE ; +spin_unlock (&opinfo->state_lock); } }
@@ -625,17 +641,46 @@ static void wake_up_oplock_break(struct oplock_info *opinfo)wake_up_bit (&opinfo->pending_break,0 ); } +static bool oplock_break_set_ack_wait (struct oplock_info *opinfo) +{ +bool ret = false; + +spin_lock (&opinfo->state_lock); +if (opinfo->op_state !=OPLOCK_CLOSING ) { + opinfo->op_state =OPLOCK_ACK_WAIT ; + ret = true; + } +spin_unlock (&opinfo->state_lock); + +return ret; +} +static int oplock_break_pending (struct oplock_info *opinfo,int req_op_level) { -while (test_and_set_bit (0 , &opinfo->pending_break)) { +for (;;) { +bool closing; + +spin_lock (&opinfo->state_lock); + closing = opinfo->op_state ==OPLOCK_CLOSING ; +if (!closing && !test_and_set_bit (0 , &opinfo->pending_break)) { +spin_unlock (&opinfo->state_lock); +break ; + } +spin_unlock (&opinfo->state_lock); +if (closing) +return -ENOENT ; +wait_on_bit (&opinfo->pending_break,0 ,TASK_UNINTERRUPTIBLE );/* Not immediately break to none. */ opinfo->open_trunc =0 ; -if (opinfo->op_state ==OPLOCK_CLOSING ) +spin_lock (&opinfo->state_lock); + closing = opinfo->op_state ==OPLOCK_CLOSING ; +spin_unlock (&opinfo->state_lock); +if (closing)return -ENOENT ; -else if (opinfo->level <= req_op_level) { +if (opinfo->level <= req_op_level) {if (opinfo->is_lease == false)return 1 ;
@@ -999,13 +1044,17 @@ static int oplock_break(struct oplock_info *brk_opinfo, struct ksmbd_inode *ci,if (lease->state & (SMB2_LEASE_WRITE_CACHING_LE |SMB2_LEASE_HANDLE_CACHING_LE )) { +if (!oplock_break_set_ack_wait (brk_opinfo)) { +atomic_dec_if_positive (&brk_opinfo->breaking_cnt); +wake_up_oplock_break (brk_opinfo); +return -ENOENT ; + } +if (in_work) {setup_async_work (in_work,NULL ,NULL );smb2_send_interim_resp (in_work,STATUS_PENDING );release_async_work (in_work); } - - brk_opinfo->op_state =OPLOCK_ACK_WAIT ; }else atomic_dec (&brk_opinfo->breaking_cnt); }else {
@@ -1014,8 +1063,12 @@ static int oplock_break(struct oplock_info *brk_opinfo, struct ksmbd_inode *ci,return err <0 ? err :0 ;if (brk_opinfo->level ==SMB2_OPLOCK_LEVEL_BATCH || - brk_opinfo->level ==SMB2_OPLOCK_LEVEL_EXCLUSIVE ) - brk_opinfo->op_state =OPLOCK_ACK_WAIT ; + brk_opinfo->level ==SMB2_OPLOCK_LEVEL_EXCLUSIVE ) { +if (!oplock_break_set_ack_wait (brk_opinfo)) { +wake_up_oplock_break (brk_opinfo); +return -ENOENT ; + } + } }if (brk_opinfo->is_lease)
fs/smb/server/oplock.h +1 -0
@@ -66,6 +66,7 @@ struct oplock_info {struct ksmbd_file *o_fp;int level;int op_state; +spinlock_t state_lock;unsigned long pending_break;u64 fid;atomic_t breaking_cnt;
fs/smb/server/smb2pdu.c +9 -3
@@ -8817,7 +8817,10 @@ static void smb20_oplock_break_ack(struct ksmbd_work *work)smb2_set_err_rsp (work); out: - opinfo->op_state =OPLOCK_STATE_NONE ; +spin_lock (&opinfo->state_lock); +if (opinfo->op_state !=OPLOCK_CLOSING ) + opinfo->op_state =OPLOCK_STATE_NONE ; +spin_unlock (&opinfo->state_lock);wake_up_interruptible_all (&opinfo->oplock_q);opinfo_put (opinfo);ksmbd_fd_put (work, fp);
@@ -8903,9 +8906,12 @@ static void smb21_lease_break_ack(struct ksmbd_work *work)if (ret) goto err_out; - opinfo->op_state =OPLOCK_STATE_NONE ; +spin_lock (&opinfo->state_lock); +if (opinfo->op_state !=OPLOCK_CLOSING ) + opinfo->op_state =OPLOCK_STATE_NONE ; +spin_unlock (&opinfo->state_lock);wake_up_interruptible_all (&opinfo->oplock_q); -atomic_dec (&opinfo->breaking_cnt); +atomic_dec_if_positive (&opinfo->breaking_cnt);wake_up_interruptible_all (&opinfo->oplock_brk);opinfo_put (opinfo);return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1402/1674 ksmbd: fix slab-out-of-bounds read in ksmbd_alloc_user()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yunseong Kim <[email protected]>
[ Upstream commit 7405d0ba294306721843bc551611775e6edef516 ]
ksmbd_alloc_user() copies resp->hash_sz bytes out of the mountd IPC login response with
user->passkey_sz = resp->hash_sz; user->passkey = kmalloc(resp->hash_sz, KSMBD_DEFAULT_GFP); if (user->passkey) memcpy(user->passkey, resp->hash, resp->hash_sz);
resp->hash_sz is a __u16 supplied by the response, but resp->hash[] is only KSMBD_REQ_MAX_HASH_SZ bytes. A malformed or malicious login response can set hash_sz well beyond that (up to 65535), so the memcpy() reads past the end of the response object. ipc_validate_msg() does not bound hash_sz, so reject any response whose hash_sz exceeds the on-stack hash[] buffer before allocating and copying.
[ 2030.238706] BUG: KASAN: slab-out-of-bounds in ksmbd_alloc_user+0x278/0x680 [ 2030.240549] Read of size 65535 at addr ffff888121bb6680 by task kworker/4:1/18611 [ 2030.242296] [ 2030.242710] CPU: 4 UID: 0 PID: 18611 Comm: kworker/4:1 Not tainted 7.1.0-next-20260623-virtme #96 PREEMPT(lazy) [ 2030.242732] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1 04/01/2014 [ 2030.242743] Workqueue: ksmbd-io handle_ksmbd_work [ 2030.242763] Call Trace: [ 2030.242769] <TASK> [ 2030.242776] dump_stack_lvl+0xa2/0xd0 [ 2030.242794] print_address_description+0x77/0x200 [ 2030.242815] ? ksmbd_alloc_user+0x278/0x680 [ 2030.242831] print_report+0x58/0x70 [ 2030.242848] kasan_report+0x117/0x150 [ 2030.242869] ? ksmbd_alloc_user+0x278/0x680 [ 2030.242888] kasan_check_range+0x3c7/0x3f0 [ 2030.242908] ? ksmbd_alloc_user+0x278/0x680 [ 2030.242925] __asan_memcpy+0x29/0x70 [ 2030.242942] ksmbd_alloc_user+0x278/0x680 [ 2030.242960] ksmbd_login_user+0xc3/0x120 [ 2030.242978] ntlm_authenticate+0x5e6/0x1b00 [ 2030.243017] ? __pfx_ntlm_authenticate+0x10/0x10 [ 2030.243035] ? ksmbd_session_lookup+0x188/0x1d0 [ 2030.243054] ? __pfx_ksmbd_session_lookup+0x10/0x10 [ 2030.243090] ? __sanitizer_cov_trace_switch+0x7b/0x140 [ 2030.243108] smb2_sess_setup+0x1e4a/0x27b0 [ 2030.243126] ? copy_from_kernel_nofault+0x199/0x300 [ 2030.243156] ? __pfx_smb2_sess_setup+0x10/0x10 [ 2030.243173] ? get_smb2_cmd_val+0xe3/0x1c0 [ 2030.243208] handle_ksmbd_work+0x954/0x1280 [ 2030.243230] ? __pfx_handle_ksmbd_work+0x10/0x10 [ 2030.243249] ? process_scheduled_works+0xa07/0x1490 [ 2030.243270] ? process_scheduled_works+0xa07/0x1490 [ 2030.243291] process_scheduled_works+0xa70/0x1490 [ 2030.243320] ? __pfx_process_scheduled_works+0x10/0x10 [ 2030.243340] ? do_raw_spin_lock+0x130/0x300 [ 2030.243358] ? lock_is_held_type+0x7b/0x110 [ 2030.243388] worker_thread+0x932/0xe20 [ 2030.243415] kthread+0x38a/0x470 [ 2030.243431] ? __pfx_worker_thread+0x10/0x10 [ 2030.243451] ? __pfx_kthread+0x10/0x10 [ 2030.243467] ret_from_fork+0x484/0x910 [ 2030.243485] ? __pfx_ret_from_fork+0x10/0x10 [ 2030.243501] ? __switch_to+0xc77/0x12c0 [ 2030.243523] ? __pfx_kthread+0x10/0x10 [ 2030.243540] ret_from_fork_asm+0x1a/0x30 [ 2030.243564] </TASK> [ 2030.243570] [ 2030.290164] Allocated by task 19279: [ 2030.290911] kasan_save_track+0x3e/0x80 [ 2030.292179] __kasan_kmalloc+0x72/0x90 [ 2030.293217] __kvmalloc_node_noprof+0x3ff/0x6b0 [ 2030.294467] handle_generic_event+0x59b/0x750 [ 2030.295345] genl_family_rcv_msg_doit+0x238/0x340 [ 2030.296553] genl_rcv_msg+0x606/0x7b0 [ 2030.297129] netlink_rcv_skb+0x22b/0x4a0 [ 2030.298500] genl_rcv+0x2d/0x40 [ 2030.299273] netlink_unicast+0x7ba/0x930 [ 2030.300019] netlink_sendmsg+0x8c3/0xb00 [ 2030.301073] __sock_sendmsg+0xec/0x140 [ 2030.301579] __sys_sendto+0x357/0x470 [ 2030.302255] __x64_sys_sendto+0xe3/0x100 [ 2030.303425] do_syscall_64+0x135/0x460 [ 2030.304763] entry_SYSCALL_64_after_hwframe+0x77/0x7f [ 2030.305594] [ 2030.305819] The buggy address belongs to the object at ffff888121bb6640 [ 2030.305819] which belongs to the cache kmalloc-192 of size 192 [ 2030.309595] The buggy address is located 64 bytes inside of [ 2030.309595] allocated 166-byte region [ffff888121bb6640, ffff888121bb66e6) [ 2030.312484] [ 2030.312719] The buggy address belongs to the physical page: [ 2030.314315] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x121bb6 [ 2030.316481] head: order:1 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 [ 2030.318248] flags: 0x100000000000040(head|node=0|zone=2) [ 2030.319662] page_type: f5(slab) [ 2030.320242] raw: 0100000000000040 ffff8881000424c0 ffffea00047c1510 ffff888100040468 [ 2030.321911] raw: 0000000000000000 0000000000150015 00000000f5000000 0000000000000000 [ 2030.324413] head: 0100000000000040 ffff8881000424c0 ffffea00047c1510 ffff888100040468 [ 2030.326150] head: 0000000000000000 0000000000150015 00000000f5000000 0000000000000000 [ 2030.327960] head: 0100000000000001 ffffffffffffff81 00000000ffffffff 00000000ffffffff [ 2030.329615] head: ffff888121bb7ab0 0000000000000000 00000000ffffffff 0000000000000000 [ 2030.331861] page dumped because: kasan: bad access detected [ 2030.332946] [ 2030.333502] Memory state around the buggy address: [ 2030.334698] ffff888121bb6580: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc [ 2030.336475] ffff888121bb6600: fc fc fc fc fc fc fc fc 00 00 00 00 00 00 00 00 [ 2030.338143] >ffff888121bb6680: 00 00 00 00 00 00 00 00 00 00 00 00 06 fc fc fc [ 2030.339116] ^ [ 2030.341315] ffff888121bb6700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc [ 2030.342801] ffff888121bb6780: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb [ 2030.344643] ==================================================================
Found with ksmbdzzer [2], a KSMBD fuzzer that drives libFuzzer with a kcov-dataflow [1] coverage vector: it folds each instrumented comparison/argument's runtime operand value together with its PC (the default arm mixes them as pc⊕val) so that a new operand value at a known site counts as new coverage.
[1] https://lwn.net/Articles/1077606/
[2] https://github.com/yskzalloc/kcov-dataflow
--- fs/smb/server/mgmt/user_config.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/smb/server/mgmt/user_config.c +11 -0
@@ -37,6 +37,17 @@ struct ksmbd_user *ksmbd_alloc_user(struct ksmbd_login_response *resp, {struct ksmbd_user *user; +/* +* resp->hash_sz is a __u16 taken from the mountd IPC login response but +* resp->hash[] is only KSMBD_REQ_MAX_HASH_SZ bytes. A malformed or +* malicious response can set hash_sz far beyond that (up to 65535), +* making the memcpy() below read past the response object +* (slab-out-of-bounds in ksmbd_alloc_user()). Reject any oversized +* hash rather than trust the length. +*/ +if (resp->hash_sz >sizeof (resp->hash)) +return NULL ; + user =kmalloc (sizeof (struct ksmbd_user ),GFP_KERNEL );if (!user)return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1403/1674 apparmor: fix deadlock in complain-mode change_hat
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
[ Upstream commit 4ec11f14d1d6fdda787d991b142537be7841d395 ]
The use of change_hat when in complain mode can cause a deadlock when the hat doesn't exist and a new learning profile is created for the missing profile. This is because change_hat() has taken the lock to search the hat list and creating the new learning profile needs to take the lock to add it to the list.
Quoted 1 line
From the bug report:
Originally found in 7.0.0 in LTS ubuntu 26.04 with pam_apparmor + su in complain mode set to change hats. Then verified in newest available vanilla kernel I've compiled to see if still present:
7.2-rc7 vanilla -> affected
checked also some other kernels:
6.18.44 vanilla -> affected
6.12.95 with debian patches -> unaffected
On systems without bug (for example 6.12.95 debian) it just prints:
aa_change_hat rc=0
On systems with bug, the executable always hangs, prints nothing and becomes unkillable. (And once stuck this way, it will cause any further hat changes to also cause the changing process to get stuck)
Then in syslog you can find hint about cause:
kernel: INFO: task hat:3409 blocked for more than 483 seconds. kernel: Not tainted 7.2.0-rc7 #1 kernel: "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. kernel: task:hat state:D stack:0 pid:3409 tgid:3409 ppid:2605 task_flags:0x400000 flags:0x00080800 kernel: Call Trace: kernel: <TASK> kernel: __schedule+0x48f/0xfe0 kernel: schedule+0x27/0xa0 kernel: schedule_preempt_disabled+0x15/0x30 kernel: __mutex_lock.constprop.0+0x569/0xa10 kernel: aa_new_learning_profile+0x15f/0x210 kernel: build_change_hat+0x19f/0x3b0 kernel: change_hat.isra.0+0x5dd/0xd60 kernel: aa_change_hat+0x2f3/0x710 kernel: aa_setprocattr_changehat+0x121/0x1f0 kernel: do_setattr+0x28c/0x340 kernel: apparmor_setselfattr+0x20/0x50 kernel: security_setselfattr+0xf6/0x110 kernel: __x64_sys_lsm_set_self_attr+0x53/0x90 kernel: do_syscall_64+0xdd/0x5e0 kernel: ? __mod_memcg_lruvec_state+0xfd/0x260 kernel: ? lruvec_stat_mod_folio+0x8d/0xd0 kernel: ? __folio_mod_stat+0x2d/0x90 kernel: ? map_anon_folio_pte_nopf+0xd1/0x1f0 kernel: ? do_anonymous_page+0x184/0xa10 kernel: ? __handle_mm_fault+0x805/0x870 kernel: ? count_memcg_events+0xef/0x230 kernel: ? handle_mm_fault+0x1f0/0x2f0 kernel: ? do_user_addr_fault+0x2bb/0x7b0 kernel: ? do_syscall_64+0x94/0x5e0 kernel: ? exc_page_fault+0x75/0x160 kernel: entry_SYSCALL_64_after_hwframe+0x76/0x7e kernel: RIP: 0033:0x7f815e134c8d kernel: RSP: 002b:00007fff6df94ea8 EFLAGS: 00000246 ORIG_RAX: 00000000000001cc kernel: RAX: ffffffffffffffda RBX: 0000556d8c81d040 RCX: 00007f815e134c8d kernel: RDX: 0000000000000046 RSI: 0000556d8c81d040 RDI: 0000000000000064 kernel: RBP: 00007fff6df94ef0 R08: 00007f815e212ac8 R09: 000000000000000c kernel: R10: 0000000000000000 R11: 0000000000000246 R12: 0000556d8c81d010 kernel: R13: 0000000000000026 R14: 0000000000000046 R15: 0000000000000064 kernel: </TASK> kernel: INFO: task hat:3409 is blocked on a mutex likely owned by task hat:3409.
To fix the issue, lift the locking out of the core of aa_new_learning_profile(), introduce a wrapper function that takes the lock where needed, and have build_change_hat() call the core function that no longer takes the lock.
In addition fix 4 other issues introduced by commit32e92764d6f8d ("apparmor: grab ns lock and refresh when looking up changehat child profiles")
- aa_get_profile_rcu() was replaced-by: aa_get_profile without the accompanying rcu_dereference_protected()
- an extra aa_get_label(label) was introduced at the start of
change_hat() without an accompanying aa_put_label() causing a
reference count leak.
- a reference count leak was introduced in the label_is_stale(label)
case, where the newest profile would be leaked instead of the
label passed to the function.
- a potential UAF when the lookup walks up the tree with new_ns != ns
the new label reference is put, and then used for the next lookup.
The mutex_lock, will block replacement, and removal in the locked
ns. However there are two cases where putting the reference can
result in the label being freed even with the lock held.
1. the label does not have a list reference (possible for temporary or special profiles) in which case the put can trigger the cleanup.
2. the new label reference is in a different namespace, which does not have a lock held on it. This extends case 1 to also include replacement, and removal that could be occurring in the namespace new is in.
--- security/apparmor/domain.c | 25 +++++++++++++++++-------- security/apparmor/include/policy.h | 3 +++ security/apparmor/policy.c | 22 +++++++++++++++++----- 3 files changed, 37 insertions(+), 13 deletions(-)
security/apparmor/domain.c +17 -8
@@ -1029,8 +1029,8 @@ static struct aa_label *build_change_hat(const struct cred *subj_cred,if (!hat) { error = -ENOENT ;if (COMPLAIN_MODE (profile)) { - hat =aa_new_learning_profile (profile, true, name, -GFP_KERNEL ); + hat =__aa_new_learning_profile (profile, true, name, +GFP_KERNEL );if (!hat) { info ="failed null profile create" ; error = -ENOMEM ;
@@ -1068,6 +1068,7 @@ static struct aa_label *change_hat(const struct cred *subj_cred,bool sibling = false;const char *name, *info =NULL ;int i, error; +bool needput = false;AA_BUG (!label);AA_BUG (!hats);
@@ -1080,7 +1081,6 @@ static struct aa_label *change_hat(const struct cred *subj_cred,* the profiles and label, we can rely on the namespaces being live * and avoid incrementing their refcounts while grabbing the lock. */ - label =aa_get_label (label); ns =labels_ns (label); retry:
@@ -1088,15 +1088,19 @@ static struct aa_label *change_hat(const struct cred *subj_cred,if (label_is_stale (label)) { new =aa_get_newest_label (label); new_ns =labels_ns (new); + +if (needput) +/* aa_put_label() is safe to call when under lock */ +aa_put_label (label); + label = new; + needput = true; +/* check if replaced with label in parent ns, and lock there */ if (new_ns != ns) { -aa_put_label (new);mutex_unlock (&ns->lock); ns = new_ns; - label = new; +/* retry will bottom out at the root of the tree */ goto retry; } -aa_put_label (label); - label = new; }if (PROFILE_IS_HAT (labels_profile (label)))
@@ -1107,7 +1111,8 @@ static struct aa_label *change_hat(const struct cred *subj_cred, name = hats[i];label_for_each_in_ns (it,labels_ns (label), label, profile) {if (sibling &&PROFILE_IS_HAT (profile)) { - root =aa_get_profile (profile->parent); + root =aa_get_profile (rcu_dereference_protected (profile->parent, +mutex_is_locked (&ns->lock))); }else if (!sibling && !PROFILE_IS_HAT (profile)) { root =aa_get_profile (profile); }else {/* conflicting change type */
@@ -1168,6 +1173,8 @@ static struct aa_label *change_hat(const struct cred *subj_cred, } }mutex_unlock (&ns->lock); +if (needput) +aa_put_label (label);return ERR_PTR (error); build:
@@ -1181,6 +1188,8 @@ static struct aa_label *change_hat(const struct cred *subj_cred, goto fail; }/* else if (IS_ERR) build_change_hat has logged error so return new */ mutex_unlock (&ns->lock); +if (needput) +aa_put_label (label);return new; }
security/apparmor/include/policy.h +3 -0
@@ -261,6 +261,9 @@ struct aa_profile *aa_alloc_profile(const char *name, struct aa_proxy *proxy, gfp_t gfp);struct aa_profile *aa_alloc_null (struct aa_profile *parent,const char *name,gfp_t gfp); +struct aa_profile *__aa_new_learning_profile (struct aa_profile *parent, +bool hat,const char *base, +gfp_t gfp);struct aa_profile *aa_new_learning_profile (struct aa_profile *parent,bool hat,const char *base,gfp_t gfp);void aa_free_profile (struct aa_profile *profile);
security/apparmor/policy.c +17 -5
@@ -665,7 +665,7 @@ struct aa_profile *aa_alloc_null(struct aa_profile *parent, const char *name, }/** -* aa_new_learning_profile - create or find a null-X learning profile +* __aa_new_learning_profile - create or find a null-X learning profile * @parent: profile that caused this profile to be created (NOT NULL) * @hat: true if the null- learning profile is a hat * @base: name to base the null profile off of
@@ -682,14 +682,16 @@ struct aa_profile *aa_alloc_null(struct aa_profile *parent, const char *name,* * Returns: new refcounted profile else NULL on failure */ -struct aa_profile *aa_new_learning_profile (struct aa_profile *parent,bool hat, -const char *base,gfp_t gfp) +struct aa_profile *__aa_new_learning_profile (struct aa_profile *parent, +bool hat,const char *base, +gfp_t gfp) {struct aa_profile *p, *profile;const char *bname;char *name =NULL ;AA_BUG (!parent); +AA_BUG (!mutex_is_locked (&parent->ns->lock));if (base) { name = kmalloc(strlen(parent->base.hname) + 8 + strlen(base),
@@ -721,7 +723,6 @@ struct aa_profile *aa_new_learning_profile(struct aa_profile *parent, bool hat,if (hat) profile->label.flags |=FLAG_HAT ; -mutex_lock_nested (&profile->ns->lock, profile->ns->level); p =__find_child (&parent->base.profiles, bname);if (p) {aa_free_profile (profile);
@@ -729,7 +730,6 @@ struct aa_profile *aa_new_learning_profile(struct aa_profile *parent, bool hat, }else {__add_profile (&parent->base.profiles, profile); } -mutex_unlock (&profile->ns->lock);/* refcount released by caller */ out:
@@ -743,6 +743,18 @@ struct aa_profile *aa_new_learning_profile(struct aa_profile *parent, bool hat,return NULL ; } +struct aa_profile *aa_new_learning_profile (struct aa_profile *parent,bool hat, +const char *base,gfp_t gfp) +{ +struct aa_profile *profile; + +mutex_lock_nested (&parent->ns->lock, parent->ns->level); + profile =__aa_new_learning_profile (parent, hat, base, gfp); +mutex_unlock (&parent->ns->lock); + +return profile; +} +/** * replacement_allowed - test to see if replacement is allowed * @profile: profile to test if it can be replaced (MAYBE NULL)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1404/1674 blk-cgroup: delay freeing policy data after rcu grace period
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yu Kuai <[email protected]>
[ Upstream commit 0af3fedb8c8ed3c07b4f76927bd7fc88f6f82efb ]
Currently blkcg_print_blkgs() must hold RCU to iterate blkgs from a blkcg, and prfill() must hold queue_lock to prevent policy data from being freed by policy deactivation. As a consequence, queue_lock has to be nested under RCU from blkcg_print_blkgs().
Delay freeing policy data until after an RCU grace period so prfill() can be protected by RCU alone.
Stable-dep-of: 97cb95d21488 ("blk-iocost: clear delay state when freeing policy data")
--- block/bfq-cgroup.c | 9 ++++++++- block/blk-cgroup.h | 2 ++ block/blk-iocost.c | 14 ++++++++++++-- block/blk-iolatency.c | 10 +++++++++- block/blk-throttle.c | 13 +++++++++++-- 5 files changed, 42 insertions(+), 6 deletions(-)
block/bfq-cgroup.c +8 -1
@@ -548,14 +548,21 @@ static void bfq_pd_init(struct blkg_policy_data *pd) bfqg->rq_pos_tree =RB_ROOT ; } -static void bfq_pd_free (struct blkg_policy_data *pd) +static void bfqg_release (struct rcu_head *rcu) { +struct blkg_policy_data *pd = + container_of(rcu, struct blkg_policy_data, rcu_head);struct bfq_group *bfqg =pd_to_bfqg (pd);bfqg_stats_exit (&bfqg->stats);bfqg_put (bfqg); } +static void bfq_pd_free (struct blkg_policy_data *pd) +{ +call_rcu (&pd->rcu_head, bfqg_release); +} +static void bfq_pd_reset_stats (struct blkg_policy_data *pd) {struct bfq_group *bfqg =pd_to_bfqg (pd);
block/blk-cgroup.h +2 -0
@@ -137,6 +137,8 @@ struct blkg_policy_data {struct blkcg_gq *blkg;int plid;bool online; + +struct rcu_head rcu_head; };/*
block/blk-iocost.c +12 -2
@@ -3019,6 +3019,16 @@ static void ioc_pd_init(struct blkg_policy_data *pd)spin_unlock_irqrestore (&ioc->lock, flags); } +static void iocg_release (struct rcu_head *rcu) +{ +struct blkg_policy_data *pd = + container_of(rcu, struct blkg_policy_data, rcu_head); +struct ioc_gq *iocg =pd_to_iocg (pd); + +free_percpu (iocg->pcpu_stat); +kfree (iocg); +} +static void ioc_pd_free (struct blkg_policy_data *pd) {struct ioc_gq *iocg =pd_to_iocg (pd);
@@ -3043,8 +3053,8 @@ static void ioc_pd_free(struct blkg_policy_data *pd)hrtimer_cancel (&iocg->waitq_timer); } -free_percpu (iocg->pcpu_stat); -kfree (iocg); + +call_rcu (&pd->rcu_head, iocg_release); }static void ioc_pd_stat (struct blkg_policy_data *pd,struct seq_file *s)
block/blk-iolatency.c +9 -1
@@ -1031,13 +1031,21 @@ static void iolatency_pd_offline(struct blkg_policy_data *pd)iolatency_clear_scaling (blkg); } -static void iolatency_pd_free (struct blkg_policy_data *pd) +static void iolat_release (struct rcu_head *rcu) { +struct blkg_policy_data *pd = + container_of(rcu, struct blkg_policy_data, rcu_head);struct iolatency_grp *iolat =pd_to_lat (pd); +free_percpu (iolat->stats);kfree (iolat); } +static void iolatency_pd_free (struct blkg_policy_data *pd) +{ +call_rcu (&pd->rcu_head, iolat_release); +} +static struct cftype iolatency_files[] = { { .name ="latency" ,
block/blk-throttle.c +11 -2
@@ -486,16 +486,25 @@ static void throtl_pd_offline(struct blkg_policy_data *pd)throtl_upgrade_state (tg->td); } -static void throtl_pd_free (struct blkg_policy_data *pd) +static void tg_release (struct rcu_head *rcu) { +struct blkg_policy_data *pd = + container_of(rcu, struct blkg_policy_data, rcu_head);struct throtl_grp *tg =pd_to_tg (pd); -del_timer_sync (&tg->service_queue.pending_timer);blkg_rwstat_exit (&tg->stat_bytes);blkg_rwstat_exit (&tg->stat_ios);kfree (tg); } +static void throtl_pd_free (struct blkg_policy_data *pd) +{ +struct throtl_grp *tg =pd_to_tg (pd); + +del_timer_sync (&tg->service_queue.pending_timer); +call_rcu (&pd->rcu_head, tg_release); +} +static struct throtl_grp *throtl_rb_first (struct throtl_service_queue *parent_sq) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1405/1674 blk-iocost: clear delay state when freeing policy data
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Usama Arif <[email protected]>
[ Upstream commit 97cb95d2148835ae86ff916b145aef332d40439d ]
iocg_kick_delay() turns sufficiently large debt into an explicit block-cgroup delay with blkcg_set_delay(), setting blkg->use_delay to -1 and incrementing blkcg->congestion_count. Clearing it again depends on iocg_kick_delay() running from the period timer, the waitq timer or the issue path.
ioc_pd_free() removes the iocg from active_iocgs and cancels its waitq timer, and no further bios can arrive, so once it has run nothing is left which can reduce the debt and clear the delay. The blkcg stays marked congested for the rest of its life.
blk_cgroup_congested() then returns true for every task in that cgroup and its descendants: page_cache_sync_ra() cuts readahead to a single page, page_cache_async_ra() skips it altogether, and __folio_throttle_swaprate() takes swap_avail_lock and schedules a throttle on anonymous folio allocation.
Clear it explicitly, after the list removal and the synchronous hrtimer_cancel() so that neither timer processing nor an I/O path can re-arm it. The free callback can also see policy data which was never attached to a blkg, hence the pd->blkg check.
--- block/blk-iocost.c | 7 +++++++ 1 file changed, 7 insertions(+)
block/blk-iocost.c +7 -0
@@ -3032,6 +3032,7 @@ static void iocg_release(struct rcu_head *rcu)static void ioc_pd_free (struct blkg_policy_data *pd) {struct ioc_gq *iocg =pd_to_iocg (pd); +struct blkcg_gq *blkg =pd_to_blkg (pd);struct ioc *ioc = iocg->ioc;unsigned long flags;
@@ -3054,6 +3055,12 @@ static void ioc_pd_free(struct blkg_policy_data *pd)hrtimer_cancel (&iocg->waitq_timer); } +/* off ->active_iocgs and timer gone, so nothing can re-arm the delay */ + iocg->delay =0 ; + iocg->indelay_since =0 ; +if (blkg) +blkcg_clear_delay (blkg); +call_rcu (&pd->rcu_head, iocg_release); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1406/1674 blk-iolatency: clear delay state when freeing policy data
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Usama Arif <[email protected]>
[ Upstream commit 8935bf22c0a0db517a7f72f7097300e05dd852f5 ]
io.latency can throttle a group which has no latency target of its own. When a sibling misses its target, check_scale_change() scales down its peers, and a peer that reaches queue depth one gets blkcg_use_delay() called on it on every further scale-down, even with min_lat_nsec == 0.
iolatency_pd_offline() resets the target through iolatency_set_min_lat_nsec(), which clears the delay only on a nonzero to zero transition, so it never clears such a peer. Freeing the policy data then leaves blkg->use_delay set and blkcg->congestion_count elevated with nothing left that can drop it.
blk_cgroup_congested() then returns true for every task in that cgroup and its descendants for as long as the cgroup lives: page_cache_sync_ra() cuts readahead to a single page, page_cache_async_ra() skips it altogether, and __folio_throttle_swaprate() takes swap_avail_lock and schedules a throttle on anonymous folio allocation.
Clear the delay in iolatency_pd_free(). By then bio-held blkg references have drained, or the queue is frozen for policy deactivation, so check_scale_change() cannot re-arm it. The free callback can also see policy data which was never attached to a blkg, hence the pd->blkg check.
--- block/blk-iolatency.c | 9 +++++++++ 1 file changed, 9 insertions(+)
block/blk-iolatency.c +9 -0
@@ -1043,6 +1043,15 @@ static void iolat_release(struct rcu_head *rcu)static void iolatency_pd_free (struct blkg_policy_data *pd) { +struct blkcg_gq *blkg =pd_to_blkg (pd); + +/* +* Groups throttled as collateral have min_lat_nsec == 0, so +* iolatency_pd_offline() leaves their delay set. Drop it here, where +* no in-flight bio can re-arm it via check_scale_change(). +*/ +if (blkg) +blkcg_clear_delay (blkg);call_rcu (&pd->rcu_head, iolat_release); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1407/1674 null_blk: free zones array on device power-off
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zizhi Wo <[email protected]>
[ Upstream commit 2a6357a9b935a34f5508618fee8a7fffbf7722a8 ]
null_init_zoned_dev() allocates dev->zones when a zoned device is powered on, but null_del_dev() never frees it on power-off; dev->zones is only freed later in null_free_dev(), when the configfs directory is removed. If the device is powered off and then on again, null_init_zoned_dev() allocates a new array and overwrites the dev->zones pointer, leaking the previous allocation each power cycle.
Free dev->zones in null_del_dev() via null_free_zoned_dev() to solve it. And calling null_free_zoned_dev() in null_free_dev() is no longer necessary because every caller already invokes null_del_dev() first: via nullb_group_drop_item() before nullb_device_release(), in the null_add_dev() error path of null_create_dev(), and in null_destroy_dev(). Remove the redundant call.
And take &lock around zone_cond_store() in the two store wrappers to serialize dev->zones check-and-deref against its alloc/free, which already run under &lock. The reason there was no problem before is that only nullb_device_release() or null_exit() frees the dev->zones, which guarantees that subsequent users won't access the configfs interface.
--- drivers/block/null_blk/main.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/block/null_blk/main.c +13 -3
@@ -552,8 +552,13 @@ static ssize_t nullb_device_zone_readonly_store(struct config_item *item, const char *page, size_t count) {struct nullb_device *dev =to_nullb_device (item); +ssize_t ret; + +mutex_lock (&lock); + ret =zone_cond_store (dev, page, count,BLK_ZONE_COND_READONLY ); +mutex_unlock (&lock); -return zone_cond_store (dev, page, count,BLK_ZONE_COND_READONLY ); +return ret; }CONFIGFS_ATTR_WO (nullb_device_, zone_readonly);
@@ -561,8 +566,13 @@ static ssize_t nullb_device_zone_offline_store(struct config_item *item, const char *page, size_t count) {struct nullb_device *dev =to_nullb_device (item); +ssize_t ret; -return zone_cond_store (dev, page, count,BLK_ZONE_COND_OFFLINE ); +mutex_lock (&lock); + ret =zone_cond_store (dev, page, count,BLK_ZONE_COND_OFFLINE ); +mutex_unlock (&lock); + +return ret; }CONFIGFS_ATTR_WO (nullb_device_, zone_offline);
@@ -785,7 +795,6 @@ static void null_free_dev(struct nullb_device *dev)if (!dev)return ; -null_free_zoned_dev (dev);badblocks_exit (&dev->badblocks);kfree (dev); }
@@ -1870,6 +1879,7 @@ static void null_del_dev(struct nullb *nullb) }put_disk (nullb->disk); +null_free_zoned_dev (dev);if (dev->queue_mode ==NULL_Q_MQ && nullb->tag_set == &nullb->__tag_set)blk_mq_free_tag_set (nullb->tag_set);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1408/1674 ocfs2: validate DIO orphan slot during inode read
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: ZhengYuan Huang <[email protected]>
[ Upstream commit bb88131c9831075b8dc08cdd375743e5d44c7ca2 ]
[BUG]
A corrupted append-DIO dinode (high byte at offset 0xa1 corrupted from 0 to 1) can carry an i_dio_orphaned_slot outside the mounted filesystem slot range and trigger a use-after-free error:
BUG: KASAN: slab-use-after-free in ocfs2_get_system_file_inode+0x780/0x820 fs/ocfs2/sysfile.c:102 Read of size 8 at addr ffff88800b767c00 by task kworker/u8:3/85 Call Trace: ... ocfs2_get_system_file_inode+0x780/0x820 fs/ocfs2/sysfile.c:102 ocfs2_wipe_inode+0x292/0xf70 fs/ocfs2/inode.c:840 ocfs2_delete_inode fs/ocfs2/inode.c:1155 [inline] ocfs2_evict_inode+0x6c9/0x1170 fs/ocfs2/inode.c:1295 evict+0x38e/0x8f0 fs/inode.c:810 iput_final fs/inode.c:1914 [inline] iput fs/inode.c:1966 [inline] iput+0x55b/0x8b0 fs/inode.c:1926 ocfs2_recover_orphans+0x610/0xe40 fs/ocfs2/journal.c:2374 ocfs2_complete_recovery+0x5af/0xd00 fs/ocfs2/journal.c:1373 ...
[CAUSE]ocfs2_del_inode_from_orphan() uses i_dio_orphaned_slot to index the slot-local system inode cache. The dinode validator does not check this active slot, so an out-of-range value produces an invalid cache entry pointer that is dereferenced as an inode pointer.
[FIX]
Reject an active i_dio_orphaned_slot outside the slot range during dinode validation, before DIO orphan recovery can consume it.
--- fs/ocfs2/inode.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ocfs2/inode.c +8 -0
@@ -1466,6 +1466,14 @@ int ocfs2_validate_inode_block(struct super_block *sb, goto bail; } +if ((le32_to_cpu (di->i_flags) &OCFS2_DIO_ORPHANED_FL ) && +le16_to_cpu (di->i_dio_orphaned_slot) >=OCFS2_SB (sb)->max_slots) { + rc =ocfs2_error (sb,"Invalid dinode %llu: DIO orphaned slot %u\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_dio_orphaned_slot)); + goto bail; + } +/* * Reject dinodes whose i_mode does not name one of the seven * canonical POSIX file types. ocfs2_populate_inode() copies
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1409/1674 ocfs2: validate orphan slot during inode read
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: ZhengYuan Huang <[email protected]>
[ Upstream commit b2d31acbd3b182755b019183fb46949ba5e39b9f ]
Patch series "ocfs2: validate active orphan slots during inode read".
OCFS2 trusts active ordinary and append-DIO orphan slots read from dinodes. A corrupted slot can therefore index osb_orphan_wipes or the slot-local system-inode cache outside their allocations before the corruption is reported.
Patch 1 validates the ordinary orphan slot used by inode wipe processing. Patch 2 validates the append-DIO orphan slot used by DIO completion and orphan recovery. Both checks reject corrupt metadata at the existing inode validation boundary.
This patch (of 2):
[BUG]
A corrupted dinode with OCFS2_ORPHANED_FL can carry an i_orphaned_slot outside the mounted filesystem slot range. ocfs2_wipe_inode() uses it to index osb_orphan_wipes before looking up the orphan directory, causing an out-of-bounds memory access.
BUG: KASAN: slab-use-after-free in ocfs2_get_system_file_inode+0x780/0x820 fs/ocfs2/sysfile.c:102 Read of size 8 at addr ffff88800b767c00 by task kworker/u8:3/85 Call Trace: ... ocfs2_get_system_file_inode+0x780/0x820 fs/ocfs2/sysfile.c:102 ocfs2_wipe_inode+0x292/0xf70 fs/ocfs2/inode.c:840 ocfs2_delete_inode fs/ocfs2/inode.c:1155 [inline] ocfs2_evict_inode+0x6c9/0x1170 fs/ocfs2/inode.c:1295 evict+0x38e/0x8f0 fs/inode.c:810 iput_final fs/inode.c:1914 [inline] iput fs/inode.c:1966 [inline] iput+0x55b/0x8b0 fs/inode.c:1926 ocfs2_recover_orphans+0x610/0xe40 fs/ocfs2/journal.c:2374 ocfs2_complete_recovery+0x5af/0xd00 fs/ocfs2/journal.c:1373 ...
[CAUSE]ocfs2_validate_inode_block() validates i_suballoc_slot but leaves the active ordinary orphan slot unchecked. Downstream consumers assume that the value is smaller than osb->max_slots.
[FIX]
Reject an active i_orphaned_slot outside the slot range during dinode validation, before the inode reaches orphan wipe processing.
--- fs/ocfs2/inode.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ocfs2/inode.c +8 -0
@@ -1474,6 +1474,14 @@ int ocfs2_validate_inode_block(struct super_block *sb, goto bail; } +if ((le32_to_cpu (di->i_flags) &OCFS2_ORPHANED_FL ) && +le16_to_cpu (di->i_orphaned_slot) >=OCFS2_SB (sb)->max_slots) { + rc =ocfs2_error (sb,"Invalid dinode %llu: orphaned slot %u\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_orphaned_slot)); + goto bail; + } +/* * Reject dinodes whose i_mode does not name one of the seven * canonical POSIX file types. ocfs2_populate_inode() copies
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1410/1674 nvmet: fix max_qid race between configfs and controller allocation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maurizio Lombardi <[email protected]>
[ Upstream commit f1a8846e06388113dfdbb89dee005083fa9afdf9 ]
The function nvmet_subsys_attr_qid_max_store() can race against nvmet_alloc_ctrl() when a subsystem's max_qid limit is modified.
Suppose max_qid is currently 64. If nvmet_alloc_ctrl() executes:ctrl->sqs = kzalloc_objs(struct nvmet_sq *, subsys->max_qid + 1); and at this exact point, a userspace process changes max_qid to 128, nvmet_subsys_attr_qid_max_store() will set the new max_qid value. It attempts to delete active controllers to force a reconnect, but the new controller won't be deleted because it hasn't been added to the subsys->ctrls list yet.
nvmet_alloc_ctrl() then proceeds and adds the new controller to the subsys->ctrls list. Later, when nvmet_install_queue() is called, it will see max_qid set to 128, but the memory allocated for sqs is only sized for 64 entries. This results in a KASAN out-of-bounds warning and potential memory corruptions.
Fix this by protecting the queue allocations and list insertion in nvmet_alloc_ctrl() with down_read(&nvmet_config_sem). Because nvmet_subsys_attr_qid_max_store() acquires down_write(&nvmet_config_sem) to modify the attribute, this safely prevents the configfs writer from modifying max_qid during controller creation.
Copy the max_qid from the subsystem to the controller's structure during the allocation; ctrl->max_qid never changes as long as the controller remains in LIVE state, so this will prevent similar race conditions.
--- drivers/nvme/target/admin-cmd.c | 8 +++--- drivers/nvme/target/core.c | 41 ++++++++++++++++++------------- drivers/nvme/target/fabrics-cmd.c | 2 +- drivers/nvme/target/nvmet.h | 6 +++++ 4 files changed, 35 insertions(+), 22 deletions(-)
drivers/nvme/target/admin-cmd.c +4 -4
@@ -818,7 +818,7 @@ u16 nvmet_set_feat_async_event(struct nvmet_req *req, u32 mask)void nvmet_execute_set_features (struct nvmet_req *req) { -struct nvmet_subsys *subsys =nvmet_req_subsys (req); +struct nvmet_ctrl *ctrl =nvmet_req_ctrl (req);u32 cdw10 =le32_to_cpu (req->cmd->common.cdw10);u32 cdw11 =le32_to_cpu (req->cmd->common.cdw11);u16 status =0 ;
@@ -837,7 +837,7 @@ void nvmet_execute_set_features(struct nvmet_req *req)break ; }nvmet_set_result (req, - (subsys->max_qid -1 ) | ((subsys->max_qid -1 ) <<16 )); + (ctrl->max_qid -1 ) | ((ctrl->max_qid -1 ) <<16 ));break ;case NVME_FEAT_KATO : status =nvmet_set_feat_kato (req);
@@ -892,7 +892,7 @@ void nvmet_get_feat_async_event(struct nvmet_req *req)void nvmet_execute_get_features (struct nvmet_req *req) { -struct nvmet_subsys *subsys =nvmet_req_subsys (req); +struct nvmet_ctrl *ctrl =nvmet_req_ctrl (req);u32 cdw10 =le32_to_cpu (req->cmd->common.cdw10);u16 status =0 ;
@@ -929,7 +929,7 @@ void nvmet_execute_get_features(struct nvmet_req *req)break ;case NVME_FEAT_NUM_QUEUES :nvmet_set_result (req, - (subsys->max_qid-1 ) | ((subsys->max_qid-1 ) <<16 )); + (ctrl->max_qid-1 ) | ((ctrl->max_qid-1 ) <<16 ));break ;case NVME_FEAT_KATO :nvmet_get_feat_kato (req);
drivers/nvme/target/core.c +24 -17
62 lines not on this page · raw message
drivers/nvme/target/fabrics-cmd.c +1 -1
@@ -351,7 +351,7 @@ static void nvmet_execute_io_connect(struct nvmet_req *req) goto out; } -if (unlikely (qid > ctrl->subsys->max_qid)) { +if (unlikely (qid > ctrl->max_qid)) {pr_warn ("invalid queue id (%d)\n" , qid); status =NVME_SC_CONNECT_INVALID_PARAM |NVME_STATUS_DNR ; req->cqe->result.u32 =IPO_IATTR_CONNECT_SQE (qid);
drivers/nvme/target/nvmet.h +6 -0
@@ -191,6 +191,7 @@ struct nvmet_ctrl {uuid_t hostid;u16 cntlid; +u16 max_qid;u32 kato;struct nvmet_port *port;
@@ -620,6 +621,11 @@ static inline struct nvmet_subsys *nvmet_req_subsys(struct nvmet_req *req)return req->sq->ctrl->subsys; } +static inline struct nvmet_ctrl *nvmet_req_ctrl (struct nvmet_req *req) +{ +return req->sq->ctrl; +} +static inline bool nvmet_is_disc_subsys (struct nvmet_subsys *subsys) {return subsys->type !=NVME_NQN_NVME ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1411/1674 clocksource/drivers/samsung_pwm: Switch to raw_spinlock_t type
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Szyprowski <[email protected]>
[ Upstream commit 3b212f9d70805d91febae01d618868f4860e267c ]
Samsung PWM timer might be used as a clock source on some legacy systems. When PREEMPT_RT is enabled on ARM, regular spinlock is converted to a sleeping lock (mutex-based), which must not be used in atomic context such as hard interrupt handlers. Switch the samsung_pwm_lock to the raw_spinlock, which remains a true non-sleeping spinlock even under PREEMPT_RT.
--- drivers/clocksource/samsung_pwm_timer.c | 22 +++++++++++----------- drivers/pwm/pwm-samsung.c | 22 +++++++++++----------- include/clocksource/samsung_pwm.h | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-)
drivers/clocksource/samsung_pwm_timer.c +11 -11
@@ -56,7 +56,7 @@#define TCON_AUTORELOAD (chan) \ ((chan < 5) ? _TCON_AUTORELOAD(chan) : _TCON_AUTORELOAD4(chan)) -DEFINE_SPINLOCK (samsung_pwm_lock); +DEFINE_RAW_SPINLOCK (samsung_pwm_lock);EXPORT_SYMBOL (samsung_pwm_lock);struct samsung_pwm_clocksource {
@@ -87,14 +87,14 @@ static void samsung_timer_set_prescale(unsigned int channel, u16 prescale)if (channel >=2 ) shift =TCFG0_PRESCALER1_SHIFT ; -spin_lock_irqsave (&samsung_pwm_lock, flags); +raw_spin_lock_irqsave (&samsung_pwm_lock, flags); reg =readl (pwm.base +REG_TCFG0 ); reg &= ~(TCFG0_PRESCALER_MASK << shift); reg |= (prescale -1 ) << shift;writel (reg, pwm.base +REG_TCFG0 ); -spin_unlock_irqrestore (&samsung_pwm_lock, flags); +raw_spin_unlock_irqrestore (&samsung_pwm_lock, flags); }static void samsung_timer_set_divisor (unsigned int channel,u8 divisor)
@@ -106,14 +106,14 @@ static void samsung_timer_set_divisor(unsigned int channel, u8 divisor) bits = (fls (divisor) -1 ) - pwm.variant.div_base; -spin_lock_irqsave (&samsung_pwm_lock, flags); +raw_spin_lock_irqsave (&samsung_pwm_lock, flags); reg =readl (pwm.base +REG_TCFG1 ); reg &= ~(TCFG1_MUX_MASK << shift); reg |= bits << shift;writel (reg, pwm.base +REG_TCFG1 ); -spin_unlock_irqrestore (&samsung_pwm_lock, flags); +raw_spin_unlock_irqrestore (&samsung_pwm_lock, flags); }static void samsung_time_stop (unsigned int channel)
@@ -124,13 +124,13 @@ static void samsung_time_stop(unsigned int channel)if (channel >0 ) ++channel; -spin_lock_irqsave (&samsung_pwm_lock, flags); +raw_spin_lock_irqsave (&samsung_pwm_lock, flags); tcon =readl_relaxed (pwm.base +REG_TCON ); tcon &= ~TCON_START (channel);writel_relaxed (tcon, pwm.base +REG_TCON ); -spin_unlock_irqrestore (&samsung_pwm_lock, flags); +raw_spin_unlock_irqrestore (&samsung_pwm_lock, flags); }static void samsung_time_setup (unsigned int channel,unsigned long tcnt)
@@ -142,7 +142,7 @@ static void samsung_time_setup(unsigned int channel, unsigned long tcnt)if (tcon_chan >0 ) ++tcon_chan; -spin_lock_irqsave (&samsung_pwm_lock, flags); +raw_spin_lock_irqsave (&samsung_pwm_lock, flags); tcon =readl_relaxed (pwm.base +REG_TCON );
@@ -153,7 +153,7 @@ static void samsung_time_setup(unsigned int channel, unsigned long tcnt)writel_relaxed (tcnt, pwm.base +REG_TCMPB (channel));writel_relaxed (tcon, pwm.base +REG_TCON ); -spin_unlock_irqrestore (&samsung_pwm_lock, flags); +raw_spin_unlock_irqrestore (&samsung_pwm_lock, flags); }static void samsung_time_start (unsigned int channel,bool periodic)
@@ -164,7 +164,7 @@ static void samsung_time_start(unsigned int channel, bool periodic)if (channel >0 ) ++channel; -spin_lock_irqsave (&samsung_pwm_lock, flags); +raw_spin_lock_irqsave (&samsung_pwm_lock, flags); tcon =readl_relaxed (pwm.base +REG_TCON );
@@ -178,7 +178,7 @@ static void samsung_time_start(unsigned int channel, bool periodic)writel_relaxed (tcon, pwm.base +REG_TCON ); -spin_unlock_irqrestore (&samsung_pwm_lock, flags); +raw_spin_unlock_irqrestore (&samsung_pwm_lock, flags); } static int samsung_set_next_event(unsigned long cycles,
drivers/pwm/pwm-samsung.c +11 -11
@@ -102,7 +102,7 @@ struct samsung_pwm_chip {* IP. Should this change, both drivers will need to be modified to * properly synchronize accesses to particular instances. */ -static DEFINE_SPINLOCK (samsung_pwm_lock); +static DEFINE_RAW_SPINLOCK (samsung_pwm_lock);#endif static inline
@@ -141,14 +141,14 @@ static void pwm_samsung_set_divisor(struct samsung_pwm_chip *pwm, bits = (fls (divisor) -1 ) - pwm->variant.div_base; -spin_lock_irqsave (&samsung_pwm_lock, flags); +raw_spin_lock_irqsave (&samsung_pwm_lock, flags); reg =readl (pwm->base +REG_TCFG1 ); reg &= ~(TCFG1_MUX_MASK << shift); reg |= bits << shift;writel (reg, pwm->base +REG_TCFG1 ); -spin_unlock_irqrestore (&samsung_pwm_lock, flags); +raw_spin_unlock_irqrestore (&samsung_pwm_lock, flags); }static int pwm_samsung_is_tdiv (struct samsung_pwm_chip *chip,unsigned int chan)
@@ -258,7 +258,7 @@ static int pwm_samsung_enable(struct pwm_chip *chip, struct pwm_device *pwm)unsigned long flags;u32 tcon; -spin_lock_irqsave (&samsung_pwm_lock, flags); +raw_spin_lock_irqsave (&samsung_pwm_lock, flags); tcon =readl (our_chip->base +REG_TCON );
@@ -272,7 +272,7 @@ static int pwm_samsung_enable(struct pwm_chip *chip, struct pwm_device *pwm) our_chip->disabled_mask &= ~BIT (pwm->hwpwm); -spin_unlock_irqrestore (&samsung_pwm_lock, flags); +raw_spin_unlock_irqrestore (&samsung_pwm_lock, flags);return 0 ; }
@@ -284,7 +284,7 @@ static void pwm_samsung_disable(struct pwm_chip *chip, struct pwm_device *pwm)unsigned long flags;u32 tcon; -spin_lock_irqsave (&samsung_pwm_lock, flags); +raw_spin_lock_irqsave (&samsung_pwm_lock, flags); tcon =readl (our_chip->base +REG_TCON ); tcon &= ~TCON_AUTORELOAD (tcon_chan);
@@ -299,7 +299,7 @@ static void pwm_samsung_disable(struct pwm_chip *chip, struct pwm_device *pwm) our_chip->disabled_mask |=BIT (pwm->hwpwm); -spin_unlock_irqrestore (&samsung_pwm_lock, flags); +raw_spin_unlock_irqrestore (&samsung_pwm_lock, flags); } static void pwm_samsung_manual_update(struct samsung_pwm_chip *chip,
@@ -307,11 +307,11 @@ static void pwm_samsung_manual_update(struct samsung_pwm_chip *chip, {unsigned long flags; -spin_lock_irqsave (&samsung_pwm_lock, flags); +raw_spin_lock_irqsave (&samsung_pwm_lock, flags);__pwm_samsung_manual_update (chip, pwm); -spin_unlock_irqrestore (&samsung_pwm_lock, flags); +raw_spin_unlock_irqrestore (&samsung_pwm_lock, flags); } static int __pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm,
@@ -400,7 +400,7 @@ static void pwm_samsung_set_invert(struct samsung_pwm_chip *chip,unsigned long flags;u32 tcon; -spin_lock_irqsave (&samsung_pwm_lock, flags); +raw_spin_lock_irqsave (&samsung_pwm_lock, flags); tcon =readl (chip->base +REG_TCON );
@@ -414,7 +414,7 @@ static void pwm_samsung_set_invert(struct samsung_pwm_chip *chip,writel (tcon, chip->base +REG_TCON ); -spin_unlock_irqrestore (&samsung_pwm_lock, flags); +raw_spin_unlock_irqrestore (&samsung_pwm_lock, flags); } static int pwm_samsung_set_polarity(struct pwm_chip *chip,
include/clocksource/samsung_pwm.h +1 -1
@@ -15,7 +15,7 @@* spinlock is not shared between both drivers. */ #ifdef CONFIG_CLKSRC_SAMSUNG_PWM -extern spinlock_t samsung_pwm_lock; +extern raw_spinlock_t samsung_pwm_lock;#endif struct samsung_pwm_variant {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1412/1674 amt: Dont support cross-netns setup.
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit e99ecc3046ea5f5c6b5e1f8b4ef854c6c6998e06 ]
When a lower device is unregistered, amt_device_event() tries to unregister its upper AMT device, but it has two problems.
1. amt_lookup_upper_dev() looks up an upper device in the lower device's netns only
2. amt_device_event() unregisters a single upper device only
If AMT device is created on a lower device in another netns, removing the lower device triggers the splat below and gets stuck until all upper devices are removed. [0]
The cross-netns setup seems unintentional considering 1. and the following points:
* amt_link_setup() sets dev->netns_immutable to true
* skb_scrub_packet() is not called in the fast path
* iproute2 binary fails to find cross-netns lower device via link-netns:
# ip -n ns1 link add amt0 link-netns ns2 type amt dev veth1 Cannot find device "veth1"
Instead of supporting it properly and preparing for per-netns netdev unreg, let's forbid cross-netns setup.
Note that the problem 2. needs a separate fix.
[0]:
WARNING: net/core/dev.c:12518 at unregister_netdevice_many_notify+0x1cce/0x2250, CPU#48: ip/2031
Modules linked in:
CPU: 48 UID: 0 PID: 2031 Comm: ip Not tainted 7.2.0-rc5+ #27 PREEMPT(full)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1 04/01/2014
RIP: 0010:unregister_netdevice_many_notify (net/core/dev.c:12518)
Code: 89 ef e8 d5 52 ae fe e9 d0 f4 ff ff 48 8d 3d f9 3b 9c 02 48 c7 c6 c0 0b 63 84 ba ab 1f 00 00 67 48 0f b9 3a e9 65 ff ff ff 90 <0f> 0b 90 eb 81 48 8d 3d f6 3b 9c 02 48 c7 c6 c0 0b 63 84 ba e2 1f
RSP: 0018:ffffc90004abf160 EFLAGS: 00010212
RAX: ffff888104d38260 RBX: ffff88800b0911b8 RCX: dffffc0000000000
RDX: 0000000000000000 RSI: 0000000000000008 RDI: ffffffff85b9f880
RBP: ffffc90004abf2d0 R08: ffffffff85b9f887 R09: 1ffffffff0b73f10
R10: dffffc0000000000 R11: fffffbfff0b73f11 R12: ffff88800b091d08
R13: ffff88800b091178 R14: dffffc0000000000 R15: ffff88800b091000
FS: 00007f555b86c600(0000) GS:ffff8881942a0000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000562107d489c0 CR3: 0000000109a40002 CR4: 0000000000372ef0
Call Trace:
<TASK>
rtnl_dellink (net/core/rtnetlink.c:3632 net/core/rtnetlink.c:3674)
rtnetlink_rcv_msg (net/core/rtnetlink.c:7112)
netlink_rcv_skb (net/netlink/af_netlink.c:2556)
netlink_unicast (net/netlink/af_netlink.c:1319)
netlink_sendmsg (net/netlink/af_netlink.c:1900)
____sys_sendmsg (net/socket.c:775)
__sys_sendmsg (net/socket.c:2738)
do_syscall_64 (arch/x86/entry/syscall_64.c:63)
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
...
unregister_netdevice: waiting for veth0 to become free. Usage count = 7
ref_tracker: netdev@ffff88800d7496d8 has 3/3 users at
__netdev_adjacent_dev_insert (./include/linux/netdevice.h:4525 ./include/linux/netdevice.h:4554 net/core/dev.c:8791)
__netdev_upper_dev_link (net/core/dev.c:8879 net/core/dev.c:8963)
netdev_upper_dev_link (net/core/dev.c:9009)
amt_newlink (drivers/net/amt.c:3321)--- drivers/net/amt.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/amt.c +3 -0
@@ -3195,6 +3195,9 @@ static int amt_newlink(struct net *net, struct net_device *dev,struct amt_dev *amt =netdev_priv (dev);int err = -EINVAL ; +if (!net_eq (net,dev_net (dev))) +return err; + amt->net = net; amt->mode =nla_get_u32 (data[IFLA_AMT_MODE ]);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1413/1674 NFS: Return a delegation the client fails to record
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 220af23d863995091f0edeb1e6aa0945b3db8b37 ]
When an NFS server grants a delegation in an OPEN reply, nfs_inode_set_delegation() records it on the client. However, three of its error flows return without sending DELEGRETURN.
A delegation can be relinquished only by DELEGRETURN (RFC 8881 Section 20.2.4), so dropping one silently leaves the server believing the client still holds it. If the server happens to recall that delegation, the client answers CB_RECALL with NFS4ERR_BADHANDLE because it has no record of the stateid. The server revokes the delegation and moves it onto its cl_revoked list, because the client never sends the FREE_STATEID that would drain it. Every subsequent SEQUENCE reply then carries SEQ4_STATUS_RECALLABLE_STATE_REVOKED, and the client's state manager loops issuing TEST_STATEID across its delegations without ever clearing the condition.
The window is easy to reach now that a server offers a write delegation on any write OPEN: a delegation recalled for one opener races a re-open that the server answers with a fresh write delegation.
Instead of dropping it, hand the delegation back during these error flows.
--- fs/nfs/delegation.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
fs/nfs/delegation.c +14 -4
@@ -436,11 +436,14 @@ int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred,struct nfs_inode *nfsi =NFS_I (inode);struct nfs_delegation *delegation, *old_delegation;struct nfs_delegation *freeme =NULL ; +bool orphaned = false;int status =0 ; delegation =kmalloc (sizeof (*delegation),GFP_KERNEL_ACCOUNT ); -if (delegation ==NULL ) +if (delegation ==NULL ) { +nfs4_proc_delegreturn (inode, cred, stateid,0 );return -ENOMEM ; + }nfs4_stateid_copy (&delegation->stateid, stateid);refcount_set (&delegation->refcount,1 ); delegation->type = type;
@@ -482,12 +485,16 @@ int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred, goto out; }if (test_and_set_bit (NFS_DELEGATION_RETURNING , - &old_delegation->flags)) + &old_delegation->flags)) { + orphaned = true; goto out; + } } freeme =nfs_detach_delegation_locked (nfsi, old_delegation, clp); -if (freeme ==NULL ) +if (freeme ==NULL ) { + orphaned = true; goto out; + } add_new:/* * If we didn't revalidate the change attribute before setting
@@ -514,8 +521,11 @@ int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred,trace_nfs4_set_delegation (inode, type); out:spin_unlock (&clp->cl_lock); -if (delegation !=NULL ) +if (delegation !=NULL ) { +if (orphaned) +nfs_do_return_delegation (inode, delegation,0 );__nfs_free_delegation (delegation); + }if (freeme !=NULL ) {nfs_do_return_delegation (inode, freeme,0 );nfs_free_delegation (freeme);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1414/1674 bpf: Fix mmap_lock leak in irq_work path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanghyun Park <[email protected]>
[ Upstream commit fa9dcacdcdf487f0ffef64bf67622f1caed509f1 ]
stack_map_get_build_id_offset() introduced a per-CPU irq_work to defer mmap_read_unlock() from NMI context, and bpf_find_vma() later reused the same mmap_unlock_work. Both callers only check whether the work is busy before taking mmap_lock, so a nested caller can reuse the slot before the first caller queues it. Two read locks may then be acquired while only one deferred unlock runs, leaking a read lock and blocking exit_mmap().
Reserve the per-CPU slot before mmap_read_trylock(). Use the same wrapper in stackmap and bpf_find_vma() so both callers release the reservation on trylock failure. Keep rejecting the slot while the irq_work remains busy. Release it after the irq_work callback unlocks the mm.
--- kernel/bpf/mmap_unlock_work.h | 51 ++++++++++++++++++++--------------- kernel/bpf/stackmap.c | 35 +++++++++++++----------- kernel/bpf/task_iter.c | 14 +++++++--- 3 files changed, 59 insertions(+), 41 deletions(-)
kernel/bpf/mmap_unlock_work.h +29 -22
@@ -4,12 +4,15 @@#ifndef __MMAP_UNLOCK_WORK_H__#define __MMAP_UNLOCK_WORK_H__ +#include <linux/atomic.h> +#include <linux/err.h> #include <linux/irq_work.h> /* irq_work to run mmap_read_unlock() in irq_work */ struct mmap_unlock_irq_work {struct irq_work irq_work;struct mm_struct *mm; +atomic_t active; }; DECLARE_PER_CPU(struct mmap_unlock_irq_work, mmap_unlock_work);
@@ -18,32 +21,36 @@ DECLARE_PER_CPU(struct mmap_unlock_irq_work, mmap_unlock_work);* We cannot do mmap_read_unlock() when the irq is disabled, because of * risk to deadlock with rq_lock. To look up vma when the irqs are * disabled, we need to run mmap_read_unlock() in irq_work. We use a -* percpu variable to do the irq_work. If the irq_work is already used -* by another lookup, we fall over. +* percpu variable to do the irq_work. The active flag reserves the slot +* before mmap_read_trylock() and until the irq_work callback consumes mm. */ -static inline bool bpf_mmap_unlock_get_irq_work (struct mmap_unlock_irq_work **work_ptr) +static inline struct mmap_unlock_irq_work *bpf_mmap_unlock_guard_get (void ) { -struct mmap_unlock_irq_work *work =NULL ; -bool irq_work_busy = false; +struct mmap_unlock_irq_work *work; -if (irqs_disabled ()) { -if (!IS_ENABLED (CONFIG_PREEMPT_RT )) { - work =this_cpu_ptr (&mmap_unlock_work); -if (irq_work_is_busy (&work->irq_work)) { -/* cannot queue more up_read, fallback */ - irq_work_busy = true; - } - }else { -/* -* PREEMPT_RT does not allow to trylock mmap sem in -* interrupt disabled context. Force the fallback code. -*/ - irq_work_busy = true; - } - } +if (!irqs_disabled ()) +return NULL ; + +/* +* PREEMPT_RT does not allow to trylock mmap sem in interrupt +* disabled context. Force the fallback code. +*/ +if (IS_ENABLED (CONFIG_PREEMPT_RT )) +return ERR_PTR (-EBUSY ); + + work =this_cpu_ptr (&mmap_unlock_work); +if (irq_work_is_busy (&work->irq_work) || +atomic_cmpxchg_acquire (&work->active,0 ,1 )) +return ERR_PTR (-EBUSY ); - *work_ptr = work; -return irq_work_busy; +return work; +} + +static inline void +bpf_mmap_unlock_guard_put (struct mmap_unlock_irq_work *work) +{ +if (work) +atomic_set_release (&work->active,0 ); }static inline void bpf_mmap_unlock_mm (struct mmap_unlock_irq_work *work,struct mm_struct *mm)
kernel/bpf/stackmap.c +20 -15
@@ -128,24 +128,20 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs, u64 *ips, u32 trace_nr, bool user) { int i; -struct mmap_unlock_irq_work *work =NULL ; -bool irq_work_busy =bpf_mmap_unlock_get_irq_work (&work); +struct mmap_unlock_irq_work *work;struct vm_area_struct *vma, *prev_vma =NULL ;const char *prev_build_id; -/* If the irq_work is in use, fall back to report ips. Same -* fallback is used for kernel stack (!user) on a stackmap with -* build_id. -*/ -if (!user || !current || !current->mm || irq_work_busy || - !mmap_read_trylock (current->mm)) { -/* cannot access current->mm, fall back to ips */ -for (i =0 ; i < trace_nr; i++) { - id_offs[i].status =BPF_STACK_BUILD_ID_IP ; - id_offs[i].ip = ips[i]; -memset (id_offs[i].build_id,0 ,BUILD_ID_SIZE_MAX ); - } -return ; +if (!user || !current || !current->mm) + goto fallback; + + work =bpf_mmap_unlock_guard_get (); +if (IS_ERR (work)) + goto fallback; + +if (!mmap_read_trylock (current->mm)) { +bpf_mmap_unlock_guard_put (work); + goto fallback; }for (i =0 ; i < trace_nr; i++) {
@@ -171,6 +167,15 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs, prev_build_id = id_offs[i].build_id; }bpf_mmap_unlock_mm (work, current->mm); +return ; + +fallback: +/* cannot access current->mm, fall back to ips */ +for (i =0 ; i < trace_nr; i++) { + id_offs[i].status =BPF_STACK_BUILD_ID_IP ; + id_offs[i].ip = ips[i]; +memset (id_offs[i].build_id,0 ,BUILD_ID_SIZE_MAX ); + } } static struct perf_callchain_entry *
kernel/bpf/task_iter.c +10 -4
@@ -780,9 +780,8 @@ static struct bpf_iter_reg task_vma_reg_info = { BPF_CALL_5(bpf_find_vma, struct task_struct *, task, u64, start, bpf_callback_t, callback_fn, void *, callback_ctx, u64, flags) { -struct mmap_unlock_irq_work *work =NULL ; +struct mmap_unlock_irq_work *work;struct vm_area_struct *vma; -bool irq_work_busy = false;bool __maybe_unused mmput_needed = false;struct mm_struct *mm;int ret = -ENOENT ;
@@ -819,9 +818,14 @@ BPF_CALL_5(bpf_find_vma, struct task_struct *, task, u64, start,if (!mm)return -ENOENT ; - irq_work_busy =bpf_mmap_unlock_get_irq_work (&work); + work =bpf_mmap_unlock_guard_get (); +if (IS_ERR (work)) { + ret =PTR_ERR (work); + goto out; + } -if (irq_work_busy || !mmap_read_trylock (mm)) { +if (!mmap_read_trylock (mm)) { +bpf_mmap_unlock_guard_put (work); ret = -EBUSY ; goto out; }
@@ -864,6 +868,8 @@ static void do_mmap_read_unlock(struct irq_work *entry) work = container_of(entry, struct mmap_unlock_irq_work, irq_work);mmap_read_unlock_non_owner (work->mm); + work->mm =NULL ; +bpf_mmap_unlock_guard_put (work); }static int __init task_iter_init (void )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1415/1674 bpf, cgroup: Fix storage null-ptr-deref after replacing prog
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pu Lehui <[email protected]>
[ Upstream commit 3f562c537e9ecf4bc5e206cfffc2cc047f1b7e94 ]
Syzkaller reported a storage null-ptr-deref issue after replacing prog. This occurs in the following scenario:
1. prog A, an empty prog, is attached to a cgrp.
2. prog B uses BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE and calls the bpf_get_local_storage helper.
3. link_update is called to replace prog A with prog B.
The reason is that __cgroup_bpf_replace fails to alloc and assign the required cgrp storage for the incoming replacement prog. Consequently, the new prog inherits an uninit storage, leading to null-ptr-deref panic when kick the new prog.
Fix this by rejecting a link update if new_prog's cgroup storage is incompatible with link->prog.
--- kernel/bpf/cgroup.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
kernel/bpf/cgroup.c +17 -0
@@ -856,6 +856,20 @@ static void replace_effective_prog(struct cgroup *cgrp, } } +static bool cgroup_bpf_storages_compatible (struct bpf_prog *old_prog, +struct bpf_prog *new_prog) +{ +enum bpf_cgroup_storage_type stype; + +for_each_cgroup_storage_type (stype) { +if (old_prog->aux->cgroup_storage[stype] != + new_prog->aux->cgroup_storage[stype]) +return false; + } + +return true; +} +/** * __cgroup_bpf_replace() - Replace link's program and propagate the change * to descendants
@@ -894,6 +908,9 @@ static int __cgroup_bpf_replace(struct cgroup *cgrp,if (!found)return -ENOENT ; +if (!cgroup_bpf_storages_compatible (link->link.prog, new_prog)) +return -EINVAL ; + old_prog =xchg (&link->link.prog, new_prog);replace_effective_prog (cgrp, atype, pl);bpf_prog_put (old_prog);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1416/1674 Bluetooth: ISO: fix race of kfree vs kref_get_unless_zero
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
[ Upstream commit af24e338bf5dafb80f42baa9a0b9e9b57b1c5d9c ]
hci_conn::iso_data is accessed and modified without lock or RCU. This leads to a race
[Task hdev->workqueue] [Task 2]
iso_recv iso_conn_put(conn)
conn = LOAD hcon->iso_data iso_conn_free(conn)
iso_conn_hold_unless_zero(conn) hcon->iso_data = NULL
kfree(conn)
kref_get_unless_zero(&conn->ref) /* UAF */and also to races in iso_conn_add() vs. iso_conn_free().
Fix by adding spinlock hci_conn::proto_lock and using it to guard hci_conn::iso_data.
Stable-dep-of: 2b66c83ff175 ("Bluetooth: L2CAP: use proto_lock for l2cap_data to fix l2cap_disconn_ind")
--- include/net/bluetooth/hci_core.h | 2 ++ net/bluetooth/hci_conn.c | 2 ++ 2 files changed, 4 insertions(+)
include/net/bluetooth/hci_core.h +2 -0
@@ -745,6 +745,8 @@ struct hci_conn {struct dentry *debugfs;struct hci_dev *hdev; + +spinlock_t proto_lock;/* lock guarding protocol data */ void *l2cap_data;void *sco_data;void *iso_data;
net/bluetooth/hci_conn.c +2 -0
@@ -1019,6 +1019,8 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, bdaddr_tINIT_DELAYED_WORK (&conn->idle_work, hci_conn_idle);INIT_DELAYED_WORK (&conn->le_conn_timeout, le_conn_timeout); +spin_lock_init (&conn->proto_lock); +atomic_set (&conn->refcnt,0 );hci_dev_hold (hdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1417/1674 Bluetooth: L2CAP: use proto_lock for l2cap_data to fix l2cap_disconn_ind
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
[ Upstream commit 2b66c83ff1751d6bd3201b3017206262ab46dc05 ]
hci_conn::l2cap_data is accessed without locks in l2cap_disconn_ind via hci_conn_timeout (disc_work) -> hci_proto_disconn_ind -> l2cap_disconn_ind. This is UAF if the l2cap_conn is deleted concurrently.
disc_work is disabled sync in hci_conn_del(), so we cannot take hci_dev_lock in disc_work.
Fix by using proto_lock to guard l2cap_data, in addition to hdev->lock which is held in other access paths.
--- net/bluetooth/l2cap_core.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
net/bluetooth/l2cap_core.c +17 -6
@@ -1824,7 +1824,10 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)hci_chan_del (conn->hchan); conn->hchan =NULL ; +spin_lock (&hcon->proto_lock); hcon->l2cap_data =NULL ; +spin_unlock (&hcon->proto_lock); +mutex_unlock (&conn->lock);l2cap_conn_put (conn); }
@@ -7105,8 +7108,6 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon) }kref_init (&conn->ref); - hcon->l2cap_data = conn; - conn->hcon =hci_conn_get (hcon); conn->hchan = hchan;BT_DBG ("hcon %p conn %p hchan %p" , hcon, conn, hchan);
@@ -7135,6 +7136,11 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon) conn->disc_reason =HCI_ERROR_REMOTE_USER_TERM ; +spin_lock (&hcon->proto_lock); + conn->hcon =hci_conn_get (hcon); + hcon->l2cap_data = conn; +spin_unlock (&hcon->proto_lock); +return conn; }
@@ -7524,13 +7530,18 @@ static void l2cap_connect_cfm(struct hci_conn *hcon, u8 status)int l2cap_disconn_ind (struct hci_conn *hcon) { -struct l2cap_conn *conn = hcon->l2cap_data; +struct l2cap_conn *conn; +int ret =HCI_ERROR_REMOTE_USER_TERM ;BT_DBG ("hcon %p" , hcon); -if (!conn) -return HCI_ERROR_REMOTE_USER_TERM ; -return conn->disc_reason; +spin_lock (&hcon->proto_lock); + conn = hcon->l2cap_data; +if (conn) + ret = conn->disc_reason; +spin_unlock (&hcon->proto_lock); + +return ret; }static void l2cap_disconn_cfm (struct hci_conn *hcon,u8 reason)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1418/1674 btrfs: qgroup: fix a wrong length calculation in qgroup_free_reserved_data()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
[ Upstream commit 9102b179512e11644fb0489ae62010a09afa199c ]
In that function, we round down the start position and round up the ending position.
But during the calculation of @len, we use "round_up(start + len, sectorsize)", which is the rounded up end position, not the rounded up length.
Which results a much larger length, and later we are still using "start + len", which is completely incorrect.
Fix it by declaring a local @aligned_start and @aligned_len and use them instead.
--- fs/btrfs/qgroup.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
fs/btrfs/qgroup.c +11 -7
@@ -3897,12 +3897,13 @@ static int qgroup_free_reserved_data(struct btrfs_inode *inode,struct ulist_node *unode;struct ulist_iterator uiter;struct extent_changeset changeset; +const u32 sectorsize = root->fs_info->sectorsize; +const u64 aligned_start =round_down (start, sectorsize); +const u64 aligned_len =round_up (start + len, sectorsize) - aligned_start;u64 freed =0 ;int ret;extent_changeset_init (&changeset); - len =round_up (start + len, root->fs_info->sectorsize); - start =round_down (start, root->fs_info->sectorsize);ULIST_ITER_INIT (&uiter);while ((unode =ulist_next (&reserved->range_changed, &uiter))) {
@@ -3914,12 +3915,15 @@ static int qgroup_free_reserved_data(struct btrfs_inode *inode,extent_changeset_release (&changeset); -/* Only free range in range [start, start + len) */ -if (range_start >= start + len || - range_start + range_len <= start) +/* +* Only free the range within +* [aligned_start, aligned_start + aligned_len). +*/ +if (range_start >= aligned_start + aligned_len || + range_start + range_len <= aligned_start)continue ; - free_start =max (range_start, start); - free_len =min (start + len, range_start + range_len) - + free_start =max (range_start, aligned_start); + free_len =min (aligned_start + aligned_len, range_start + range_len) - free_start;/* * TODO: To also modify reserved->ranges_reserved to reflect
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1419/1674 btrfs: check if root is readonly when setting posix acl
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sun YangKai <[email protected]>
[ Upstream commit 01c2f41fc441f75b3f9326443372faceb1cb6638 ]
For a filesystem which has btrfs read-only property set to true, all write operations including acl and xattr should be denied. However, acl can still be set even if btrfs ro property is true.
This happens because no function on the set_acl code path checks the root is readonly or not. It was checked in btrfs_setxattr_trans() but got removed in commit 353c2ea735e4 ("btrfs: remove redundant readonly root check in btrfs_setxattr_trans")
That commit didn't check if all the callers properly check the root's read-only flag. A previous fix is commit b51111271b03 ("btrfs: check if root is readonly while setting security xattr").
Always check if the root is read-only before performing the set acl operation.
--- fs/btrfs/acl.c | 3 +++ 1 file changed, 3 insertions(+)
fs/btrfs/acl.c +3 -0
@@ -117,6 +117,9 @@ int btrfs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,struct inode *inode =d_inode (dentry);umode_t old_mode = inode->i_mode; +if (btrfs_root_readonly (BTRFS_I (inode)->root)) +return -EROFS ; +if (type ==ACL_TYPE_ACCESS && acl) { ret =posix_acl_update_mode (idmap, inode, &inode->i_mode, &acl);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1420/1674 btrfs: always wait for ordered extents to avoid OE races
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
[ Upstream commit ec78575dde998c21be7e0cb2503b5620f34b6255 ]
[BUG]
Syzbot reported a bug that there can be conflicting OEs for the same range:
BTRFS critical (device loop4): panic in insert_ordered_extent:264: overlapping ordered extents, existing oe file_offset 16384 num_bytes 430080 flags 0x1089, new oe file_offset 16384 num_bytes 430080 flags 0x80 (errno=-17 Object alrea[ 179.162726][ T6897] BTRFS critical (device loop4): panic in insert_ordered_extent:264: overlapping ordered extents, existing oe file_offset 16384 num_bytes 430080 flags 0x1089, new oe file_offset 16384 num_bytes 430080 flags 0x80 (errno=-17 Object already exists)
------------[ cut here ]------------ kernel BUG at fs/btrfs/ordered-data.c:264! Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/09/2026 RIP: 0010:btrfs_alloc_ordered_extent+0x943/0xad0 Call Trace: <TASK> cow_file_range+0x744/0x12a0 fallback_to_cow+0x5ea/0xa00 run_delalloc_nocow+0x110c/0x17a0 btrfs_run_delalloc_range+0xbe4/0x1c20 writepage_delalloc+0x104d/0x1ba0 btrfs_writepages+0x1667/0x28b0 do_writepages+0x338/0x560 filemap_fdatawrite_range+0x1f2/0x300 btrfs_fdatawrite_range+0x54/0xf0 btrfs_direct_write+0x6a0/0xc30 btrfs_do_write_iter+0x329/0x790 do_iter_readv_writev+0x624/0x8d0 vfs_writev+0x34c/0x990 __se_sys_pwritev2+0x17a/0x2a0 do_syscall_64+0x174/0x580 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK> ---[ end trace 0000000000000000 ]---
[CAUSE]
Since commit ff66fe666233 ("btrfs: fix incorrect buffered IO fallback for append direct writes"), if the direct IO finished short, we will revert the isize back to the original one, so that append writes can be respected during the buffered fallback.
Normally we rely on lock_and_cleanup_extent_if_need() function during buffered writeback to wait for any existing ordered extents.
But that ordered extent waiting only happens if the start_pos is inside the isize.
Since we have reverted the isize during failed direct IO, we will not wait for any ordered extents.
This means we can have a race where the direct IO OE is still in the tree, finished but not yet removed, then we're inserting the OE for the buffered write, causing the above crash.
[FIX]
Make the OE wait to be unconditional, to handle the reverted isize situation.
And since lock_and_cleanup_extent_if_need() now either lock the extents or return -EAGAIN, also remove the branches that handles no-extent-locked cases, and rename it to remove the "_if_need" suffix.
The following micro benchmark shows the runtime difference for btrfs_buffered_write(), doing xfs_io -f -c "pwrite 0 1m" workload, all values are the average runtime in nano seconds.
function runtime | before | after
-----------------------------------+-------------+---------------
lock_and_cleanup_extent_if_need() | 58.2 | 183.0 btrfs_buffered_write() | 2115.6 | 2973.3
The overall runtime of btrfs_buffered_write() is still pretty tiny (still less than 3 micro seconds), I'd say the extra cost is still acceptable.
An alternative to fix this problem is to wait ordered extents during iomap_end() where the isize revert is done.
But that solution will break nowait requirement, as if a nowait direct IO finished short, we have to wait for the OEs unconditionally or the next append buffered IO can still hit the same problem.
So here we have to move the wait cost to buffered write, but at least the code is slightly more streamline.
--- fs/btrfs/file.c | 106 ++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 62 deletions(-)
fs/btrfs/file.c +44 -62
@@ -956,70 +956,64 @@ static noinline int prepare_pages(struct inode *inode, struct page **pages,/* * This function locks the extent and properly waits for data=ordered extents -* to finish before allowing the pages to be modified if need. +* to finish before allowing the pages to be modified. * * The return value: -* 1 - the extent is locked -* 0 - the extent is not locked, and everything is OK +* 0 - the extent is locked * -EAGAIN - need re-prepare the pages * the other < 0 number - Something wrong happens */ static noinline int -lock_and_cleanup_extent_if_need (struct btrfs_inode *inode,struct page **pages, -size_t num_pages,loff_t pos, -size_t write_bytes, -u64 *lockstart,u64 *lockend,bool nowait, -struct extent_state **cached_state) +lock_and_cleanup_extent (struct btrfs_inode *inode,struct page **pages, +size_t num_pages,loff_t pos, +size_t write_bytes, +u64 *lockstart,u64 *lockend,bool nowait, +struct extent_state **cached_state) {struct btrfs_fs_info *fs_info = inode->root->fs_info; +struct btrfs_ordered_extent *ordered;u64 start_pos;u64 last_pos;int i; -int ret =0 ; start_pos =round_down (pos, fs_info->sectorsize); last_pos =round_up (pos + write_bytes, fs_info->sectorsize) -1 ; -if (start_pos < inode->vfs_inode.i_size) { -struct btrfs_ordered_extent *ordered; - -if (nowait) { -if (!try_lock_extent (&inode->io_tree, start_pos, last_pos, - cached_state)) { -for (i =0 ; i < num_pages; i++) { -unlock_page (pages[i]); -put_page (pages[i]); - pages[i] =NULL ; - } - -return -EAGAIN ; - } - }else { -lock_extent (&inode->io_tree, start_pos, last_pos, cached_state); - } - - ordered =btrfs_lookup_ordered_range (inode, start_pos, - last_pos - start_pos +1 ); -if (ordered && - ordered->file_offset + ordered->num_bytes > start_pos && - ordered->file_offset <= last_pos) { -unlock_extent (&inode->io_tree, start_pos, last_pos, - cached_state); +if (nowait) { +if (!try_lock_extent (&inode->io_tree, start_pos, last_pos, + cached_state)) {for (i =0 ; i < num_pages; i++) {unlock_page (pages[i]);put_page (pages[i]); + pages[i] =NULL ; } -btrfs_start_ordered_extent (ordered); -btrfs_put_ordered_extent (ordered); +return -EAGAIN ; } -if (ordered) -btrfs_put_ordered_extent (ordered); + }else { +lock_extent (&inode->io_tree, start_pos, last_pos, cached_state); + } - *lockstart = start_pos; - *lockend = last_pos; - ret =1 ; + ordered =btrfs_lookup_ordered_range (inode, start_pos, + last_pos - start_pos +1 ); +if (ordered && + ordered->file_offset + ordered->num_bytes > start_pos && + ordered->file_offset <= last_pos) { +unlock_extent (&inode->io_tree, start_pos, last_pos, + cached_state); +for (i =0 ; i < num_pages; i++) { +unlock_page (pages[i]); +put_page (pages[i]); + } +btrfs_start_ordered_extent (ordered); +btrfs_put_ordered_extent (ordered); +return -EAGAIN ; } +if (ordered) +btrfs_put_ordered_extent (ordered); + + *lockstart = start_pos; + *lockend = last_pos;/* * We should be called after prepare_pages() which should have locked
@@ -1028,7 +1022,7 @@ lock_and_cleanup_extent_if_need(struct btrfs_inode *inode, struct page **pages,for (i =0 ; i < num_pages; i++)WARN_ON (!PageLocked (pages[i])); -return ret; +return 0 ; }/*
@@ -1224,7 +1218,6 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,size_t copied;size_t dirty_sectors;size_t num_sectors; -int extents_locked;/* * Fault pages before locking them in prepare_pages
@@ -1308,17 +1301,16 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,break ; } - extents_locked =lock_and_cleanup_extent_if_need ( -BTRFS_I (inode), pages, - num_pages, pos, write_bytes, &lockstart, - &lockend, nowait, &cached_state); -if (extents_locked <0 ) { -if (!nowait && extents_locked == -EAGAIN ) + ret =lock_and_cleanup_extent (BTRFS_I (inode), pages, + num_pages, pos, write_bytes, + &lockstart, &lockend, nowait, + &cached_state); +if (ret <0 ) { +if (!nowait && ret == -EAGAIN ) goto again;btrfs_delalloc_release_extents (BTRFS_I (inode), reserve_bytes); - ret = extents_locked;break ; }
@@ -1371,18 +1363,8 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, dirty_pages, pos, copied, &cached_state, only_release_metadata); -/* -* If we have not locked the extent range, because the range's -* start offset is >= i_size, we might still have a non-NULL -* cached extent state, acquired while marking the extent range -* as delalloc through btrfs_dirty_pages(). Therefore free any -* possible cached extent state to avoid a memory leak. -*/ -if (extents_locked) -unlock_extent (&BTRFS_I (inode)->io_tree, lockstart, - lockend, &cached_state); -else -free_extent_state (cached_state); +unlock_extent (&BTRFS_I (inode)->io_tree, lockstart, lockend, + &cached_state);btrfs_delalloc_release_extents (BTRFS_I (inode), reserve_bytes);if (ret) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1421/1674 btrfs: defrag: fix deadlock between defrag and delalloc space reservation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit ba02eab28041f9a4bbe9fc90c7249644fef6de0f ]
While running fsstress with autodefrag and flushoncommit, hit a deadlock due to the fact that defrag reserves delalloc space while it's holding dirty and locked folios, besides the extent range lock. The stack traces are the following:
[958.624] task:kworker/u50:3 state:D stack:0 pid:20365 tgid:20365 ppid:2 task_flags:0x4208060 flags:0x00080000 [958.626] Workqueue: events_unbound btrfs_async_reclaim_metadata_space [btrfs] [958.627] Call Trace: [958.628] <TASK> [958.628] __schedule+0x4be/0x10f0 [958.629] ? preempt_count_add+0x69/0xa0 [958.630] schedule+0x26/0xd0 [958.631] wait_current_trans+0x102/0x160 [btrfs] [958.632] ? __pfx_autoremove_wake_function+0x10/0x10 [958.633] start_transaction+0x374/0x900 [btrfs] [958.634] btrfs_commit_current_transaction+0x1d/0x70 [btrfs] [958.635] flush_space+0xca/0x5e0 [btrfs] [958.636] ? _raw_spin_unlock+0x15/0x30 [958.637] ? btrfs_reduce_alloc_profile+0x8c/0x190 [btrfs] [958.639] ? _raw_spin_unlock+0x15/0x30 [958.640] ? calc_available_free_space.isra.0+0x6f/0x110 [btrfs] [958.641] do_async_reclaim_metadata_space+0x84/0x190 [btrfs] [958.642] btrfs_async_reclaim_metadata_space+0x64/0x80 [btrfs] [958.644] process_one_work+0x19d/0x3a0 [958.644] worker_thread+0x1c4/0x330 [958.645] ? __pfx_worker_thread+0x10/0x10 [958.646] kthread+0xfc/0x130 [958.647] ? __pfx_kthread+0x10/0x10 [958.648] ret_from_fork+0x1f7/0x2c0 [958.648] ? __pfx_kthread+0x10/0x10 [958.649] ret_from_fork_asm+0x1a/0x30 [958.650] </TASK> [958.651] task:kworker/u49:7 state:D stack:0 pid:52990 tgid:52990 ppid:2 task_flags:0x4208060 flags:0x00080000 [958.653] Workqueue: writeback wb_workfn (flush-btrfs-334) [958.655] Call Trace: [958.655] <TASK> [958.656] __schedule+0x4be/0x10f0 [958.657] ? __blk_flush_plug+0xe9/0x140 [958.658] schedule+0x26/0xd0 [958.658] io_schedule+0x42/0x70 [958.659] folio_wait_bit_common+0x12b/0x330 [958.660] ? folio_wait_bit_common+0x100/0x330 [958.662] ? __pfx_wake_page_function+0x10/0x10 [958.663] extent_write_cache_pages+0x599/0x830 [btrfs] [958.664] ? acpi_fwnode_get_reference_args+0x1fa/0x270 [958.665] btrfs_writepages+0x77/0x130 [btrfs] [958.666] ? __pfx_end_bbio_data_write+0x10/0x10 [btrfs] [958.667] do_writepages+0xc6/0x160 [958.668] __writeback_single_inode+0x42/0x310 [958.669] writeback_sb_inodes+0x231/0x570 [958.670] wb_writeback+0x8a/0x340 [958.671] wb_workfn+0xbf/0x450 [958.672] ? finish_task_switch.isra.0+0xc1/0x350 [958.673] process_one_work+0x19d/0x3a0 [958.673] worker_thread+0x1c4/0x330 [958.674] ? __pfx_worker_thread+0x10/0x10 [958.675] kthread+0xfc/0x130 [958.676] ? __pfx_kthread+0x10/0x10 [958.676] ret_from_fork+0x1f7/0x2c0 [958.677] ? __pfx_kthread+0x10/0x10 [958.678] ret_from_fork_asm+0x1a/0x30 [958.679] </TASK> [958.679] task:btrfs-cleaner state:D stack:0 pid:296750 tgid:296750 ppid:2 task_flags:0x208040 flags:0x00080000 [958.681] Call Trace: [958.682] <TASK> [958.682] __schedule+0x4be/0x10f0 [958.683] schedule+0x26/0xd0 [958.684] handle_reserve_ticket+0x1b9/0x2c0 [btrfs] [958.685] ? __pfx_autoremove_wake_function+0x10/0x10 [958.686] reserve_bytes+0x283/0x4c0 [btrfs] [958.687] btrfs_reserve_metadata_bytes+0x18/0xb0 [btrfs] [958.688] btrfs_delalloc_reserve_metadata+0x121/0x320 [btrfs] [958.690] btrfs_delalloc_reserve_space+0x46/0xb0 [btrfs] [958.691] btrfs_defrag_file+0x903/0x1110 [btrfs] [958.692] btrfs_run_defrag_inodes+0x334/0x430 [btrfs] [958.694] cleaner_kthread+0x97/0x1c0 [btrfs] [958.694] ? __pfx_cleaner_kthread+0x10/0x10 [btrfs] [958.696] kthread+0xfc/0x130 [958.696] ? __pfx_kthread+0x10/0x10 [958.697] ret_from_fork+0x1f7/0x2c0 [958.698] ? __pfx_kthread+0x10/0x10 [958.699] ret_from_fork_asm+0x1a/0x30 [958.700] </TASK> [958.716] task:fsstress state:D stack:0 pid:296769 tgid:296769 ppid:296768 task_flags:0x400140 flags:0x00080000 [958.718] Call Trace: [958.719] <TASK> [958.719] __schedule+0x4be/0x10f0 [958.720] ? preempt_count_add+0x69/0xa0 [958.721] schedule+0x26/0xd0 [958.722] wb_wait_for_completion+0x79/0xc0 [958.723] ? __pfx_autoremove_wake_function+0x10/0x10 [958.724] __writeback_inodes_sb_nr+0xc5/0xf0 [958.725] try_to_writeback_inodes_sb+0x55/0x70 [958.726] btrfs_commit_transaction+0x19d/0xeb0 [btrfs] [958.727] ? start_transaction+0x343/0x900 [btrfs] [958.728] btrfs_mksubvol+0x28b/0x4e0 [btrfs] [958.729] btrfs_mksnapshot+0x74/0xa0 [btrfs] [958.730] __btrfs_ioctl_snap_create+0x194/0x210 [btrfs] [958.732] btrfs_ioctl_snap_create_v2+0xef/0x150 [btrfs] [958.733] btrfs_ioctl+0x7ec/0x2a70 [btrfs] [958.734] ? __virt_addr_valid+0xe4/0x180 [958.735] ? __check_object_size+0x1cd/0x1f0 [958.736] ? kmem_cache_free+0x146/0x380 [958.737] ? _raw_spin_unlock+0x15/0x30 [958.738] ? do_sys_openat2+0x83/0xd0 [958.739] __x64_sys_ioctl+0x92/0xe0 [958.740] do_syscall_64+0x60/0x590 [958.741] ? clear_bhb_loop+0x60/0xb0 [958.742] entry_SYSCALL_64_after_hwframe+0x76/0x7e [958.743] RIP: 0033:0x7f4431e108db [958.744] RSP: 002b:00007ffcd147db20 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 [958.746] RAX: ffffffffffffffda RBX: 0000000000000004 RCX: 00007f4431e108db [958.747] RDX: 00007ffcd147eb90 RSI: 0000000050009417 RDI: 0000000000000005 [958.749] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000 [958.751] R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffcd147fbf0 [958.752] R13: 00007ffcd147eb90 R14: 0000000000000005 R15: 0000000000000003 [958.754] </TASK>
What happens is the following:
1) The cleaner kthread is running autodefrag, and in defrag_one_range() it acquired all the folios for the range and locked them.
Then it locked the extent range in the inode's iotree.
It got two subranges from defrag_collect_targets(), the first one with folio A and the second one with folio B.
After it defragged the first subrange, folio A remains locked and dirty - it's only unlocked when defrag_one_range() returns.
When it attempts to defrag the second subrange (containing folio B), btrfs_delalloc_reserve_space() creates a space reservation ticket, due to lack of free metadata space and blocks waiting for the async metadata reclaim task to free space and wake it up;
2) The async reclaim metadata task attempts to commit the current transaction, but it blocks because there is another task that started the commit first;
3) A task creating a snapshot is committing the transaction and because the fs was mounted with flushoncommit, it calls try_to_writeback_inodes_sb(), which spawns a task to flush delalloc and waits for it to complete;
4) The task flushing delalloc (kworker/u49:7), finds that folio A for the inode being defragged is dirty, so it tries to lock it...
But it blocks because folio A is locked by the defrag task (the cleaner kthread) which is blocked waiting for the reservation ticket to be served, but the async reclaim metadata task is blocked waiting for the transaction commit, which in turn is blocked waiting for the delalloc flush task, which is trying to lock folio A, resulting in a deadlock.
The same type of problem can happen if the async reclaim task starts to flush delalloc, as that requires both locking the folio and the extent range in the inode's io tree, and in this case we don't need the fs to be mounted with flushoncommit. This type of problem has ocurred several times in the past with reflinks for example, where we had a dirty folio while holding the extent range locked and then starting a transaction blocked waiting for the async reclaim task due to lack of free metadata space.
So fix this by reserving delalloc space before locking folios and locking the extent range in the inode's iotree. We can not simply unlock the folios for each subrange given by defrag_collect_targets() after we defrag it because the same folio may be present too in the next subrange (due to large folios).
--- fs/btrfs/defrag.c | 50 +++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 17 deletions(-)
fs/btrfs/defrag.c +33 -17
@@ -1017,26 +1017,21 @@ static_assert(PAGE_ALIGNED(CLUSTER_SIZE));* * - Extent bits are locked */ -static int defrag_one_locked_target (struct btrfs_inode *inode, -struct defrag_target_range *target, -struct page **pages,int nr_pages, -struct extent_state **cached_state) +static void defrag_one_locked_target (struct btrfs_inode *inode, +struct defrag_target_range *target, +struct page **pages,int nr_pages, +struct extent_state **cached_state) {struct btrfs_fs_info *fs_info = inode->root->fs_info; -struct extent_changeset *data_reserved =NULL ;const u64 start = target->start;const u64 len = target->len;unsigned long last_index = (start + len -1 ) >>PAGE_SHIFT ;unsigned long start_index = start >>PAGE_SHIFT ;unsigned long first_index =page_index (pages[0 ]); -int ret =0 ;int i;ASSERT (last_index - first_index +1 <= nr_pages); - ret =btrfs_delalloc_reserve_space (inode, &data_reserved, start, len); -if (ret <0 ) -return ret;clear_extent_bit (&inode->io_tree, start, start + len -1 ,EXTENT_DELALLOC |EXTENT_DO_ACCOUNTING |EXTENT_DEFRAG , cached_state);
@@ -1048,10 +1043,6 @@ static int defrag_one_locked_target(struct btrfs_inode *inode,ClearPageChecked (pages[i]);btrfs_page_clamp_set_dirty (fs_info, pages[i], start, len); } -btrfs_delalloc_release_extents (inode, len); -extent_changeset_free (data_reserved); - -return ret; } static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,
@@ -1067,6 +1058,8 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,u64 last_index = (start + len -1 ) >>PAGE_SHIFT ;u64 start_index = start >>PAGE_SHIFT ;unsigned int nr_pages = last_index - start_index +1 ; +struct extent_changeset *data_reserved =NULL ; +u64 last_defrag_end = start;int ret =0 ;int i;
@@ -1077,6 +1070,22 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,if (!pages)return -ENOMEM ; +/* +* Reserve delalloc space before locking the range and before locking +* and dirtying any folios - otherwise we could deadlock, for example +* after defrag of one range we dirty folios and keep them locked when +* we move to the next range, so reserving delalloc space right before +* each range could trigger flushing of delalloc and deadlock on the +* extent lock or trigger a transaction commit with flushoncommit, which +* can either deadlock on the lock of a folio made dirty in the previous +* range or the extent lock. +*/ + ret =btrfs_delalloc_reserve_space (inode, &data_reserved, start, len); +if (ret <0 ) { +kfree (pages); +return ret; + } +/* Prepare all pages */ for (i =0 ; i < nr_pages; i++) { pages[i] =defrag_prepare_one_page (inode, start_index + i);
@@ -1107,10 +1116,11 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len, goto unlock_extent;list_for_each_entry (entry, &target_list, list) { - ret =defrag_one_locked_target (inode, entry, pages, nr_pages, - &cached_state); -if (ret <0 ) -break ; +defrag_one_locked_target (inode, entry, pages, nr_pages, &cached_state); +if (entry->start > last_defrag_end) +btrfs_delalloc_release_space (inode, data_reserved, last_defrag_end, + entry->start - last_defrag_end, true); + last_defrag_end = entry->start + entry->len; }list_for_each_entry_safe (entry, tmp, &target_list, list) {
@@ -1129,6 +1139,12 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len, } }kfree (pages); +btrfs_delalloc_release_extents (inode, len); +if (last_defrag_end < start + len) +btrfs_delalloc_release_space (inode, data_reserved, last_defrag_end, + start + len - last_defrag_end, true); +extent_changeset_free (data_reserved); +return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1422/1674 scsi: sd: Fix special_vec mempool leak when scsi_alloc_sgtables() fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Xiuwei <[email protected]>
[ Upstream commit bb31844d88b77138b67aa20c3600203baff40140 ]
sd_set_special_bvec() allocates a special payload page for UNMAP and WRITE SAME commands. If scsi_alloc_sgtables() fails afterward in sd_setup_unmap_cmnd() or sd_setup_write_same{10,16}_cmnd(), the SCSI midlayer does not call uninit_command() because RQF_DONTPREP is not set yet, leaking the page.
Call sd_uninit_command() on error, and clear RQF_SPECIAL_PAYLOAD after freeing the page.
--- drivers/scsi/sd.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-)
drivers/scsi/sd.c +26 -11
@@ -872,6 +872,17 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)blk_queue_max_discard_sectors (q, max_blocks * (logical_block_size >>9 )); } +static void sd_uninit_command (struct scsi_cmnd *cmd) +{ +struct request *rq =scsi_cmd_to_rq (cmd); + +if (!(rq->rq_flags &RQF_SPECIAL_PAYLOAD )) +return ; + +mempool_free (rq->special_vec.bv_page, sd_page_pool); + rq->rq_flags &= ~RQF_SPECIAL_PAYLOAD ; +} +static void *sd_set_special_bvec (struct request *rq,unsigned int data_len) {struct page *page;
@@ -894,6 +905,7 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)u32 nr_blocks =sectors_to_logical (sdp,blk_rq_sectors (rq));unsigned int data_len =24 ;char *buf; +blk_status_t ret; buf =sd_set_special_bvec (rq, data_len);if (!buf)
@@ -912,7 +924,10 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd) cmd->transfersize = data_len; rq->timeout =SD_TIMEOUT ; -return scsi_alloc_sgtables (cmd); + ret =scsi_alloc_sgtables (cmd); +if (ret !=BLK_STS_OK ) +sd_uninit_command (cmd); +return ret; } static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd,
@@ -924,6 +939,7 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd,u64 lba =sectors_to_logical (sdp,blk_rq_pos (rq));u32 nr_blocks =sectors_to_logical (sdp,blk_rq_sectors (rq));u32 data_len = sdp->sector_size; +blk_status_t ret;if (!sd_set_special_bvec (rq, data_len))return BLK_STS_RESOURCE ;
@@ -939,7 +955,10 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, cmd->transfersize = data_len; rq->timeout = unmap ?SD_TIMEOUT :SD_WRITE_SAME_TIMEOUT ; -return scsi_alloc_sgtables (cmd); + ret =scsi_alloc_sgtables (cmd); +if (ret !=BLK_STS_OK ) +sd_uninit_command (cmd); +return ret; } static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd,
@@ -951,6 +970,7 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd,u64 lba =sectors_to_logical (sdp,blk_rq_pos (rq));u32 nr_blocks =sectors_to_logical (sdp,blk_rq_sectors (rq));u32 data_len = sdp->sector_size; +blk_status_t ret;if (!sd_set_special_bvec (rq, data_len))return BLK_STS_RESOURCE ;
@@ -966,7 +986,10 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd, cmd->transfersize = data_len; rq->timeout = unmap ?SD_TIMEOUT :SD_WRITE_SAME_TIMEOUT ; -return scsi_alloc_sgtables (cmd); + ret =scsi_alloc_sgtables (cmd); +if (ret !=BLK_STS_OK ) +sd_uninit_command (cmd); +return ret; }static blk_status_t sd_setup_write_zeroes_cmnd (struct scsi_cmnd *cmd)
@@ -1340,14 +1363,6 @@ static blk_status_t sd_init_command(struct scsi_cmnd *cmd) } } -static void sd_uninit_command (struct scsi_cmnd *SCpnt) -{ -struct request *rq =scsi_cmd_to_rq (SCpnt); - -if (rq->rq_flags &RQF_SPECIAL_PAYLOAD ) -mempool_free (rq->special_vec.bv_page, sd_page_pool); -} -static bool sd_need_revalidate (struct gendisk *disk,struct scsi_disk *sdkp) {if (sdkp->device->removable || sdkp->write_prot) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1423/1674 coresight: etm4x: missing cscfg_csdev_disable_active_config() in perf enable
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yeoreum Yun <[email protected]>
[ Upstream commit 0a47f0be6557b4a851addd430383a4dc7ee08752 ]
In the perf enable path, there are missing cases where cscfg_csdev_disable_active_config() is not called:
- Branch broadcast is selected but not supported by the hardware
- etm4_enable_hw() fails
This can lead to a leak of config_desc->active_cnt. Fix this by properly calling cscfg_csdev_disable_active_config() in these error paths.
--- .../coresight/coresight-etm4x-core.c | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +27 -18
@@ -698,8 +698,6 @@ static int etm4_parse_event_config(struct coresight_device *csdev,struct etmv4_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);struct etmv4_config *config = &drvdata->config;struct perf_event_attr *attr = &event->attr; -unsigned long cfg_hash; -int preset;/* Clear configuration from previous run */ memset (config,0 ,sizeof (struct etmv4_config ));
@@ -769,20 +767,6 @@ static int etm4_parse_event_config(struct coresight_device *csdev,/* bit[12], Return stack enable bit */ config->cfg |=TRCCONFIGR_RS ; -/* -* Set any selected configuration and preset. -* -* This extracts the values of PMU_FORMAT_ATTR(configid) and PMU_FORMAT_ATTR(preset) -* in the perf attributes defined in coresight-etm-perf.c. -* configid uses bits 63:32 of attr->config2, preset uses bits 3:0 of attr->config. -* A zero configid means no configuration active, preset = 0 means no preset selected. -*/ -if (attr->config2 &GENMASK_ULL (63 ,32 )) { - cfg_hash = (u32)(attr->config2 >>32 ); - preset = attr->config &0xF ; - ret =cscfg_csdev_enable_active_config (csdev, cfg_hash, preset); - } -/* branch broadcast - enable if selected and supported */ if (attr->config &BIT (ETM_OPT_BRANCH_BROADCAST )) {if (!drvdata->trcbb) {
@@ -804,8 +788,10 @@ static int etm4_parse_event_config(struct coresight_device *csdev,static int etm4_enable_perf (struct coresight_device *csdev,struct perf_event *event) { -int ret =0 , trace_id; +int ret =0 , trace_id, preset;struct etmv4_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent); +struct perf_event_attr *attr = &event->attr; +unsigned long cfg_hash =0 ;if (WARN_ON_ONCE (drvdata->cpu !=smp_processor_id ())) { ret = -EINVAL ;
@@ -817,6 +803,22 @@ static int etm4_enable_perf(struct coresight_device *csdev,if (ret) goto out; +/* +* Set any selected configuration and preset. +* +* This extracts the values of PMU_FORMAT_ATTR(configid) and PMU_FORMAT_ATTR(preset) +* in the perf attributes defined in coresight-etm-perf.c. +* configid uses bits 63:32 of attr->config2, preset uses bits 3:0 of attr->config. +* A zero configid means no configuration active, preset = 0 means no preset selected. +*/ +if (attr->config2 &GENMASK_ULL (63 ,32 )) { + cfg_hash = (u32)(attr->config2 >>32 ); + preset = attr->config &0xF ; + ret =cscfg_csdev_enable_active_config (csdev, cfg_hash, preset); +if (ret) + goto out; + } +/* * perf allocates cpu ids as part of _setup_aux() - device needs to use * the allocated ID. This reads the current version without allocation.
@@ -830,13 +832,20 @@ static int etm4_enable_perf(struct coresight_device *csdev,dev_err (&drvdata->csdev->dev,"Failed to set trace ID for %s on CPU%d\n" ,dev_name (&drvdata->csdev->dev), drvdata->cpu); ret = -EINVAL ; - goto out; + goto err_cfg; } drvdata->trcid = (u8 )trace_id;/* And enable it */ ret =etm4_enable_hw (drvdata); +if (ret) + goto err_cfg; + +return 0 ; +err_cfg: +if (cfg_hash) +cscfg_csdev_disable_active_config (csdev); out:return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1424/1674 drm/amd/display: Resize MST HDCP per-connector arrays to 32
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harry Wentland <[email protected]>
[ Upstream commit 261e0fe4e2c99f687114b64b10b98db964b475f4 ]
AMDGPU_DM_MAX_DISPLAY_INDEX is 31. It suggest a maximum number of 32 connectors. But the way it's used is like MAX_DISPLAY_COUNT. Hence we're off by one with DRM core, which supports a max of 32 connectors.
Rename AMDGPU_DM_MAX_DISPLAY_INDEX to AMDGPU_DM_MAX_DISPLAY_COUNT to match its actual use, and increase the size to 32 to match the originally intended size.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 2 +- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c | 10 +++++----- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +1 -1
@@ -43,7 +43,7 @@* in amdgpu_dm_kms.h file */ -#define AMDGPU_DM_MAX_DISPLAY_INDEX 31 +#define AMDGPU_DM_MAX_DISPLAY_COUNT 32#define AMDGPU_DM_MAX_CRTC 6
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c +5 -5
@@ -256,7 +256,7 @@ void hdcp_reset_display(struct hdcp_workqueue *hdcp_work, unsigned int link_indecancel_delayed_work (&hdcp_w->property_validate_dwork); -for (conn_index =0 ; conn_index <AMDGPU_DM_MAX_DISPLAY_INDEX ; conn_index++) { +for (conn_index =0 ; conn_index <AMDGPU_DM_MAX_DISPLAY_COUNT ; conn_index++) { hdcp_w->encryption_status[conn_index] =MOD_HDCP_ENCRYPTION_STATUS_HDCP_OFF ;if (hdcp_w->aconnector[conn_index]) {
@@ -303,7 +303,7 @@ static void event_property_update(struct work_struct *work)struct drm_connector *connector;struct drm_connector_state *conn_state; -for (conn_index =0 ; conn_index <AMDGPU_DM_MAX_DISPLAY_INDEX ; conn_index++) { +for (conn_index =0 ; conn_index <AMDGPU_DM_MAX_DISPLAY_COUNT ; conn_index++) { aconnector = hdcp_work->aconnector[conn_index];if (!aconnector)
@@ -372,7 +372,7 @@ static void event_property_validate(struct work_struct *work)guard (mutex)(&hdcp_work->mutex); -for (conn_index =0 ; conn_index <AMDGPU_DM_MAX_DISPLAY_INDEX ; +for (conn_index =0 ; conn_index <AMDGPU_DM_MAX_DISPLAY_COUNT ; conn_index++) { aconnector = hdcp_work->aconnector[conn_index];
@@ -747,10 +747,10 @@ struct hdcp_workqueue *hdcp_create_workqueue(struct amdgpu_device *adev,memset (hdcp_work[i].aconnector,0 ,sizeof (struct amdgpu_dm_connector *) * -AMDGPU_DM_MAX_DISPLAY_INDEX ); +AMDGPU_DM_MAX_DISPLAY_COUNT );memset (hdcp_work[i].encryption_status,0 ,sizeof (enum mod_hdcp_encryption_status ) * -AMDGPU_DM_MAX_DISPLAY_INDEX ); +AMDGPU_DM_MAX_DISPLAY_COUNT ); } cp_psp->funcs.update_stream_config = update_config;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h +4 -4
@@ -43,7 +43,7 @@ struct hdcp_workqueue {struct delayed_work callback_dwork;struct delayed_work watchdog_timer_dwork;struct delayed_work property_validate_dwork; -struct amdgpu_dm_connector *aconnector[AMDGPU_DM_MAX_DISPLAY_INDEX ]; +struct amdgpu_dm_connector *aconnector[AMDGPU_DM_MAX_DISPLAY_COUNT ];struct mutex mutex;struct mod_hdcp hdcp;
@@ -51,7 +51,7 @@ struct hdcp_workqueue {struct mod_hdcp_display display;struct mod_hdcp_link link; -enum mod_hdcp_encryption_status encryption_status[AMDGPU_DM_MAX_DISPLAY_INDEX ]; +enum mod_hdcp_encryption_status encryption_status[AMDGPU_DM_MAX_DISPLAY_COUNT ];/* when display is unplugged from mst hub, connctor will be * destroyed within dm_dp_mst_connector_destroy. connector * hdcp perperties, like type, undesired, desired, enabled,
@@ -61,9 +61,9 @@ struct hdcp_workqueue {* will be retrieved from hdcp_work within dm_dp_mst_get_modes */ /* un-desired, desired, enabled */ -unsigned int content_protection[AMDGPU_DM_MAX_DISPLAY_INDEX ]; +unsigned int content_protection[AMDGPU_DM_MAX_DISPLAY_COUNT ];/* hdcp1.x, hdcp2.x */ -unsigned int hdcp_content_type[AMDGPU_DM_MAX_DISPLAY_INDEX ]; +unsigned int hdcp_content_type[AMDGPU_DM_MAX_DISPLAY_COUNT ];uint8_t max_link;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1425/1674 module/dups: Fix use-after-free in kmod_dup_req lifetime handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Petr Pavlu <[email protected]>
[ Upstream commit 5eecb11b543f9f417bcf0dea239ff99c6af65dbd ]
The kmod dups code uses RCU to ensure that a kmod_dup_req instance is freed only after it is no longer referenced. When releasing an instance, the kmod_dup_request_delete() function removes the kmod_dup_req from the dup_kmod_reqs list, waits via synchronize_rcu() and finally frees it. However, this doesn't work correctly because parallel users referencing the instance in kmod_dup_request_exists_wait() don't enter an RCU read-side critical section. This can result in a use-after-free.
The kmod_dup_request_exists_wait() function may need to hold a valid reference to a kmod_dup_req instance across a blocking wait until the corresponding modprobe command completes. This makes it unsuitable for RCU.
Fix the issue by changing the lifecycle management of kmod_dup_req to use reference counting.
--- kernel/module/dups.c | 66 ++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 17 deletions(-)
kernel/module/dups.c +49 -17
@@ -31,6 +31,7 @@#include <linux/ptrace.h> #include <linux/async.h> #include <linux/uaccess.h> +#include <linux/refcount.h> #include "internal.h"
@@ -39,13 +40,12 @@static bool enable_dups_trace =IS_ENABLED (CONFIG_MODULE_DEBUG_AUTOLOAD_DUPS_TRACE );module_param (enable_dups_trace, bool_enable_only,0644 ); -/* -* Protects dup_kmod_reqs list, adds / removals with RCU. -*/ +/* A mutex-protected list of active kmod requests. */ static DEFINE_MUTEX (kmod_dup_mutex);static LIST_HEAD (dup_kmod_reqs);struct kmod_dup_req { +refcount_t refcount;struct list_head list;char name[MODULE_NAME_LEN ];struct completion first_req_done;
@@ -54,12 +54,24 @@ struct kmod_dup_req {int dup_ret; }; +static void get_kmod_req (struct kmod_dup_req *kmod_req) +{ +refcount_inc (&kmod_req->refcount); +} + +static void put_kmod_req (struct kmod_dup_req *kmod_req) +{ +if (refcount_dec_and_test (&kmod_req->refcount)) +kfree (kmod_req); +} +static struct kmod_dup_req *kmod_dup_request_lookup (char *module_name) {struct kmod_dup_req *kmod_req; -list_for_each_entry_rcu (kmod_req, &dup_kmod_reqs, list, -lockdep_is_held (&kmod_dup_mutex)) { +lockdep_assert_held (&kmod_dup_mutex); + +list_for_each_entry (kmod_req, &dup_kmod_reqs, list) {if (strlen (kmod_req->name) ==strlen (module_name) && !memcmp (kmod_req->name, module_name,strlen (module_name))) {return kmod_req;
@@ -88,10 +100,10 @@ static void kmod_dup_request_delete(struct work_struct *work)* just returning 0. */ mutex_lock (&kmod_dup_mutex); -list_del_rcu (&kmod_req->list); -synchronize_rcu (); +list_del (&kmod_req->list);mutex_unlock (&kmod_dup_mutex); -kfree (kmod_req); + +put_kmod_req (kmod_req); }static void kmod_dup_request_complete (struct work_struct *work)
@@ -100,6 +112,9 @@ static void kmod_dup_request_complete(struct work_struct *work) kmod_req = container_of(work, struct kmod_dup_req, complete_work); +if (completion_done (&kmod_req->first_req_done)) + goto out; +/* * This will ensure that the kernel will let all the waiters get * informed its time to check the return value. It's time to
@@ -115,6 +130,9 @@ static void kmod_dup_request_complete(struct work_struct *work)* possible abuses of vmalloc() incurred by finit_module() thrashing. */ queue_delayed_work (system_wq, &kmod_req->delete_work,60 *HZ ); + +out: +put_kmod_req (kmod_req); }bool kmod_dup_request_exists_wait (char *module_name,bool wait,int *dup_ret)
@@ -130,6 +148,7 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret)if (!new_kmod_req)return false; +refcount_set (&new_kmod_req->refcount,1 );memcpy (new_kmod_req->name, module_name,strlen (module_name));INIT_WORK (&new_kmod_req->complete_work, kmod_dup_request_complete);INIT_DELAYED_WORK (&new_kmod_req->delete_work, kmod_dup_request_delete);
@@ -162,10 +181,12 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret)* keep tab on duplicates later. */ pr_debug ("New request_module() for %s\n" , module_name); -list_add_rcu (&new_kmod_req->list, &dup_kmod_reqs); +list_add (&new_kmod_req->list, &dup_kmod_reqs);mutex_unlock (&kmod_dup_mutex);return false; } + +get_kmod_req (kmod_req);mutex_unlock (&kmod_dup_mutex);/* We are dealing with a duplicate request now */
@@ -195,7 +216,7 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret)* calls bail out right away. */ *dup_ret =0 ; -return true; + goto out; }/*
@@ -210,12 +231,14 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret) TASK_UNINTERRUPTIBLE | TASK_KILLABLE);if (ret) { *dup_ret = ret; -return true; + goto out; }/* Now the duplicate request has the same exact return value as the first request */ *dup_ret = kmod_req->dup_ret; +out: +put_kmod_req (kmod_req);return true; }
@@ -225,12 +248,23 @@ void kmod_dup_request_announce(char *module_name, int ret)mutex_lock (&kmod_dup_mutex); +/* +* Look for a kmod_dup_req previously added in +* kmod_dup_request_exists_wait(). Note that a request_module_nowait() +* without its own kmod_dup_req entry can announce a result of +* a concurrent request_module() call. +*/ kmod_req =kmod_dup_request_lookup (module_name); -if (!kmod_req) - goto out; +if (!kmod_req ||completion_done (&kmod_req->first_req_done)) { +mutex_unlock (&kmod_dup_mutex); +return ; + } kmod_req->dup_ret = ret; +get_kmod_req (kmod_req); +mutex_unlock (&kmod_dup_mutex); +/* * If we complete() here we may allow duplicate threads * to continue before the first one that submitted the
@@ -241,8 +275,6 @@ void kmod_dup_request_announce(char *module_name, int ret)* There is no rush. But we also don't want to hold the * caller up forever or introduce any boot delays. */ -queue_work (system_wq, &kmod_req->complete_work); - -out: -mutex_unlock (&kmod_dup_mutex); +if (!queue_work (system_wq, &kmod_req->complete_work)) +put_kmod_req (kmod_req); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1426/1674 bpf: Clear buf on error in __bpf_get_task_stack
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Olsa <[email protected]>
[ Upstream commit f5d242825ca417bb6afe35fde6e8880f97ca43fb ]
Both bpf_get_task_stack and bpf_get_task_stack_sleepable helpers that use __bpf_get_task_stack have buf defined as ARG_PTR_TO_UNINIT_MEM argument and we should initialize the buf on every return path.
Adding missing buf memset for __bpf_get_task_stack fail paths. This provides deterministic buffer contents, which is useful when the buffer is used directly as a map key.
--- kernel/bpf/stackmap.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/bpf/stackmap.c +5 -2
@@ -493,14 +493,17 @@ BPF_CALL_4(bpf_get_task_stack, struct task_struct *, task, void *, buf,struct pt_regs *regs;long res = -EINVAL ; -if (!try_get_task_stack (task)) +if (!try_get_task_stack (task)) { +memset (buf,0 , size);return -EFAULT ; + } regs =task_pt_regs (task);if (regs) res =__bpf_get_stack (regs, task,NULL , buf, size, flags); +else +memset (buf,0 , size);put_task_stack (task); -return res; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1427/1674 ocfs2/heartbeat: fix slot mapping rollback leaks on error paths
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yufan Chen <[email protected]>
[ Upstream commit 5686459423d03d192134166f0ec45f98bb2d5d57 ]
o2hb_map_slot_data() allocates hr_tmp_block, hr_slots, hr_slot_data, and pages in stages. If a later allocation fails, the current code returns without unwinding the earlier allocations.
o2hb_region_dev_store() also leaves slot mapping resources behind when setup aborts, and it keeps hr_aborted_start/hr_node_deleted set across retries. That leaves stale state behind after a failed start.
Factor the slot cleanup into o2hb_unmap_slot_data(), use it from both o2hb_map_slot_data() and o2hb_region_release(), and call it from the dev_store() rollback after stopping a started heartbeat thread. While freeing pages, clear each hr_slot_data entry as it is released, and reset the start state before each new setup attempt.
This closes the slot mapping leak on allocation/setup failure paths and keeps failed setup attempts retryable.
Stable-dep-of: 011291b70ba4 ("ocfs2: o2hb: quiesce negotiate handlers and timeout work")
--- fs/ocfs2/cluster/heartbeat.c | 69 +++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 20 deletions(-)
fs/ocfs2/cluster/heartbeat.c +49 -20
@@ -1511,33 +1511,45 @@ static struct o2hb_region *to_o2hb_region(struct config_item *item) return item ? container_of(item, struct o2hb_region, hr_item) : NULL; } -/* drop_item only drops its ref after killing the thread, nothing should -* be using the region anymore. this has to clean up any state that -* attributes might have built up. */ -static void o2hb_region_release (struct config_item *item) +static void o2hb_unmap_slot_data (struct o2hb_region *reg) {int i;struct page *page; -struct o2hb_region *reg =to_o2hb_region (item); - -mlog (ML_HEARTBEAT ,"hb region release (%pg)\n" , reg->hr_bdev); - -kfree (reg->hr_tmp_block);if (reg->hr_slot_data) {for (i =0 ; i < reg->hr_num_pages; i++) { page = reg->hr_slot_data[i]; -if (page) +if (page) {__free_page (page); + reg->hr_slot_data[i] =NULL ; + } }kfree (reg->hr_slot_data); + reg->hr_slot_data =NULL ; } +kfree (reg->hr_slots); + reg->hr_slots =NULL ; + +kfree (reg->hr_tmp_block); + reg->hr_tmp_block =NULL ; +} + +/* drop_item only drops its ref after killing the thread, nothing should +* be using the region anymore. this has to clean up any state that +* attributes might have built up. +*/ +static void o2hb_region_release (struct config_item *item) +{ +struct o2hb_region *reg =to_o2hb_region (item); + +mlog (ML_HEARTBEAT ,"hb region release (%pg)\n" , reg->hr_bdev); + +o2hb_unmap_slot_data (reg); +if (reg->hr_bdev)blkdev_put (reg->hr_bdev,NULL ); -kfree (reg->hr_slots); -debugfs_remove_recursive (reg->hr_debug_dir);kfree (reg->hr_db_livenodes);kfree (reg->hr_db_regnum);
@@ -1688,6 +1700,7 @@ static void o2hb_init_region_params(struct o2hb_region *reg)static int o2hb_map_slot_data (struct o2hb_region *reg) {int i, j; +int ret = -ENOMEM ;unsigned int last_slot;unsigned int spp = reg->hr_slots_per_page;struct page *page;
@@ -1695,15 +1708,15 @@ static int o2hb_map_slot_data(struct o2hb_region *reg)struct o2hb_disk_slot *slot; reg->hr_tmp_block =kmalloc (reg->hr_block_bytes,GFP_KERNEL ); -if (reg->hr_tmp_block ==NULL ) -return -ENOMEM ; +if (!reg->hr_tmp_block) + goto out; reg->hr_slots =kcalloc (reg->hr_blocks,sizeof (struct o2hb_disk_slot ),GFP_KERNEL ); -if (reg->hr_slots ==NULL ) -return -ENOMEM ; +if (!reg->hr_slots) + goto out; -for (i =0 ; i < reg->hr_blocks; i++) { +for (i =0 ; i < reg->hr_blocks; i++) { slot = ®->hr_slots[i]; slot->ds_node_num = i;INIT_LIST_HEAD (&slot->ds_live_item);
@@ -1718,12 +1731,12 @@ static int o2hb_map_slot_data(struct o2hb_region *reg) reg->hr_slot_data =kcalloc (reg->hr_num_pages,sizeof (struct page *),GFP_KERNEL );if (!reg->hr_slot_data) -return -ENOMEM ; + goto out; -for (i =0 ; i < reg->hr_num_pages; i++) { +for (i =0 ; i < reg->hr_num_pages; i++) { page =alloc_page (GFP_KERNEL );if (!page) -return -ENOMEM ; + goto out; reg->hr_slot_data[i] = page;
@@ -1743,6 +1756,10 @@ static int o2hb_map_slot_data(struct o2hb_region *reg) }return 0 ; + +out: +o2hb_unmap_slot_data (reg); +return ret; }/* Read in all the slots available and populate the tracking
@@ -1834,6 +1851,8 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, goto out3; } + reg->hr_aborted_start =0 ; + reg->hr_node_deleted =0 ;o2hb_init_region_params (reg);/* Generation of zero is invalid */
@@ -1925,6 +1944,16 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, out3:if (ret <0 ) { +spin_lock (&o2hb_live_lock); + hb_task = reg->hr_task; + reg->hr_task =NULL ; +spin_unlock (&o2hb_live_lock); + +if (hb_task) +kthread_stop (hb_task); + +o2hb_unmap_slot_data (reg); +blkdev_put (reg->hr_bdev,NULL ); reg->hr_bdev =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1428/1674 ocfs2/cluster: keep heartbeat local node stable
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 688bc88e2046dd6ce81ce18079b5254cb8dadc0e ]
o2nm_node_local_store() handles local=0 by stopping o2net and setting cl_local_node to O2NM_INVALID_NODE_NUM, but it leaves cl_has_local set. That stale state makes o2nm_this_node() return 255, blocks a later local=1 attempt with -EBUSY, and can feed 255 to heartbeat users that call o2nm_this_node() dynamically.
Clearing cl_has_local is required when the local node is reset. But heartbeat threads can still be running at that point. They pin the local node config item at startup, yet o2hb_do_disk_heartbeat() and thread teardown re-read o2nm_this_node() for the local slot and for o2nm_undepend_this_node(). Once local=0 has cleared the live local-node state, those dynamic reads return O2NM_MAX_NODES, which is also the invalid node number 255.
Store the local node number in the heartbeat region when the region starts. Use that stable node for heartbeat slot writes/checks, negotiation messages, and the final configfs undepend. Stop the heartbeat loop when the current local node no longer matches the stored node, and clear cl_has_local together with cl_local_node in the local=0 path so nodemanager state matches node removal.
Validation reproduced this kernel report:
KASAN slab-out-of-bounds in o2hb_do_disk_heartbeat+0x372/0xb30
RIP: 0010:memset+0xf/0x20 Read of size 8 Call trace: dump_stack_lvl+0x66/0xa0 print_report+0xd0/0x630 o2hb_do_disk_heartbeat+0x372/0xb30 (fs/ocfs2/cluster/heartbeat.c:1079) srso_alias_return_thunk+0x5/0xfbef5 __virt_addr_valid+0x188/0x2f0 kasan_report+0xe4/0x120 o2hb_do_disk_heartbeat+0x5/0xb30 (fs/ocfs2/cluster/heartbeat.c:1079) o2hb_thread+0x14e/0x770 kthread_affine_node+0x139/0x180 lockdep_hardirqs_on_prepare+0xda/0x190 trace_hardirqs_on+0x18/0x130 kthread+0x19d/0x1e0 ret_from_fork+0x37a/0x4d0 __switch_to+0x2d5/0x6f0 ret_from_fork_asm+0x1a/0x30
Stable-dep-of: 011291b70ba4 ("ocfs2: o2hb: quiesce negotiate handlers and timeout work")
--- fs/ocfs2/cluster/heartbeat.c | 43 +++++++++++++++++++++++----------- fs/ocfs2/cluster/nodemanager.c | 19 +++++++++++---- fs/ocfs2/cluster/nodemanager.h | 2 ++ 3 files changed, 46 insertions(+), 18 deletions(-)
fs/ocfs2/cluster/heartbeat.c +29 -14
@@ -210,6 +210,7 @@ struct o2hb_region {/* protected by the hr_callback_sem */ struct task_struct *hr_task; +u8 hr_node_num;unsigned int hr_blocks;unsigned long long hr_start_block;
@@ -352,12 +353,12 @@ static void o2hb_disarm_timeout(struct o2hb_region *reg)cancel_delayed_work_sync (®->hr_nego_timeout_work); } -static int o2hb_send_nego_msg (int key,int type,u8 target) +static int o2hb_send_nego_msg (int key,int type,u8 target,u8 node_num) {struct o2hb_nego_msg msg;int status, ret; - msg.node_num =o2nm_this_node (); + msg.node_num = node_num; again: ret =o2net_send_message (type, key, &msg,sizeof (msg), target, &status);
@@ -375,8 +376,10 @@ static void o2hb_nego_timeout(struct work_struct *work)unsigned long live_node_bitmap[BITS_TO_LONGS (O2NM_MAX_NODES )];int master_node, i, ret;struct o2hb_region *reg; +u8 node_num; reg = container_of(work, struct o2hb_region, hr_nego_timeout_work.work); + node_num = reg->hr_node_num;/* don't negotiate timeout if last hb failed since it is very * possible io failed. Should let write timeout fence self. */
@@ -387,10 +390,10 @@ static void o2hb_nego_timeout(struct work_struct *work)/* lowest node as master node to make negotiate decision. */ master_node =find_first_bit (live_node_bitmap,O2NM_MAX_NODES ); -if (master_node ==o2nm_this_node ()) { +if (master_node == node_num) {if (!test_bit (master_node, reg->hr_nego_node_bitmap)) {printk (KERN_NOTICE "o2hb: node %d hb write hung for %ds on region %s (%pg).\n" , -o2nm_this_node (),O2HB_NEGO_TIMEOUT_MS /1000 , + node_num,O2HB_NEGO_TIMEOUT_MS /1000 ,config_item_name (®->hr_item), reg->hr_bdev);set_bit (master_node, reg->hr_nego_node_bitmap); }
@@ -418,7 +421,7 @@ static void o2hb_nego_timeout(struct work_struct *work)mlog (ML_HEARTBEAT ,"send NEGO_APPROVE msg to node %d\n" , i); ret =o2hb_send_nego_msg (reg->hr_key, -O2HB_NEGO_APPROVE_MSG , i); +O2HB_NEGO_APPROVE_MSG , i, node_num);if (ret)mlog (ML_ERROR ,"send NEGO_APPROVE msg to node %d fail %d\n" , i, ret);
@@ -426,10 +429,10 @@ static void o2hb_nego_timeout(struct work_struct *work) }else {/* negotiate timeout with master node. */ printk (KERN_NOTICE "o2hb: node %d hb write hung for %ds on region %s (%pg), negotiate timeout with node %d.\n" , -o2nm_this_node (),O2HB_NEGO_TIMEOUT_MS /1000 ,config_item_name (®->hr_item), + node_num,O2HB_NEGO_TIMEOUT_MS /1000 ,config_item_name (®->hr_item), reg->hr_bdev, master_node); ret =o2hb_send_nego_msg (reg->hr_key,O2HB_NEGO_TIMEOUT_MSG , - master_node); + master_node, node_num);if (ret)mlog (ML_ERROR ,"send NEGO_TIMEOUT msg to node %d fail %d\n" , master_node, ret);
@@ -601,7 +604,9 @@ static int o2hb_issue_node_write(struct o2hb_region *reg,o2hb_bio_wait_init (write_wc); - slot =o2nm_this_node (); + slot = reg->hr_node_num; +if (slot >=O2NM_MAX_NODES ) +return -EINVAL ; bio =o2hb_setup_one_bio (reg, write_wc, &slot, slot+1 ,REQ_OP_WRITE |REQ_SYNC );
@@ -670,8 +675,12 @@ static int o2hb_check_own_slot(struct o2hb_region *reg)struct o2hb_disk_slot *slot;struct o2hb_disk_heartbeat_block *hb_block;char *errstr; +u8 node_num = reg->hr_node_num; + +if (node_num >=O2NM_MAX_NODES ) +return 0 ; - slot = ®->hr_slots[o2nm_this_node ()]; + slot = ®->hr_slots[node_num];/* Don't check on our 1st timestamp */ if (!slot->ds_last_time)return 0 ;
@@ -712,7 +721,10 @@ static inline void o2hb_prepare_block(struct o2hb_region *reg,struct o2hb_disk_slot *slot;struct o2hb_disk_heartbeat_block *hb_block; - node_num =o2nm_this_node (); + node_num = reg->hr_node_num; +if (node_num >=O2NM_MAX_NODES ) +return ; + slot = ®->hr_slots[node_num]; hb_block = (struct o2hb_disk_heartbeat_block *)slot->ds_raw_block;
@@ -1206,7 +1218,7 @@ static int o2hb_thread(void *data)set_user_nice (current,MIN_NICE );/* Pin node */ - ret =o2nm_depend_this_node (); + ret =o2nm_depend_node (reg->hr_node_num);if (ret) {mlog (ML_ERROR ,"Node has been deleted, ret = %d\n" , ret); reg->hr_node_deleted =1 ;
@@ -1215,7 +1227,8 @@ static int o2hb_thread(void *data) }while (!kthread_should_stop () && - !reg->hr_unclean_stop && !reg->hr_aborted_start) { + !reg->hr_unclean_stop && !reg->hr_aborted_start && +o2nm_this_node () == reg->hr_node_num) {/* We track the time spent inside * o2hb_do_disk_heartbeat so that we avoid more than * hr_timeout_ms between disk writes. On busy systems
@@ -1264,7 +1277,7 @@ static int o2hb_thread(void *data) }/* Unpin node */ -o2nm_undepend_this_node (); +o2nm_undepend_node (reg->hr_node_num);mlog (ML_HEARTBEAT |ML_KTHREAD ,"o2hb thread exiting\n" );
@@ -1812,7 +1825,8 @@ static ssize_t o2hb_region_dev_store(struct config_item *item,/* We can't heartbeat without having had our node number * configured yet. */ -if (o2nm_this_node () ==O2NM_MAX_NODES ) + reg->hr_node_num =o2nm_this_node (); +if (reg->hr_node_num ==O2NM_MAX_NODES ) goto out; fd =simple_strtol (p, &p,0 );
@@ -2061,6 +2075,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g ret = -ENAMETOOLONG ; goto free; } + reg->hr_node_num =O2NM_MAX_NODES ;spin_lock (&o2hb_live_lock); reg->hr_region_num =0 ;
fs/ocfs2/cluster/nodemanager.c +15 -4
@@ -368,6 +368,7 @@ static ssize_t o2nm_node_local_store(struct config_item *item, const char *page,if (!tmp && cluster->cl_has_local && cluster->cl_local_node == node->nd_num) {o2net_stop_listening (node); + cluster->cl_has_local =0 ; cluster->cl_local_node =O2NM_INVALID_NODE_NUM ; }
@@ -791,12 +792,12 @@ void o2nm_undepend_item(struct config_item *item)configfs_undepend_item (item); } -int o2nm_depend_this_node (void ) +int o2nm_depend_node (u8 node_num) {int ret =0 ;struct o2nm_node *local_node; - local_node =o2nm_get_node_by_num (o2nm_this_node ()); + local_node =o2nm_get_node_by_num (node_num);if (!local_node) { ret = -EINVAL ; goto out;
@@ -809,17 +810,27 @@ int o2nm_depend_this_node(void)return ret; } -void o2nm_undepend_this_node (void ) +void o2nm_undepend_node (u8 node_num) {struct o2nm_node *local_node; - local_node =o2nm_get_node_by_num (o2nm_this_node ()); + local_node =o2nm_get_node_by_num (node_num);BUG_ON (!local_node);o2nm_undepend_item (&local_node->nd_item);o2nm_node_put (local_node); } +int o2nm_depend_this_node (void ) +{ +return o2nm_depend_node (o2nm_this_node ()); +} + +void o2nm_undepend_this_node (void ) +{ +o2nm_undepend_node (o2nm_this_node ()); +} + static void __exit exit_o2nm(void) {
fs/ocfs2/cluster/nodemanager.h +2 -0
@@ -66,6 +66,8 @@ void o2nm_node_put(struct o2nm_node *node);int o2nm_depend_item (struct config_item *item);int o2nm_depend_item_unlocked (struct config_item *item);void o2nm_undepend_item (struct config_item *item); +int o2nm_depend_node (u8 node_num); +void o2nm_undepend_node (u8 node_num);int o2nm_depend_this_node (void );void o2nm_undepend_this_node (void );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1429/1674 ocfs2: o2hb: quiesce negotiate handlers and timeout work
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 011291b70ba4832e136b7b581825b2bc0f525bf6 ]
Heartbeat regions publish struct o2hb_region as the private data for the NEGO_TIMEOUT and NEGO_APPROVE o2net handlers as soon as make_item() creates the configfs region. The approve handler can call o2hb_arm_timeout(), so a peer can touch the region timeout work before dev_store() has finished building the heartbeat runtime, or after teardown has started to shut that runtime back down.
The final configfs put also has to keep reg alive until the last in-flight o2net callback drops its handler reference. o2net_unregister_handler_list() blocks future handler lookups, but it does not wait for sc_rx_work that already passed o2net_handler_get(). That drain needs to cover local listener teardown as well, where the o2net ordered workqueue may already be inside destroy_workqueue().
Fix the lifetime rule in both directions. Initialize the region delayed works before publishing reg through the o2net handler table, keep new or stopping regions non-armable with hr_stopping, and quiesce both delayed works on failed-start and teardown paths even when no heartbeat thread is left to call o2hb_disarm_timeout(). Then unregister handlers before tearing down handler-visible region state and make the drain wait for the active or destroying o2net ordered workqueue before release frees reg.
The buggy scenario involves two paths, with each column showing the order within that path:
region lifecycle: late negotiate callback:
1. make_item() registers the 1. o2net_process_message() gets a
region handlers before heartbeat handler for reg.
dev_store() has built a 2. The callback runs after the lookup
runnable heartbeat context. lock is dropped and dereferences reg.
2. A failed start or rmdir 3. An approve or timeout path tries to
stops the heartbeat thread, queue reg's delayed work, or release quiesces existing work, and races the callback body after handler drops the final configfs ref. unregister.
3. region_release() must drain 4. The callback or delayed work can
handler-visible o2net rx work outlive reg unless lifecycle code
before freeing reg. keeps the region non-armable and
drains the active-or-destroying o2net workqueue.
Validation reproduced this kernel report:
KASAN slab-use-after-free in __run_timers+0x22c/0x5b0
Write of size 8 Call trace: dump_stack_lvl+0x66/0xa0 print_report+0xce/0x630 __run_timers+0x22c/0x5b0 kasan_report+0xe0/0x110 _raw_spin_unlock_irqrestore+0x27/0x60 try_to_wake_up+0x191/0xf70 timer_expire_remote+0xae/0xf0 run_timer_softirq+0x19b/0x1a0 handle_softirqs+0x156/0x660 __irq_exit_rcu+0xc4/0x160 irq_exit_rcu+0xe/0x20 sysvec_apic_timer_interrupt+0x6c/0x80 asm_sysvec_apic_timer_interrupt+0x1a/0x20 Allocated by task stack: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 o2hb_heartbeat_group_make_item+0x3c/0x600
--- fs/ocfs2/cluster/heartbeat.c | 56 ++++++++++++++++--- fs/ocfs2/cluster/tcp.c | 105 ++++++++++++++++++++++++++++++----- fs/ocfs2/cluster/tcp.h | 1 + 3 files changed, 139 insertions(+), 23 deletions(-)
fs/ocfs2/cluster/heartbeat.c +48 -8
@@ -14,6 +14,7 @@#include <linux/file.h> #include <linux/kthread.h> #include <linux/configfs.h> +#include <linux/mutex.h> #include <linux/random.h> #include <linux/crc32.h> #include <linux/time.h>
@@ -265,6 +266,9 @@ struct o2hb_region {/* Message key for negotiate timeout message. */ unsigned int hr_key;struct list_head hr_handler_list; +/* Serializes timeout arming against failed-start and teardown. */ +struct mutex hr_arming_mutex; +bool hr_stopping;/* last hb status, 0 for success, other value for error. */ int hr_last_hb_status;
@@ -324,9 +328,14 @@ static void o2hb_write_timeout(struct work_struct *work)static void o2hb_arm_timeout (struct o2hb_region *reg) { +mutex_lock (®->hr_arming_mutex); + +if (reg->hr_stopping) + goto out_unlock; +/* Arm writeout only after thread reaches steady state */ if (atomic_read (®->hr_steady_iterations) !=0 ) -return ; + goto out_unlock;mlog (ML_HEARTBEAT ,"Queue write timeout for %u ms\n" ,O2HB_MAX_WRITE_TIMEOUT_MS );
@@ -345,6 +354,18 @@ static void o2hb_arm_timeout(struct o2hb_region *reg)schedule_delayed_work (®->hr_nego_timeout_work,msecs_to_jiffies (O2HB_NEGO_TIMEOUT_MS ));bitmap_zero (reg->hr_nego_node_bitmap,O2NM_MAX_NODES ); + +out_unlock: +mutex_unlock (®->hr_arming_mutex); +} + +static void o2hb_queue_nego_timeout (struct o2hb_region *reg, +unsigned long delay) +{ +mutex_lock (®->hr_arming_mutex); +if (!reg->hr_stopping) +schedule_delayed_work (®->hr_nego_timeout_work, delay); +mutex_unlock (®->hr_arming_mutex); }static void o2hb_disarm_timeout (struct o2hb_region *reg)
@@ -353,6 +374,19 @@ static void o2hb_disarm_timeout(struct o2hb_region *reg)cancel_delayed_work_sync (®->hr_nego_timeout_work); } +static void o2hb_set_region_stopping (struct o2hb_region *reg,bool stopping) +{ +mutex_lock (®->hr_arming_mutex); + reg->hr_stopping = stopping; +mutex_unlock (®->hr_arming_mutex); +} + +static void o2hb_quiesce_timeout (struct o2hb_region *reg) +{ +o2hb_set_region_stopping (reg, true); +o2hb_disarm_timeout (reg); +} +static int o2hb_send_nego_msg (int key,int type,u8 target,u8 node_num) {struct o2hb_nego_msg msg;
@@ -402,8 +436,7 @@ static void o2hb_nego_timeout(struct work_struct *work)/* check negotiate bitmap every second to do timeout * approve decision. */ -schedule_delayed_work (®->hr_nego_timeout_work, -msecs_to_jiffies (1000 )); +o2hb_queue_nego_timeout (reg,msecs_to_jiffies (1000 ));return ; }
@@ -1558,6 +1591,8 @@ static void o2hb_region_release(struct config_item *item)mlog (ML_HEARTBEAT ,"hb region release (%pg)\n" , reg->hr_bdev); +o2hb_quiesce_timeout (reg); +o2net_unregister_and_flush_handler_list (®->hr_handler_list);o2hb_unmap_slot_data (reg);if (reg->hr_bdev)
@@ -1573,7 +1608,6 @@ static void o2hb_region_release(struct config_item *item)list_del (®->hr_all_item);spin_unlock (&o2hb_live_lock); -o2net_unregister_handler_list (®->hr_handler_list);kfree (reg); }
@@ -1887,9 +1921,6 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, goto out3; } -INIT_DELAYED_WORK (®->hr_write_timeout_work, o2hb_write_timeout); -INIT_DELAYED_WORK (®->hr_nego_timeout_work, o2hb_nego_timeout); -/* * A node is considered live after it has beat LIVE_THRESHOLD * times. We're not steady until we've given them a chance
@@ -1909,6 +1940,7 @@ static ssize_t o2hb_region_dev_store(struct config_item *item,atomic_set (®->hr_steady_iterations, live_threshold);/* unsteady_iterations is triple the steady_iterations */ atomic_set (®->hr_unsteady_iterations, (live_threshold *3 )); +o2hb_set_region_stopping (reg, false); hb_task =kthread_run (o2hb_thread, reg,"o2hb-%s" , reg->hr_item.ci_name);
@@ -1958,6 +1990,8 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, out3:if (ret <0 ) { +o2hb_quiesce_timeout (reg); +spin_lock (&o2hb_live_lock); hb_task = reg->hr_task; reg->hr_task =NULL ;
@@ -2100,6 +2134,10 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g*/ reg->hr_key =crc32_le (reg->hr_region_num +O2NM_MAX_REGIONS , name,strlen (name)); +mutex_init (®->hr_arming_mutex); + reg->hr_stopping = true; +INIT_DELAYED_WORK (®->hr_write_timeout_work, o2hb_write_timeout); +INIT_DELAYED_WORK (®->hr_nego_timeout_work, o2hb_nego_timeout);INIT_LIST_HEAD (®->hr_handler_list); ret = o2net_register_handler(O2HB_NEGO_TIMEOUT_MSG, reg->hr_key, sizeof(struct o2hb_nego_msg),
@@ -2120,7 +2158,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *greturn ®->hr_item; unregister_handler: -o2net_unregister_handler_list (®->hr_handler_list); +o2net_unregister_and_flush_handler_list (®->hr_handler_list); remove_item:spin_lock (&o2hb_live_lock);list_del (®->hr_all_item);
@@ -2139,6 +2177,8 @@ static void o2hb_heartbeat_group_drop_item(struct config_group *group,struct o2hb_region *reg =to_o2hb_region (item);int quorum_region =0 ; +o2hb_quiesce_timeout (reg); +/* stop the thread when the user removes the region dir */ spin_lock (&o2hb_live_lock); hb_task = reg->hr_task;
fs/ocfs2/cluster/tcp.c +90 -15
162 lines not on this page · raw message
fs/ocfs2/cluster/tcp.h +1 -0
@@ -89,6 +89,7 @@ int o2net_register_handler(u32 msg_type, u32 key, u32 max_len,o2net_post_msg_handler_func *post_func, struct list_head *unreg_list);void o2net_unregister_handler_list (struct list_head *list); +void o2net_unregister_and_flush_handler_list (struct list_head *list);void o2net_fill_node_map (unsigned long *map,unsigned bytes);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1430/1674 RDMA/erdma: Hold QP references for AE and CM processing
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cheng Xu <[email protected]>
[ Upstream commit a52eeff32024f190b3bdc99088c7becccd4fa60b ]
AE QP fatal events and iWARP CM paths load QPs from dev->qp_xa and then use or reference them outside the xarray lock. erdma_destroy_qp() can drop the destroy-path reference and free QP resources while such a lookup is in flight.
Add erdma_qp_get_by_qpn() to acquire a kref under the xarray lock with kref_get_unless_zero(). Remove the QP from the xarray before dropping the destroy-path reference so no new lookup can acquire it while destruction waits for existing users.
--- drivers/infiniband/hw/erdma/erdma_cm.c | 6 ++---- drivers/infiniband/hw/erdma/erdma_eq.c | 3 ++- drivers/infiniband/hw/erdma/erdma_verbs.c | 6 +++++- drivers/infiniband/hw/erdma/erdma_verbs.h | 15 +++++++++++++++ 4 files changed, 24 insertions(+), 6 deletions(-)
drivers/infiniband/hw/erdma/erdma_cm.c +2 -4
@@ -1017,10 +1017,9 @@ int erdma_connect(struct iw_cm_id *id, struct iw_cm_conn_param *params)if (laddr->sa_family !=AF_INET || raddr->sa_family !=AF_INET )return -EAFNOSUPPORT ; - qp =find_qp_by_qpn (dev, params->qpn); + qp =erdma_qp_get_by_qpn (dev, params->qpn);if (!qp)return -ENOENT ; -erdma_qp_get (qp); ret =sock_create (AF_INET ,SOCK_STREAM ,IPPROTO_TCP , &s);if (ret <0 )
@@ -1149,10 +1148,9 @@ int erdma_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)return -ECONNRESET ; } - qp =find_qp_by_qpn (dev, params->qpn); + qp =erdma_qp_get_by_qpn (dev, params->qpn);if (!qp)return -ENOENT ; -erdma_qp_get (qp);down_write (&qp->state_lock);if (qp->attrs.state >ERDMA_QP_STATE_RTR ) {
drivers/infiniband/hw/erdma/erdma_eq.c +2 -1
@@ -65,7 +65,7 @@ void erdma_aeq_event_handler(struct erdma_dev *dev)erdma_cq_put (cq); }else { qpn =le32_to_cpu (aeqe->event_data0); - qp =find_qp_by_qpn (dev, qpn); + qp =erdma_qp_get_by_qpn (dev, qpn);if (!qp)continue ;
@@ -75,6 +75,7 @@ void erdma_aeq_event_handler(struct erdma_dev *dev)if (qp->ibqp.event_handler) qp->ibqp.event_handler (&event, qp->ibqp.qp_context); +erdma_qp_put (qp); } }
drivers/infiniband/hw/erdma/erdma_verbs.c +5 -1
@@ -1266,6 +1266,7 @@ int erdma_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)struct erdma_ucontext *ctx =rdma_udata_to_drv_context ( udata, struct erdma_ucontext, ibucontext);struct erdma_qp_attrs qp_attrs; +unsigned long flags;int err;struct erdma_cmdq_destroy_qp_req req;
@@ -1284,6 +1285,10 @@ int erdma_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)if (err)return err; +xa_lock_irqsave (&dev->qp_xa, flags); +__xa_erase (&dev->qp_xa,QP_ID (qp)); +xa_unlock_irqrestore (&dev->qp_xa, flags); +erdma_qp_put (qp);wait_for_completion (&qp->safe_free);
@@ -1306,7 +1311,6 @@ int erdma_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)if (qp->cep)erdma_cep_put (qp->cep); -xa_erase (&dev->qp_xa,QP_ID (qp));return 0 ; }
drivers/infiniband/hw/erdma/erdma_verbs.h +15 -0
@@ -280,6 +280,21 @@ static inline struct erdma_qp *find_qp_by_qpn(struct erdma_dev *dev, int id)return (struct erdma_qp *)xa_load (&dev->qp_xa, id); } +static inline struct erdma_qp *erdma_qp_get_by_qpn (struct erdma_dev *dev, +int id) +{ +struct erdma_qp *qp; +unsigned long flags; + +xa_lock_irqsave (&dev->qp_xa, flags); + qp =xa_load (&dev->qp_xa, id); +if (qp && !kref_get_unless_zero (&qp->ref)) + qp =NULL ; +xa_unlock_irqrestore (&dev->qp_xa, flags); + +return qp; +} +static inline struct erdma_cq *erdma_cq_get_by_cqn (struct erdma_dev *dev,int id) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1431/1674 thermal: hwmon: Remove hwmon class device along with its parent
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 2b57e24d34b2dfc43c81942bb359d6315bf302fb ]
The current code creates one hwmon device per thermal zone type and that device is registered under the first thermal zone of the given type.
That turns out to be problematic when the thermal zone holding the hwmon device is removed.
For example, say that there are two ACPI thermal zones on a system
/sys/devices/virtual/thermal/thermal_zone0/
/sys/devices/virtual/thermal/thermal_zone1/
The current code registers a hwmon class device for thermal_zone0 only:
/sys/devices/virtual/thermal/thermal_zone0/hwmon0/
because the type is "acpitz" for both of them, but it adds a sysfs attribute that belongs to thermal_zone1 under it:
/sys/devices/virtual/thermal/thermal_zone0/hwmon0/temp2_input
There is also
/sys/devices/virtual/thermal/thermal_zone0/hwmon0/temp1_input
which belongs to thermal_zone0.
When thermal_zone0 is removed, say because the ACPI thermal driver is unbound from the underlying platform device, thermal_remove_hwmon_sysfs() skips the removal of hwmon0 because of the temp2_input attribute belonging to thermal_zone1 which effectively prevents thermal_zone0 removal from making progress.
Address this by making thermal_remove_hwmon_sysfs() remove the entire hwmon class device interface for the given thermal zone type when the thermal zone device holding it is removed.
To prevent races with thermal_add_hwmon_sysfs() that may interfere with this, carry out the entire addition and removal of hwmon sysfs interfaces for thermal zones under thermal_hwmon_list_lock.
Also adjust the layout of the labels in thermal_add_hwmon_sysfs() to the current kernel coding style to align with the new "unlock" label.
--- drivers/thermal/thermal_hwmon.c | 87 +++++++++++++-------------------- 1 file changed, 34 insertions(+), 53 deletions(-)
drivers/thermal/thermal_hwmon.c +34 -53
@@ -101,34 +101,12 @@ thermal_hwmon_lookup_by_type(const struct thermal_zone_device *tz)struct thermal_hwmon_device *hwmon;char type[THERMAL_NAME_LENGTH ]; -mutex_lock (&thermal_hwmon_list_lock);list_for_each_entry (hwmon, &thermal_hwmon_list, node) {strcpy (type, tz->type);strreplace (type,'-' ,'_' ); -if (!strcmp (hwmon->type, type)) { -mutex_unlock (&thermal_hwmon_list_lock); +if (!strcmp (hwmon->type, type))return hwmon; - } } -mutex_unlock (&thermal_hwmon_list_lock); - -return NULL ; -} - -/* Find the temperature input matching a given thermal zone */ -static struct thermal_hwmon_temp * -thermal_hwmon_lookup_temp (const struct thermal_hwmon_device *hwmon, -const struct thermal_zone_device *tz) -{ -struct thermal_hwmon_temp *temp; - -mutex_lock (&thermal_hwmon_list_lock); -list_for_each_entry (temp, &hwmon->tz_list, hwmon_node) -if (temp->tz == tz) { -mutex_unlock (&thermal_hwmon_list_lock); -return temp; - } -mutex_unlock (&thermal_hwmon_list_lock);return NULL ; }
@@ -144,7 +122,9 @@ int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)struct thermal_hwmon_device *hwmon;struct thermal_hwmon_temp *temp;int new_hwmon_device =1 ; -int result; +int result =0 ; + +mutex_lock (&thermal_hwmon_list_lock); hwmon =thermal_hwmon_lookup_by_type (tz);if (hwmon) {
@@ -153,8 +133,10 @@ int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) } hwmon =kzalloc (sizeof (*hwmon),GFP_KERNEL ); -if (!hwmon) -return -ENOMEM ; +if (!hwmon) { + result = -ENOMEM ; + goto unlock; + }INIT_LIST_HEAD (&hwmon->tz_list);strscpy (hwmon->type, tz->type,THERMAL_NAME_LENGTH );
@@ -202,24 +184,24 @@ int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) temp->temp_crit_present = true; } -mutex_lock (&thermal_hwmon_list_lock);if (new_hwmon_device)list_add_tail (&hwmon->node, &thermal_hwmon_list);list_add_tail (&temp->hwmon_node, &hwmon->tz_list); -mutex_unlock (&thermal_hwmon_list_lock); -return 0 ; + goto unlock; - unregister_input: +unregister_input:device_remove_file (hwmon->device, &temp->temp_input.attr); - free_temp_mem: +free_temp_mem:kfree (temp); - unregister_name: +unregister_name:if (new_hwmon_device)hwmon_device_unregister (hwmon->device); - free_mem: +free_mem:if (new_hwmon_device)kfree (hwmon); +unlock: +mutex_unlock (&thermal_hwmon_list_lock);return result; }
@@ -227,8 +209,11 @@ EXPORT_SYMBOL_GPL(thermal_add_hwmon_sysfs);void thermal_remove_hwmon_sysfs (struct thermal_zone_device *tz) { +struct thermal_hwmon_temp *temp, *entry;struct thermal_hwmon_device *hwmon; -struct thermal_hwmon_temp *temp; +bool unregister; + +guard (mutex)(&thermal_hwmon_list_lock); hwmon =thermal_hwmon_lookup_by_type (tz);if (unlikely (!hwmon)) {
@@ -237,29 +222,25 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)return ; } - temp =thermal_hwmon_lookup_temp (hwmon, tz); -if (unlikely (!temp)) { -/* Should never happen... */ -dev_dbg (&tz->device,"temperature input lookup failed!\n" ); -return ; - } + unregister = hwmon->device->parent == &tz->device; -device_remove_file (hwmon->device, &temp->temp_input.attr); -if (temp->temp_crit_present) -device_remove_file (hwmon->device, &temp->temp_crit.attr); +list_for_each_entry_safe_reverse (temp, entry, &hwmon->tz_list, hwmon_node) { +if (!unregister && temp->tz != tz) +continue ; -mutex_lock (&thermal_hwmon_list_lock); -list_del (&temp->hwmon_node); -kfree (temp); -if (!list_empty (&hwmon->tz_list)) { -mutex_unlock (&thermal_hwmon_list_lock); -return ; +device_remove_file (hwmon->device, &temp->temp_input.attr); +if (temp->temp_crit_present) +device_remove_file (hwmon->device, &temp->temp_crit.attr); + +list_del (&temp->hwmon_node); +kfree (temp); } -list_del (&hwmon->node); -mutex_unlock (&thermal_hwmon_list_lock); -hwmon_device_unregister (hwmon->device); -kfree (hwmon); +if (unregister) { +list_del (&hwmon->node); +hwmon_device_unregister (hwmon->device); +kfree (hwmon); + } }EXPORT_SYMBOL_GPL (thermal_remove_hwmon_sysfs);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1432/1674 ocfs2: validate inline xattrs during inode block validation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 8914a3330b72378136c2c02d6328a826f6abdad7 ]
Patch series "ocfs2: validate xattr entry bounds", v7.
This series validates OCFS2 xattr entry name/value bounds when xattr metadata is read and validated, before getxattr() or listxattr() can walk out-of-range entry arrays or offsets from corrupted metadata.
This patch (of 2):
ocfs2_validate_inode_block() verifies a dinode before OCFS2 users walk metadata from it, but inline xattr metadata is still checked only in operation-specific consumers. The existing ibody lookup helper validates inline header placement and entry count, but inode block validation does not reject entry name/value bounds.
Add a flat xattr entry validator and call it from inode block validation for inline xattrs. Keep the operation paths on their existing header/count lookup checks; the full entry bounds check now runs when the inode block is validated at read time.
Reject corrupted inline xattr metadata before ocfs2_xattr_ibody_get() or listxattr() can walk past the inline storage.
Validation reproduced this kernel report:
BUG: KASAN: use-after-free in ocfs2_xattr_find_entry+0x5a/0x170 Read of size 2 at addr ffff8881242a2000 by task python3/529 Call Trace: dump_stack_lvl+0x66/0xa0 print_report+0xce/0x630 kasan_report+0xe0/0x110 ocfs2_xattr_find_entry+0x5a/0x170 ocfs2_xattr_get_nolock+0x20a/0x820 ocfs2_xattr_get+0x10c/0x1e0 __vfs_getxattr+0xe2/0x130 vfs_getxattr+0x185/0x1b0
--- fs/ocfs2/inode.c | 4 ++ fs/ocfs2/xattr.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++ fs/ocfs2/xattr.h | 2 + 3 files changed, 124 insertions(+)
fs/ocfs2/inode.c +4 -0
@@ -1562,6 +1562,10 @@ int ocfs2_validate_inode_block(struct super_block *sb, goto bail; } + rc =ocfs2_validate_inode_xattr (sb, bh->b_blocknr, di); +if (rc) + goto bail; +if (le16_to_cpu (di->i_dyn_features) &OCFS2_INLINE_DATA_FL ) {struct ocfs2_inline_data *data = &di->id2.i_data;
fs/ocfs2/xattr.c +118 -0
124 lines not on this page · raw message
fs/ocfs2/xattr.h +2 -0
@@ -43,6 +43,8 @@ int ocfs2_xattr_set_handle(handle_t *, struct inode *, struct buffer_head *, struct ocfs2_alloc_context *);int ocfs2_has_inline_xattr_value_outside (struct inode *inode,struct ocfs2_dinode *di); +int ocfs2_validate_inode_xattr (struct super_block *sb,u64 blkno, +struct ocfs2_dinode *di);int ocfs2_xattr_remove (struct inode *,struct buffer_head *); int ocfs2_init_security_get(struct inode *, struct inode *, const struct qstr *,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1433/1674 ublk: check import_ubuf() return value
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Caleb Sander Mateos <[email protected]>
[ Upstream commit 3831568792af75b6523fa93bb91560e29189cf55 ]
import_ubuf() can fail if the address range (provided by the userspace ublk server) is outside the allowed user address space. Return that 0 bytes were copied if import_ubuf() fails rather than passing an uninitialized struct iov_iter to ublk_copy_user_pages().
--- drivers/block/ublk_drv.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/block/ublk_drv.c +7 -4
@@ -938,8 +938,9 @@ static int ublk_map_io(const struct ublk_queue *ubq, const struct request *req,struct iovec iov;const int dir =ITER_DEST ; -import_single_range (dir,u64_to_user_ptr (io->addr), rq_bytes, - &iov, &iter); +if (import_single_range (dir,u64_to_user_ptr (io->addr), rq_bytes, + &iov, &iter) <0 ) +return 0 ;return ublk_copy_user_pages (req,0 , &iter, dir); }
@@ -962,8 +963,10 @@ static int ublk_unmap_io(const struct ublk_queue *ubq,WARN_ON_ONCE (io->res > rq_bytes); -import_single_range (dir,u64_to_user_ptr (io->addr), io->res, - &iov, &iter); +if (import_single_range (dir,u64_to_user_ptr (io->addr), io->res, + &iov, &iter) <0 ) +return 0 ; +return ublk_copy_user_pages (req,0 , &iter, dir); }return rq_bytes;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1434/1674 blk-cgroup: fix race between policy activation and blkg destruction
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zheng Qixing <[email protected]>
[ Upstream commit 5313d4d41739b0cb63000747c97bb1217ac45f3e ]
When switching an IO scheduler on a block device, blkcg_activate_policy() allocates blkg_policy_data (pd) for all blkgs attached to the queue. However, blkcg_activate_policy() may race with concurrent blkcg deletion, leading to use-after-free and memory leak issues.
The use-after-free occurs in the following race:
T1 (blkcg_activate_policy):
- Successfully allocates pd for blkg1 (loop0->queue, blkcgA)
- Fails to allocate pd for blkg2 (loop0->queue, blkcgB)
- Enters the enomem rollback path to release blkg1 resources
T2 (blkcg deletion):
- blkcgA is deleted concurrently
- blkg1 is freed via blkg_free_workfn()
- blkg1->pd is freed
T1 (continued):
- Rollback path accesses blkg1->pd->online after pd is freed
- Triggers use-after-free
In addition, blkg_free_workfn() frees pd before removing the blkg from q->blkg_list. This allows blkcg_activate_policy() to allocate a new pd for a blkg that is being destroyed, leaving the newly allocated pd unreachable when the blkg is finally freed.
Fix these races by extending blkcg_mutex coverage to serialize blkcg_activate_policy() rollback and blkg destruction, ensuring pd lifecycle is synchronized with blkg list visibility.
--- block/blk-cgroup.c | 3 +++ 1 file changed, 3 insertions(+)
block/blk-cgroup.c +3 -0
@@ -1574,6 +1574,8 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)if (queue_is_mq (q))blk_mq_freeze_queue (q); + +mutex_lock (&q->blkcg_mutex); retry:spin_lock_irq (&q->queue_lock);
@@ -1638,6 +1640,7 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)spin_unlock_irq (&q->queue_lock); out: +mutex_unlock (&q->blkcg_mutex);if (queue_is_mq (q))blk_mq_unfreeze_queue (q);if (pinned_blkg)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1435/1674 HID: steam: Reject short reads
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vicki Pfau <[email protected]>
[ Upstream commit 33ff7b49c38b39b1f3d27db508ac0720fb25c08a ]
Steam Controller FEATURE reports encode the size of the message in the message itself. Previously we were trusting that the size reported matched the size we actually read, leading to a potential issue with short reads. Instead, we should actually verify the length of the read.
--- drivers/hid/hid-steam.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)
drivers/hid/hid-steam.c +31 -3
@@ -323,6 +323,13 @@ static int steam_recv_report(struct steam_device *steam,u8 *buf;int ret; +/* +* All reports start with a two byte header. +* We must read at least two bytes to get a sensible output. +*/ +if (size <2 ) +return -EINVAL ; + r = steam->hdev->report_enum[HID_FEATURE_REPORT ].report_id_hash[0 ];if (!r) {hid_err (steam->hdev,"No HID_FEATURE_REPORT submitted - nothing to read\n" );
@@ -345,10 +352,31 @@ static int steam_recv_report(struct steam_device *steam, ret =hid_hw_raw_request (steam->hdev,0x00 , buf,hid_report_len (r) +1 ,HID_FEATURE_REPORT ,HID_REQ_GET_REPORT ); -if (ret >0 ) -memcpy (data, buf +1 ,min (size, ret -1 )); +if (ret >0 ) { +/* Remove the report ID from the return buffer */ + ret--; + size =min (size, ret); +memcpy (data, buf +1 , size); + }kfree (buf); -return ret; + +if (ret <0 ) +hid_err (steam->hdev,"%s: error %d\n" , __func__, ret); +else +hid_dbg (steam->hdev,"Received report %*ph\n" , size, data); +if (ret <0 ) +return ret; + +if (ret <2 ) { +hid_err (steam->hdev,"%s: reply too short\n" , __func__); +return -EPROTO ; + } +if (ret < data[1 ] +2 ) { +hid_err (steam->hdev,"%s: expected %u bytes, read %i\n" , + __func__, data[1 ] +2 , ret); +return -EPROTO ; + } +return size; } static int steam_send_report(struct steam_device *steam,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1436/1674 HID: logitech-hidpp: Fix FF device cleanup on init failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
[ Upstream commit dd5be4d9ce2dfc4d4a4527ef7d31d21a78e3cdac ]
hidpp_ff_init() creates the input force-feedback device with input_ff_create(), then allocates the HID++ FF private data, effect ID array, and workqueue.
If any of those allocations fail after input_ff_create() succeeds, the function returns an error without destroying the FF device. Add an unwind path that frees the private allocations made by hidpp_ff_init() and calls input_ff_destroy() for failures after input_ff_create() succeeds.
--- drivers/hid/hid-logitech-hidpp.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
drivers/hid/hid-logitech-hidpp.c +16 -7
@@ -2879,18 +2879,19 @@ static int hidpp_ff_init(struct hidpp_device *hidpp,* ownership to FF core */ data =kmemdup (data,sizeof (*data),GFP_KERNEL ); -if (!data) -return -ENOMEM ; +if (!data) { + error = -ENOMEM ; + goto err_destroy_ff; + } data->effect_ids =kcalloc (num_slots,sizeof (int ),GFP_KERNEL );if (!data->effect_ids) { -kfree (data); -return -ENOMEM ; + error = -ENOMEM ; + goto err_free_data; } data->wq =create_singlethread_workqueue ("hidpp-ff-sendqueue" );if (!data->wq) { -kfree (data->effect_ids); -kfree (data); -return -ENOMEM ; + error = -ENOMEM ; + goto err_free_effect_ids; } data->hidpp = hidpp;
@@ -2920,6 +2921,14 @@ static int hidpp_ff_init(struct hidpp_device *hidpp, version);return 0 ; + +err_free_effect_ids: +kfree (data->effect_ids); +err_free_data: +kfree (data); +err_destroy_ff: +input_ff_destroy (dev); +return error; }/* ************************************************************************** */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1437/1674 tty: skip cdev_del() when no cdev is registered
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit c3b5623fd97648f2747444aa8932ae604662df93 ]
TTY device registration can fail before a cdev is allocated. Serial core keeps the port so setserial can still use it, and later removal passes the NULL cdev slot to cdev_del(), causing a NULL-pointer dereference.
Only delete the cdev when the slot is not NULL.
--- drivers/tty/tty_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/tty_io.c +1 -1
@@ -3317,7 +3317,7 @@ EXPORT_SYMBOL_GPL(tty_register_device_attr);void tty_unregister_device (struct tty_driver *driver,unsigned index) {device_destroy (&tty_class,MKDEV (driver->major, driver->minor_start) + index); -if (!(driver->flags &TTY_DRIVER_DYNAMIC_ALLOC )) { +if (!(driver->flags &TTY_DRIVER_DYNAMIC_ALLOC ) && driver->cdevs[index]) {cdev_del (driver->cdevs[index]); driver->cdevs[index] =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1438/1674 serial: core: clear freed pointers on uart_register_driver() failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 61a2fb25551be0375bc16ef2a70c987dfca26183 ]
uart_register_driver() leaves drv->state pointing to freed memory when tty_alloc_driver() fails. If tty_register_driver() fails, drv->tty_driver also retains a pointer after its reference is dropped.
Drivers that use drv->state as an "already registered" flag can then skip registration on the next probe and pass the freed state to uart_add_one_port().
This issue was found with failslab on QEMU's raspi1ap board by failing registration and binding the PL011 port again.
Clear both pointers on their failure paths, as uart_unregister_driver() already does.
--- drivers/tty/serial/serial_core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/tty/serial/serial_core.c +2 -0
@@ -2877,8 +2877,10 @@ int uart_register_driver(struct uart_driver *drv)for (i =0 ; i < drv->nr; i++)tty_port_destroy (&drv->state[i].port);tty_driver_kref_put (normal); + drv->tty_driver =NULL ; out_kfree:kfree (drv->state); + drv->state =NULL ; out:return retval; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1439/1674 serial: core: do fallible allocations before the console can be registered
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 1a0e4fbce5d9c1bc179a35a2fd9ed142664299e3 ]
serial_core_add_one_port() allocates uport->tty_groups after uart_configure_port(), which may register the console. If the allocation fails, the driver unwinds the port while its console remains registered. The earlier uport->name allocation has a related failure path that leaves state->uart_port linked to a port being freed.
Failslab reproduced a NULL dereference in PL011 console output and a KASAN use-after-free in i.MX console output after failed binds.
Allocate the name and tty_groups before linking the port and configuring it. Reserve space for the optional driver attribute group because config_port() may populate uport->attr_group during configuration.
--- drivers/tty/serial/serial_core.c | 37 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/tty/serial/serial_core.c +19 -18
@@ -3160,7 +3160,6 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *ustruct tty_port *port;int ret =0 ;struct device *tty_dev; -int num_groups;if (uport->line >= drv->nr)return -EINVAL ;
@@ -3174,6 +3173,25 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u goto out; } + uport->name =kasprintf (GFP_KERNEL ,"%s%d" , drv->dev_name, + drv->tty_driver->name_base + uport->line); +if (!uport->name) { + ret = -ENOMEM ; + goto out; + } + +/* +* uart_configure_port() may set uport->attr_group and register the +* console. Allocate room for both groups and a NULL terminator first. +*/ + uport->tty_groups =kcalloc (3 ,sizeof (*uport->tty_groups),GFP_KERNEL ); +if (!uport->tty_groups) { +kfree (uport->name); + ret = -ENOMEM ; + goto out; + } + uport->tty_groups[0 ] = &tty_dev_attr_group; +/* Link the port to the driver state table and vice versa */ atomic_set (&state->refcount,1 );init_waitqueue_head (&state->remove_wait);
@@ -3183,12 +3201,6 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u state->pm_state =UART_PM_STATE_UNDEFINED ; uport->cons = drv->cons; uport->minor = drv->tty_driver->minor_start + uport->line; - uport->name =kasprintf (GFP_KERNEL ,"%s%d" , drv->dev_name, - drv->tty_driver->name_base + uport->line); -if (!uport->name) { - ret = -ENOMEM ; - goto out; - }/* * If this port is in use as a console then the spinlock is already
@@ -3205,17 +3217,6 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u port->console =uart_console (uport); - num_groups =2 ; -if (uport->attr_group) - num_groups++; - - uport->tty_groups =kcalloc (num_groups,sizeof (*uport->tty_groups), -GFP_KERNEL ); -if (!uport->tty_groups) { - ret = -ENOMEM ; - goto out; - } - uport->tty_groups[0 ] = &tty_dev_attr_group;if (uport->attr_group) uport->tty_groups[1 ] = uport->attr_group;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1440/1674 wifi: cfg80211: stop PMSR before P2P and NAN teardown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Li <[email protected]>
[ Upstream commit 6c5fc504d0d6934132637aa3db4b9b58148eaa78 ]
PMSR request teardown must abort active measurements while the wireless_dev is still present in the driver. cfg80211_leave_locked() and cfg80211_stop_pd() already do this before invoking the driver's stop callback, but cfg80211_stop_p2p_device() and cfg80211_stop_nan() do not.
Those helpers are also called directly by nl80211, rfkill shutdown, and wireless_dev unregister paths. If one of these paths stops a P2P device or NAN interface with a pending request, it removes the mac80211 subinterface from the driver first. Subsequent request cleanup cannot reach the lower driver's abort callback, but cfg80211 frees the request regardless. Driver state can then retain a stale request and use it when it later reports a result.
Call cfg80211_pmsr_wdev_down() before stopping the P2P device or NAN interface. This keeps lower-driver request state and cfg80211 request ownership in sync for all of the helpers' callers.
--- net/wireless/core.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/wireless/core.c +7 -0
@@ -237,6 +237,9 @@ void cfg80211_stop_p2p_device(struct cfg80211_registered_device *rdev,if (!wdev_running (wdev))return ; +wdev_lock (wdev); +cfg80211_pmsr_wdev_down (wdev); +wdev_unlock (wdev);rdev_stop_p2p_device (rdev, wdev); wdev->is_running = false;
@@ -262,6 +265,10 @@ void cfg80211_stop_nan(struct cfg80211_registered_device *rdev,if (!wdev_running (wdev))return ; +wdev_lock (wdev); +cfg80211_pmsr_wdev_down (wdev); +wdev_unlock (wdev); +rdev_stop_nan (rdev, wdev); wdev->is_running = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1441/1674 wifi: brcmfmac: fix P2P action frame handling without device vif
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason Huang <[email protected]>
[ Upstream commit 1b1edb9ebed49099bdc924cef49a9aea8b552199 ]
Some P2P action frame paths assume the P2P device vif is always available. That is not true when userspace sends non-P2P public action frames through the primary interface, or when action-frame abort runs after the P2P device vif has not been created.
Fall back to the primary vif when aborting an action frame without a P2P device vif, and guard P2P device saved IE access before using it for peer channel search.
--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +4 -0
@@ -1281,6 +1281,9 @@ static s32 brcmf_p2p_abort_action_frame(struct brcmf_cfg80211_info *cfg)brcmf_dbg (TRACE ,"Enter\n" ); vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE ].vif; +if (!vif) + vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY ].vif; + err =brcmf_fil_bsscfg_data_set (vif->ifp,"actframe_abort" , &int_val,sizeof (s32));if (err)
@@ -1817,6 +1820,7 @@ bool brcmf_p2p_send_action_frame(struct brcmf_if *ifp,/* validate channel and p2p ies */ if (config_af_params.search_channel &&IS_P2P_SOCIAL_CHANNEL (le32_to_cpu (af_params->channel)) && + p2p->bss_idx[P2PAPI_BSSCFG_DEVICE ].vif && p2p->bss_idx[P2PAPI_BSSCFG_DEVICE ].vif->saved_ie.probe_req_ie_len) { afx_hdl = &p2p->afx_hdl; afx_hdl->peer_listen_chan =le32_to_cpu (af_params->channel);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1442/1674 wifi: nl80211: check link is beaconing for color change
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit 55308cee9c2196f39cd1ce8ee6c1fed9e12a00d4 ]
When trying to do a color change, validate that the link is beaconing first, to avoid calling the driver with an invalid link.
Stable-dep-of: 927ee844c47a ("wifi: nl80211: clean up color-change beacon data on errors")
--- net/wireless/nl80211.c | 5 +++++ 1 file changed, 5 insertions(+)
net/wireless/nl80211.c +5 -0
@@ -16090,6 +16090,7 @@ static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info)struct net_device *dev = info->user_ptr[1 ];struct wireless_dev *wdev = dev->ieee80211_ptr;struct nlattr **tb; +unsigned int link_id;u16 offset;int err;
@@ -16111,6 +16112,10 @@ static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info) params.count =nla_get_u8 (info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT ]); params.color =nla_get_u8 (info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR ]); + link_id =nl80211_link_id (info->attrs); +if (!wdev->links[link_id].ap.beacon_interval) +return -EINVAL ; + err =nl80211_parse_beacon (rdev, info->attrs, ¶ms.beacon_next, info->extack);if (err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1443/1674 wifi: nl80211: clean up color-change beacon data on errors
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Li <[email protected]>
[ Upstream commit 927ee844c47ac2aef22c8f7a35f098ff576b398b ]
nl80211_color_change() calls nl80211_parse_beacon() for the beacon_next template, which can allocate params.beacon_next.mbssid_ies and .rnr_ies. A parsing failure returned directly instead of using the out: cleanup, leaking any allocations completed before the error.
Allocate the nested attribute table before parsing beacon_next. Its allocation failure can then return before beacon data exists, while a later parsing failure uses out: to release the parsed data.
--- net/wireless/nl80211.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/wireless/nl80211.c +5 -5
@@ -16116,15 +16116,15 @@ static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info)if (!wdev->links[link_id].ap.beacon_interval)return -EINVAL ; - err =nl80211_parse_beacon (rdev, info->attrs, ¶ms.beacon_next, - info->extack); -if (err) -return err; - tb =kcalloc (NL80211_ATTR_MAX +1 ,sizeof (*tb),GFP_KERNEL );if (!tb)return -ENOMEM ; + err =nl80211_parse_beacon (rdev, info->attrs, ¶ms.beacon_next, + info->extack); +if (err) + goto out; + err =nla_parse_nested (tb,NL80211_ATTR_MAX , info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS ], nl80211_policy, info->extack);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1444/1674 arm64: ptrace: Keep orig_x0 in-sync with x0 on syscall entry
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
[ Upstream commit 88b839ce497ccb1ff92f7ae742c78dd2937ba572 ]
Commit e057b9477232 ("arm64: syscall: Ensure saved x0 is kept in-sync with tracer updates") attempted to resolve a long-standing issue with syscall entry tracing, where a tracer is able to manipulate the first syscall argument without being subjected to seccomp or audit checking.
Unfortunately, that fix was incomplete [1], as it failed to update 'orig_x0' between a tracer updating x0 during a seccomp ptrace exit (SECCOMP_RET_TRACE) and the seccomp filter being re-evaluated.
Rather than add hooks to the core seccomp code, instead move the synchronisation code into the ptrace GPR and syscall setting code so that 'orig_x0' is kept up to date with x0 whenever we're stopped on the syscall entry path.
--- arch/arm64/kernel/ptrace.c | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
arch/arm64/kernel/ptrace.c +50 -0
@@ -559,6 +559,42 @@ static int gpr_get(struct task_struct *target,return membuf_write (&to, uregs,sizeof (*uregs)); } +static void update_syscall_orig_x0_after_ptrace (struct task_struct *target) +{ +struct pt_regs *regs =task_pt_regs (target); +struct kernel_siginfo *info = target->last_siginfo; + +/* +* Skip the update for NO_SYSCALL (set either by the user or the +* tracer), as regs[0] holds the return value (see the comment in +* el0_svc_common()) and can be unwound using syscall_rollback(). +*/ +if (regs->syscallno ==NO_SYSCALL ) +return ; + +/* We should only be called when target is in a ptrace stop */ +if (WARN_ON_ONCE (!info)) +return ; + +/* +* For compat tasks, orig_r0 is provided directly through GPR index +* 17. +*/ +if (is_compat_thread (task_thread_info (target))) +return ; + +/* +* Don't update orig_x0 for a syscall-exit-stop, as x0 now contains the +* return value of the system call. +*/ +if ((info->si_code & ~0x80 ) ==SIGTRAP && + target->ptrace_message ==PTRACE_EVENTMSG_SYSCALL_EXIT ) { +return ; + } + + regs->orig_x0 = regs->regs[0 ]; +} +static int gpr_set (struct task_struct *target,const struct user_regset *regset,unsigned int pos,unsigned int count,const void *kbuf,const void __user *ubuf)
@@ -574,6 +610,14 @@ static int gpr_set(struct task_struct *target, const struct user_regset *regset,return -EINVAL ;task_pt_regs (target)->user_regs = newregs; + +/* +* Keep orig_x0 authoritative so that seccomp (via +* syscall_get_arguments()), audit and the restart path all see the same +* first argument the syscall is dispatched with, even if it has been +* updated by a tracer. +*/ +update_syscall_orig_x0_after_ptrace (target);return 0 ; }
@@ -717,6 +761,12 @@ static int system_call_set(struct task_struct *target,return ret;task_pt_regs (target)->syscallno = syscallno; + +/* +* Re-sync orig_x0 in case the syscall number has been changed +* from NO_SYSCALL. +*/ +update_syscall_orig_x0_after_ptrace (target);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1445/1674 bpf, x86: Fix trampoline stack size for 128-bit arguments
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yonghong Song <[email protected]>
[ Upstream commit 814cba835ef648e0c5eb79505c96c0493b29eea6 ]
btf_distill_func_proto() accepts a function argument up to 16 bytes, so a 128-bit scalar such as __int128 reaches the x86 trampoline with arg_size == 16. But the current implementation assumes an __int128 argument only needs one register, so the register save area is under-allocated and save_args() overwrites adjacent stack slots.
Compute the register count from arg_size for all arguments to fix it.
--- arch/x86/net/bpf_jit_comp.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/x86/net/bpf_jit_comp.c +1 -3
@@ -2467,10 +2467,8 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *iu8 *prog;bool save_ret; -/* extra registers for struct arguments */ for (i =0 ; i < m->nr_args; i++) -if (m->arg_flags[i] &BTF_FMODEL_STRUCT_ARG ) - nr_regs += (m->arg_size[i] +7 ) /8 -1 ; + nr_regs += (m->arg_size[i] +7 ) /8 -1 ;/* x86-64 supports up to MAX_BPF_FUNC_ARGS arguments. 1-6 * are passed through regs, the remains are through stack.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1446/1674 wifi: mt76: cancel reset and rc work on device unregister
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit e995d3dccc9d980af13a60ad37409ed1561f9eeb ]
Both drivers cancelled dump_work on unregister but left reset_work and rc_work to be flushed only by destroy_workqueue() in mt76_free_device(), which runs after the hw is unregistered and the hardware stopped. A reset_work that fires in that window calls ieee80211_restart_hw() and re-arms mac_work on an unregistered hw, and rc_work touches station state being torn down. Cancel both up front, alongside dump_work.
--- drivers/net/wireless/mediatek/mt76/mt7915/init.c | 2 ++ drivers/net/wireless/mediatek/mt76/mt7996/init.c | 2 ++ 2 files changed, 4 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7915/init.c +2 -0
@@ -1261,6 +1261,8 @@ int mt7915_register_device(struct mt7915_dev *dev)void mt7915_unregister_device (struct mt7915_dev *dev) {cancel_work_sync (&dev->dump_work); +cancel_work_sync (&dev->reset_work); +cancel_work_sync (&dev->rc_work);mt7915_unregister_ext_phy (dev);mt7915_coredump_unregister (dev);mt7915_unregister_thermal (&dev->phy);
drivers/net/wireless/mediatek/mt76/mt7996/init.c +2 -0
@@ -931,6 +931,8 @@ int mt7996_register_device(struct mt7996_dev *dev)void mt7996_unregister_device (struct mt7996_dev *dev) {cancel_work_sync (&dev->dump_work); +cancel_work_sync (&dev->reset_work); +cancel_work_sync (&dev->rc_work);mt7996_unregister_phy (mt7996_phy3 (dev),MT_BAND2 );mt7996_unregister_phy (mt7996_phy2 (dev),MT_BAND1 );mt7996_coredump_unregister (dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1447/1674 wifi: mt76: mt7996: hold dev->mt76.mutex while disabling tx worker in SER
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit 6190db312b8230813f529f014b26247c6d9800d0 ]
mt7996_mac_reset_work() parked the tx worker and disabled the RX/TX NAPIs before taking dev->mt76.mutex. mt76_worker_disable()/_enable() are plain kthread park/unpark, not refcounted, and __mt76_set_channel() toggles the same worker and the MT76_RESET bit under the mutex. An L1 SER racing a channel switch could therefore have the worker unparked and MT76_RESET cleared while the reset path resets the DMA rings, corrupting descriptors or tokens. Take the mutex before disabling the worker, as mt7915 does.
--- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +3 -2
@@ -1845,13 +1845,14 @@ void mt7996_mac_reset_work(struct work_struct *work)set_bit (MT76_RESET , &phy3->mt76->state);cancel_delayed_work_sync (&phy3->mt76->mac_work); } + +mutex_lock (&dev->mt76.mutex); +mt76_worker_disable (&dev->mt76.tx_worker);mt76_for_each_q_rx (&dev->mt76, i)napi_disable (&dev->mt76.napi[i]);napi_disable (&dev->mt76.tx_napi); -mutex_lock (&dev->mt76.mutex); -mt76_wr (dev,MT_MCU_INT_EVENT ,MT_MCU_INT_EVENT_DMA_STOPPED );if (mt7996_wait_reset_state (dev,MT_MCU_CMD_RESET_DONE )) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1448/1674 wifi: mt76: mt7915: allocate vif wcid in the same range as stations
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit f3049b88b2b32326df97461813ae73e8bbc296fc ]
Reduces the amount of unnecessary WTBL bank switching, while still reserving WTBL entries for vifs.
Stable-dep-of: 2fb6480c52f6 ("wifi: mt76: mt7915: unwind state on add_interface failure")
--- drivers/net/wireless/mediatek/mt76/mt7915/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/main.c +4 -1
@@ -245,7 +245,9 @@ static int mt7915_add_interface(struct ieee80211_hw *hw, dev->mt76.vif_mask |=BIT_ULL (mvif->mt76.idx); phy->omac_mask |=BIT_ULL (mvif->mt76.omac_idx); - idx =MT7915_WTBL_RESERVED - mvif->mt76.idx; + idx =mt76_wcid_alloc (dev->mt76.wcid_mask,mt7915_wtbl_size (dev)); +if (idx <0 ) +return -ENOSPC ;INIT_LIST_HEAD (&mvif->sta.rc_list);INIT_LIST_HEAD (&mvif->sta.wcid.poll_list);
@@ -292,6 +294,7 @@ static void mt7915_remove_interface(struct ieee80211_hw *hw,mt7915_mcu_add_bss_info (phy, vif, false);mt7915_mcu_add_sta (dev, vif,NULL , false); +mt76_wcid_mask_clear (dev->mt76.wcid_mask, mvif->sta.wcid.idx);mutex_lock (&dev->mt76.mutex);mt76_testmode_reset (phy->mt76, true);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1449/1674 wifi: mt76: mt7915: Fix an error handling path in mt7915_add_interface()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christophe JAILLET <[email protected]>
[ Upstream commit 126a516fe30639708e759678bcb10178938cc718 ]
If mt76_wcid_alloc() fails, the "mt76.mutex" mutex needs to be released as done in the other error handling paths of mt7915_add_interface().
Stable-dep-of: 2fb6480c52f6 ("wifi: mt76: mt7915: unwind state on add_interface failure")
--- drivers/net/wireless/mediatek/mt76/mt7915/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/main.c +4 -2
@@ -246,8 +246,10 @@ static int mt7915_add_interface(struct ieee80211_hw *hw, phy->omac_mask |=BIT_ULL (mvif->mt76.omac_idx); idx =mt76_wcid_alloc (dev->mt76.wcid_mask,mt7915_wtbl_size (dev)); -if (idx <0 ) -return -ENOSPC ; +if (idx <0 ) { + ret = -ENOSPC ; + goto out; + }INIT_LIST_HEAD (&mvif->sta.rc_list);INIT_LIST_HEAD (&mvif->sta.wcid.poll_list);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1450/1674 wifi: mt76: mt7915: unwind state on add_interface failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit 2fb6480c52f611338e1b0abe5e6219be1fc9ab75 ]
When mt76_wcid_alloc() fails, mt7915_add_interface() returned without clearing the vif_mask/omac_mask bits it had already set, without removing the firmware dev info added earlier, and without clearing a monitor_vif pointer to the vif mac80211 is about to free. mac80211 does not call remove_interface() for a failed add, so the indices and firmware dev entry leaked permanently and testmode could dereference the stale monitor_vif. Add a proper error unwind.
--- drivers/net/wireless/mediatek/mt76/mt7915/main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/main.c +11 -1
@@ -248,7 +248,7 @@ static int mt7915_add_interface(struct ieee80211_hw *hw, idx =mt76_wcid_alloc (dev->mt76.wcid_mask,mt7915_wtbl_size (dev));if (idx <0 ) { ret = -ENOSPC ; - goto out; + goto err; }INIT_LIST_HEAD (&mvif->sta.rc_list);
@@ -279,7 +279,17 @@ static int mt7915_add_interface(struct ieee80211_hw *hw,mt7915_mcu_add_sta (dev, vif,NULL , true);rcu_assign_pointer (dev->mt76.wcid[idx], &mvif->sta.wcid); +mutex_unlock (&dev->mt76.mutex); + +return 0 ; + +err: + dev->mt76.vif_mask &= ~BIT_ULL (mvif->mt76.idx); + phy->omac_mask &= ~BIT_ULL (mvif->mt76.omac_idx); +mt7915_mcu_add_dev_info (phy, vif, false); out: +if (phy->monitor_vif == vif) + phy->monitor_vif =NULL ;mutex_unlock (&dev->mt76.mutex);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1451/1674 wifi: mt76: fix non-AQL packet accounting for MLO stations
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael-CY Lee <[email protected]>
[ Upstream commit 8ae659743ba936b22ecb4620815887728e2820d6 ]
__mt76_tx_queue_skb() overrides the wcid passed by the driver with sta->drv_priv, so the wcid might incorrectly be changed after TX, causing wcid->non_aql_packets to be counted on the wrong wcid. For example, on the AP side, if a station's setup link is the 5G link and the station uses 2G to transmit a frame, the value of non_aql_packets is increased on the 5G wcid but decreased on the 2G wcid. Once the inflated counter exceeds MT_MAX_NON_AQL_PKT, the TX scheduler permanently refuses to service the station.
Drop the reassignment and account on the wcid used for transmission. This also records the actual wcid in the queue entry.
--- drivers/net/wireless/mediatek/mt76/tx.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/wireless/mediatek/mt76/tx.c +0 -1
@@ -313,7 +313,6 @@ __mt76_tx_queue_skb(struct mt76_phy *phy, int qid, struct sk_buff *skb,if (idx <0 || !sta)return idx; - wcid = (struct mt76_wcid *)sta->drv_priv; q->entry[idx].wcid = wcid->idx;if (!non_aql)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1452/1674 mm/treewide: replace pmd_large() with pmd_leaf()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Xu <[email protected]>
[ Upstream commit 2f709f7bfd3d13f8878070a79e0983b5fac2225f ]
pmd_large() is always defined as pmd_leaf(). Merge their usages. Chose pmd_leaf() because pmd_leaf() is a global API, while pmd_large() is not.
Stable-dep-of: 928a8e9f523d ("misc: sgi-gru: remove interrupt-context page-table walks")
--- arch/arm/mm/dump.c | 4 ++-- arch/powerpc/mm/book3s64/pgtable.c | 2 +- arch/powerpc/mm/book3s64/radix_pgtable.c | 2 +- arch/powerpc/mm/pgtable_64.c | 2 +- arch/s390/boot/vmem.c | 2 +- arch/s390/include/asm/pgtable.h | 8 ++++---- arch/s390/mm/gmap.c | 12 ++++++------ arch/s390/mm/hugetlbpage.c | 2 +- arch/s390/mm/pageattr.c | 2 +- arch/s390/mm/pgtable.c | 6 +++--- arch/s390/mm/vmem.c | 6 +++--- arch/sparc/mm/init_64.c | 4 ++-- arch/x86/boot/compressed/ident_map_64.c | 2 +- arch/x86/kvm/mmu/mmu.c | 2 +- arch/x86/mm/fault.c | 8 ++++---- arch/x86/mm/init_32.c | 2 +- arch/x86/mm/init_64.c | 8 ++++---- arch/x86/mm/kasan_init_64.c | 2 +- arch/x86/mm/mem_encrypt_identity.c | 4 ++-- arch/x86/mm/pat/set_memory.c | 4 ++-- arch/x86/mm/pgtable.c | 2 +- arch/x86/mm/pti.c | 4 ++-- arch/x86/power/hibernate.c | 2 +- arch/x86/xen/mmu_pv.c | 4 ++-- drivers/misc/sgi-gru/grufault.c | 2 +- 25 files changed, 49 insertions(+), 49 deletions(-)
arch/arm/mm/dump.c +2 -2
@@ -349,12 +349,12 @@ static void walk_pmd(struct pg_state *st, pud_t *pud, unsigned long start)for (i =0 ; i <PTRS_PER_PMD ; i++, pmd++) { addr = start + i *PMD_SIZE ; domain =get_domain_name (pmd); -if (pmd_none (*pmd) ||pmd_large (*pmd) || !pmd_present (*pmd)) +if (pmd_none (*pmd) ||pmd_leaf (*pmd) || !pmd_present (*pmd))note_page (st, addr,4 ,pmd_val (*pmd), domain);else walk_pte (st, pmd, addr, domain); -if (SECTION_SIZE <PMD_SIZE &&pmd_large (pmd[1 ])) { +if (SECTION_SIZE <PMD_SIZE &&pmd_leaf (pmd[1 ])) { addr +=SECTION_SIZE ; pmd++; domain =get_domain_name (pmd);
arch/powerpc/mm/book3s64/pgtable.c +1 -1
@@ -113,7 +113,7 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,WARN_ON (pte_hw_valid (pmd_pte (*pmdp)) && !pte_protnone (pmd_pte (*pmdp)));assert_spin_locked (pmd_lockptr (mm, pmdp)); -WARN_ON (!(pmd_large (pmd))); +WARN_ON (!(pmd_leaf (pmd)));#endif trace_hugepage_set_pmd (addr,pmd_val (pmd));return set_pte_at (mm, addr,pmdp_ptep (pmdp),pmd_pte (pmd));
arch/powerpc/mm/book3s64/radix_pgtable.c +1 -1
@@ -1001,7 +1001,7 @@ bool vmemmap_can_optimize(struct vmem_altmap *altmap, struct dev_pagemap *pgmap)int __meminit vmemmap_check_pmd (pmd_t *pmdp,int node,unsigned long addr,unsigned long next) { -int large =pmd_large (*pmdp); +int large =pmd_leaf (*pmdp);if (large)vmemmap_verify (pmdp_ptep (pmdp), node, addr, next);
arch/powerpc/mm/pgtable_64.c +1 -1
@@ -132,7 +132,7 @@ struct page *pmd_page(pmd_t pmd)* enabled so these checks can't be used. */ if (!IS_ENABLED (CONFIG_HAVE_ARCH_HUGE_VMAP )) -VM_WARN_ON (!(pmd_large (pmd) ||pmd_huge (pmd))); +VM_WARN_ON (!(pmd_leaf (pmd) ||pmd_huge (pmd)));return pte_page (pmd_pte (pmd)); }return virt_to_page (pmd_page_vaddr (pmd));
arch/s390/boot/vmem.c +1 -1
@@ -327,7 +327,7 @@ static void pgtable_pmd_populate(pud_t *pud, unsigned long addr, unsigned long e } pte =boot_pte_alloc ();pmd_populate (&init_mm, pmd, pte); - }else if (pmd_large (*pmd)) { + }else if (pmd_leaf (*pmd)) {continue ; }pgtable_pte_populate (pmd, addr, next, mode);
arch/s390/include/asm/pgtable.h +4 -4
@@ -730,7 +730,7 @@ static inline int pmd_large(pmd_t pmd)static inline int pmd_bad (pmd_t pmd) { -if ((pmd_val (pmd) & _SEGMENT_ENTRY_TYPE_MASK) >0 ||pmd_large (pmd)) +if ((pmd_val (pmd) & _SEGMENT_ENTRY_TYPE_MASK) >0 ||pmd_leaf (pmd))return 1 ;return (pmd_val (pmd) & ~_SEGMENT_ENTRY_BITS) !=0 ; }
@@ -828,8 +828,8 @@ static inline int pte_protnone(pte_t pte)static inline int pmd_protnone (pmd_t pmd) { -/* pmd_large(pmd) implies pmd_present(pmd) */ -return pmd_large (pmd) && !(pmd_val (pmd) & _SEGMENT_ENTRY_READ); +/* pmd_leaf(pmd) implies pmd_present(pmd) */ +return pmd_leaf (pmd) && !(pmd_val (pmd) & _SEGMENT_ENTRY_READ); }#endif
@@ -1389,7 +1389,7 @@ static inline unsigned long pmd_deref(pmd_t pmd)unsigned long origin_mask; origin_mask = _SEGMENT_ENTRY_ORIGIN; -if (pmd_large (pmd)) +if (pmd_leaf (pmd)) origin_mask = _SEGMENT_ENTRY_ORIGIN_LARGE;return (unsigned long )__va (pmd_val (pmd) & origin_mask); }
arch/s390/mm/gmap.c +6 -6
@@ -601,7 +601,7 @@ int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr) pmd =pmd_offset (pud, vmaddr);VM_BUG_ON (pmd_none (*pmd));/* Are we allowed to use huge pages? */ -if (pmd_large (*pmd) && !gmap->mm->context.allow_gmap_hpage_1m) +if (pmd_leaf (*pmd) && !gmap->mm->context.allow_gmap_hpage_1m)return -EFAULT ;/* Link gmap segment table entry location to page table. */ rc =radix_tree_preload (GFP_KERNEL_ACCOUNT );
@@ -613,7 +613,7 @@ int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr) rc =radix_tree_insert (&gmap->host_to_guest, vmaddr >>PMD_SHIFT , table);if (!rc) { -if (pmd_large (*pmd)) { +if (pmd_leaf (*pmd)) { *table = (pmd_val (*pmd) & _SEGMENT_ENTRY_HARDWARE_BITS_LARGE) | _SEGMENT_ENTRY_GMAP_UC;
@@ -943,7 +943,7 @@ static inline pmd_t *gmap_pmd_op_walk(struct gmap *gmap, unsigned long gaddr) }/* 4k page table entries are locked via the pte (pte_alloc_map_lock). */ -if (!pmd_large (*pmdp)) +if (!pmd_leaf (*pmdp))spin_unlock (&gmap->guest_table_lock);return pmdp; }
@@ -955,7 +955,7 @@ static inline pmd_t *gmap_pmd_op_walk(struct gmap *gmap, unsigned long gaddr)*/ static inline void gmap_pmd_op_end (struct gmap *gmap,pmd_t *pmdp) { -if (pmd_large (*pmdp)) +if (pmd_leaf (*pmdp))spin_unlock (&gmap->guest_table_lock); }
@@ -1066,7 +1066,7 @@ static int gmap_protect_range(struct gmap *gmap, unsigned long gaddr, rc = -EAGAIN ; pmdp =gmap_pmd_op_walk (gmap, gaddr);if (pmdp) { -if (!pmd_large (*pmdp)) { +if (!pmd_leaf (*pmdp)) { rc =gmap_protect_pte (gmap, gaddr, pmdp, prot, bits);if (!rc) {
@@ -2498,7 +2498,7 @@ void gmap_sync_dirty_log_pmd(struct gmap *gmap, unsigned long bitmap[4],if (!pmdp)return ; -if (pmd_large (*pmdp)) { +if (pmd_leaf (*pmdp)) {if (gmap_test_and_clear_dirty_pmd (gmap, pmdp, gaddr))bitmap_fill (bitmap, _PAGE_ENTRIES); }else {
arch/s390/mm/hugetlbpage.c +1 -1
@@ -235,7 +235,7 @@ pte_t *huge_pte_offset(struct mm_struct *mm,int pmd_huge (pmd_t pmd) { -return pmd_large (pmd); +return pmd_leaf (pmd); }int pud_huge (pud_t pud)
arch/s390/mm/pageattr.c +1 -1
@@ -185,7 +185,7 @@ static int walk_pmd_level(pud_t *pudp, unsigned long addr, unsigned long end,if (pmd_none (*pmdp))return -EINVAL ; next =pmd_addr_end (addr, end); -if (pmd_large (*pmdp)) { +if (pmd_leaf (*pmdp)) { need_split = !!(flags &SET_MEMORY_4K ); need_split |= !!(addr & ~PMD_MASK ); need_split |= !!(addr +PMD_SIZE > next);
arch/s390/mm/pgtable.c +3 -3
@@ -836,7 +836,7 @@ int set_guest_storage_key(struct mm_struct *mm, unsigned long addr,return key ? -EFAULT :0 ; } -if (pmd_large (*pmdp)) { +if (pmd_leaf (*pmdp)) { paddr =pmd_val (*pmdp) &HPAGE_MASK ; paddr |= addr & ~HPAGE_MASK ;/*
@@ -947,7 +947,7 @@ int reset_guest_reference_bit(struct mm_struct *mm, unsigned long addr)return 0 ; } -if (pmd_large (*pmdp)) { +if (pmd_leaf (*pmdp)) { paddr =pmd_val (*pmdp) &HPAGE_MASK ; paddr |= addr & ~HPAGE_MASK ; cc =page_reset_referenced (paddr);
@@ -1011,7 +1011,7 @@ int get_guest_storage_key(struct mm_struct *mm, unsigned long addr,return 0 ; } -if (pmd_large (*pmdp)) { +if (pmd_leaf (*pmdp)) { paddr =pmd_val (*pmdp) &HPAGE_MASK ; paddr |= addr & ~HPAGE_MASK ; *key =page_get_storage_key (paddr);
arch/s390/mm/vmem.c +3 -3
@@ -229,7 +229,7 @@ static int __ref modify_pmd_table(pud_t *pud, unsigned long addr,if (!add) {if (pmd_none (*pmd))continue ; -if (pmd_large (*pmd)) { +if (pmd_leaf (*pmd)) {if (IS_ALIGNED (addr,PMD_SIZE ) &&IS_ALIGNED (next,PMD_SIZE )) {if (!direct)
@@ -274,7 +274,7 @@ static int __ref modify_pmd_table(pud_t *pud, unsigned long addr,if (!pte) goto out;pmd_populate (&init_mm, pmd, pte); - }else if (pmd_large (*pmd)) { + }else if (pmd_leaf (*pmd)) {if (!direct)vmemmap_use_sub_pmd (addr, next);continue ;
@@ -597,7 +597,7 @@ pte_t *vmem_get_alloc_pte(unsigned long addr, bool alloc)if (!pte) goto out;pmd_populate (&init_mm, pmd, pte); - }else if (WARN_ON_ONCE (pmd_large (*pmd))) { + }else if (WARN_ON_ONCE (pmd_leaf (*pmd))) { goto out; } ptep =pte_offset_kernel (pmd, addr);
arch/sparc/mm/init_64.c +2 -2
@@ -1672,7 +1672,7 @@ bool kern_addr_valid(unsigned long addr)if (pmd_none (*pmd))return false; -if (pmd_large (*pmd)) +if (pmd_leaf (*pmd))return pfn_valid (pmd_pfn (*pmd)); pte =pte_offset_kernel (pmd, addr);
@@ -2968,7 +2968,7 @@ void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr,struct mm_struct *mm;pmd_t entry = *pmd; -if (!pmd_large (entry) || !pmd_young (entry)) +if (!pmd_leaf (entry) || !pmd_young (entry))return ; pte =pmd_val (entry);
arch/x86/boot/compressed/ident_map_64.c +1 -1
@@ -284,7 +284,7 @@ static int set_clr_page_flags(struct x86_mapping_info *info, pudp =pud_offset (p4dp, address); pmdp =pmd_offset (pudp, address); -if (pmd_large (*pmdp)) +if (pmd_leaf (*pmdp)) ptep =split_large_pmd (info, pmdp, address);else ptep =pte_offset_kernel (pmdp, address);
arch/x86/kvm/mmu/mmu.c +1 -1
@@ -3135,7 +3135,7 @@ static int host_pfn_mapping_level(struct kvm *kvm, gfn_t gfn,if (pmd_none (pmd) || !pmd_present (pmd)) goto out; -if (pmd_large (pmd)) +if (pmd_leaf (pmd)) level =PG_LEVEL_2M ; out:
arch/x86/mm/fault.c +4 -4
@@ -250,7 +250,7 @@ static noinline int vmalloc_fault(unsigned long address)if (!pmd_k)return -1 ; -if (pmd_large (*pmd_k)) +if (pmd_leaf (*pmd_k))return 0 ; pte_k =pte_offset_kernel (pmd_k, address);
@@ -319,7 +319,7 @@ static void dump_pagetable(unsigned long address)* And let's rather not kmap-atomic the pte, just in case * it's allocated already: */ -if (!low_pfn (pmd_pfn (*pmd)) || !pmd_present (*pmd) ||pmd_large (*pmd)) +if (!low_pfn (pmd_pfn (*pmd)) || !pmd_present (*pmd) ||pmd_leaf (*pmd)) goto out; pte =pte_offset_kernel (pmd, address);
@@ -384,7 +384,7 @@ static void dump_pagetable(unsigned long address) goto bad;pr_cont ("PMD %lx " ,pmd_val (*pmd)); -if (!pmd_present (*pmd) ||pmd_large (*pmd)) +if (!pmd_present (*pmd) ||pmd_leaf (*pmd)) goto out; pte =pte_offset_kernel (pmd, address);
@@ -1011,7 +1011,7 @@ spurious_kernel_fault(unsigned long error_code, unsigned long address)if (!pmd_present (*pmd))return 0 ; -if (pmd_large (*pmd)) +if (pmd_leaf (*pmd))return spurious_kernel_fault_check (error_code, (pte_t *) pmd); pte =pte_offset_kernel (pmd, address);
arch/x86/mm/init_32.c +1 -1
@@ -463,7 +463,7 @@ void __init native_pagetable_init(void)break ;/* should not be large page here */ -if (pmd_large (*pmd)) { +if (pmd_leaf (*pmd)) {pr_warn ("try to clear pte for ram above max_low_pfn: pfn: %lx pmd: %p pmd phys: %lx, but pmd is big page and is not using pte !\n" , pfn, pmd,__pa (pmd));BUG_ON (1 );
arch/x86/mm/init_64.c +4 -4
@@ -548,7 +548,7 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long paddr, unsigned long paddr_end, }if (!pmd_none (*pmd)) { -if (!pmd_large (*pmd)) { +if (!pmd_leaf (*pmd)) {spin_lock (&init_mm.page_table_lock); pte = (pte_t *)pmd_page_vaddr (*pmd); paddr_last = phys_pte_init(pte, paddr,
@@ -1145,7 +1145,7 @@ remove_pmd_table(pmd_t *pmd_start, unsigned long addr, unsigned long end,if (!pmd_present (*pmd))continue ; -if (pmd_large (*pmd)) { +if (pmd_leaf (*pmd)) {if (IS_ALIGNED (addr,PMD_SIZE ) &&IS_ALIGNED (next,PMD_SIZE )) {if (!direct)
@@ -1553,9 +1553,9 @@ void __meminit vmemmap_set_pmd(pmd_t *pmd, void *p, int node,int __meminit vmemmap_check_pmd (pmd_t *pmd,int node,unsigned long addr,unsigned long next) { -int large =pmd_large (*pmd); +int large =pmd_leaf (*pmd); -if (pmd_large (*pmd)) { +if (pmd_leaf (*pmd)) {vmemmap_verify ((pte_t *)pmd, node, addr, next);vmemmap_use_sub_pmd (addr, next); }
arch/x86/mm/kasan_init_64.c +1 -1
@@ -95,7 +95,7 @@ static void __init kasan_populate_pud(pud_t *pud, unsigned long addr, pmd =pmd_offset (pud, addr);do { next =pmd_addr_end (addr, end); -if (!pmd_large (*pmd)) +if (!pmd_leaf (*pmd))kasan_populate_pmd (pmd, addr, next, nid); }while (pmd++, addr = next, addr != end); }
arch/x86/mm/mem_encrypt_identity.c +2 -2
@@ -157,7 +157,7 @@ static void __head sme_populate_pgd_large(struct sme_populate_pgd_data *ppd)return ; pmd =pmd_offset (pud, ppd->vaddr); -if (pmd_large (*pmd)) +if (pmd_leaf (*pmd))return ;set_pmd (pmd,__pmd (ppd->paddr | ppd->pmd_flags));
@@ -181,7 +181,7 @@ static void __head sme_populate_pgd(struct sme_populate_pgd_data *ppd)set_pmd (pmd,__pmd (PMD_FLAGS |__pa (pte))); } -if (pmd_large (*pmd)) +if (pmd_leaf (*pmd))return ; pte =pte_offset_kernel (pmd, ppd->vaddr);
arch/x86/mm/pat/set_memory.c +2 -2
@@ -709,7 +709,7 @@ pte_t *lookup_address_in_pgd_attr(pgd_t *pgd, unsigned long address,return NULL ; *level =PG_LEVEL_2M ; -if (pmd_large (*pmd) || !pmd_present (*pmd)) +if (pmd_leaf (*pmd) || !pmd_present (*pmd))return (pte_t *)pmd; *nx |=pmd_flags (*pmd) & _PAGE_NX;
@@ -1267,7 +1267,7 @@ static void unmap_pmd_range(pud_t *pud, unsigned long start, unsigned long end)* Try to unmap in 2M chunks. */ while (end - start >=PMD_SIZE ) { -if (pmd_large (*pmd)) +if (pmd_leaf (*pmd))pmd_clear (pmd);else __unmap_pmd_range (pud, pmd, start, start +PMD_SIZE );
arch/x86/mm/pgtable.c +1 -1
@@ -791,7 +791,7 @@ int pud_clear_huge(pud_t *pud)*/ int pmd_clear_huge (pmd_t *pmd) { -if (pmd_large (*pmd)) { +if (pmd_leaf (*pmd)) {pmd_clear (pmd);return 1 ; }
arch/x86/mm/pti.c +2 -2
@@ -252,7 +252,7 @@ static pte_t *pti_user_pagetable_walk_pte(unsigned long address, bool late_text)return NULL ;/* Large PMD mapping found */ -if (pmd_large (*pmd)) { +if (pmd_leaf (*pmd)) {/* Clear the PMD if we hit a large mapping from the first round */ if (late_text) {set_pmd (pmd,__pmd (0 ));
@@ -346,7 +346,7 @@ pti_clone_pgtable(unsigned long start, unsigned long end,continue ; } -if (pmd_large (*pmd) || level ==PTI_CLONE_PMD ) { +if (pmd_leaf (*pmd) || level ==PTI_CLONE_PMD ) { target_pmd =pti_user_pagetable_walk_pmd (addr);if (WARN_ON (!target_pmd))return ;
arch/x86/power/hibernate.c +1 -1
@@ -175,7 +175,7 @@ int relocate_restore_code(void) goto out; } pmd =pmd_offset (pud, relocated_restore_code); -if (pmd_large (*pmd)) { +if (pmd_leaf (*pmd)) {set_pmd (pmd,__pmd (pmd_val (*pmd) & ~_PAGE_NX)); goto out; }
arch/x86/xen/mmu_pv.c +2 -2
@@ -1112,7 +1112,7 @@ static void __init xen_cleanmfnmap_pmd(pmd_t *pmd, bool unpin)pte_t *pte_tbl;int i; -if (pmd_large (*pmd)) { +if (pmd_leaf (*pmd)) { pa =pmd_val (*pmd) &PHYSICAL_PAGE_MASK ;xen_free_ro_pages (pa,PMD_SIZE );return ;
@@ -1924,7 +1924,7 @@ static phys_addr_t __init xen_early_virt_to_phys(unsigned long vaddr)if (!pmd_present (pmd))return 0 ; pa =pmd_val (pmd) &PTE_PFN_MASK ; -if (pmd_large (pmd)) +if (pmd_leaf (pmd))return pa + (vaddr & ~PMD_MASK ); pte = native_make_pte(xen_read_phys_ulong(pa + pte_index(vaddr) *
drivers/misc/sgi-gru/grufault.c +1 -1
@@ -227,7 +227,7 @@ static int atomic_pte_lookup(struct vm_area_struct *vma, unsigned long vaddr,if (unlikely (pmd_none (*pmdp))) goto err;#ifdef CONFIG_X86_64 -if (unlikely (pmd_large (*pmdp))) +if (unlikely (pmd_leaf (*pmdp))) pte =ptep_get ((pte_t *)pmdp); else#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1453/1674 misc: sgi-gru: remove interrupt-context page-table walks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Usama Anjum <[email protected]>
[ Upstream commit 928a8e9f523df845fc496bcb9811013b67aabec5 ]
The GRU TLB miss handler walks a process's page tables without holding page-table locks or a reference to the mapped page. It also uses a kernel page-table accessor on user page tables and supports only PMD-level large mappings on x86-64.
Remove the direct walker. Send interrupt faults directly to user polling mode so the existing call-OS fallback retries them in process context.
Remove the mmap-lock failure statistic that can no longer be incremented.
--- drivers/misc/sgi-gru/grufault.c | 101 ++++--------------------------- drivers/misc/sgi-gru/gruprocfs.c | 1 - drivers/misc/sgi-gru/grutables.h | 1 - 3 files changed, 12 insertions(+), 91 deletions(-)
drivers/misc/sgi-gru/grufault.c +12 -89
@@ -166,13 +166,8 @@ static void get_clear_fault_map(struct gru_state *gru, }/* -* Atomic (interrupt context) & non-atomic (user context) functions to -* convert a vaddr into a physical address. The size of the page -* is returned in pageshift. -* returns: -* 0 - successful -* < 0 - error code -* 1 - (atomic only) try again in non-atomic context +* Convert a user virtual address to a physical address in process context. +* The size of the page is returned in pageshift. */ static int non_atomic_pte_lookup(struct vm_area_struct *vma, unsigned long vaddr, int write,
@@ -192,87 +187,25 @@ static int non_atomic_pte_lookup(struct vm_area_struct *vma,return 0 ; } -/* -* atomic_pte_lookup -* -* Convert a user virtual address to a physical address -* Only supports Intel large pages (2MB only) on x86_64. -* ZZZ - hugepage support is incomplete -* -* NOTE: mmap_lock is already held on entry to this function. This -* guarantees existence of the page tables. -*/ -static int atomic_pte_lookup (struct vm_area_struct *vma,unsigned long vaddr, -int write,unsigned long *paddr,int *pageshift) -{ -pgd_t *pgdp; -p4d_t *p4dp; -pud_t *pudp; -pmd_t *pmdp; -pte_t pte; - - pgdp =pgd_offset (vma->vm_mm, vaddr); -if (unlikely (pgd_none (*pgdp))) - goto err; - - p4dp =p4d_offset (pgdp, vaddr); -if (unlikely (p4d_none (*p4dp))) - goto err; - - pudp =pud_offset (p4dp, vaddr); -if (unlikely (pud_none (*pudp))) - goto err; - - pmdp =pmd_offset (pudp, vaddr); -if (unlikely (pmd_none (*pmdp))) - goto err; -#ifdef CONFIG_X86_64 -if (unlikely (pmd_leaf (*pmdp))) - pte =ptep_get ((pte_t *)pmdp); - else -#endif - pte = *pte_offset_kernel (pmdp, vaddr); - -if (unlikely (!pte_present (pte) || - (write && (!pte_write (pte) || !pte_dirty (pte))))) -return 1 ; - - *paddr =pte_pfn (pte) <<PAGE_SHIFT ; -#ifdef CONFIG_HUGETLB_PAGE - *pageshift =is_vm_hugetlb_page (vma) ?HPAGE_SHIFT :PAGE_SHIFT ; -#else - *pageshift =PAGE_SHIFT ; -#endif -return 0 ; - -err: -return 1 ; -} -static int gru_vtop (struct gru_thread_state *gts,unsigned long vaddr,int write,int atomic,unsigned long *gpa,int *pageshift) {struct mm_struct *mm = gts->ts_mm;struct vm_area_struct *vma;unsigned long paddr; -int ret, ps; +int ps; vma =find_vma (mm, vaddr);if (!vma) goto inval; -/* -* Atomic lookup is faster & usually works even if called in non-atomic -* context. -*/ -rmb ();/* Must/check ms_range_active before loading PTEs */ - ret =atomic_pte_lookup (vma, vaddr, write, &paddr, &ps); -if (ret) { -if (atomic) - goto upm; -if (non_atomic_pte_lookup (vma, vaddr, write, &paddr, &ps)) - goto inval; - } +if (atomic) + goto upm; + +/* Order the caller's ms_range_active check before loading PTEs. */ +rmb (); +if (non_atomic_pte_lookup (vma, vaddr, write, &paddr, &ps)) + goto inval;if (is_gru_paddr (paddr)) goto inval; paddr = paddr & ~((1UL << ps) -1 );
@@ -569,19 +502,9 @@ static irqreturn_t gru_intr(int chiplet, int blade)continue ; } -/* -* This is running in interrupt context. Trylock the mmap_lock. -* If it fails, retry the fault in user context. -*/ +/* Address translation may sleep, so retry the fault in user context. */ gts->ustats.fmm_tlbmiss++; -if (!gts->ts_force_cch_reload && -mmap_read_trylock (gts->ts_mm)) { -gru_try_dropin (gru, gts, tfh,NULL ); -mmap_read_unlock (gts->ts_mm); - }else { -tfh_user_polling_mode (tfh); -STAT (intr_mm_lock_failed); - } +tfh_user_polling_mode (tfh); }return IRQ_HANDLED ; }
drivers/misc/sgi-gru/gruprocfs.c +0 -1
@@ -54,7 +54,6 @@ static int statistics_show(struct seq_file *s, void *p)printstat (s, intr_cbr);printstat (s, intr_tfh);printstat (s, intr_spurious); -printstat (s, intr_mm_lock_failed);printstat (s, call_os);printstat (s, call_os_wait_queue);printstat (s, user_flush_tlb);
drivers/misc/sgi-gru/grutables.h +0 -1
@@ -182,7 +182,6 @@ struct gru_stats_s {atomic_long_t intr_cbr;atomic_long_t intr_tfh;atomic_long_t intr_spurious; -atomic_long_t intr_mm_lock_failed;atomic_long_t call_os;atomic_long_t call_os_wait_queue;atomic_long_t user_flush_tlb;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1454/1674 md/raid1: create serial pool adding rdev to array with serialize_policy=1
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Wilck <[email protected]>
[ Upstream commit 140234b2380ffb8ffb0cfc46fee0e822f43adef7 ]
The following bug has been observed with kernel 7.1.3 after adding a new rdev to an existing RAID1 array with serialize_policy enabled:
Oops: 0002 [#1] CPU: 0 UID: 0 PID: 19639 Comm: ext4lazyinit Not tainted 7.1.3-1-default RIP: _raw_spin_lock_irqsave+0x27/0x50 CR2: 0000000000004960 Call Trace: wait_for_serialization+0xb9/0x260 [raid1] raid1_make_request+0x762/0xaff [raid1] md_handle_request+0x1c9/0x2e0 [md_mod]
The raid1.c code calls wait_for_serialization() if the MD_SERIALIZE_POLICY is set, and wait_for_serialization assumes that rdev->serial is initialized. Normally this will be the case for arrays that have the serialize_policy sysfs attribute set to 1.
But when a new rdev is added to an existing array in bind_rdev_to_array(), the condition at mddev_create_serial_pool() causes creation of rdev->serial to be skipped. Fix it.
--- drivers/md/md.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/md.c +2 -1
@@ -211,7 +211,8 @@ void mddev_create_serial_pool(struct mddev *mddev, struct md_rdev *rdev, {int ret =0 ; -if (rdev && !rdev_need_serial (rdev) && +if (!mddev->serialize_policy && + rdev && !rdev_need_serial (rdev) && !test_bit (CollisionCheck, &rdev->flags))return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1455/1674 firmware: qcom: scm: Fix NULL dereference in IRQ handler before __scm is published
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mukesh Ojha <[email protected]>
[ Upstream commit 966d23c7e68ea32679275a7e3d2383181002c868 ]
In qcom_scm_probe(), devm_request_threaded_irq() is called before smp_store_release(&__scm, scm). Two paths can dereference __scm before it is published, both causing a NULL pointer dereference.
The IRQ handler receives scm via its data argument but passes only wq_ctx to qcom_scm_waitq_wakeup() and qcom_scm_get_completion(), which then dereference __scm directly. Thread scm through both functions so the IRQ handler path never touches __scm.
Non-atomic SMC calls made during probe (e.g. from qcom_tzmem_init via qcom_scm_shm_bridge_enable) can return WAITQ_SLEEP, causing qcom_scm_wait_for_wq_completion() to run before __scm is published and dereference it. Add platform_set_drvdata(pdev, scm) early in probe and change qcom_scm_wait_for_wq_completion() to take the device pointer and use dev_get_drvdata() to reach scm, removing any dependency on __scm.
--- drivers/firmware/qcom_scm-smc.c | 2 +- drivers/firmware/qcom_scm.c | 8 +++++--- drivers/firmware/qcom_scm.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-)
drivers/firmware/qcom_scm-smc.c +1 -1
@@ -103,7 +103,7 @@ static int __scm_smc_do_quirk_handle_waitq(struct device *dev, struct arm_smccc_ wq_ctx = res->a1; smc_call_ctx = res->a2; - ret =qcom_scm_wait_for_wq_completion (wq_ctx); + ret =qcom_scm_wait_for_wq_completion (dev, wq_ctx);if (ret)return ret;
drivers/firmware/qcom_scm.c +5 -3
@@ -1358,15 +1358,16 @@ static int qcom_scm_assert_valid_wq_ctx(u32 wq_ctx)return 0 ; } -int qcom_scm_wait_for_wq_completion (u32 wq_ctx) +int qcom_scm_wait_for_wq_completion (struct device *dev,u32 wq_ctx) { +struct qcom_scm *scm =dev_get_drvdata (dev);int ret; ret =qcom_scm_assert_valid_wq_ctx (wq_ctx);if (ret)return ret; -wait_for_completion (&__scm->waitq_comp); +wait_for_completion (&scm->waitq_comp);return 0 ; }
@@ -1379,7 +1380,7 @@ static int qcom_scm_waitq_wakeup(struct qcom_scm *scm, unsigned int wq_ctx)if (ret)return ret; -complete (&__scm->waitq_comp); +complete (&scm->waitq_comp);return 0 ; }
@@ -1422,6 +1423,7 @@ static int qcom_scm_probe(struct platform_device *pdev)return -ENOMEM ; scm->dev = &pdev->dev; +platform_set_drvdata (pdev, scm); ret =qcom_scm_find_dload_address (&pdev->dev, &scm->dload_mode_addr);if (ret <0 )return ret;
drivers/firmware/qcom_scm.h +1 -1
@@ -60,7 +60,7 @@ struct qcom_scm_res {u64 result[MAX_QCOM_SCM_RETS ]; }; -int qcom_scm_wait_for_wq_completion (u32 wq_ctx); +int qcom_scm_wait_for_wq_completion (struct device *dev,u32 wq_ctx);int scm_get_wq_ctx (u32 *wq_ctx,u32 *flags,u32 *more_pending);#define SCM_SMC_FNID (s, c) ((((s) & 0xFF) << 8) | ((c) & 0xFF))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1456/1674 wifi: ath11k: fix stride mismatch in mac_phy_caps_parse()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Johnson <[email protected]>
[ Upstream commit 7a246c72132eb943b5844ba79dad597b47429dba ]
Currently, in ath11k_wmi_tlv_mac_phy_caps_parse(), kcalloc() sizes the mac_phy_caps buffer as tot_phy_id * len, where len is clamped to min(firmware_len, sizeof(struct wmi_mac_phy_capabilities)). The subsequent memcpy() destination advances by sizeof(full struct) per slot via C pointer arithmetic, not by the clamped len. When firmware sends short TLVs, the second and later slots are written past the end of the allocation.
The reader in ath11k_pull_mac_phy_cap_svc_ready_ext() also indexes the buffer with full-struct pointer arithmetic, so the allocation must match that stride.
Fix by using kzalloc_objs(), which derives the element size from the pointer type, making allocation size and pointer stride provably consistent regardless of what len the firmware provides.
Compile tested only.
--- drivers/net/wireless/ath/ath11k/wmi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/wireless/ath/ath11k/wmi.c +5 -3
@@ -4649,14 +4649,16 @@ static int ath11k_wmi_tlv_mac_phy_caps_parse(struct ath11k_base *soc,if (svc_rdy_ext->n_mac_phy_caps >= svc_rdy_ext->tot_phy_id)return -ENOBUFS ; - len =min_t (u16, len,sizeof (struct wmi_mac_phy_capabilities ));if (!svc_rdy_ext->n_mac_phy_caps) { - svc_rdy_ext->mac_phy_caps =kcalloc (svc_rdy_ext->tot_phy_id, - len,GFP_ATOMIC ); + svc_rdy_ext->mac_phy_caps = +kcalloc (svc_rdy_ext->tot_phy_id, +sizeof (*svc_rdy_ext->mac_phy_caps), +GFP_ATOMIC );if (!svc_rdy_ext->mac_phy_caps)return -ENOMEM ; } + len =min_t (u16, len,sizeof (struct wmi_mac_phy_capabilities ));memcpy (svc_rdy_ext->mac_phy_caps + svc_rdy_ext->n_mac_phy_caps, ptr, len); svc_rdy_ext->n_mac_phy_caps++;return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1457/1674 wifi: ath12k: fix stride mismatch in mac_phy_caps_parse()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Johnson <[email protected]>
[ Upstream commit 4c6eb712a91fa079be6f9f1419c96e0ad2227081 ]
Currently, in ath12k_wmi_mac_phy_caps_parse(), kzalloc() sizes the mac_phy_caps buffer as tot_phy_id * len, where len is clamped to min(firmware_len, sizeof(struct ath12k_wmi_mac_phy_caps_params)). The subsequent memcpy() destination advances by sizeof(full struct) per slot via C pointer arithmetic, not by the clamped len. When firmware sends short TLVs, the second and later slots are written past the end of the allocation.
The reader in ath12k_pull_mac_phy_cap_svc_ready_ext() also indexes the buffer with full-struct pointer arithmetic, so the allocation must match that stride.
Fix by using kzalloc_objs(), which derives the element size from the pointer type, making allocation size and pointer stride provably consistent regardless of what len the firmware provides.
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3
--- drivers/net/wireless/ath/ath12k/wmi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/wireless/ath/ath12k/wmi.c +5 -3
@@ -3830,14 +3830,16 @@ static int ath12k_wmi_mac_phy_caps_parse(struct ath12k_base *soc,if (svc_rdy_ext->n_mac_phy_caps >= svc_rdy_ext->tot_phy_id)return -ENOBUFS ; - len =min_t (u16, len,sizeof (struct ath12k_wmi_mac_phy_caps_params ));if (!svc_rdy_ext->n_mac_phy_caps) { - svc_rdy_ext->mac_phy_caps =kzalloc ((svc_rdy_ext->tot_phy_id) * len, -GFP_ATOMIC ); + svc_rdy_ext->mac_phy_caps = +kcalloc (svc_rdy_ext->tot_phy_id, +sizeof (*svc_rdy_ext->mac_phy_caps), +GFP_ATOMIC );if (!svc_rdy_ext->mac_phy_caps)return -ENOMEM ; } + len =min_t (u16, len,sizeof (struct ath12k_wmi_mac_phy_caps_params ));memcpy (svc_rdy_ext->mac_phy_caps + svc_rdy_ext->n_mac_phy_caps, ptr, len); svc_rdy_ext->n_mac_phy_caps++;return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1458/1674 wifi: ath12k: fix overreads in ath12k_wmi_process_csa_switch_count_event()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Johnson <[email protected]>
[ Upstream commit 878654eb78c6aa0ff585baf1376567c775ca28ec ]
There is no policy entry for WMI_TAG_PDEV_CSA_SWITCH_COUNT_STATUS_EVENT, so the parse infrastructure does not enforce a minimum length for the event struct. Additionally, the num_vdevs field is taken directly from firmware and used as a loop bound over the vdev_ids array without checking that it fits within the TLV payload. Either condition can cause an out-of-bounds read.
Add a TLV policy entry for WMI_TAG_PDEV_CSA_SWITCH_COUNT_STATUS_EVENT so the parse infrastructure enforces a minimum length for the fixed-size event struct. Add a helper ath12k_wmi_tlv_data_len() to recover the payload length of a parsed TLV from the header preceding its data pointer. Use it in ath12k_wmi_process_csa_switch_count_event() to bound num_vdevs before the loop.
Compile tested only.
--- drivers/net/wireless/ath/ath12k/wmi.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/net/wireless/ath/ath12k/wmi.c +17 -0
@@ -160,6 +160,8 @@ static const struct ath12k_wmi_tlv_policy ath12k_wmi_tlv_policies[] = { .min_len = sizeof(struct wmi_probe_resp_tx_status_event) }, [WMI_TAG_VDEV_DELETE_RESP_EVENT] = { .min_len = sizeof(struct wmi_vdev_delete_resp_event) }, + [WMI_TAG_PDEV_CSA_SWITCH_COUNT_STATUS_EVENT] = { + .min_len = sizeof(struct ath12k_wmi_pdev_csa_event) }, };static __le32 ath12k_wmi_tlv_hdr (u32 cmd,u32 len)
@@ -376,6 +378,13 @@ ath12k_wmi_tlv_parse_alloc(struct ath12k_base *ab, const void *ptr,return tb; } +static u32 ath12k_wmi_tlv_data_len (const void *data) +{ +const struct wmi_tlv *tlv = (const struct wmi_tlv *)data -1 ; + +return le32_get_bits (tlv->header,WMI_TLV_LEN ); +} +static int ath12k_wmi_cmd_send_nowait (struct ath12k_wmi_pdev *wmi,struct sk_buff *skb,u32 cmd_id) {
@@ -6449,6 +6458,8 @@ ath12k_wmi_process_csa_switch_count_event(struct ath12k_base *ab,const struct ath12k_wmi_pdev_csa_event *ev, const u32 *vdev_ids) { + u32 vdev_ids_len = ath12k_wmi_tlv_data_len(vdev_ids); +u32 num_vdevs =le32_to_cpu (ev->num_vdevs);int i;struct ath12k_vif *arvif;
@@ -6456,6 +6467,12 @@ ath12k_wmi_process_csa_switch_count_event(struct ath12k_base *ab,if (ev->current_switch_count)return ; +if (num_vdevs > vdev_ids_len /sizeof (*vdev_ids)) { +ath12k_warn (ab,"csa switch count num_vdevs %u exceeds tlv array length %u\n" , + num_vdevs, vdev_ids_len); +return ; + } +rcu_read_lock ();for (i =0 ; i <le32_to_cpu (ev->num_vdevs); i++) { arvif =ath12k_mac_get_arvif_by_vdev_id (ab, vdev_ids[i]);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1459/1674 RDMA/cxgb4: Fix dereg_skb leak and double free in write_tpt_entry()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit 373f3716a2de7adc739269ebb4d87e5bf4dc180c ]
When the device is in the fatal error state, write_tpt_entry() returns -EIO before handing the caller's preallocated skb to the transmit path; its allocation-failure returns do the same. c4iw_dereg_mr() ignores the error and frees mhp, leaking mhp->dereg_skb. c4iw_get_dma_mr() instead frees the skb a second time after dereg_mem() already consumed it, a double free.
Make write_tpt_entry() the sole owner of a non-NULL skb, freeing it on every return preceding handoff to c4iw_ofld_send(): fatal error, tpt and stag allocation failure. c4iw_ofld_send() consumes the skb on success and error alike, so drop the redundant kfree_skb() in c4iw_get_dma_mr() after dereg_mem().
--- drivers/infiniband/hw/cxgb4/mem.c | 46 ++++++++++++------------------- 1 file changed, 17 insertions(+), 29 deletions(-)
drivers/infiniband/hw/cxgb4/mem.c +17 -29
@@ -199,7 +199,8 @@ static int _c4iw_write_mem_dma(struct c4iw_rdev *rdev, u32 addr, u32 len, daddr =dma_map_single (&rdev->lldi.pdev->dev, data, len,DMA_TO_DEVICE );if (dma_mapping_error (&rdev->lldi.pdev->dev, daddr)) -return -1 ; +return _c4iw_write_mem_inline (rdev, addr, len, data, skb, + wr_waitp); save = daddr;while (remain > inline_threshold) {
@@ -235,30 +236,12 @@ static int write_adapter_mem(struct c4iw_rdev *rdev, u32 addr, u32 len, void *data, struct sk_buff *skb, struct c4iw_wr_wait *wr_waitp) { - int ret; - -if (!rdev->lldi.ulptx_memwrite_dsgl || !use_dsgl) { - ret =_c4iw_write_mem_inline (rdev, addr, len, data, skb, - wr_waitp); - goto out; - } - -if (len <= inline_threshold) { - ret =_c4iw_write_mem_inline (rdev, addr, len, data, skb, + if (!rdev->lldi.ulptx_memwrite_dsgl || !use_dsgl || + len <= inline_threshold) + return _c4iw_write_mem_inline(rdev, addr, len, data, skb, wr_waitp); - goto out; - } - - ret =_c4iw_write_mem_dma (rdev, addr, len, data, skb, wr_waitp); -if (ret) { -pr_warn_ratelimited ("%s: dma map failure (non fatal)\n" , -pci_name (rdev->lldi.pdev)); - ret =_c4iw_write_mem_inline (rdev, addr, len, data, skb, - wr_waitp); - } -out: -return ret; + return _c4iw_write_mem_dma(rdev, addr, len, data, skb, wr_waitp); }/*
@@ -280,12 +263,16 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,bool stag_idx_allocated = false;static atomic_t key; -if (c4iw_fatal_error (rdev)) +if (c4iw_fatal_error (rdev)) { +kfree_skb (skb);return -EIO ; + } tpt =kmalloc (sizeof (*tpt),GFP_KERNEL ); -if (!tpt) +if (!tpt) { +kfree_skb (skb);return -ENOMEM ; + } stag_state = stag_state >0 ; stag_idx = (*stag) >>8 ;
@@ -297,6 +284,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry, rdev->stats.stag.fail++;mutex_unlock (&rdev->stats.lock);kfree (tpt); +kfree_skb (skb);return -ENOMEM ; }mutex_lock (&rdev->stats.lock);
@@ -471,8 +459,10 @@ struct ib_mr *c4iw_get_dma_mr(struct ib_pd *pd, int acc)FW_RI_STAG_NSMR , mhp->attr.perms, mhp->attr.mw_bind_enable,0 ,0 , ~0ULL ,0 ,0 ,0 , NULL, mhp->wr_waitp); -if (ret) - goto err_free_skb; +if (ret) { +kfree_skb (mhp->dereg_skb); + goto err_free_wr_wait; + } ret =finish_mem_reg (mhp, stag);if (ret)
@@ -481,8 +471,6 @@ struct ib_mr *c4iw_get_dma_mr(struct ib_pd *pd, int acc) err_dereg_mem:dereg_mem (&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size, mhp->attr.pbl_addr, mhp->dereg_skb, mhp->wr_waitp); -err_free_skb: -kfree_skb (mhp->dereg_skb); err_free_wr_wait:c4iw_put_wr_wait (mhp->wr_waitp); err_free_mhp:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1460/1674 PCI: Initialize temporary device in new_id_store()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Samiullah Khawaja <[email protected]>
[ Upstream commit f45a49a2380a47332817b7248c61a0ebbc6f0d00 ]
When setting new_id of a PCI device driver using sysfs a lockdep splat occurs. This is because new_id_store() builds a temporary pci_dev for pci_match_device(), which calls device_match_driver_override(). That depends on the driver_override.lock added by cb3d1049f4ea ("driver core:
generalize driver_override in struct device").
The new driver_override.lock was not initialized in the temporary pci_dev, resulting in this lockdep splat.
Initialize the temporary pci_dev to fix this.
Repro:
Build with CONFIG_LOCKDEP=y, boot with QEMU, and add a new ID:
# echo "8086 10f5" > /sys/bus/pci/drivers/e1000e/new_id
INFO: trying to register non-static key.
The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use? turning off the locking correctness validator.
CPU: 2 UID: 0 PID: 177 Comm: liveupdate-iomm Not tainted 7.0.0+ #9 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x5d/0x80 register_lock_class+0x77e/0x790 lock_acquire+0xbf/0x2e0 pci_match_device+0x24/0x180 new_id_store+0x189/0x1d0 kernfs_fop_write_iter+0x14f/0x210 vfs_write+0x263/0x5e0 ksys_write+0x79/0xf0 do_syscall_64+0x117/0xf80
Stable-dep-of: 3ffc4c9690c3 ("PCI: Fix UAF when probe runs concurrent to dyn ID removal")
--- drivers/pci/pci-driver.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/pci/pci-driver.c +8 -1
@@ -179,6 +179,11 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,return NULL ; } +static void _pci_free_device (struct device *dev) +{ +kfree (to_pci_dev (dev)); +} +/** * new_id_store - sysfs frontend to pci_add_dynid() * @driver: target device driver
@@ -214,11 +219,13 @@ static ssize_t new_id_store(struct device_driver *driver, const char *buf, pdev->subsystem_vendor = subvendor; pdev->subsystem_device = subdevice; pdev->class = class; + pdev->dev.release = _pci_free_device; +device_initialize (&pdev->dev);if (pci_match_device (pdrv, pdev)) retval = -EEXIST ; -kfree (pdev); +put_device (&pdev->dev);if (retval)return retval;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1461/1674 PCI: Make pci_match_one_device() match on ID instead of device
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gary Guo <[email protected]>
[ Upstream commit c967b365d7b51c2297d9be5df39ac3e20638faf4 ]
PCI dynamic ID needs to match IDs against a new ID to see if it already exists. Existing APIs can only match IDs against devices, so the dynamic ID insertion code creates a temporary device only for matching purposes. Rename pci_match_one_device() to pci_match_one_id() so it can be used for this purpose instead; add a pci_id_from_device() helper to make it easy to convert users.
Similarly, convert pci_match_id() to do_pci_match_id(). But keep the existing API because there are many users.
Stable-dep-of: 3ffc4c9690c3 ("PCI: Fix UAF when probe runs concurrent to dyn ID removal")
--- drivers/pci/pci-driver.c | 38 +++++++++++++++++++++++++---------- drivers/pci/pci.h | 43 +++++++++++++++++++++++++++++----------- drivers/pci/search.c | 8 +++++--- 3 files changed, 64 insertions(+), 25 deletions(-)
drivers/pci/pci-driver.c +28 -10
@@ -90,6 +90,27 @@ static void pci_free_dynids(struct pci_driver *drv)spin_unlock (&drv->dynids.lock); } +/** +* do_pci_match_id - See if a PCI ID matches a given pci_id table +* @ids: array of PCI device ID structures to search in +* @dev_id: the actual PCI device ID structure to match against. +* +* Return: the matching pci_device_id structure or %NULL if there is no match. +*/ +static const struct pci_device_id * +do_pci_match_id (const struct pci_device_id *ids, +const struct pci_device_id *dev_id) +{ +if (ids) { +while (ids->vendor || ids->subvendor || ids->class_mask) { +if (pci_match_one_id (ids, dev_id)) +return ids; + ids++; + } + } +return NULL ; +} +/** * pci_match_id - See if a PCI device matches a given pci_id table * @ids: array of PCI device ID structures to search in
@@ -105,14 +126,9 @@ static void pci_free_dynids(struct pci_driver *drv)const struct pci_device_id *pci_match_id (const struct pci_device_id *ids,struct pci_dev *dev) { -if (ids) { -while (ids->vendor || ids->subvendor || ids->class_mask) { -if (pci_match_one_device (ids, dev)) -return ids; - ids++; - } - } -return NULL ; +struct pci_device_id dev_id =pci_id_from_device (dev); + +return do_pci_match_id (ids, &dev_id); }EXPORT_SYMBOL (pci_match_id);
@@ -138,6 +154,7 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv, {struct pci_dynid *dynid;const struct pci_device_id *found_id =NULL , *ids; +struct pci_device_id dev_id;int ret;/* When driver_override is set, only bind to the matching driver */
@@ -145,10 +162,11 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,if (ret ==0 )return NULL ; + dev_id =pci_id_from_device (dev);/* Look at the dynamic ids first, before the static ones */ spin_lock (&drv->dynids.lock);list_for_each_entry (dynid, &drv->dynids.list, node) { -if (pci_match_one_device (&dynid->id, dev)) { +if (pci_match_one_id (&dynid->id, &dev_id)) { found_id = &dynid->id;break ; }
@@ -158,7 +176,7 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,if (found_id)return found_id; -for (ids = drv->id_table; (found_id =pci_match_id (ids, dev)); +for (ids = drv->id_table; (found_id =do_pci_match_id (ids, &dev_id)); ids = found_id +1 ) {/* * The match table is split based on driver_override.
drivers/pci/pci.h +31 -12
52 lines not on this page · raw message
drivers/pci/search.c +5 -3
@@ -243,8 +243,10 @@ static int match_pci_dev_by_id(struct device *dev, const void *data) {struct pci_dev *pdev =to_pci_dev (dev);const struct pci_device_id *id = data; +struct pci_device_id dev_id; -if (pci_match_one_device (id, pdev)) + dev_id =pci_id_from_device (pdev); +if (pci_match_one_id (id, &dev_id))return 1 ;return 0 ; }
@@ -368,9 +370,9 @@ EXPORT_SYMBOL(pci_get_class);* @class: search for a PCI device with this base class code * @from: Previous PCI device found in search, or %NULL for new search. * -* Iterates through the list of known PCI devices. If a PCI device is found +* Iterate through the list of known PCI devices. If a PCI device is found * with a matching base class code, the reference count to the device is -* incremented. See pci_match_one_device() to figure out how does this works. +* incremented. See pci_match_one_id() to figure out how this works. * A new search is initiated by passing %NULL as the @from argument. * Otherwise if @from is not %NULL, searches continue from next device on the * global list. The reference count for @from is always decremented if it is
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1462/1674 PCI: Fix dyn_id add TOCTOU
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gary Guo <[email protected]>
[ Upstream commit 04fde70f782b6ce984f9f80c2023786caea28287 ]
Currently there is a TOCTOU issue in new_id_store() as the dyn ID insertion in pci_add_dynid() and the pci_match_device() are in separate critical sections.
Fix this by moving the existing ID check to inside pci_add_dynid() and only check against the static ID table outside the critical section.
Stable-dep-of: 3ffc4c9690c3 ("PCI: Fix UAF when probe runs concurrent to dyn ID removal")
--- drivers/pci/pci-driver.c | 140 ++++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 68 deletions(-)
drivers/pci/pci-driver.c +72 -68
@@ -29,6 +29,47 @@ struct pci_dynid {struct pci_device_id id; }; +/** +* do_pci_add_dynid - Add a new PCI device ID to this driver and re-probe +* @drv: target PCI driver +* @id: ID to be added +* @check_dup: whether to check if matching ID is already present +* +* Add a new dynamic PCI device ID to this driver and causes the driver to +* probe for all devices again. @drv must have been registered prior to calling +* this function. +* +* Context: Does GFP_KERNEL allocation. +* +* Return: 0 on success, -errno on failure. +*/ +static int do_pci_add_dynid (struct pci_driver *drv, +const struct pci_device_id *id, +bool check_dup) +{ +struct pci_dynid *dynid, *existing_dynid; + + dynid =kzalloc (sizeof (*dynid),GFP_KERNEL ); +if (!dynid) +return -ENOMEM ; + + dynid->id = *id; + + scoped_guard(spinlock, &drv->dynids.lock) { +if (check_dup) { +list_for_each_entry (existing_dynid, &drv->dynids.list, node) { +if (pci_match_one_id (&existing_dynid->id, id)) { +kfree (dynid); +return -EEXIST ; + } + } + } +list_add_tail (&dynid->node, &drv->dynids.list); + } + +return driver_attach (&drv->driver); +} +/** * pci_add_dynid - add a new PCI device ID to this driver and re-probe devices * @drv: target pci driver
@@ -56,25 +97,17 @@ int pci_add_dynid(struct pci_driver *drv, unsigned int class, unsigned int class_mask, unsigned long driver_data) { - struct pci_dynid *dynid; - - dynid =kzalloc (sizeof (*dynid),GFP_KERNEL ); -if (!dynid) -return -ENOMEM ; - - dynid->id.vendor = vendor; - dynid->id.device = device; - dynid->id.subvendor = subvendor; - dynid->id.subdevice = subdevice; - dynid->id.class = class; - dynid->id.class_mask = class_mask; - dynid->id.driver_data = driver_data; - -spin_lock (&drv->dynids.lock); -list_add_tail (&dynid->node, &drv->dynids.list); -spin_unlock (&drv->dynids.lock); + struct pci_device_id id = { + .vendor = vendor, + .device = device, + .subvendor = subvendor, + .subdevice = subdevice, + .class = class, + .class_mask = class_mask, + .driver_data = driver_data, + }; -return driver_attach (&drv->driver); +return do_pci_add_dynid (drv, &id, false); }EXPORT_SYMBOL_GPL (pci_add_dynid);
@@ -94,16 +127,20 @@ static void pci_free_dynids(struct pci_driver *drv)* do_pci_match_id - See if a PCI ID matches a given pci_id table * @ids: array of PCI device ID structures to search in * @dev_id: the actual PCI device ID structure to match against. +* @include_override_only: also match against device ID entries marked as +* override only. * * Return: the matching pci_device_id structure or %NULL if there is no match. */ static const struct pci_device_id *do_pci_match_id (const struct pci_device_id *ids, -const struct pci_device_id *dev_id) +const struct pci_device_id *dev_id, +bool include_override_only) {if (ids) {while (ids->vendor || ids->subvendor || ids->class_mask) { -if (pci_match_one_id (ids, dev_id)) +if ((!ids->override_only || include_override_only) && +pci_match_one_id (ids, dev_id))return ids; ids++; }
@@ -128,7 +165,7 @@ const struct pci_device_id *pci_match_id(const struct pci_device_id *ids, {struct pci_device_id dev_id =pci_id_from_device (dev); -return do_pci_match_id (ids, &dev_id); +return do_pci_match_id (ids, &dev_id, true); }EXPORT_SYMBOL (pci_match_id);
@@ -153,7 +190,7 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv, struct pci_dev *dev) {struct pci_dynid *dynid; -const struct pci_device_id *found_id =NULL , *ids; +const struct pci_device_id *found_id =NULL ;struct pci_device_id dev_id;int ret;
@@ -176,20 +213,9 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,if (found_id)return found_id; -for (ids = drv->id_table; (found_id =do_pci_match_id (ids, &dev_id)); - ids = found_id +1 ) { -/* -* The match table is split based on driver_override. -* In case override_only was set, enforce driver_override -* matching. -*/ -if (found_id->override_only) { -if (ret >0 ) -return found_id; - }else { -return found_id; - } - } + found_id =do_pci_match_id (drv->id_table, &dev_id, ret >0 ); +if (found_id) +return found_id;/* driver_override will always match, send a dummy id */ if (ret >0 )
@@ -197,11 +223,6 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,return NULL ; } -static void _pci_free_device (struct device *dev) -{ -kfree (to_pci_dev (dev)); -} -/** * new_id_store - sysfs frontend to pci_add_dynid() * @driver: target device driver
@@ -215,38 +236,22 @@ static ssize_t new_id_store(struct device_driver *driver, const char *buf, {struct pci_driver *pdrv =to_pci_driver (driver);const struct pci_device_id *ids = pdrv->id_table; -u32 vendor, device, subvendor =PCI_ANY_ID , - subdevice =PCI_ANY_ID , class =0 , class_mask =0 ; -unsigned long driver_data =0 ; +struct pci_device_id id = { + .subvendor =PCI_ANY_ID , + .subdevice =PCI_ANY_ID + };int fields;int retval =0 ; fields =sscanf (buf,"%x %x %x %x %x %x %lx" , - &vendor, &device, &subvendor, &subdevice, - &class, &class_mask, &driver_data); + &id.vendor, &id.device, &id.subvendor, &id.subdevice, + &id.class, &id.class_mask, &id.driver_data);if (fields <2 )return -EINVAL ;if (fields !=7 ) { -struct pci_dev *pdev =kzalloc (sizeof (*pdev),GFP_KERNEL ); -if (!pdev) -return -ENOMEM ; - - pdev->vendor = vendor; - pdev->device = device; - pdev->subsystem_vendor = subvendor; - pdev->subsystem_device = subdevice; - pdev->class = class; - pdev->dev.release = _pci_free_device; - -device_initialize (&pdev->dev); -if (pci_match_device (pdrv, pdev)) - retval = -EEXIST ; - -put_device (&pdev->dev); - -if (retval) -return retval; +if (do_pci_match_id (pdrv->id_table, &id, false)) +return -EEXIST ; }/* Only accept driver_data values that match an existing id_table
@@ -254,7 +259,7 @@ static ssize_t new_id_store(struct device_driver *driver, const char *buf,if (ids) { retval = -EINVAL ;while (ids->vendor || ids->subvendor || ids->class_mask) { -if (driver_data == ids->driver_data) { +if (id.driver_data == ids->driver_data) { retval =0 ;break ; }
@@ -264,8 +269,7 @@ static ssize_t new_id_store(struct device_driver *driver, const char *buf,return retval; } - retval =pci_add_dynid (pdrv, vendor, device, subvendor, subdevice, - class, class_mask, driver_data); + retval =do_pci_add_dynid (pdrv, &id, fields !=7 );if (retval)return retval;return count;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1463/1674 PCI: Fix UAF when probe runs concurrent to dyn ID removal
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gary Guo <[email protected]>
[ Upstream commit 3ffc4c9690c33ee28cdb3d0182b12f9c623e3acc ]
Dynamic IDs are only guaranteed to be valid when dynids.lock is held, as remove_id_store() can free the node. Thus, make a copy in pci_match_device(). Also, clarify that the id parameter is only valid during probe.
--- drivers/pci/pci-driver.c | 28 +++++++++++++++------------- include/linux/pci.h | 1 + 2 files changed, 16 insertions(+), 13 deletions(-)
drivers/pci/pci-driver.c +15 -13
@@ -180,6 +180,7 @@ static const struct pci_device_id pci_device_id_any = {* pci_match_device - See if a device matches a driver's list of IDs * @drv: the PCI driver to match against * @dev: the PCI device structure to match against +* @id_copy: place to store copy of pci_device_id for dynamic ID * * Used by a driver to check whether a PCI device is in its list of * supported devices or in the dynids list, which may have been augmented
@@ -187,9 +188,9 @@ static const struct pci_device_id pci_device_id_any = {* structure or %NULL if there is no match. */ static const struct pci_device_id *pci_match_device (struct pci_driver *drv, -struct pci_dev *dev) +struct pci_dev *dev, +struct pci_device_id *id_copy) { -struct pci_dynid *dynid;const struct pci_device_id *found_id =NULL ;struct pci_device_id dev_id;int ret;
@@ -201,17 +202,16 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv, dev_id =pci_id_from_device (dev);/* Look at the dynamic ids first, before the static ones */ -spin_lock (&drv->dynids.lock); -list_for_each_entry (dynid, &drv->dynids.list, node) { -if (pci_match_one_id (&dynid->id, &dev_id)) { - found_id = &dynid->id; -break ; + scoped_guard(spinlock, &drv->dynids.lock) { +struct pci_dynid *dynid; + +list_for_each_entry (dynid, &drv->dynids.list, node) { +if (pci_match_one_id (&dynid->id, &dev_id)) { + *id_copy = dynid->id; +return id_copy; + } } } -spin_unlock (&drv->dynids.lock); - -if (found_id) -return found_id; found_id =do_pci_match_id (drv->id_table, &dev_id, ret >0 );if (found_id)
@@ -438,12 +438,13 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,static int __pci_device_probe (struct pci_driver *drv,struct pci_dev *pci_dev) {const struct pci_device_id *id; +struct pci_device_id id_copy;int error =0 ;if (drv->probe) { error = -ENODEV ; - id =pci_match_device (drv, pci_dev); + id =pci_match_device (drv, pci_dev, &id_copy);if (id) error =pci_call_probe (drv, pci_dev, id); }
@@ -1549,12 +1550,13 @@ static int pci_bus_match(struct device *dev, struct device_driver *drv)struct pci_dev *pci_dev =to_pci_dev (dev);struct pci_driver *pci_drv;const struct pci_device_id *found_id; +struct pci_device_id id_copy;if (!pci_dev->match_driver)return 0 ; pci_drv =to_pci_driver (drv); - found_id =pci_match_device (pci_drv, pci_dev); + found_id =pci_match_device (pci_drv, pci_dev, &id_copy);if (found_id)return 1 ;
include/linux/pci.h +1 -0
@@ -892,6 +892,7 @@ struct module;* function returns zero when the driver chooses to * take "ownership" of the device or an error code * (negative number) otherwise. +* The pci_device_id parameter is only valid during probe. * The probe function always gets called from process * context, so it can sleep. * @remove: The remove() function gets called whenever a device
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1464/1674 clk: mediatek: pllfh: Fix IO remapping leak in register_pllfhs error path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Louis-Alexis Eyraud <[email protected]>
[ Upstream commit 540d91480bcb1b28a62d7023aa70947ea44c55b9 ]
When mtk_clk_register_pllfhs function fails to register a PLL, it unregisters all PLLs and cleans up itself in its error path before returning, so the function callers don't need to do it.
But contrary to mtk_clk_unregister_pllfhs function, that does almost the same sequence, it does not free the IO memory mapped on fhctl node, leading to a leak.
Fix this leak by factorizing the cleanup sequence in a new private function and use it both mtk_clk_register_pllfhs and mtk_clk_unregister_pllfhs functions.
Also, change the loop index start value to avoid the -1 operation on index at each loop.
--- drivers/clk/mediatek/clk-pllfh.c | 97 ++++++++++++++++---------------- 1 file changed, 48 insertions(+), 49 deletions(-)
drivers/clk/mediatek/clk-pllfh.c +48 -49
@@ -194,12 +194,55 @@ static void mtk_clk_unregister_pllfh(struct clk_hw *hw)kfree (fh); } +static void mtk_clk_cleanup_pllfhs (void __iomem *iomem_base, +const struct mtk_pll_data *plls,int num_plls, +void __iomem *iomem_fhctl_base, +struct mtk_pllfh_data *pllfhs,int num_fhs, +struct clk_hw_onecell_data *clk_data) +{ +void __iomem *base = iomem_base; +void __iomem *fhctl_base = iomem_fhctl_base; +int i; + +for (i = num_plls -1 ; i >=0 ; i--) { +const struct mtk_pll_data *pll = &plls[i]; +struct mtk_pllfh_data *pllfh; +bool use_fhctl; + +if (IS_ERR_OR_NULL (clk_data->hws[pll->id])) +continue ; + + pllfh =get_pllfh_by_id (pllfhs, num_fhs, pll->id); + use_fhctl =fhctl_is_supported_and_enabled (pllfh); + +if (!base) + base =mtk_clk_pll_get_base (clk_data->hws[pll->id], + pll); + +if (use_fhctl) { +if (!fhctl_base) + fhctl_base = pllfh->state.base; +mtk_clk_unregister_pllfh (clk_data->hws[pll->id]); + }else { +mtk_clk_unregister_pll (clk_data->hws[pll->id]); + } + + clk_data->hws[pll->id] =ERR_PTR (-ENOENT ); + } + +if (fhctl_base) +iounmap (fhctl_base); + +if (base) +iounmap (base); +} +int mtk_clk_register_pllfhs (struct device_node *node,const struct mtk_pll_data *plls,int num_plls,struct mtk_pllfh_data *pllfhs,int num_fhs,struct clk_hw_onecell_data *clk_data) { -void __iomem *base; +void __iomem *base, *fhctl_base =NULL ;int i;struct clk_hw *hw;
@@ -235,24 +278,8 @@ int mtk_clk_register_pllfhs(struct device_node *node,return 0 ; err: -while (--i >=0 ) { -const struct mtk_pll_data *pll = &plls[i]; -struct mtk_pllfh_data *pllfh; -bool use_fhctl; - - pllfh =get_pllfh_by_id (pllfhs, num_fhs, pll->id); - use_fhctl =fhctl_is_supported_and_enabled (pllfh); - -if (use_fhctl) -mtk_clk_unregister_pllfh (clk_data->hws[pll->id]); -else -mtk_clk_unregister_pll (clk_data->hws[pll->id]); - - clk_data->hws[pll->id] =ERR_PTR (-ENOENT ); - } - -iounmap (base); - +mtk_clk_cleanup_pllfhs (base, plls, i, fhctl_base, pllfhs, num_fhs, + clk_data);return PTR_ERR (hw); }EXPORT_SYMBOL_GPL (mtk_clk_register_pllfhs);
@@ -261,38 +288,10 @@ void mtk_clk_unregister_pllfhs(const struct mtk_pll_data *plls, int num_plls, struct mtk_pllfh_data *pllfhs, int num_fhs, struct clk_hw_onecell_data *clk_data) { - void __iomem *base = NULL, *fhctl_base = NULL; -int i; - if (!clk_data) return; -for (i = num_plls; i >0 ; i--) { -const struct mtk_pll_data *pll = &plls[i -1 ]; -struct mtk_pllfh_data *pllfh; -bool use_fhctl; - -if (IS_ERR_OR_NULL (clk_data->hws[pll->id])) -continue ; - - pllfh =get_pllfh_by_id (pllfhs, num_fhs, pll->id); - use_fhctl =fhctl_is_supported_and_enabled (pllfh); - -if (use_fhctl) { - fhctl_base = pllfh->state.base; -mtk_clk_unregister_pllfh (clk_data->hws[pll->id]); - }else { - base =mtk_clk_pll_get_base (clk_data->hws[pll->id], - pll); -mtk_clk_unregister_pll (clk_data->hws[pll->id]); - } - - clk_data->hws[pll->id] =ERR_PTR (-ENOENT ); - } - -if (fhctl_base) -iounmap (fhctl_base); - -iounmap (base); +mtk_clk_cleanup_pllfhs (NULL ,plls ,num_plls ,NULL ,pllfhs , +num_fhs ,clk_data ); }EXPORT_SYMBOL_GPL (mtk_clk_unregister_pllfhs);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1465/1674 spi: oc-tiny: switch to managed controller allocation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit d710f43ce30975d197f73c543bfe47b958d8ba17 ]
The controller is allocated with the non-managed spi_alloc_host() while the interrupt is registered with devm_request_irq(). During removal, spi_bitbang_stop() only unregisters the controller; the subsequent spi_controller_put() then frees the controller together with its embedded driver-private devdata, which is the IRQ handler's dev_id. The devm_request_irq() release action (free_irq()), which drains the handler, does not run until after .remove() returns. A late or latched interrupt can therefore reach tiny_spi_irq() and dereference already-freed memory (e.g. hw->base).
Switch to devm_spi_alloc_host() so that the devres LIFO order releases the controller only after free_irq() has drained the handler, and drop the now-redundant spi_controller_put() from .remove(). The probe error path is simplified to direct returns.
This issue was found by an in-house static analysis tool.
--- drivers/spi/spi-oc-tiny.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)
drivers/spi/spi-oc-tiny.c +8 -16
@@ -213,11 +213,11 @@ static int tiny_spi_probe(struct platform_device *pdev)struct tiny_spi_platform_data *platp =dev_get_platdata (&pdev->dev);struct tiny_spi *hw;struct spi_master *master; -int err = -ENODEV ; +int err; - master =spi_alloc_master (&pdev->dev,sizeof (struct tiny_spi )); + master =devm_spi_alloc_master (&pdev->dev,sizeof (struct tiny_spi ));if (!master) -return err; +return -ENOMEM ;/* setup the master state. */ master->bus_num = pdev->id;
@@ -235,10 +235,8 @@ static int tiny_spi_probe(struct platform_device *pdev)/* find and map our resources */ hw->base =devm_platform_ioremap_resource (pdev,0 ); -if (IS_ERR (hw->base)) { - err =PTR_ERR (hw->base); - goto exit; - } +if (IS_ERR (hw->base)) +return PTR_ERR (hw->base);/* irq is optional */ hw->irq =platform_get_irq (pdev,0 );if (hw->irq >=0 ) {
@@ -246,7 +244,7 @@ static int tiny_spi_probe(struct platform_device *pdev) err =devm_request_irq (&pdev->dev, hw->irq, tiny_spi_irq,0 , pdev->name, hw);if (err) - goto exit; +return err; }/* find platform data */ if (platp) {
@@ -255,29 +253,23 @@ static int tiny_spi_probe(struct platform_device *pdev) }else { err =tiny_spi_of_probe (pdev);if (err) - goto exit; +return err; }/* register our spi controller */ err =spi_bitbang_start (&hw->bitbang);if (err) - goto exit; +return err;dev_info (&pdev->dev,"base %p, irq %d\n" , hw->base, hw->irq);return 0 ; - -exit: -spi_master_put (master); -return err; }static void tiny_spi_remove (struct platform_device *pdev) {struct tiny_spi *hw =platform_get_drvdata (pdev); -struct spi_master *master = hw->bitbang.master;spi_bitbang_stop (&hw->bitbang); -spi_master_put (master); }#ifdef CONFIG_OF
Signature · 1 line
2.53.0