5.15.203-rc1 review
Subsystems (7)
Greg Kroah-Hartman
maintainerPATCH 128/570 octeontx2-af: devlink health: use retained error fmsg API
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Przemek Kitszel <[email protected]>
[ Upstream commit d8cf03fca3411de8a493dae5e9fcf815a4f0977e ]
Drop unneeded error checking.
devlink_fmsg_*() family of functions is now retaining errors, so there is no need to check for them after each call.
Stable-dep-of: 87f7dff3ec75 ("octeontx2-af: devlink: fix NIX RAS reporter to use RAS interrupt status")
--- .../marvell/octeontx2/af/rvu_devlink.c | 464 +++++------------- 1 file changed, 133 insertions(+), 331 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c +133 -331
@@ -13,26 +13,16 @@#define DRV_NAME "octeontx2-af" -static int rvu_report_pair_start (struct devlink_fmsg *fmsg,const char *name) +static void rvu_report_pair_start (struct devlink_fmsg *fmsg,const char *name) { -int err; - - err =devlink_fmsg_pair_nest_start (fmsg, name); -if (err) -return err; - -return devlink_fmsg_obj_nest_start (fmsg); +devlink_fmsg_pair_nest_start (fmsg, name); +devlink_fmsg_obj_nest_start (fmsg); } -static int rvu_report_pair_end (struct devlink_fmsg *fmsg) +static void rvu_report_pair_end (struct devlink_fmsg *fmsg) { -int err; - - err =devlink_fmsg_obj_nest_end (fmsg); -if (err) -return err; - -return devlink_fmsg_pair_nest_end (fmsg); +devlink_fmsg_obj_nest_end (fmsg); +devlink_fmsg_pair_nest_end (fmsg); } static bool rvu_common_request_irq(struct rvu *rvu, int offset,
@@ -283,175 +273,81 @@ static int rvu_nix_report_show(struct devlink_fmsg *fmsg, void *ctx, {struct rvu_nix_event_ctx *nix_event_context;u64 intr_val; -int err; nix_event_context = ctx;switch (health_reporter) {case NIX_AF_RVU_INTR : intr_val = nix_event_context->nix_af_rvu_int; - err =rvu_report_pair_start (fmsg,"NIX_AF_RVU" ); -if (err) -return err; - err =devlink_fmsg_u64_pair_put (fmsg,"\tNIX RVU Interrupt Reg " , - nix_event_context->nix_af_rvu_int); -if (err) -return err; -if (intr_val &BIT_ULL (0 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tUnmap Slot Error" ); -if (err) -return err; - } - err =rvu_report_pair_end (fmsg); -if (err) -return err; +rvu_report_pair_start (fmsg,"NIX_AF_RVU" ); +devlink_fmsg_u64_pair_put (fmsg,"\tNIX RVU Interrupt Reg " , + nix_event_context->nix_af_rvu_int); +if (intr_val &BIT_ULL (0 )) +devlink_fmsg_string_put (fmsg,"\n\tUnmap Slot Error" ); +rvu_report_pair_end (fmsg);break ;case NIX_AF_RVU_GEN : intr_val = nix_event_context->nix_af_rvu_gen; - err =rvu_report_pair_start (fmsg,"NIX_AF_GENERAL" ); -if (err) -return err; - err =devlink_fmsg_u64_pair_put (fmsg,"\tNIX General Interrupt Reg " , - nix_event_context->nix_af_rvu_gen); -if (err) -return err; -if (intr_val &BIT_ULL (0 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tRx multicast pkt drop" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (1 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tRx mirror pkt drop" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (4 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tSMQ flush done" ); -if (err) -return err; - } - err =rvu_report_pair_end (fmsg); -if (err) -return err; +rvu_report_pair_start (fmsg,"NIX_AF_GENERAL" ); +devlink_fmsg_u64_pair_put (fmsg,"\tNIX General Interrupt Reg " , + nix_event_context->nix_af_rvu_gen); +if (intr_val &BIT_ULL (0 )) +devlink_fmsg_string_put (fmsg,"\n\tRx multicast pkt drop" ); +if (intr_val &BIT_ULL (1 )) +devlink_fmsg_string_put (fmsg,"\n\tRx mirror pkt drop" ); +if (intr_val &BIT_ULL (4 )) +devlink_fmsg_string_put (fmsg,"\n\tSMQ flush done" ); +rvu_report_pair_end (fmsg);break ;case NIX_AF_RVU_ERR : intr_val = nix_event_context->nix_af_rvu_err; - err =rvu_report_pair_start (fmsg,"NIX_AF_ERR" ); -if (err) -return err; - err =devlink_fmsg_u64_pair_put (fmsg,"\tNIX Error Interrupt Reg " , - nix_event_context->nix_af_rvu_err); -if (err) -return err; -if (intr_val &BIT_ULL (14 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tFault on NIX_AQ_INST_S read" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (13 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tFault on NIX_AQ_RES_S write" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (12 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tAQ Doorbell Error" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (6 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tRx on unmapped PF_FUNC" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (5 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tRx multicast replication error" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (4 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tFault on NIX_RX_MCE_S read" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (3 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tFault on multicast WQE read" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (2 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tFault on mirror WQE read" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (1 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tFault on mirror pkt write" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (0 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tFault on multicast pkt write" ); -if (err) -return err; - } - err =rvu_report_pair_end (fmsg); -if (err) -return err; +rvu_report_pair_start (fmsg,"NIX_AF_ERR" ); +devlink_fmsg_u64_pair_put (fmsg,"\tNIX Error Interrupt Reg " , + nix_event_context->nix_af_rvu_err); +if (intr_val &BIT_ULL (14 )) +devlink_fmsg_string_put (fmsg,"\n\tFault on NIX_AQ_INST_S read" ); +if (intr_val &BIT_ULL (13 )) +devlink_fmsg_string_put (fmsg,"\n\tFault on NIX_AQ_RES_S write" ); +if (intr_val &BIT_ULL (12 )) +devlink_fmsg_string_put (fmsg,"\n\tAQ Doorbell Error" ); +if (intr_val &BIT_ULL (6 )) +devlink_fmsg_string_put (fmsg,"\n\tRx on unmapped PF_FUNC" ); +if (intr_val &BIT_ULL (5 )) +devlink_fmsg_string_put (fmsg,"\n\tRx multicast replication error" ); +if (intr_val &BIT_ULL (4 )) +devlink_fmsg_string_put (fmsg,"\n\tFault on NIX_RX_MCE_S read" ); +if (intr_val &BIT_ULL (3 )) +devlink_fmsg_string_put (fmsg,"\n\tFault on multicast WQE read" ); +if (intr_val &BIT_ULL (2 )) +devlink_fmsg_string_put (fmsg,"\n\tFault on mirror WQE read" ); +if (intr_val &BIT_ULL (1 )) +devlink_fmsg_string_put (fmsg,"\n\tFault on mirror pkt write" ); +if (intr_val &BIT_ULL (0 )) +devlink_fmsg_string_put (fmsg,"\n\tFault on multicast pkt write" ); +rvu_report_pair_end (fmsg);break ;case NIX_AF_RVU_RAS : intr_val = nix_event_context->nix_af_rvu_err; - err =rvu_report_pair_start (fmsg,"NIX_AF_RAS" ); -if (err) -return err; - err =devlink_fmsg_u64_pair_put (fmsg,"\tNIX RAS Interrupt Reg " , - nix_event_context->nix_af_rvu_err); -if (err) -return err; - err =devlink_fmsg_string_put (fmsg,"\n\tPoison Data on:" ); -if (err) -return err; -if (intr_val &BIT_ULL (34 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tNIX_AQ_INST_S" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (33 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tNIX_AQ_RES_S" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (32 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tHW ctx" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (4 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tPacket from mirror buffer" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (3 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tPacket from multicast buffer" ); - -if (err) -return err; - } -if (intr_val &BIT_ULL (2 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tWQE read from mirror buffer" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (1 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tWQE read from multicast buffer" ); -if (err) -return err; - } -if (intr_val &BIT_ULL (0 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tNIX_RX_MCE_S read" ); -if (err) -return err; - } - err =rvu_report_pair_end (fmsg); -if (err) -return err; +rvu_report_pair_start (fmsg,"NIX_AF_RAS" ); +devlink_fmsg_u64_pair_put (fmsg,"\tNIX RAS Interrupt Reg " , + nix_event_context->nix_af_rvu_err); +devlink_fmsg_string_put (fmsg,"\n\tPoison Data on:" ); +if (intr_val &BIT_ULL (34 )) +devlink_fmsg_string_put (fmsg,"\n\tNIX_AQ_INST_S" ); +if (intr_val &BIT_ULL (33 )) +devlink_fmsg_string_put (fmsg,"\n\tNIX_AQ_RES_S" ); +if (intr_val &BIT_ULL (32 )) +devlink_fmsg_string_put (fmsg,"\n\tHW ctx" ); +if (intr_val &BIT_ULL (4 )) +devlink_fmsg_string_put (fmsg,"\n\tPacket from mirror buffer" ); +if (intr_val &BIT_ULL (3 )) +devlink_fmsg_string_put (fmsg,"\n\tPacket from multicast buffer" ); +if (intr_val &BIT_ULL (2 )) +devlink_fmsg_string_put (fmsg,"\n\tWQE read from mirror buffer" ); +if (intr_val &BIT_ULL (1 )) +devlink_fmsg_string_put (fmsg,"\n\tWQE read from multicast buffer" ); +if (intr_val &BIT_ULL (0 )) +devlink_fmsg_string_put (fmsg,"\n\tNIX_RX_MCE_S read" ); +rvu_report_pair_end (fmsg);break ;default :return -EINVAL ;
@@ -918,181 +814,87 @@ static int rvu_npa_report_show(struct devlink_fmsg *fmsg, void *ctx,struct rvu_npa_event_ctx *npa_event_context;unsigned int alloc_dis, free_dis;u64 intr_val; -int err; npa_event_context = ctx;switch (health_reporter) {case NPA_AF_RVU_GEN : intr_val = npa_event_context->npa_af_rvu_gen; - err =rvu_report_pair_start (fmsg,"NPA_AF_GENERAL" ); -if (err) -return err; - err =devlink_fmsg_u64_pair_put (fmsg,"\tNPA General Interrupt Reg " , - npa_event_context->npa_af_rvu_gen); -if (err) -return err; -if (intr_val &BIT_ULL (32 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tUnmap PF Error" ); -if (err) -return err; - } +rvu_report_pair_start (fmsg,"NPA_AF_GENERAL" ); +devlink_fmsg_u64_pair_put (fmsg,"\tNPA General Interrupt Reg " , + npa_event_context->npa_af_rvu_gen); +if (intr_val &BIT_ULL (32 )) +devlink_fmsg_string_put (fmsg,"\n\tUnmap PF Error" ); free_dis =FIELD_GET (GENMASK (15 ,0 ), intr_val); -if (free_dis &BIT (NPA_INPQ_NIX0_RX )) { - err =devlink_fmsg_string_put (fmsg,"\n\tNIX0: free disabled RX" ); -if (err) -return err; - } -if (free_dis &BIT (NPA_INPQ_NIX0_TX )) { - err =devlink_fmsg_string_put (fmsg,"\n\tNIX0:free disabled TX" ); -if (err) -return err; - } -if (free_dis &BIT (NPA_INPQ_NIX1_RX )) { - err =devlink_fmsg_string_put (fmsg,"\n\tNIX1: free disabled RX" ); -if (err) -return err; - } -if (free_dis &BIT (NPA_INPQ_NIX1_TX )) { - err =devlink_fmsg_string_put (fmsg,"\n\tNIX1:free disabled TX" ); -if (err) -return err; - } -if (free_dis &BIT (NPA_INPQ_SSO )) { - err =devlink_fmsg_string_put (fmsg,"\n\tFree Disabled for SSO" ); -if (err) -return err; - } -if (free_dis &BIT (NPA_INPQ_TIM )) { - err =devlink_fmsg_string_put (fmsg,"\n\tFree Disabled for TIM" ); -if (err) -return err; - } -if (free_dis &BIT (NPA_INPQ_DPI )) { - err =devlink_fmsg_string_put (fmsg,"\n\tFree Disabled for DPI" ); -if (err) -return err; - } -if (free_dis &BIT (NPA_INPQ_AURA_OP )) { - err =devlink_fmsg_string_put (fmsg,"\n\tFree Disabled for AURA" ); -if (err) -return err; - } +if (free_dis &BIT (NPA_INPQ_NIX0_RX )) +devlink_fmsg_string_put (fmsg,"\n\tNIX0: free disabled RX" ); +if (free_dis &BIT (NPA_INPQ_NIX0_TX )) +devlink_fmsg_string_put (fmsg,"\n\tNIX0:free disabled TX" ); +if (free_dis &BIT (NPA_INPQ_NIX1_RX )) +devlink_fmsg_string_put (fmsg,"\n\tNIX1: free disabled RX" ); +if (free_dis &BIT (NPA_INPQ_NIX1_TX )) +devlink_fmsg_string_put (fmsg,"\n\tNIX1:free disabled TX" ); +if (free_dis &BIT (NPA_INPQ_SSO )) +devlink_fmsg_string_put (fmsg,"\n\tFree Disabled for SSO" ); +if (free_dis &BIT (NPA_INPQ_TIM )) +devlink_fmsg_string_put (fmsg,"\n\tFree Disabled for TIM" ); +if (free_dis &BIT (NPA_INPQ_DPI )) +devlink_fmsg_string_put (fmsg,"\n\tFree Disabled for DPI" ); +if (free_dis &BIT (NPA_INPQ_AURA_OP )) +devlink_fmsg_string_put (fmsg,"\n\tFree Disabled for AURA" ); alloc_dis =FIELD_GET (GENMASK (31 ,16 ), intr_val); -if (alloc_dis &BIT (NPA_INPQ_NIX0_RX )) { - err =devlink_fmsg_string_put (fmsg,"\n\tNIX0: alloc disabled RX" ); -if (err) -return err; - } -if (alloc_dis &BIT (NPA_INPQ_NIX0_TX )) { - err =devlink_fmsg_string_put (fmsg,"\n\tNIX0:alloc disabled TX" ); -if (err) -return err; - } -if (alloc_dis &BIT (NPA_INPQ_NIX1_RX )) { - err =devlink_fmsg_string_put (fmsg,"\n\tNIX1: alloc disabled RX" ); -if (err) -return err; - } -if (alloc_dis &BIT (NPA_INPQ_NIX1_TX )) { - err =devlink_fmsg_string_put (fmsg,"\n\tNIX1:alloc disabled TX" ); -if (err) -return err; - } -if (alloc_dis &BIT (NPA_INPQ_SSO )) { - err =devlink_fmsg_string_put (fmsg,"\n\tAlloc Disabled for SSO" ); -if (err) -return err; - } -if (alloc_dis &BIT (NPA_INPQ_TIM )) { - err =devlink_fmsg_string_put (fmsg,"\n\tAlloc Disabled for TIM" ); -if (err) -return err; - } -if (alloc_dis &BIT (NPA_INPQ_DPI )) { - err =devlink_fmsg_string_put (fmsg,"\n\tAlloc Disabled for DPI" ); -if (err) -return err; - } -if (alloc_dis &BIT (NPA_INPQ_AURA_OP )) { - err =devlink_fmsg_string_put (fmsg,"\n\tAlloc Disabled for AURA" ); -if (err) -return err; - } - err =rvu_report_pair_end (fmsg); -if (err) -return err; +if (alloc_dis &BIT (NPA_INPQ_NIX0_RX )) +devlink_fmsg_string_put (fmsg,"\n\tNIX0: alloc disabled RX" ); +if (alloc_dis &BIT (NPA_INPQ_NIX0_TX )) +devlink_fmsg_string_put (fmsg,"\n\tNIX0:alloc disabled TX" ); +if (alloc_dis &BIT (NPA_INPQ_NIX1_RX )) +devlink_fmsg_string_put (fmsg,"\n\tNIX1: alloc disabled RX" ); +if (alloc_dis &BIT (NPA_INPQ_NIX1_TX )) +devlink_fmsg_string_put (fmsg,"\n\tNIX1:alloc disabled TX" ); +if (alloc_dis &BIT (NPA_INPQ_SSO )) +devlink_fmsg_string_put (fmsg,"\n\tAlloc Disabled for SSO" ); +if (alloc_dis &BIT (NPA_INPQ_TIM )) +devlink_fmsg_string_put (fmsg,"\n\tAlloc Disabled for TIM" ); +if (alloc_dis &BIT (NPA_INPQ_DPI )) +devlink_fmsg_string_put (fmsg,"\n\tAlloc Disabled for DPI" ); +if (alloc_dis &BIT (NPA_INPQ_AURA_OP )) +devlink_fmsg_string_put (fmsg,"\n\tAlloc Disabled for AURA" ); + +rvu_report_pair_end (fmsg);break ;case NPA_AF_RVU_ERR : - err =rvu_report_pair_start (fmsg,"NPA_AF_ERR" ); -if (err) -return err; - err =devlink_fmsg_u64_pair_put (fmsg,"\tNPA Error Interrupt Reg " , - npa_event_context->npa_af_rvu_err); -if (err) -return err; - -if (npa_event_context->npa_af_rvu_err &BIT_ULL (14 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tFault on NPA_AQ_INST_S read" ); -if (err) -return err; - } -if (npa_event_context->npa_af_rvu_err &BIT_ULL (13 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tFault on NPA_AQ_RES_S write" ); -if (err) -return err; - } -if (npa_event_context->npa_af_rvu_err &BIT_ULL (12 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tAQ Doorbell Error" ); -if (err) -return err; - } - err =rvu_report_pair_end (fmsg); -if (err) -return err; +rvu_report_pair_start (fmsg,"NPA_AF_ERR" ); +devlink_fmsg_u64_pair_put (fmsg,"\tNPA Error Interrupt Reg " , + npa_event_context->npa_af_rvu_err); +if (npa_event_context->npa_af_rvu_err &BIT_ULL (14 )) +devlink_fmsg_string_put (fmsg,"\n\tFault on NPA_AQ_INST_S read" ); +if (npa_event_context->npa_af_rvu_err &BIT_ULL (13 )) +devlink_fmsg_string_put (fmsg,"\n\tFault on NPA_AQ_RES_S write" ); +if (npa_event_context->npa_af_rvu_err &BIT_ULL (12 )) +devlink_fmsg_string_put (fmsg,"\n\tAQ Doorbell Error" ); +rvu_report_pair_end (fmsg);break ;case NPA_AF_RVU_RAS : - err =rvu_report_pair_start (fmsg,"NPA_AF_RVU_RAS" ); -if (err) -return err; - err =devlink_fmsg_u64_pair_put (fmsg,"\tNPA RAS Interrupt Reg " , - npa_event_context->npa_af_rvu_ras); -if (err) -return err; -if (npa_event_context->npa_af_rvu_ras &BIT_ULL (34 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tPoison data on NPA_AQ_INST_S" ); -if (err) -return err; - } -if (npa_event_context->npa_af_rvu_ras &BIT_ULL (33 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tPoison data on NPA_AQ_RES_S" ); -if (err) -return err; - } -if (npa_event_context->npa_af_rvu_ras &BIT_ULL (32 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tPoison data on HW context" ); -if (err) -return err; - } - err =rvu_report_pair_end (fmsg); -if (err) -return err; +rvu_report_pair_start (fmsg,"NPA_AF_RVU_RAS" ); +devlink_fmsg_u64_pair_put (fmsg,"\tNPA RAS Interrupt Reg " , + npa_event_context->npa_af_rvu_ras); +if (npa_event_context->npa_af_rvu_ras &BIT_ULL (34 )) +devlink_fmsg_string_put (fmsg,"\n\tPoison data on NPA_AQ_INST_S" ); +if (npa_event_context->npa_af_rvu_ras &BIT_ULL (33 )) +devlink_fmsg_string_put (fmsg,"\n\tPoison data on NPA_AQ_RES_S" ); +if (npa_event_context->npa_af_rvu_ras &BIT_ULL (32 )) +devlink_fmsg_string_put (fmsg,"\n\tPoison data on HW context" ); +rvu_report_pair_end (fmsg);break ;case NPA_AF_RVU_INTR : - err =rvu_report_pair_start (fmsg,"NPA_AF_RVU" ); -if (err) -return err; - err =devlink_fmsg_u64_pair_put (fmsg,"\tNPA RVU Interrupt Reg " , - npa_event_context->npa_af_rvu_int); -if (err) -return err; -if (npa_event_context->npa_af_rvu_int &BIT_ULL (0 )) { - err =devlink_fmsg_string_put (fmsg,"\n\tUnmap Slot Error" ); -if (err) -return err; - } -return rvu_report_pair_end (fmsg); +rvu_report_pair_start (fmsg,"NPA_AF_RVU" ); +devlink_fmsg_u64_pair_put (fmsg,"\tNPA RVU Interrupt Reg " , + npa_event_context->npa_af_rvu_int); +if (npa_event_context->npa_af_rvu_int &BIT_ULL (0 )) +devlink_fmsg_string_put (fmsg,"\n\tUnmap Slot Error" ); +rvu_report_pair_end (fmsg); +break ;default :return -EINVAL ; }
Signature · 1 line
2.51.0
Re: [PATCH 5.15 128/570] octeontx2-af: devlink health: use retained error fmsg API
Hi,
Quoted 4 lines · Greg Kroah-Hartman
5.15-stable review patch. If anyone has any objections, please let me know.
------------------
Quoted 9 lines
From: Przemek Kitszel <[email protected]>
[ Upstream commit
d8cf03fca3411de8a493dae5e9fcf815a4f0977e]Drop unneeded error checking.
devlink_fmsg_*() family of functions is now retaining errors, so there is no need to check for them after each call.
I have run an AI assisted backport review and it spotted an issue: I have taken a look and the issues goes like:
commit: db80d3b2558f ("devlink: retain error in struct devlink_fmsg") is not present in 5.15.y, so backporting this patch which assumes the presence of the commit referenced looks wrong.
Upstream(v6.7+) has something like:
struct devlink_fmsg {
struct list_head item_list;
int err; /* first error encountered on some devlink_fmsg_XXX() call */
bool putting_binary;
};
if (fmsg->err)
return fmsg->err;
...
fmsg->err = -ENOMEM;
return fmsg->err;5.15.y has something like:
struct devlink_fmsg {
struct list_head item_list;
bool putting_binary;
};
err = devlink_fmsg_nest_common(fmsg, DEVLINK_ATTR_FMSG_PAIR_NEST_START);
if (err)
return err;
...
return 0;So it looks like we shouldn't be backporting this without the commit: db80d3b2558f ("devlink: retain error in struct devlink_fmsg") in 5.15.y
Thanks,
Harshit
Quoted 48 lines
Reviewed-by Jesse Brandeburg <[email protected]>Reviewed-by Jiri Pirko <[email protected]>Signed-off-by Przemek Kitszel <[email protected]>Reviewed-by Simon Horman <[email protected]>Signed-off-by David S. Miller <[email protected]>Stable-dep-of:
87f7dff3ec75("octeontx2-af: devlink: fix NIX RAS reporter to use RAS interrupt status")Signed-off-by Sasha Levin <[email protected]>--- .../marvell/octeontx2/af/rvu_devlink.c | 464 +++++------------- 1 file changed, 133 insertions(+), 331 deletions(-)drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c +6
-16@@ -13,26 +13,16 @@#define DRV_NAME "octeontx2-af" -static int rvu_report_pair_start (struct devlink_fmsg *fmsg,const char *name) +static void rvu_report_pair_start (struct devlink_fmsg *fmsg,const char *name) { -int err; - - err =devlink_fmsg_pair_nest_start (fmsg, name); -if (err) -return err; - -return devlink_fmsg_obj_nest_start (fmsg); +devlink_fmsg_pair_nest_start (fmsg, name); +devlink_fmsg_obj_nest_start (fmsg); } -static int rvu_report_pair_end (struct devlink_fmsg *fmsg) +static void rvu_report_pair_end (struct devlink_fmsg *fmsg) { -int err; - - err =devlink_fmsg_obj_nest_end (fmsg); -if (err) -return err; - -return devlink_fmsg_pair_nest_end (fmsg); +devlink_fmsg_obj_nest_end (fmsg); +devlink_fmsg_pair_nest_end (fmsg); } stati
Greg Kroah-Hartman
maintainerPATCH 129/570 octeontx2-af: devlink: fix NIX RAS reporter to use RAS interrupt status
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alok Tiwari <[email protected]>
[ Upstream commit 87f7dff3ec75b91def0024ebaaf732457f47a63b ]
The NIX RAS health report path uses nix_af_rvu_err when handling the NIX_AF_RVU_RAS case, so the report prints the ERR interrupt status rather than the RAS interrupt status.
Use nix_af_rvu_ras for the NIX_AF_RVU_RAS report.
--- drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c +2 -2
@@ -326,10 +326,10 @@ static int rvu_nix_report_show(struct devlink_fmsg *fmsg, void *ctx,rvu_report_pair_end (fmsg);break ;case NIX_AF_RVU_RAS : - intr_val = nix_event_context->nix_af_rvu_err; + intr_val = nix_event_context->nix_af_rvu_ras;rvu_report_pair_start (fmsg,"NIX_AF_RAS" );devlink_fmsg_u64_pair_put (fmsg,"\tNIX RAS Interrupt Reg " , - nix_event_context->nix_af_rvu_err); + nix_event_context->nix_af_rvu_ras);devlink_fmsg_string_put (fmsg,"\n\tPoison Data on:" );if (intr_val &BIT_ULL (34 ))devlink_fmsg_string_put (fmsg,"\n\tNIX_AQ_INST_S" );
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 130/570 Revert "arm64: dts: qcom: sdm845-oneplus: Mark l14a regulator as boot-on"
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 018e8512fed90cb3f67851dcd3e4fb0891544871.
The backport applied regulator-boot-on to vreg_l12a_1p8 (ldo12) instead of vreg_l14a_1p88 (ldo14) due to identical surrounding context lines.
--- arch/arm64/boot/dts/qcom/sdm845-oneplus-common.dtsi | 1 - 1 file changed, 1 deletion(-)
arch/arm64/boot/dts/qcom/sdm845-oneplus-common.dtsi +0 -1
@@ -226,7 +226,6 @@ vreg_l12a_1p8: ldo12 { regulator-min-microvolt = <1800000>; regulator-max-microvolt = <1800000>; regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>; - regulator-boot-on; }; vreg_l14a_1p88: ldo14 {
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 131/570 cgroup: fix race between task migration and iteration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qingye Zhao <[email protected]>
commit 5ee01f1a7343d6a3547b6802ca2d4cdce0edacb1 upstream.
When a task is migrated out of a css_set, cgroup_migrate_add_task() first moves it from cset->tasks to cset->mg_tasks via:
list_move_tail(&task->cg_list, &cset->mg_tasks);
If a css_task_iter currently has it->task_pos pointing to this task, css_set_move_task() calls css_task_iter_skip() to keep the iterator valid. However, since the task has already been moved to ->mg_tasks, the iterator is advanced relative to the mg_tasks list instead of the original tasks list. As a result, remaining tasks on cset->tasks, as well as tasks queued on cset->mg_tasks, can be skipped by iteration.
Fix this by calling css_set_skip_task_iters() before unlinking task->cg_list from cset->tasks. This advances all active iterators to the next task on cset->tasks, so iteration continues correctly even when a task is concurrently being migrated.
This race is hard to hit in practice without instrumentation, but it can be reproduced by artificially slowing down cgroup_procs_show(). For example, on an Android device a temporary /sys/kernel/cgroup/cgroup_test knob can be added to inject a delay into cgroup_procs_show(), and then:
1) Spawn three long-running tasks (PIDs 101, 102, 103).
2) Create a test cgroup and move the tasks into it.
3) Enable a large delay via /sys/kernel/cgroup/cgroup_test.
4) In one shell, read cgroup.procs from the test cgroup.
5) Within the delay window, in another shell migrate PID 102 by writing it to a different cgroup.procs file.
Under this setup, cgroup.procs can intermittently show only PID 101 while skipping PID 103. Once the migration completes, reading the file again shows all tasks as expected.
Note that this change does not allow removing the existing css_set_skip_task_iters() call in css_set_move_task(). The new call in cgroup_migrate_add_task() only handles iterators that are racing with migration while the task is still on cset->tasks. Iterators may also start after the task has been moved to cset->mg_tasks. If we dropped css_set_skip_task_iters() from css_set_move_task(), such iterators could keep task_pos pointing to a migrating task, causing css_task_iter_advance() to malfunction on the destination css_set, up to and including crashes or infinite loops.
The race window between migration and iteration is very small, and css_task_iter is not on a hot path. In the worst case, when an iterator is positioned on the first thread of the migrating process, cgroup_migrate_add_task() may have to skip multiple tasks via css_set_skip_task_iters(). However, this only happens when migration and iteration actually race, so the performance impact is negligible compared to the correctness fix provided here.
--- kernel/cgroup/cgroup.c | 1 + 1 file changed, 1 insertion(+)
kernel/cgroup/cgroup.c +1 -0
@@ -2454,6 +2454,7 @@ static void cgroup_migrate_add_task(stru mgctx->tset.nr_tasks++; +css_set_skip_task_iters (cset, task);list_move_tail (&task->cg_list, &cset->mg_tasks);if (list_empty (&cset->mg_node)) list_add_tail(&cset->mg_node,
Greg Kroah-Hartman
maintainerPATCH 132/570 net: usb: lan78xx: fix silent drop of packets with checksum errors
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oleksij Rempel <[email protected]>
commit e4f774a0cc955ce762aec91c66915a6e15087ab7 upstream.
Do not drop packets with checksum errors at the USB driver level; pass them to the network stack.
Previously, the driver dropped all packets where the 'Receive Error Detected' (RED) bit was set, regardless of the specific error type. This caused packets with only IP or TCP/UDP checksum errors to be dropped before reaching the kernel, preventing the network stack from accounting for them or performing software fallback.
Add a mask for hard hardware errors to safely drop genuinely corrupt frames, while allowing checksum-errored frames to pass with their ip_summed field explicitly set to CHECKSUM_NONE.
--- drivers/net/usb/lan78xx.c | 4 +++- drivers/net/usb/lan78xx.h | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/net/usb/lan78xx.c +3 -1
@@ -3334,6 +3334,7 @@ static void lan78xx_rx_csum_offload(stru*/ if (!(dev->net->features &NETIF_F_RXCSUM ) ||unlikely (rx_cmd_a &RX_CMD_A_ICSM_ ) || +unlikely (rx_cmd_a &RX_CMD_A_CSE_MASK_ ) || ((rx_cmd_a &RX_CMD_A_FVTG_ ) && !(dev->net->features &NETIF_F_HW_VLAN_CTAG_RX ))) { skb->ip_summed =CHECKSUM_NONE ;
@@ -3401,7 +3402,8 @@ static int lan78xx_rx(struct lan78xx_net size = (rx_cmd_a &RX_CMD_A_LEN_MASK_ ); align_count = (4 - ((size +RXW_PADDING ) %4 )) %4 ; -if (unlikely (rx_cmd_a &RX_CMD_A_RED_ )) { +if (unlikely (rx_cmd_a &RX_CMD_A_RED_ ) && + (rx_cmd_a &RX_CMD_A_RX_HARD_ERRS_MASK_ )) {netif_dbg (dev, rx_err, dev->net,"Error rx_cmd_a=0x%08x" , rx_cmd_a); }else {
drivers/net/usb/lan78xx.h +3 -0
@@ -74,6 +74,9 @@#define RX_CMD_A_ICSM_ (0x00004000)#define RX_CMD_A_LEN_MASK_ (0x00003FFF) +#define RX_CMD_A_RX_HARD_ERRS_MASK_ \ + (RX_CMD_A_RX_ERRS_MASK_ & ~RX_CMD_A_CSE_MASK_) +/* Rx Command B */ #define RX_CMD_B_CSUM_SHIFT_ (16)#define RX_CMD_B_CSUM_MASK_ (0xFFFF0000)
Greg Kroah-Hartman
maintainerPATCH 133/570 net: usb: lan78xx: skip LTM configuration for LAN7850
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oleksij Rempel <[email protected]>
commit d9cc0e440f0664f6f3e2c26e39ab9dd5f3badba7 upstream.
Do not configure Latency Tolerance Messaging (LTM) on USB 2.0 hardware.
The LAN7850 is a High-Speed (USB 2.0) only device and does not support SuperSpeed features like LTM. Currently, the driver unconditionally attempts to configure LTM registers during initialization. On the LAN7850, these registers do not exist, resulting in writes to invalid or undocumented memory space.
This issue was identified during a port to the regmap API with strict register validation enabled. While no functional issues or crashes have been observed from these invalid writes, bypassing LTM initialization on the LAN7850 ensures the driver strictly adheres to the hardware's valid register map.
--- drivers/net/usb/lan78xx.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/usb/lan78xx.c +4 -0
@@ -2518,6 +2518,10 @@ static void lan78xx_init_ltm(struct lan7u32 buf;u32 regs[6 ] = {0 }; +/* LAN7850 is USB 2.0 and does not support LTM */ +if (dev->chipid ==ID_REV_CHIP_ID_7850_ ) +return ; + ret =lan78xx_read_reg (dev,USB_CFG1 , &buf);if (buf &USB_CFG1_LTM_ENABLE_ ) {u8 temp[2 ];
Greg Kroah-Hartman
maintainerPATCH 134/570 usb/core/quirks: Add Huawei ME906S-device to wakeup quirk
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoffer Sandberg <[email protected]>
commit 0326ff28d56b4fa202de36ffc8462a354f383a64 upstream.
Similar to other Huawei LTE modules using this quirk, this version with another vid/pid suffers from spurious wakeups.
Setting the quirk fixes the issue for this device as well.
--- drivers/usb/core/quirks.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/core/quirks.c +4 -0
@@ -205,6 +205,10 @@ static const struct usb_device_id usb_qu/* HP v222w 16GB Mini USB Drive */ { USB_DEVICE(0x03f0, 0x3f40), .driver_info = USB_QUIRK_DELAY_INIT }, + /* Huawei 4G LTE module ME906S */ + { USB_DEVICE(0x03f0, 0xa31d), .driver_info = + USB_QUIRK_DISCONNECT_SUSPEND }, + /* Creative SB Audigy 2 NX */ { USB_DEVICE(0x041e, 0x3020), .driver_info = USB_QUIRK_RESET_RESUME },
Greg Kroah-Hartman
maintainerPATCH 135/570 usb: xhci: Fix memory leak in xhci_disable_slot()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zilin Guan <[email protected]>
commit c1c8550e70401159184130a1afc6261db01fc0ce upstream.
xhci_alloc_command() allocates a command structure and, when the second argument is true, also allocates a completion structure. Currently, the error handling path in xhci_disable_slot() only frees the command structure using kfree(), causing the completion structure to leak.
Use xhci_free_command() instead of kfree(). xhci_free_command() correctly frees both the command structure and the associated completion structure. Since the command structure is allocated with zero-initialization, command->in_ctx is NULL and will not be erroneously freed by xhci_free_command().
This bug was found using an experimental static analysis tool we are developing. The tool is based on the LLVM framework and is specifically designed to detect memory management issues. It is currently under active development and not yet publicly available, but we plan to open-source it after our research is published.
The bug was originally detected on v6.13-rc1 using our static analysis tool, and we have verified that the issue persists in the latest mainline kernel.
We performed build testing on x86_64 with allyesconfig using GCC=11.4.0. Since triggering these error paths in xhci_disable_slot() requires specific hardware conditions or abnormal state, we were unable to construct a test case to reliably trigger these specific error paths at runtime.
--- drivers/usb/host/xhci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/xhci.c +2 -2
@@ -4056,7 +4056,7 @@ int xhci_disable_slot(struct xhci_hcd *xif (state ==0xffffffff || (xhci->xhc_state &XHCI_STATE_DYING ) || (xhci->xhc_state &XHCI_STATE_HALTED )) {spin_unlock_irqrestore (&xhci->lock, flags); -kfree (command); +xhci_free_command (xhci, command);return -ENODEV ; }
@@ -4064,7 +4064,7 @@ int xhci_disable_slot(struct xhci_hcd *x slot_id);if (ret) {spin_unlock_irqrestore (&xhci->lock, flags); -kfree (command); +xhci_free_command (xhci, command);return ret; }xhci_ring_cmd_db (xhci);
Greg Kroah-Hartman
maintainerPATCH 136/570 usb: yurex: fix race in probe
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Neukum <[email protected]>
commit 7a875c09899ba0404844abfd8f0d54cdc481c151 upstream.
The bbu member of the descriptor must be set to the value standing for uninitialized values before the URB whose completion handler sets bbu is submitted. Otherwise there is a window during which probing can overwrite already retrieved data.
--- drivers/usb/misc/yurex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/misc/yurex.c +1 -1
@@ -272,6 +272,7 @@ static int yurex_probe(struct usb_interf dev->int_buffer,YUREX_BUF_SIZE , yurex_interrupt, dev, 1); dev->urb->transfer_flags |=URB_NO_TRANSFER_DMA_MAP ; + dev->bbu =-1 ;if (usb_submit_urb (dev->urb,GFP_KERNEL )) { retval = -EIO ;dev_err (&interface->dev,"Could not submitting URB\n" );
@@ -280,7 +281,6 @@ static int yurex_probe(struct usb_interf/* save our data pointer in this interface device */ usb_set_intfdata (interface, dev); - dev->bbu =-1 ;/* we can register the device now, as it is ready */ retval =usb_register_dev (interface, &yurex_class);
Greg Kroah-Hartman
maintainerPATCH 137/570 usb: misc: uss720: properly clean up reference in uss720_probe()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit 45dba8011efac11a2f360383221b541f5ea53ce5 upstream.
If get_1284_register() fails, the usb device reference count is incorrect and needs to be properly dropped before returning. That will happen when the kref is dropped in the call to destroy_priv(), so jump to that error path instead of returning directly.
--- drivers/usb/misc/uss720.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/misc/uss720.c +1 -1
@@ -733,7 +733,7 @@ static int uss720_probe(struct usb_inter ret =get_1284_register (pp,0 , ®,GFP_KERNEL );dev_dbg (&intf->dev,"reg: %7ph\n" , priv->reg);if (ret <0 ) -return ret; + goto probe_abort; ret =usb_find_last_int_in_endpoint (interface, &epd);if (!ret) {
Greg Kroah-Hartman
maintainerPATCH 138/570 usb: core: dont power off roothub PHYs if phy_set_mode() fails
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gabor Juhos <[email protected]>
commit e293015ba76eb96ce4ebed7e3b2cb1a7d319f3e9 upstream.
Remove the error path from the usb_phy_roothub_set_mode() function. The code is clearly wrong, because phy_set_mode() calls can't be balanced with phy_power_off() calls.
Additionally, the usb_phy_roothub_set_mode() function is called only from usb_add_hcd() before it powers on the PHYs, so powering off those makes no sense anyway.
Presumably, the code is copy-pasted from the phy_power_on() function without adjusting the error handling.
--- drivers/usb/core/phy.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/usb/core/phy.c +1 -7
@@ -138,16 +138,10 @@ int usb_phy_roothub_set_mode(struct usb_list_for_each_entry (roothub_entry, head, list) { err =phy_set_mode (roothub_entry->phy, mode);if (err) - goto err_out; +return err; }return 0 ; - -err_out: -list_for_each_entry_continue_reverse (roothub_entry, head, list) -phy_power_off (roothub_entry->phy); - -return err; }EXPORT_SYMBOL_GPL (usb_phy_roothub_set_mode);
Greg Kroah-Hartman
maintainerPATCH 139/570 usb: cdc-acm: Restore CAP_BRK functionnality to CH343
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
commit 14ae24cba291bddfdc296bbcbfd00cd09d0498ef upstream.
The CH343 USB/serial adapter is as buggy as it is popular (very). One of its quirks is that despite being capable of signalling a BREAK condition, it doesn't advertise it.
This used to work nonetheless until 66aad7d8d3ec5 ("usb: cdc-acm:
return correct error code on unsupported break") applied some reasonable restrictions, preventing breaks from being emitted on devices that do not advertise CAP_BRK.
Add a quirk for this particular device, so that breaks can still be produced on some of my machines attached to my console server.
--- drivers/usb/class/cdc-acm.c | 5 +++++ drivers/usb/class/cdc-acm.h | 1 + 2 files changed, 6 insertions(+)
drivers/usb/class/cdc-acm.c +5 -0
@@ -1359,6 +1359,8 @@ made_compressed_probe: acm->ctrl_caps = h.usb_cdc_acm_descriptor->bmCapabilities;if (quirks &NO_CAP_LINE ) acm->ctrl_caps &= ~USB_CDC_CAP_LINE ; +if (quirks &MISSING_CAP_BRK ) + acm->ctrl_caps |=USB_CDC_CAP_BRK ; acm->ctrlsize = ctrlsize; acm->readsize = readsize; acm->rx_buflimit = num_rx_buf;
@@ -1988,6 +1990,9 @@ static const struct usb_device_id acm_id .driver_info = IGNORE_DEVICE, }, +/* CH343 supports CAP_BRK, but doesn't advertise it */ + { USB_DEVICE(0x1a86, 0x55d3), .driver_info = MISSING_CAP_BRK, }, + /* control interfaces without any protocol set */ { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, USB_CDC_PROTO_NONE) },
drivers/usb/class/cdc-acm.h +1 -0
@@ -141,3 +141,4 @@ struct acm {#define CLEAR_HALT_CONDITIONS BIT(5)#define SEND_ZERO_PACKET BIT(6)#define DISABLE_ECHO BIT(7) +#define MISSING_CAP_BRK BIT(8)
Greg Kroah-Hartman
maintainerPATCH 140/570 USB: usbcore: Introduce usb_bulk_msg_killable()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alan Stern <[email protected]>
commit 416909962e7cdf29fd01ac523c953f37708df93d upstream.
The synchronous message API in usbcore (usb_control_msg(), usb_bulk_msg(), and so on) uses uninterruptible waits. However, drivers may call these routines in the context of a user thread, which means it ought to be possible to at least kill them.
For this reason, introduce a new usb_bulk_msg_killable() function which behaves the same as usb_bulk_msg() except for using wait_for_completion_killable_timeout() instead of wait_for_completion_timeout(). The same can be done later for usb_control_msg() later on, if it turns out to be needed.
--- drivers/usb/core/message.c | 79 +++++++++++++++++++++++++++++++++++++++------ include/linux/usb.h | 5 +- 2 files changed, 72 insertions(+), 12 deletions(-)
drivers/usb/core/message.c +69 -10
@@ -41,16 +41,17 @@ static void usb_api_blocking_completion(/* -* Starts urb and waits for completion or timeout. Note that this call -* is NOT interruptible. Many device driver i/o requests should be -* interruptible and therefore these drivers should implement their -* own interruptible routines. +* Starts urb and waits for completion or timeout. +* Whether or not the wait is killable depends on the flag passed in. +* For example, compare usb_bulk_msg() and usb_bulk_msg_killable(). */ -static int usb_start_wait_urb (struct urb *urb,int timeout,int *actual_length) +static int usb_start_wait_urb (struct urb *urb,int timeout,int *actual_length, +bool killable) {struct api_context ctx;unsigned long expire;int retval; +long rc;init_completion (&ctx.done); urb->context = &ctx;
@@ -60,12 +61,21 @@ static int usb_start_wait_urb(struct urb goto out; expire = timeout ?msecs_to_jiffies (timeout) :MAX_SCHEDULE_TIMEOUT ; -if (!wait_for_completion_timeout (&ctx.done, expire)) { +if (killable) + rc =wait_for_completion_killable_timeout (&ctx.done, expire); +else + rc =wait_for_completion_timeout (&ctx.done, expire); +if (rc <=0 ) {usb_kill_urb (urb); - retval = (ctx.status == -ENOENT ? -ETIMEDOUT : ctx.status); +if (ctx.status != -ENOENT ) + retval = ctx.status; +else if (rc ==0 ) + retval = -ETIMEDOUT ; +else + retval = rc; dev_dbg(&urb->dev->dev, - "%s timed out on ep%d%s len=%u/%u\n", + "%s timed out or killed on ep%d%s len=%u/%u\n", current->comm, usb_endpoint_num(&urb->ep->desc), usb_urb_dir_in(urb) ? "in" : "out",
@@ -99,7 +109,7 @@ static int usb_internal_control_msg(struusb_fill_control_urb (urb, usb_dev, pipe, (unsigned char *)cmd, data, len, usb_api_blocking_completion,NULL ); - retv =usb_start_wait_urb (urb, timeout, &length); + retv =usb_start_wait_urb (urb, timeout, &length, false);if (retv <0 )return retv;else
@@ -384,10 +394,59 @@ int usb_bulk_msg(struct usb_device *usb_usb_fill_bulk_urb (urb, usb_dev, pipe, data, len, usb_api_blocking_completion,NULL ); -return usb_start_wait_urb (urb, timeout, actual_length); +return usb_start_wait_urb (urb, timeout, actual_length, false); }EXPORT_SYMBOL_GPL (usb_bulk_msg); +/** +* usb_bulk_msg_killable - Builds a bulk urb, sends it off and waits for completion in a killable state +* @usb_dev: pointer to the usb device to send the message to +* @pipe: endpoint "pipe" to send the message to +* @data: pointer to the data to send +* @len: length in bytes of the data to send +* @actual_length: pointer to a location to put the actual length transferred +* in bytes +* @timeout: time in msecs to wait for the message to complete before +* timing out (if 0 the wait is forever) +* +* Context: task context, might sleep. +* +* This function is just like usb_blk_msg() except that it waits in a +* killable state. +* +* Return: +* If successful, 0. Otherwise a negative error number. The number of actual +* bytes transferred will be stored in the @actual_length parameter. +* +*/ +int usb_bulk_msg_killable (struct usb_device *usb_dev,unsigned int pipe, +void *data,int len,int *actual_length,int timeout) +{ +struct urb *urb; +struct usb_host_endpoint *ep; + + ep =usb_pipe_endpoint (usb_dev, pipe); +if (!ep || len <0 ) +return -EINVAL ; + + urb =usb_alloc_urb (0 ,GFP_KERNEL ); +if (!urb) +return -ENOMEM ; + +if ((ep->desc.bmAttributes &USB_ENDPOINT_XFERTYPE_MASK ) == +USB_ENDPOINT_XFER_INT ) { + pipe = (pipe & ~(3 <<30 )) | (PIPE_INTERRUPT <<30 ); +usb_fill_int_urb (urb, usb_dev, pipe, data, len, + usb_api_blocking_completion,NULL , + ep->desc.bInterval); + }else +usb_fill_bulk_urb (urb, usb_dev, pipe, data, len, + usb_api_blocking_completion,NULL ); + +return usb_start_wait_urb (urb, timeout, actual_length, true); +} +EXPORT_SYMBOL_GPL (usb_bulk_msg_killable); +/*-------------------------------------------------------------------*/ static void sg_clean (struct usb_sg_request *io)
include/linux/usb.h +3 -2
@@ -1811,8 +1811,9 @@ extern int usb_control_msg(struct usb_deextern int usb_interrupt_msg (struct usb_device *usb_dev,unsigned int pipe,void *data,int len,int *actual_length,int timeout);extern int usb_bulk_msg (struct usb_device *usb_dev,unsigned int pipe, -void *data,int len,int *actual_length, -int timeout); +void *data,int len,int *actual_length,int timeout); +extern int usb_bulk_msg_killable (struct usb_device *usb_dev,unsigned int pipe, +void *data,int len,int *actual_length,int timeout);/* wrappers around usb_control_msg() for the most common standard requests */ int usb_control_msg_send(struct usb_device *dev, __u8 endpoint, __u8 request,
Greg Kroah-Hartman
maintainerPATCH 141/570 USB: usbtmc: Use usb_bulk_msg_killable() with user-specified timeouts
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alan Stern <[email protected]>
commit 7784caa413a89487dd14dd5c41db8753483b2acb upstream.
The usbtmc driver accepts timeout values specified by the user in an ioctl command, and uses these timeouts for some usb_bulk_msg() calls. Since the user can specify arbitrarily long timeouts and usb_bulk_msg() uses unkillable waits, call usb_bulk_msg_killable() instead to avoid the possibility of the user hanging a kernel thread indefinitely.
--- drivers/usb/class/usbtmc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/class/usbtmc.c +3 -3
@@ -727,7 +727,7 @@ static int usbtmc488_ioctl_trigger(struc buffer[1 ] = data->bTag; buffer[2 ] = ~data->bTag; - retval = usb_bulk_msg(data->usb_dev, + retval = usb_bulk_msg_killable(data->usb_dev, usb_sndbulkpipe(data->usb_dev, data->bulk_out), buffer, USBTMC_HEADER_SIZE,
@@ -1347,7 +1347,7 @@ static int send_request_dev_dep_msg_in(s buffer[11 ] =0 ;/* Reserved */ /* Send bulk URB */ - retval = usb_bulk_msg(data->usb_dev, + retval = usb_bulk_msg_killable(data->usb_dev, usb_sndbulkpipe(data->usb_dev, data->bulk_out), buffer, USBTMC_HEADER_SIZE,
@@ -1419,7 +1419,7 @@ static ssize_t usbtmc_read(struct file * actual =0 ;/* Send bulk URB */ - retval = usb_bulk_msg(data->usb_dev, + retval = usb_bulk_msg_killable(data->usb_dev, usb_rcvbulkpipe(data->usb_dev, data->bulk_in), buffer, bufsize, &actual,
Greg Kroah-Hartman
maintainerPATCH 142/570 USB: core: Limit the length of unkillable synchronous timeouts
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alan Stern <[email protected]>
commit 1015c27a5e1a63efae2b18a9901494474b4d1dc3 upstream.
The usb_control_msg(), usb_bulk_msg(), and usb_interrupt_msg() APIs in usbcore allow unlimited timeout durations. And since they use uninterruptible waits, this leaves open the possibility of hanging a task for an indefinitely long time, with no way to kill it short of unplugging the target device.
To prevent this sort of problem, enforce a maximum limit on the length of these unkillable timeouts. The limit chosen here, somewhat arbitrarily, is 60 seconds. On many systems (although not all) this is short enough to avoid triggering the kernel's hung-task detector.
In addition, clear up the ambiguity of negative timeout values by treating them the same as 0, i.e., using the maximum allowed timeout.
--- drivers/usb/core/message.c | 27 +++++++++++++-------------- include/linux/usb.h | 3 +++ 2 files changed, 16 insertions(+), 14 deletions(-)
drivers/usb/core/message.c +13 -14
@@ -44,6 +44,8 @@ static void usb_api_blocking_completion(* Starts urb and waits for completion or timeout. * Whether or not the wait is killable depends on the flag passed in. * For example, compare usb_bulk_msg() and usb_bulk_msg_killable(). +* +* For non-killable waits, we enforce a maximum limit on the timeout value. */ static int usb_start_wait_urb (struct urb *urb,int timeout,int *actual_length,bool killable)
@@ -60,7 +62,9 @@ static int usb_start_wait_urb(struct urbif (unlikely (retval)) goto out; - expire = timeout ?msecs_to_jiffies (timeout) :MAX_SCHEDULE_TIMEOUT ; +if (!killable && (timeout <=0 || timeout >USB_MAX_SYNCHRONOUS_TIMEOUT )) + timeout =USB_MAX_SYNCHRONOUS_TIMEOUT ; + expire = (timeout >0 ) ?msecs_to_jiffies (timeout) :MAX_SCHEDULE_TIMEOUT ;if (killable) rc =wait_for_completion_killable_timeout (&ctx.done, expire);else
@@ -126,8 +130,7 @@ static int usb_internal_control_msg(stru* @index: USB message index value * @data: pointer to the data to send * @size: length in bytes of the data to send -* @timeout: time in msecs to wait for the message to complete before timing -* out (if 0 the wait is forever) +* @timeout: time in msecs to wait for the message to complete before timing out * * Context: task context, might sleep. *
@@ -182,8 +185,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);* @index: USB message index value * @driver_data: pointer to the data to send * @size: length in bytes of the data to send -* @timeout: time in msecs to wait for the message to complete before timing -* out (if 0 the wait is forever) +* @timeout: time in msecs to wait for the message to complete before timing out * @memflags: the flags for memory allocation for buffers * * Context: !in_interrupt ()
@@ -241,8 +243,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg_send);* @index: USB message index value * @driver_data: pointer to the data to be filled in by the message * @size: length in bytes of the data to be received -* @timeout: time in msecs to wait for the message to complete before timing -* out (if 0 the wait is forever) +* @timeout: time in msecs to wait for the message to complete before timing out * @memflags: the flags for memory allocation for buffers * * Context: !in_interrupt ()
@@ -313,8 +314,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg_recv);* @len: length in bytes of the data to send * @actual_length: pointer to a location to put the actual length transferred * in bytes -* @timeout: time in msecs to wait for the message to complete before -* timing out (if 0 the wait is forever) +* @timeout: time in msecs to wait for the message to complete before timing out * * Context: task context, might sleep. *
@@ -346,8 +346,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);* @len: length in bytes of the data to send * @actual_length: pointer to a location to put the actual length transferred * in bytes -* @timeout: time in msecs to wait for the message to complete before -* timing out (if 0 the wait is forever) +* @timeout: time in msecs to wait for the message to complete before timing out * * Context: task context, might sleep. *
@@ -407,12 +406,12 @@ EXPORT_SYMBOL_GPL(usb_bulk_msg);* @actual_length: pointer to a location to put the actual length transferred * in bytes * @timeout: time in msecs to wait for the message to complete before -* timing out (if 0 the wait is forever) +* timing out (if <= 0, the wait is as long as possible) * * Context: task context, might sleep. * -* This function is just like usb_blk_msg() except that it waits in a -* killable state. +* This function is just like usb_blk_msg(), except that it waits in a +* killable state and there is no limit on the timeout length. * * Return: * If successful, 0. Otherwise a negative error number. The number of actual
include/linux/usb.h +3 -0
@@ -1805,6 +1805,9 @@ void usb_buffer_unmap_sg(const struct us* SYNCHRONOUS CALL SUPPORT * *-------------------------------------------------------------------*/ +/* Maximum value allowed for timeout in synchronous routines below */ +#define USB_MAX_SYNCHRONOUS_TIMEOUT 60000/* ms */ +extern int usb_control_msg (struct usb_device *dev,unsigned int pipe,__u8 request,__u8 requesttype,__u16 value,__u16 index,void *data,__u16 size,int timeout);
Greg Kroah-Hartman
maintainerPATCH 143/570 usb: class: cdc-wdm: fix reordering issue in read code path
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Neukum <[email protected]>
commit 8df672bfe3ec2268c2636584202755898e547173 upstream.
Quoting the bug report:
Due to compiler optimization or CPU out-of-order execution, the desc->length update can be reordered before the memmove. If this happens, wdm_read() can see the new length and call copy_to_user() on uninitialized memory. This also violates LKMM data race rules [1].
Fix it by using WRITE_ONCE and memory barriers.
--- drivers/usb/class/cdc-wdm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/class/cdc-wdm.c +3 -1
@@ -225,7 +225,8 @@ static void wdm_in_callback(struct urb */* we may already be in overflow */ if (!test_bit (WDM_OVERFLOW , &desc->flags)) {memmove (desc->ubuf + desc->length, desc->inbuf, length); - desc->length += length; +smp_wmb ();/* against wdm_read() */ +WRITE_ONCE (desc->length, desc->length + length); } } skip_error:
@@ -533,6 +534,7 @@ static ssize_t wdm_readreturn -ERESTARTSYS ; cntr =READ_ONCE (desc->length); +smp_rmb ();/* against wdm_in_callback() */ if (cntr ==0 ) { desc->read =0 ; retry:
Greg Kroah-Hartman
maintainerPATCH 144/570 usb: renesas_usbhs: fix use-after-free in ISR during device removal
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit 3cbc242b88c607f55da3d0d0d336b49bf1e20412 upstream.
In usbhs_remove(), the driver frees resources (including the pipe array) while the interrupt handler (usbhs_interrupt) is still registered. If an interrupt fires after usbhs_pipe_remove() but before the driver is fully unbound, the ISR may access freed memory, causing a use-after-free.
Fix this by calling devm_free_irq() before freeing resources. This ensures the interrupt handler is both disabled and synchronized (waits for any running ISR to complete) before usbhs_pipe_remove() is called.
--- drivers/usb/renesas_usbhs/common.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/usb/renesas_usbhs/common.c +9 -0
@@ -804,6 +804,15 @@ static void usbhs_remove(struct platformusbhs_platform_call (priv, hardware_exit, pdev);reset_control_assert (priv->rsts); + +/* +* Explicitly free the IRQ to ensure the interrupt handler is +* disabled and synchronized before freeing resources. +* devm_free_irq() calls free_irq() which waits for any running +* ISR to complete, preventing UAF. +*/ +devm_free_irq (&pdev->dev, priv->irq, priv); +usbhs_mod_remove (priv);usbhs_fifo_remove (priv);usbhs_pipe_remove (priv);
Greg Kroah-Hartman
maintainerPATCH 145/570 usb: mdc800: handle signal and read racing
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Neukum <[email protected]>
commit 2d6d260e9a3576256fe9ef6d1f7930c9ec348723 upstream.
If a signal arrives after a read has partially completed, we need to return the number of bytes read. -EINTR is correct only if that number is zero.
--- drivers/usb/image/mdc800.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/image/mdc800.c +1 -1
@@ -708,7 +708,7 @@ static ssize_t mdc800_device_read (strucif (signal_pending (current)) {mutex_unlock (&mdc800->io_lock); -return -EINTR ; +return len == left ? -EINTR : len-left; } sts=left > (mdc800->out_count-mdc800->out_ptr)?mdc800->out_count-mdc800->out_ptr:left;
Greg Kroah-Hartman
maintainerPATCH 146/570 usb: image: mdc800: kill download URB on timeout
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ziyi Guo <[email protected]>
commit 1be3b77de4eb89af8ae2fd6610546be778e25589 upstream.
mdc800_device_read() submits download_urb and waits for completion. If the timeout fires and the device has not responded, the function returns without killing the URB, leaving it active.
A subsequent read() resubmits the same URB while it is still in-flight, triggering the WARN in usb_submit_urb():
"URB submitted while active"
Check the return value of wait_event_timeout() and kill the URB if it indicates timeout, ensuring the URB is complete before its status is inspected or the URB is resubmitted.
Similar to
- commit 372c93131998 ("USB: yurex: fix control-URB timeout handling")
- commit b98d5000c505 ("media: rc: iguanair: handle timeouts")
--- drivers/usb/image/mdc800.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/image/mdc800.c +3 -1
@@ -731,9 +731,11 @@ static ssize_t mdc800_device_read (strucmutex_unlock (&mdc800->io_lock);return len-left; } -wait_event_timeout (mdc800->download_wait, + retval =wait_event_timeout (mdc800->download_wait, mdc800->downloaded,msecs_to_jiffies (TO_DOWNLOAD_GET_READY )); +if (!retval) +usb_kill_urb (mdc800->download_urb); mdc800->downloaded =0 ;if (mdc800->download_urb->status !=0 ) {
Greg Kroah-Hartman
maintainerPATCH 147/570 mm/tracing: rss_stat: ensure curr is false from kthread context
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kalesh Singh <[email protected]>
commit 079c24d5690262e83ee476e2a548e416f3237511 upstream.
The rss_stat trace event allows userspace tools, like Perfetto [1], to inspect per-process RSS metric changes over time.
The curr field was introduced to rss_stat in commit e4dcad204d3a ("rss_stat: add support to detect RSS updates of external mm"). Its intent is to indicate whether the RSS update is for the mm_struct of the current execution context; and is set to false when operating on a remote mm_struct (e.g., via kswapd or a direct reclaimer).
However, an issue arises when a kernel thread temporarily adopts a user process's mm_struct. Kernel threads do not have their own mm_struct and normally have current->mm set to NULL. To operate on user memory, they can "borrow" a memory context using kthread_use_mm(), which sets current->mm to the user process's mm.
This can be observed, for example, in the USB Function Filesystem (FFS) driver. The ffs_user_copy_worker() handles AIO completions and uses kthread_use_mm() to copy data to a user-space buffer. If a page fault occurs during this copy, the fault handler executes in the kthread's context.
At this point, current is the kthread, but current->mm points to the user process's mm. Since the rss_stat event (from the page fault) is for that same mm, the condition current->mm == mm becomes true, causing curr to be incorrectly set to true when the trace event is emitted.
This is misleading because it suggests the mm belongs to the kthread, confusing userspace tools that track per-process RSS changes and corrupting their mm_id-to-process association.
Fix this by ensuring curr is always false when the trace event is emitted from a kthread context by checking for the PF_KTHREAD flag.
--- include/trace/events/kmem.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
include/trace/events/kmem.h +7 -1
@@ -384,7 +384,13 @@ TRACE_EVENT(rss_stat,TP_fast_assign ( __entry->mm_id = mm_ptr_to_hash(mm); - __entry->curr = !!(current->mm == mm); +/* +* curr is true if the mm matches the current task's mm_struct. +* Since kthreads (PF_KTHREAD) have no mm_struct of their own +* but can borrow one via kthread_use_mm(), we must filter them +* out to avoid incorrectly attributing the RSS update to them. +*/ + __entry->curr = current->mm == mm && !(current->flags &PF_KTHREAD ); __entry->member = member; __entry->size = (count <<PAGE_SHIFT ); ),
Greg Kroah-Hartman
maintainerPATCH 148/570 mmc: mmci: Fix device_node reference leak in of_get_dml_pipe_index()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Gu <[email protected]>
commit af12e64ae0661546e8b4f5d30d55c5f53a11efe7 upstream.
When calling of_parse_phandle_with_args(), the caller is responsible to call of_node_put() to release the reference of device node. In of_get_dml_pipe_index(), it does not release the reference.
--- drivers/mmc/host/mmci_qcom_dml.c | 1 + 1 file changed, 1 insertion(+)
drivers/mmc/host/mmci_qcom_dml.c +1 -0
@@ -109,6 +109,7 @@ static int of_get_dml_pipe_index(struct &dma_spec))return -ENODEV ; +of_node_put (dma_spec.np);if (dma_spec.args_count)return dma_spec.args[0 ];
Greg Kroah-Hartman
maintainerPATCH 149/570 mmc: core: Avoid bitfield RMW for claim/retune flags
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Penghe Geng <[email protected]>
commit 901084c51a0a8fb42a3f37d2e9c62083c495f824 upstream.
Move claimed and retune control flags out of the bitfield word to avoid unrelated RMW side effects in asynchronous contexts.
The host->claimed bit shared a word with retune flags. Writes to claimed in __mmc_claim_host() or retune_now in mmc_mq_queue_rq() can overwrite other bits when concurrent updates happen in other contexts, triggering spurious WARN_ON(!host->claimed). Convert claimed, can_retune, retune_now and retune_paused to bool to remove shared-word coupling.
--- include/linux/mmc/host.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
include/linux/mmc/host.h +5 -4
@@ -418,14 +418,12 @@ struct mmc_host {struct mmc_ios ios;/* current io bus settings */ +bool claimed;/* host exclusively claimed */ +/* group bitfields together to minimize padding */ unsigned int use_spi_crc:1; - unsigned int claimed:1; /* host exclusively claimed */ unsigned int doing_init_tune:1; /* initial tuning in progress */ - unsigned int can_retune:1; /* re-tuning can be used */ unsigned int doing_retune:1; /* re-tuning in progress */ - unsigned int retune_now:1; /* do re-tuning at next req */ - unsigned int retune_paused:1; /* re-tuning is temporarily disabled */ unsigned int retune_crc_disable:1; /* don't trigger retune upon crc */ unsigned int can_dma_map_merge:1; /* merging can be used */ unsigned int vqmmc_enabled:1; /* vqmmc regulator is enabled */
@@ -433,6 +431,9 @@ struct mmc_host {int rescan_disable;/* disable card detection */ int rescan_entered;/* used with nonremovable devices */ +bool can_retune;/* re-tuning can be used */ +bool retune_now;/* do re-tuning at next req */ +bool retune_paused;/* re-tuning is temporarily disabled */ int need_retune;/* re-tuning is needed */ int hold_retune;/* hold off re-tuning */ unsigned int retune_period;/* re-tuning period in secs */
Greg Kroah-Hartman
maintainerPATCH 150/570 tipc: fix divide-by-zero in tipc_sk_filter_connect()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mehul Rao <[email protected]>
commit 6c5a9baa15de240e747263aba435a0951da8d8d2 upstream.
A user can set conn_timeout to any value via setsockopt(TIPC_CONN_TIMEOUT), including values less than 4. When a SYN is rejected with TIPC_ERR_OVERLOAD and the retry path in tipc_sk_filter_connect() executes:
delay %= (tsk->conn_timeout / 4);
If conn_timeout is in the range [0, 3], the integer division yields 0, and the modulo operation triggers a divide-by-zero exception, causing a kernel oops/panic.
Fix this by clamping conn_timeout to a minimum of 4 at the point of use in tipc_sk_filter_connect().
Oops: divide error: 0000 [#1] SMP KASAN NOPTI CPU: 0 UID: 0 PID: 119 Comm: poc-F144 Not tainted 7.0.0-rc2+ RIP: 0010:tipc_sk_filter_rcv (net/tipc/socket.c:2236 net/tipc/socket.c:2362) Call Trace: tipc_sk_backlog_rcv (include/linux/instrumented.h:82 include/linux/atomic/atomic-instrumented.h:32 include/net/sock.h:2357 net/tipc/socket.c:2406) __release_sock (include/net/sock.h:1185 net/core/sock.c:3213) release_sock (net/core/sock.c:3797) tipc_connect (net/tipc/socket.c:2570) __sys_connect (include/linux/file.h:62 include/linux/file.h:83 net/socket.c:2098)
--- net/tipc/socket.c | 2 ++ 1 file changed, 2 insertions(+)
net/tipc/socket.c +2 -0
@@ -2235,6 +2235,8 @@ static bool tipc_sk_filter_connect(strucif (skb_queue_empty (&sk->sk_write_queue))break ;get_random_bytes (&delay,2 ); +if (tsk->conn_timeout <4 ) + tsk->conn_timeout =4 ; delay %= (tsk->conn_timeout /4 ); delay =msecs_to_jiffies (delay +100 );sk_reset_timer (sk, &sk->sk_timer, jiffies + delay);
Greg Kroah-Hartman
maintainerPATCH 151/570 libceph: Fix potential out-of-bounds access in ceph_handle_auth_reply()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raphael Zimmer <[email protected]>
commit b282c43ed156ae15ea76748fc15cd5c39dc9ab72 upstream.
This patch fixes an out-of-bounds access in ceph_handle_auth_reply() that can be triggered by a message of type CEPH_MSG_AUTH_REPLY. In ceph_handle_auth_reply(), the value of the payload_len field of such a message is stored in a variable of type int. A value greater than INT_MAX leads to an integer overflow and is interpreted as a negative value. This leads to decrementing the pointer address by this value and subsequently accessing it because ceph_decode_need() only checks that the memory access does not exceed the end address of the allocation.
This patch fixes the issue by changing the data type of payload_len to u32. Additionally, the data type of result_msg_len is changed to u32, as it is also a variable holding a non-negative length.
Also, an additional layer of sanity checks is introduced, ensuring that directly after reading it from the message, payload_len and result_msg_len are not greater than the overall segment length.
BUG: KASAN: slab-out-of-bounds in ceph_handle_auth_reply+0x642/0x7a0 [libceph] Read of size 4 at addr ffff88811404df14 by task kworker/20:1/262 CPU: 20 UID: 0 PID: 262 Comm: kworker/20:1 Not tainted 6.19.2 #5 PREEMPT(voluntary) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Workqueue: ceph-msgr ceph_con_workfn [libceph] Call Trace: <TASK> dump_stack_lvl+0x76/0xa0 print_report+0xd1/0x620 ? __pfx__raw_spin_lock_irqsave+0x10/0x10 ? kasan_complete_mode_report_info+0x72/0x210 kasan_report+0xe7/0x130 ? ceph_handle_auth_reply+0x642/0x7a0 [libceph] ? ceph_handle_auth_reply+0x642/0x7a0 [libceph] __asan_report_load_n_noabort+0xf/0x20 ceph_handle_auth_reply+0x642/0x7a0 [libceph] mon_dispatch+0x973/0x23d0 [libceph] ? apparmor_socket_recvmsg+0x6b/0xa0 ? __pfx_mon_dispatch+0x10/0x10 [libceph] ? __kasan_check_write+0x14/0x30i ? mutex_unlock+0x7f/0xd0 ? __pfx_mutex_unlock+0x10/0x10 ? __pfx_do_recvmsg+0x10/0x10 [libceph] ceph_con_process_message+0x1f1/0x650 [libceph] process_message+0x1e/0x450 [libceph] ceph_con_v2_try_read+0x2e48/0x6c80 [libceph] ? __pfx_ceph_con_v2_try_read+0x10/0x10 [libceph] ? save_fpregs_to_fpstate+0xb0/0x230 ? raw_spin_rq_unlock+0x17/0xa0 ? finish_task_switch.isra.0+0x13b/0x760 ? __switch_to+0x385/0xda0 ? __kasan_check_write+0x14/0x30 ? mutex_lock+0x8d/0xe0 ? __pfx_mutex_lock+0x10/0x10 ceph_con_workfn+0x248/0x10c0 [libceph] process_one_work+0x629/0xf80 ? __kasan_check_write+0x14/0x30 worker_thread+0x87f/0x1570 ? __pfx__raw_spin_lock_irqsave+0x10/0x10 ? __pfx_try_to_wake_up+0x10/0x10 ? kasan_print_address_stack_frame+0x1f7/0x280 ? __pfx_worker_thread+0x10/0x10 kthread+0x396/0x830 ? __pfx__raw_spin_lock_irq+0x10/0x10 ? __pfx_kthread+0x10/0x10 ? __kasan_check_write+0x14/0x30 ? recalc_sigpending+0x180/0x210 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x3f7/0x610 ? __pfx_ret_from_fork+0x10/0x10 ? __switch_to+0x385/0xda0 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK>
[ idryomov: replace if statements with ceph_decode_need() for
payload_len and result_msg_len ]
--- net/ceph/auth.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/ceph/auth.c +4 -2
@@ -205,9 +205,9 @@ int ceph_handle_auth_reply(struct ceph_as32 result;u64 global_id;void *payload, *payload_end; -int payload_len; +u32 payload_len;char *result_msg; -int result_msg_len; +u32 result_msg_len;int ret = -EINVAL ;mutex_lock (&ac->mutex);
@@ -217,10 +217,12 @@ int ceph_handle_auth_reply(struct ceph_a result =ceph_decode_32 (&p); global_id =ceph_decode_64 (&p); payload_len =ceph_decode_32 (&p); +ceph_decode_need (&p, end, payload_len, bad); payload = p; p += payload_len;ceph_decode_need (&p, end,sizeof (u32), bad); result_msg_len =ceph_decode_32 (&p); +ceph_decode_need (&p, end, result_msg_len, bad); result_msg = p; p += result_msg_len;if (p != end)
Greg Kroah-Hartman
maintainerPATCH 152/570 libceph: reject preamble if control segment is empty
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Dryomov <[email protected]>
commit c4c22b846eceff05b1129b8844a80310e55a7f87 upstream.
While head_onwire_len() has a branch to handle ctrl_len == 0 case, prepare_read_control() always sets up a kvec for the CRC meaning that a non-empty control segment is effectively assumed. All frames that clients deal with meet that assumption, so let's make it official and treat the preamble with an empty control segment as malformed.
--- net/ceph/messenger_v2.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
net/ceph/messenger_v2.c +8 -9
@@ -391,7 +391,7 @@ static int head_onwire_len(int ctrl_len,int head_len;int rem_len; -BUG_ON (ctrl_len <0 || ctrl_len >CEPH_MSG_MAX_CONTROL_LEN ); +BUG_ON (ctrl_len <1 || ctrl_len >CEPH_MSG_MAX_CONTROL_LEN );if (secure) { head_len =CEPH_PREAMBLE_SECURE_LEN ;
@@ -400,9 +400,7 @@ static int head_onwire_len(int ctrl_len, head_len +=padded_len (rem_len) +CEPH_GCM_TAG_LEN ; } }else { - head_len =CEPH_PREAMBLE_PLAIN_LEN ; -if (ctrl_len) - head_len += ctrl_len +CEPH_CRC_LEN ; + head_len =CEPH_PREAMBLE_PLAIN_LEN + ctrl_len +CEPH_CRC_LEN ; }return head_len; }
@@ -527,11 +525,16 @@ static int decode_preamble(void *p, stru desc->fd_aligns[i] =ceph_decode_16 (&p); } -if (desc->fd_lens[0 ] <0 || +/* +* This would fire for FRAME_TAG_WAIT (it has one empty +* segment), but we should never get it as client. +*/ +if (desc->fd_lens[0 ] <1 || desc->fd_lens[0 ] >CEPH_MSG_MAX_CONTROL_LEN ) {pr_err ("bad control segment length %d\n" , desc->fd_lens[0 ]);return -EINVAL ; } +if (desc->fd_lens[1 ] <0 || desc->fd_lens[1 ] >CEPH_MSG_MAX_FRONT_LEN ) {pr_err ("bad front segment length %d\n" , desc->fd_lens[1 ]);
@@ -548,10 +551,6 @@ static int decode_preamble(void *p, strureturn -EINVAL ; } -/* -* This would fire for FRAME_TAG_WAIT (it has one empty -* segment), but we should never get it as client. -*/ if (!desc->fd_lens[desc->fd_seg_cnt -1 ]) {pr_err ("last segment empty, segment count %d\n" , desc->fd_seg_cnt);
Greg Kroah-Hartman
maintainerPATCH 153/570 libceph: prevent potential out-of-bounds reads in process_message_header()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Dryomov <[email protected]>
commit 69fb5d91bba44ecf7eb80530b85fa4fb028921d5 upstream.
If the message frame is (maliciously) corrupted in a way that the length of the control segment ends up being less than the size of the message header or a different frame is made to look like a message frame, out-of-bounds reads may ensue in process_message_header().
Perform an explicit bounds check before decoding the message header.
--- net/ceph/messenger_v2.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/ceph/messenger_v2.c +8 -1
@@ -2527,12 +2527,15 @@ static int process_message_header(struct void *p, void *end) { struct ceph_frame_desc *desc = &con->v2.in_desc; -struct ceph_msg_header2 *hdr2 = p; +struct ceph_msg_header2 *hdr2;struct ceph_msg_header hdr;int skip;int ret;u64 seq; +ceph_decode_need (&p, end,sizeof (*hdr2), bad); + hdr2 = p; +/* verify seq# */ seq =le64_to_cpu (hdr2->seq);if ((s64 )seq - (s64 )con->in_seq <1 ) {
@@ -2563,6 +2566,10 @@ static int process_message_header(structWARN_ON (!con->in_msg);WARN_ON (con->in_msg->con != con);return 1 ; + +bad: +pr_err ("failed to decode message header\n" ); +return -EINVAL ; }static int process_message (struct ceph_connection *con)
Greg Kroah-Hartman
maintainerPATCH 154/570 libceph: Use u32 for non-negative values in ceph_monmap_decode()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raphael Zimmer <[email protected]>
commit 770444611f047dbfd4517ec0bc1b179d40c2f346 upstream.
This patch fixes unnecessary implicit conversions that change signedness of blob_len and num_mon in ceph_monmap_decode().
Currently blob_len and num_mon are (signed) int variables. They are used to hold values that are always non-negative and get assigned in ceph_decode_32_safe(), which is meant to assign u32 values. Both variables are subsequently used as unsigned values, and the value of num_mon is further assigned to monmap->num_mon, which is of type u32. Therefore, both variables should be of type u32. This is especially relevant for num_mon. If the value read from the incoming message is very large, it is interpreted as a negative value, and the check for num_mon > CEPH_MAX_MON does not catch it. This leads to the attempt to allocate a very large chunk of memory for monmap, which will most likely fail. In this case, an unnecessary attempt to allocate memory is performed, and -ENOMEM is returned instead of -EINVAL.
--- net/ceph/mon_client.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/ceph/mon_client.c +3 -3
@@ -72,8 +72,8 @@ static struct ceph_monmap *ceph_monmap_dstruct ceph_monmap *monmap =NULL ;struct ceph_fsid fsid;u32 struct_len; -int blob_len; -int num_mon; +u32 blob_len; +u32 num_mon;u8 struct_v;u32 epoch;int ret;
@@ -112,7 +112,7 @@ static struct ceph_monmap *ceph_monmap_d }ceph_decode_32_safe (p, end, num_mon, e_inval); -dout ("%s fsid %pU epoch %u num_mon %d\n" , __func__, &fsid, epoch, +dout ("%s fsid %pU epoch %u num_mon %u\n" , __func__, &fsid, epoch, num_mon);if (num_mon >CEPH_MAX_MON ) goto e_inval;
Greg Kroah-Hartman
maintainerPATCH 155/570 libceph: admit message frames only in CEPH_CON_S_OPEN state
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Dryomov <[email protected]>
commit a5a373705081d7cc6363e16990e2361b0b362314 upstream.
Similar checks are performed for all control frames, but an early check for message frames was missing. process_message() is already set up to terminate the loop in case the state changes while con->ops->dispatch() handler is being executed.
--- net/ceph/messenger_v2.c | 5 +++++ 1 file changed, 5 insertions(+)
net/ceph/messenger_v2.c +5 -0
@@ -2599,6 +2599,11 @@ static int __handle_control(struct ceph_if (con->v2.in_desc.fd_tag !=FRAME_TAG_MESSAGE )return process_control (con, p, end); +if (con->state !=CEPH_CON_S_OPEN ) { + con->error_msg ="protocol error, unexpected message" ; +return -EINVAL ; + } + ret =process_message_header (con, p, end);if (ret <0 )return ret;
Greg Kroah-Hartman
maintainerPATCH 156/570 ceph: fix i_nlink underrun during async unlink
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Max Kellermann <[email protected]>
commit ce0123cbb4a40a2f1bbb815f292b26e96088639f upstream.
During async unlink, we drop the i_nlink counter before we receive the completion (that will eventually update the i_nlink) because "we assume that the unlink will succeed". That is not a bad idea, but it races against deletions by other clients (or against the completion of our own unlink) and can lead to an underrun which emits a WARNING like this one:
WARNING: CPU: 85 PID: 25093 at fs/inode.c:407 drop_nlink+0x50/0x68 Modules linked in: CPU: 85 UID: 3221252029 PID: 25093 Comm: php-cgi8.1 Not tainted 6.14.11-cm4all1-ampere #655 Hardware name: Supermicro ARS-110M-NR/R12SPD-A, BIOS 1.1b 10/17/2023 pstate: 60400009 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : drop_nlink+0x50/0x68 lr : ceph_unlink+0x6c4/0x720 sp : ffff80012173bc90 x29: ffff80012173bc90 x28: ffff086d0a45aaf8 x27: ffff0871d0eb5680 x26: ffff087f2a64a718 x25: 0000020000000180 x24: 0000000061c88647 x23: 0000000000000002 x22: ffff07ff9236d800 x21: 0000000000001203 x20: ffff07ff9237b000 x19: ffff088b8296afc0 x18: 00000000f3c93365 x17: 0000000000070000 x16: ffff08faffcbdfe8 x15: ffff08faffcbdfec x14: 0000000000000000 x13: 45445f65645f3037 x12: 34385f6369706f74 x11: 0000a2653104bb20 x10: ffffd85f26d73290 x9 : ffffd85f25664f94 x8 : 00000000000000c0 x7 : 0000000000000000 x6 : 0000000000000002 x5 : 0000000000000081 x4 : 0000000000000481 x3 : 0000000000000000 x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff08727d3f91e8 Call trace: drop_nlink+0x50/0x68 (P) vfs_unlink+0xb0/0x2e8 do_unlinkat+0x204/0x288 __arm64_sys_unlinkat+0x3c/0x80 invoke_syscall.constprop.0+0x54/0xe8 do_el0_svc+0xa4/0xc8 el0_svc+0x18/0x58 el0t_64_sync_handler+0x104/0x130 el0t_64_sync+0x154/0x158
In ceph_unlink(), a call to ceph_mdsc_submit_request() submits the CEPH_MDS_OP_UNLINK to the MDS, but does not wait for completion.
Meanwhile, between this call and the following drop_nlink() call, a worker thread may process a CEPH_CAP_OP_IMPORT, CEPH_CAP_OP_GRANT or just a CEPH_MSG_CLIENT_REPLY (the latter of which could be our own completion). These will lead to a set_nlink() call, updating the i_nlink counter to the value received from the MDS. If that new i_nlink value happens to be zero, it is illegal to decrement it further. But that is exactly what ceph_unlink() will do then.
The WARNING can be reproduced this way:
1. Force async unlink; only the async code path is affected. Having no real clue about Ceph internals, I was unable to find out why the MDS wouldn't give me the "Fxr" capabilities, so I patched get_caps_for_async_unlink() to always succeed.
(Note that the WARNING dump above was found on an unpatched kernel, without this kludge - this is not a theoretical bug.)
2. Add a sleep call after ceph_mdsc_submit_request() so the unlink completion gets handled by a worker thread before drop_nlink() is called. This guarantees that the i_nlink is already zero before drop_nlink() runs.
The solution is to skip the counter decrement when it is already zero, but doing so without a lock is still racy (TOCTOU). Since ceph_fill_inode() and handle_cap_grant() both hold the ceph_inode_info.i_ceph_lock spinlock while set_nlink() runs, this seems like the proper lock to protect the i_nlink updates.
I found prior art in NFS and SMB (using inode.i_lock) and AFS (using afs_vnode.cb_lock). All three have the zero check as well.
--- fs/ceph/dir.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
fs/ceph/dir.c +14 -1
@@ -1148,6 +1148,7 @@ static int ceph_unlink(struct inode *dirstruct ceph_fs_client *fsc =ceph_sb_to_client (dir->i_sb);struct ceph_mds_client *mdsc = fsc->mdsc;struct inode *inode =d_inode (dentry); +struct ceph_inode_info *ci =ceph_inode (inode);struct ceph_mds_request *req;bool try_async =ceph_test_mount_opt (fsc,ASYNC_DIROPS );int err = -EROFS ;
@@ -1193,7 +1194,19 @@ retry:* We have enough caps, so we assume that the unlink * will succeed. Fix up the target inode and dcache. */ -drop_nlink (inode); + +/* +* Protect the i_nlink update with i_ceph_lock +* to precent racing against ceph_fill_inode() +* handling our completion on a worker thread +* and don't decrement if i_nlink has already +* been updated to zero by this completion. +*/ +spin_lock (&ci->i_ceph_lock); +if (inode->i_nlink >0 ) +drop_nlink (inode); +spin_unlock (&ci->i_ceph_lock); +d_delete (dentry); }else if (err == -EJUKEBOX ) { try_async = false;
Greg Kroah-Hartman
maintainerPATCH 157/570 time: add kernel-doc in time.c
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Randy Dunlap <[email protected]>
[ Upstream commit 67b3f564cb1e769ef8e45835129a4866152fcfdb ]
Add kernel-doc for all APIs that do not already have it.
Stable-dep-of: 755a648e78f1 ("time/jiffies: Mark jiffies_64_to_clock_t() notrace")
--- kernel/time/time.c | 169 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 158 insertions(+), 11 deletions(-)
kernel/time/time.c +158 -11
@@ -365,11 +365,14 @@ SYSCALL_DEFINE1(adjtimex_time32, struct old_timex32 __user *, utp) }#endif -/* -* Convert jiffies to milliseconds and back. +/** +* jiffies_to_msecs - Convert jiffies to milliseconds +* @j: jiffies value * * Avoid unnecessary multiplications/divisions in the -* two most common HZ cases: +* two most common HZ cases. +* +* Return: milliseconds value */ unsigned int jiffies_to_msecs (const unsigned long j) {
@@ -388,6 +391,12 @@ unsigned int jiffies_to_msecs(const unsigned long j) }EXPORT_SYMBOL (jiffies_to_msecs); +/** +* jiffies_to_usecs - Convert jiffies to microseconds +* @j: jiffies value +* +* Return: microseconds value +*/ unsigned int jiffies_to_usecs (const unsigned long j) {/*
@@ -408,8 +417,15 @@ unsigned int jiffies_to_usecs(const unsigned long j) }EXPORT_SYMBOL (jiffies_to_usecs); -/* +/** * mktime64 - Converts date to seconds. +* @year0: year to convert +* @mon0: month to convert +* @day: day to convert +* @hour: hour to convert +* @min: minute to convert +* @sec: second to convert +* * Converts Gregorian date to seconds since 1970-01-01 00:00:00. * Assumes input in normal date format, i.e. 1980-12-31 23:59:59 * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
@@ -427,6 +443,8 @@ EXPORT_SYMBOL(jiffies_to_usecs);* * An encoding of midnight at the end of the day as 24:00:00 - ie. midnight * tomorrow - (allowable under ISO 8601) is supported. +* +* Return: seconds since the epoch time for the given input date */ time64_t mktime64(const unsigned int year0, const unsigned int mon0, const unsigned int day, const unsigned int hour,
@@ -471,8 +489,7 @@ EXPORT_SYMBOL(ns_to_kernel_old_timeval);* Set seconds and nanoseconds field of a timespec variable and * normalize to the timespec storage format * -* Note: The tv_nsec part is always in the range of -* 0 <= tv_nsec < NSEC_PER_SEC +* Note: The tv_nsec part is always in the range of 0 <= tv_nsec < NSEC_PER_SEC. * For negative values only the tv_sec field is negative ! */ void set_normalized_timespec64 (struct timespec64 *ts,time64_t sec,s64 nsec)
@@ -501,7 +518,7 @@ EXPORT_SYMBOL(set_normalized_timespec64);* ns_to_timespec64 - Convert nanoseconds to timespec64 * @nsec: the nanoseconds value to be converted * -* Returns the timespec64 representation of the nsec parameter. +* Return: the timespec64 representation of the nsec parameter. */ struct timespec64 ns_to_timespec64 (const s64 nsec) {
@@ -548,6 +565,8 @@ EXPORT_SYMBOL(ns_to_timespec64);* runtime. * the _msecs_to_jiffies helpers are the HZ dependent conversion * routines found in include/linux/jiffies.h +* +* Return: jiffies value */ unsigned long __msecs_to_jiffies (const unsigned int m) {
@@ -560,6 +579,12 @@ unsigned long __msecs_to_jiffies(const unsigned int m) }EXPORT_SYMBOL (__msecs_to_jiffies); +/** +* __usecs_to_jiffies: - convert microseconds to jiffies +* @u: time in milliseconds +* +* Return: jiffies value +*/ unsigned long __usecs_to_jiffies (const unsigned int u) {if (u >jiffies_to_usecs (MAX_JIFFY_OFFSET ))
@@ -568,7 +593,10 @@ unsigned long __usecs_to_jiffies(const unsigned int u) }EXPORT_SYMBOL (__usecs_to_jiffies); -/* +/** +* timespec64_to_jiffies - convert a timespec64 value to jiffies +* @value: pointer to &struct timespec64 +* * The TICK_NSEC - 1 rounds up the value to the next resolution. Note * that a remainder subtract here would not do the right thing as the * resolution values don't fall on second boundaries. I.e. the line:
@@ -582,8 +610,9 @@ EXPORT_SYMBOL(__usecs_to_jiffies);* * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec * value to a scaled second value. +* +* Return: jiffies value */ -unsigned long timespec64_to_jiffies (const struct timespec64 *value) {
@@ -601,6 +630,11 @@ timespec64_to_jiffies(const struct timespec64 *value) }EXPORT_SYMBOL (timespec64_to_jiffies); +/** +* jiffies_to_timespec64 - convert jiffies value to &struct timespec64 +* @jiffies: jiffies value +* @value: pointer to &struct timespec64 +*/ void jiffies_to_timespec64 (const unsigned long jiffies,struct timespec64 *value) {
@@ -618,6 +652,13 @@ EXPORT_SYMBOL(jiffies_to_timespec64);/* * Convert jiffies/jiffies_64 to clock_t and back. */ + +/** +* jiffies_to_clock_t - Convert jiffies to clock_t +* @x: jiffies value +* +* Return: jiffies converted to clock_t (CLOCKS_PER_SEC) +*/ clock_t jiffies_to_clock_t (unsigned long x) {#if (TICK_NSEC % (NSEC_PER_SEC /USER_HZ )) ==0
@@ -632,6 +673,12 @@ clock_t jiffies_to_clock_t(unsigned long x) }EXPORT_SYMBOL (jiffies_to_clock_t); +/** +* clock_t_to_jiffies - Convert clock_t to jiffies +* @x: clock_t value +* +* Return: clock_t value converted to jiffies +*/ unsigned long clock_t_to_jiffies (unsigned long x) {#if (HZ %USER_HZ )==0
@@ -649,6 +696,12 @@ unsigned long clock_t_to_jiffies(unsigned long x) }EXPORT_SYMBOL (clock_t_to_jiffies); +/** +* jiffies_64_to_clock_t - Convert jiffies_64 to clock_t +* @x: jiffies_64 value +* +* Return: jiffies_64 value converted to 64-bit "clock_t" (CLOCKS_PER_SEC) +*/ u64 jiffies_64_to_clock_t (u64 x) {#if (TICK_NSEC % (NSEC_PER_SEC /USER_HZ )) ==0
@@ -671,6 +724,12 @@ u64 jiffies_64_to_clock_t(u64 x) }EXPORT_SYMBOL (jiffies_64_to_clock_t); +/** +* nsec_to_clock_t - Convert nsec value to clock_t +* @x: nsec value +* +* Return: nsec value converted to 64-bit "clock_t" (CLOCKS_PER_SEC) +*/ u64 nsec_to_clock_t (u64 x) {#if (NSEC_PER_SEC %USER_HZ ) ==0
@@ -687,6 +746,12 @@ u64 nsec_to_clock_t(u64 x)#endif } +/** +* jiffies64_to_nsecs - Convert jiffies64 to nanoseconds +* @j: jiffies64 value +* +* Return: nanoseconds value +*/ u64 jiffies64_to_nsecs (u64 j) {#if !(NSEC_PER_SEC %HZ )
@@ -697,6 +762,12 @@ u64 jiffies64_to_nsecs(u64 j) }EXPORT_SYMBOL (jiffies64_to_nsecs); +/** +* jiffies64_to_msecs - Convert jiffies64 to milliseconds +* @j: jiffies64 value +* +* Return: milliseconds value +*/ u64 jiffies64_to_msecs (const u64 j) {#if HZ <=MSEC_PER_SEC && !(MSEC_PER_SEC %HZ )
@@ -719,6 +790,8 @@ EXPORT_SYMBOL(jiffies64_to_msecs);* note: * NSEC_PER_SEC = 10^9 = (5^9 * 2^9) = (1953125 * 512) * ULLONG_MAX ns = 18446744073.709551615 secs = about 584 years +* +* Return: nsecs converted to jiffies64 value */ u64 nsecs_to_jiffies64 (u64 n) {
@@ -750,6 +823,8 @@ EXPORT_SYMBOL(nsecs_to_jiffies64);* note: * NSEC_PER_SEC = 10^9 = (5^9 * 2^9) = (1953125 * 512) * ULLONG_MAX ns = 18446744073.709551615 secs = about 584 years +* +* Return: nsecs converted to jiffies value */ unsigned long nsecs_to_jiffies (u64 n) {
@@ -757,10 +832,16 @@ unsigned long nsecs_to_jiffies(u64 n) }EXPORT_SYMBOL_GPL (nsecs_to_jiffies); -/* -* Add two timespec64 values and do a safety check for overflow. +/** +* timespec64_add_safe - Add two timespec64 values and do a safety check +* for overflow. +* @lhs: first (left) timespec64 to add +* @rhs: second (right) timespec64 to add +* * It's assumed that both values are valid (>= 0). * And, each timespec64 is in normalized form. +* +* Return: sum of @lhs + @rhs */ struct timespec64 timespec64_add_safe (const struct timespec64 lhs,const struct timespec64 rhs)
@@ -778,6 +859,15 @@ struct timespec64 timespec64_add_safe(const struct timespec64 lhs,return res; } +/** +* get_timespec64 - get user's time value into kernel space +* @ts: destination &struct timespec64 +* @uts: user's time value as &struct __kernel_timespec +* +* Handles compat or 32-bit modes. +* +* Return: %0 on success or negative errno on error +*/ int get_timespec64 (struct timespec64 *ts,const struct __kernel_timespec __user *uts) {
@@ -801,6 +891,14 @@ int get_timespec64(struct timespec64 *ts, }EXPORT_SYMBOL_GPL (get_timespec64); +/** +* put_timespec64 - convert timespec64 value to __kernel_timespec format and +* copy the latter to userspace +* @ts: input &struct timespec64 +* @uts: user's &struct __kernel_timespec +* +* Return: %0 on success or negative errno on error +*/ int put_timespec64 (const struct timespec64 *ts,struct __kernel_timespec __user *uts) {
@@ -839,6 +937,15 @@ static int __put_old_timespec32(const struct timespec64 *ts64,return copy_to_user (cts, &ts,sizeof (ts)) ? -EFAULT :0 ; } +/** +* get_old_timespec32 - get user's old-format time value into kernel space +* @ts: destination &struct timespec64 +* @uts: user's old-format time value (&struct old_timespec32) +* +* Handles X86_X32_ABI compatibility conversion. +* +* Return: %0 on success or negative errno on error +*/ int get_old_timespec32 (struct timespec64 *ts,const void __user *uts) {if (COMPAT_USE_64BIT_TIME )
@@ -848,6 +955,16 @@ int get_old_timespec32(struct timespec64 *ts, const void __user *uts) }EXPORT_SYMBOL_GPL (get_old_timespec32); +/** +* put_old_timespec32 - convert timespec64 value to &struct old_timespec32 and +* copy the latter to userspace +* @ts: input &struct timespec64 +* @uts: user's &struct old_timespec32 +* +* Handles X86_X32_ABI compatibility conversion. +* +* Return: %0 on success or negative errno on error +*/ int put_old_timespec32 (const struct timespec64 *ts,void __user *uts) {if (COMPAT_USE_64BIT_TIME )
@@ -857,6 +974,13 @@ int put_old_timespec32(const struct timespec64 *ts, void __user *uts) }EXPORT_SYMBOL_GPL (put_old_timespec32); +/** +* get_itimerspec64 - get user's &struct __kernel_itimerspec into kernel space +* @it: destination &struct itimerspec64 +* @uit: user's &struct __kernel_itimerspec +* +* Return: %0 on success or negative errno on error +*/ int get_itimerspec64 (struct itimerspec64 *it,const struct __kernel_itimerspec __user *uit) {
@@ -872,6 +996,14 @@ int get_itimerspec64(struct itimerspec64 *it, }EXPORT_SYMBOL_GPL (get_itimerspec64); +/** +* put_itimerspec64 - convert &struct itimerspec64 to __kernel_itimerspec format +* and copy the latter to userspace +* @it: input &struct itimerspec64 +* @uit: user's &struct __kernel_itimerspec +* +* Return: %0 on success or negative errno on error +*/ int put_itimerspec64 (const struct itimerspec64 *it,struct __kernel_itimerspec __user *uit) {
@@ -887,6 +1019,13 @@ int put_itimerspec64(const struct itimerspec64 *it, }EXPORT_SYMBOL_GPL (put_itimerspec64); +/** +* get_old_itimerspec32 - get user's &struct old_itimerspec32 into kernel space +* @its: destination &struct itimerspec64 +* @uits: user's &struct old_itimerspec32 +* +* Return: %0 on success or negative errno on error +*/ int get_old_itimerspec32 (struct itimerspec64 *its,const struct old_itimerspec32 __user *uits) {
@@ -898,6 +1037,14 @@ int get_old_itimerspec32(struct itimerspec64 *its, }EXPORT_SYMBOL_GPL (get_old_itimerspec32); +/** +* put_old_itimerspec32 - convert &struct itimerspec64 to &struct +* old_itimerspec32 and copy the latter to userspace +* @its: input &struct itimerspec64 +* @uits: user's &struct old_itimerspec32 +* +* Return: %0 on success or negative errno on error +*/ int put_old_itimerspec32 (const struct itimerspec64 *its,struct old_itimerspec32 __user *uits) {
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 158/570 time/jiffies: Mark jiffies_64_to_clock_t() notrace
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
[ Upstream commit 755a648e78f12574482d4698d877375793867fa1 ]
The trace_clock_jiffies() function that handles the "uptime" clock for tracing calls jiffies_64_to_clock_t(). This causes the function tracer to constantly recurse when the tracing clock is set to "uptime". Mark it notrace to prevent unnecessary recursion when using the "uptime" clock.
--- kernel/time/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/time.c +1 -1
@@ -702,7 +702,7 @@ EXPORT_SYMBOL(clock_t_to_jiffies);* * Return: jiffies_64 value converted to 64-bit "clock_t" (CLOCKS_PER_SEC) */ -u64 jiffies_64_to_clock_t (u64 x) +notrace u64 jiffies_64_to_clock_t(u64 x) {#if (TICK_NSEC % (NSEC_PER_SEC /USER_HZ )) ==0 # if HZ <USER_HZ
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 159/570 device property: Allow secondary lookup in fwnode_get_next_child_node()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
commit 2692c614f8f05929d692b3dbfd3faef1f00fbaf0 upstream.
When device_get_child_node_count() got split to the fwnode and device respective APIs, the fwnode didn't inherit the ability to traverse over the secondary fwnode. Hence any user, that switches from device to fwnode API misses this feature. In particular, this was revealed by the commit 1490cbb9dbfd ("device property: Split fwnode_get_child_node_count()") that effectively broke the GPIO enumeration on Intel Galileo boards. Fix this by moving the secondary lookup from device to fwnode API.
Note, in general no device_*() API should go into the depth of the fwnode implementation.
--- drivers/base/property.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/base/property.c +13 -14
@@ -748,7 +748,18 @@ struct fwnode_handle * fwnode_get_next_child_node(const struct fwnode_handle *fwnode, struct fwnode_handle *child) { - return fwnode_call_ptr_op(fwnode, get_next_child_node, child); + struct fwnode_handle *next; + +if (IS_ERR_OR_NULL (fwnode)) +return NULL ; + +/* Try to find a child in primary fwnode */ + next =fwnode_call_ptr_op (fwnode, get_next_child_node, child); +if (next) +return next; + +/* When no more children in primary, continue with secondary */ +return fwnode_call_ptr_op (fwnode->secondary, get_next_child_node, child); }EXPORT_SYMBOL_GPL (fwnode_get_next_child_node);
@@ -785,19 +796,7 @@ EXPORT_SYMBOL_GPL(fwnode_get_next_availastruct fwnode_handle *device_get_next_child_node (struct device *dev,struct fwnode_handle *child) { -const struct fwnode_handle *fwnode =dev_fwnode (dev); -struct fwnode_handle *next; - -if (IS_ERR_OR_NULL (fwnode)) -return NULL ; - -/* Try to find a child in primary fwnode */ - next =fwnode_get_next_child_node (fwnode, child); -if (next) -return next; - -/* When no more children in primary, continue with secondary */ -return fwnode_get_next_child_node (fwnode->secondary, child); +return fwnode_get_next_child_node (dev_fwnode (dev), child); }EXPORT_SYMBOL_GPL (device_get_next_child_node);
Greg Kroah-Hartman
maintainerPATCH 160/570 irqchip/gic-v3-its: Limit number of per-device MSIs to the range the ITS supports
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
commit ce9e40a9a5e5cff0b1b0d2fa582b3d71a8ce68e8 upstream.
The ITS driver blindly assumes that EventIDs are in abundant supply, to the point where it never checks how many the hardware actually supports.
It turns out that some pretty esoteric integrations make it so that only a few bits are available, all the way down to a single bit.
Enforce the advertised limitation at the point of allocating the device structure, and hope that the endpoint driver can deal with such limitation.
--- drivers/irqchip/irq-gic-v3-its.c | 4 ++++ include/linux/irqchip/arm-gic-v3.h | 1 + 2 files changed, 5 insertions(+)
drivers/irqchip/irq-gic-v3-its.c +4 -0
@@ -3397,6 +3397,7 @@ static struct its_device *its_create_devint lpi_base;int nr_lpis;int nr_ites; +int id_bits;int sz;if (!its_alloc_device_table (its, dev_id))
@@ -3409,7 +3410,10 @@ static struct its_device *its_create_dev/* * Even if the device wants a single LPI, the ITT must be * sized as a power of two (and you need at least one bit...). +* Also honor the ITS's own EID limit. */ + id_bits =FIELD_GET (GITS_TYPER_IDBITS , its->typer) +1 ; + nvecs = min_t(unsigned int, nvecs, BIT(id_bits)); nr_ites =max (2 , nvecs); sz = nr_ites * (FIELD_GET (GITS_TYPER_ITT_ENTRY_SIZE , its->typer) +1 ); sz =max (sz,ITS_ITT_ALIGN ) +ITS_ITT_ALIGN -1 ;
include/linux/irqchip/arm-gic-v3.h +1 -0
@@ -392,6 +392,7 @@#define GITS_TYPER_VLPIS (1UL << 1)#define GITS_TYPER_ITT_ENTRY_SIZE_SHIFT 4#define GITS_TYPER_ITT_ENTRY_SIZE GENMASK_ULL(7, 4) +#define GITS_TYPER_IDBITS GENMASK_ULL(12, 8)#define GITS_TYPER_IDBITS_SHIFT 8#define GITS_TYPER_DEVBITS_SHIFT 13#define GITS_TYPER_DEVBITS GENMASK_ULL(17, 13)
Greg Kroah-Hartman
maintainerPATCH 161/570 staging: rtl8723bs: fix potential out-of-bounds read in rtw_restruct_wmm_ie
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luka Gejak <[email protected]>
commit a75281626fc8fa6dc6c9cc314ee423e8bc45203b upstream.
The current code checks 'i + 5 < in_len' at the end of the if statement. However, it accesses 'in_ie[i + 5]' before that check, which can lead to an out-of-bounds read. Move the length check to the beginning of the conditional to ensure the index is within bounds before accessing the array.
--- drivers/staging/rtl8723bs/core/rtw_mlme.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_mlme.c +4 -1
@@ -2008,7 +2008,10 @@ int rtw_restruct_wmm_ie(struct adapter *while (i < in_len) { ielength = initial_out_len; -if (in_ie[i] ==0xDD && in_ie[i+2 ] ==0x00 && in_ie[i+3 ] ==0x50 && in_ie[i+4 ] ==0xF2 && in_ie[i+5 ] ==0x02 && i+5 < in_len) {/* WMM element ID and OUI */ +if (i +5 < in_len && + in_ie[i] ==0xDD && in_ie[i +2 ] ==0x00 && + in_ie[i +3 ] ==0x50 && in_ie[i +4 ] ==0xF2 && + in_ie[i +5 ] ==0x02 ) {for (j = i; j < i +9 ; j++) { out_ie[ielength] = in_ie[j]; ielength++;
Greg Kroah-Hartman
maintainerPATCH 162/570 staging: rtl8723bs: properly validate the data in rtw_get_ie_ex()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit f0109b9d3e1e455429279d602f6276e34689750a upstream.
Just like in commit 154828bf9559 ("staging: rtl8723bs: fix out-of-bounds read in rtw_get_ie() parser"), we don't trust the data in the frame so we should check the length better before acting on it
--- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +10 -6
@@ -187,21 +187,25 @@ u8 *rtw_get_ie_ex(u8 *in_ie, uint in_len cnt =0 ; -while (cnt < in_len) { +while (cnt +2 <= in_len) { +u8 ie_len = in_ie[cnt +1 ]; + +if (cnt +2 + ie_len > in_len) +break ; +if (eid == in_ie[cnt] - && (!oui || !memcmp (&in_ie[cnt+2 ], oui, oui_len))) { + && (!oui || (ie_len >= oui_len && !memcmp (&in_ie[cnt +2 ], oui, oui_len)))) { target_ie = &in_ie[cnt];if (ie) -memcpy (ie, &in_ie[cnt], in_ie[cnt+1 ]+2 ); +memcpy (ie, &in_ie[cnt], ie_len +2 );if (ielen) - *ielen = in_ie[cnt+1 ]+2 ; + *ielen = ie_len +2 ;break ; - }else { - cnt += in_ie[cnt+1 ]+2 ;/* goto next */ } + cnt += ie_len +2 ;/* goto next */ }return target_ie;
Greg Kroah-Hartman
maintainerPATCH 163/570 media: dvb-net: fix OOB access in ULE extension header tables
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ariel Silver <[email protected]>
commit 24d87712727a5017ad142d63940589a36cd25647 upstream.
The ule_mandatory_ext_handlers[] and ule_optional_ext_handlers[] tables in handle_one_ule_extension() are declared with 255 elements (valid indices 0-254), but the index htype is derived from network-controlled data as (ule_sndu_type & 0x00FF), giving a range of 0-255. When htype equals 255, an out-of-bounds read occurs on the function pointer table, and the OOB value may be called as a function pointer.
Add a bounds check on htype against the array size before either table is accessed. Out-of-range values now cause the SNDU to be discarded.
--- drivers/media/dvb-core/dvb_net.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/media/dvb-core/dvb_net.c +3 -0
@@ -228,6 +228,9 @@ static int handle_one_ule_extension( strunsigned char hlen = (p->ule_sndu_type &0x0700 ) >>8 ;unsigned char htype = p->ule_sndu_type &0x00FF ; +if (htype >=ARRAY_SIZE (ule_mandatory_ext_handlers)) +return -1 ; +/* Discriminate mandatory and optional extension headers. */ if (hlen ==0 ) {/* Mandatory extension header */
Greg Kroah-Hartman
maintainerPATCH 164/570 net: mana: Ring doorbell at 4 CQ wraparounds
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Long Li <[email protected]>
commit dabffd08545ffa1d7183bc45e387860984025291 upstream.
MANA hardware requires at least one doorbell ring every 8 wraparounds of the CQ. The driver rings the doorbell as a form of flow control to inform hardware that CQEs have been consumed.
The NAPI poll functions mana_poll_tx_cq() and mana_poll_rx_cq() can poll up to CQE_POLLING_BUFFER (512) completions per call. If the CQ has fewer than 512 entries, a single poll call can process more than 4 wraparounds without ringing the doorbell. The doorbell threshold check also uses ">" instead of ">=", delaying the ring by one extra CQE beyond 4 wraparounds. Combined, these issues can cause the driver to exceed the 8-wraparound hardware limit, leading to missed completions and stalled queues.
Fix this by capping the number of CQEs polled per call to 4 wraparounds of the CQ in both TX and RX paths. Also change the doorbell threshold from ">" to ">=" so the doorbell is rung as soon as 4 wraparounds are reached.
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_en.c +18 -5
@@ -798,8 +798,14 @@ static void mana_poll_tx_cq(struct mana_ ndev = txq->ndev; apc =netdev_priv (ndev); +/* Limit CQEs polled to 4 wraparounds of the CQ to ensure the +* doorbell can be rung in time for the hardware's requirement +* of at least one doorbell ring every 8 wraparounds. +*/ comp_read =mana_gd_poll_cq (cq->gdma_cq, completions, -CQE_POLLING_BUFFER ); +min ((cq->gdma_cq->queue_size / +COMP_ENTRY_SIZE ) *4 , +CQE_POLLING_BUFFER ));if (comp_read <1 )return ;
@@ -1056,7 +1062,14 @@ static void mana_poll_rx_cq(struct mana_struct gdma_comp *comp = cq->gdma_comp_buf;int comp_read, i; - comp_read =mana_gd_poll_cq (cq->gdma_cq, comp,CQE_POLLING_BUFFER ); +/* Limit CQEs polled to 4 wraparounds of the CQ to ensure the +* doorbell can be rung in time for the hardware's requirement +* of at least one doorbell ring every 8 wraparounds. +*/ + comp_read =mana_gd_poll_cq (cq->gdma_cq, comp, +min ((cq->gdma_cq->queue_size / +COMP_ENTRY_SIZE ) *4 , +CQE_POLLING_BUFFER ));WARN_ON_ONCE (comp_read >CQE_POLLING_BUFFER );for (i =0 ; i < comp_read; i++) {
@@ -1090,11 +1103,11 @@ static int mana_cq_handler(void *contextmana_gd_ring_cq (gdma_queue,SET_ARM_BIT ); cq->work_done_since_doorbell =0 ;napi_complete_done (&cq->napi, w); - }else if (cq->work_done_since_doorbell > - cq->gdma_cq->queue_size /COMP_ENTRY_SIZE *4 ) { + }else if (cq->work_done_since_doorbell >= + (cq->gdma_cq->queue_size /COMP_ENTRY_SIZE ) *4 ) {/* MANA hardware requires at least one doorbell ring every 8 * wraparounds of CQ even if there is no need to arm the CQ. -* This driver rings the doorbell as soon as we have exceeded +* This driver rings the doorbell as soon as it has processed * 4 wraparounds. */ mana_gd_ring_cq (gdma_queue,0 );
Greg Kroah-Hartman
maintainerPATCH 165/570 ice: fix retry for AQ command 0x06EE
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Staniszewski <[email protected]>
commit fb4903b3354aed4a2301180cf991226f896c87ed upstream.
Executing ethtool -m can fail reporting a netlink I/O error while firmware link management holds the i2c bus used to communicate with the module.
According to Intel(R) Ethernet Controller E810 Datasheet Rev 2.8 [1] Section 3.3.10.4 Read/Write SFF EEPROM (0x06EE)
request should to be retried upon receiving EBUSY from firmware.
Commit e9c9692c8a81 ("ice: Reimplement module reads used by ethtool") implemented it only for part of ice_get_module_eeprom(), leaving all other calls to ice_aq_sff_eeprom() vulnerable to returning early on getting EBUSY without retrying.
Remove the retry loop from ice_get_module_eeprom() and add Admin Queue (AQ) command with opcode 0x06EE to the list of commands that should be retried on receiving EBUSY from firmware.
--- drivers/net/ethernet/intel/ice/ice_common.c | 1 drivers/net/ethernet/intel/ice/ice_ethtool.c | 35 ++++++++++----------------- 2 files changed, 15 insertions(+), 21 deletions(-)
drivers/net/ethernet/intel/ice/ice_common.c +1 -0
@@ -1386,6 +1386,7 @@ static bool ice_should_retry_sq_send_cmdcase ice_aqc_opc_lldp_stop:case ice_aqc_opc_lldp_start:case ice_aqc_opc_lldp_filter_ctrl: +case ice_aqc_opc_sff_eeprom:return true; }
drivers/net/ethernet/intel/ice/ice_ethtool.c +14 -21
@@ -3944,7 +3944,7 @@ ice_get_module_eeprom(struct net_devicestruct ice_hw *hw = &pf->hw;enum ice_status status;bool is_sfp = false; -unsigned int i, j; +unsigned int i;u16 offset =0 ;u8 page =0 ;
@@ -3985,26 +3985,19 @@ ice_get_module_eeprom(struct net_deviceif (page ==0 || !(data[0x2 ] &0x4 )) {u32 copy_len; -/* If i2c bus is busy due to slow page change or -* link management access, call can fail. This is normal. -* So we retry this a few times. -*/ -for (j =0 ; j <4 ; j++) { - status =ice_aq_sff_eeprom (hw,0 , addr, offset, page, - !is_sfp, value, -SFF_READ_BLOCK_SIZE , -0 ,NULL ); -netdev_dbg (netdev,"SFF %02X %02X %02X %X = %02X%02X%02X%02X.%02X%02X%02X%02X (%X)\n" , - addr, offset, page, is_sfp, - value[0 ], value[1 ], value[2 ], value[3 ], - value[4 ], value[5 ], value[6 ], value[7 ], - status); -if (status) { -usleep_range (1500 ,2500 ); -memset (value,0 ,SFF_READ_BLOCK_SIZE ); -continue ; - } -break ; + status =ice_aq_sff_eeprom (hw,0 , addr, offset, page, + !is_sfp, value, +SFF_READ_BLOCK_SIZE , +0 ,NULL ); +netdev_dbg (netdev,"SFF %02X %02X %02X %X = %02X%02X%02X%02X.%02X%02X%02X%02X (%pe)\n" , + addr, offset, page, is_sfp, + value[0 ], value[1 ], value[2 ], value[3 ], + value[4 ], value[5 ], value[6 ], value[7 ], +ERR_PTR (status)); +if (status) { +netdev_err (netdev,"%s: error reading module EEPROM: status %pe\n" , + __func__,ERR_PTR (status)); +return status; }/* Make sure we have enough room for the new block */
Greg Kroah-Hartman
maintainerPATCH 166/570 batman-adv: Avoid double-rtnl_lock ELP metric worker
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit cfc83a3c71517b59c1047db57da31e26a9dc2f33 upstream.
batadv_v_elp_get_throughput() might be called when the RTNL lock is already held. This could be problematic when the work queue item is cancelled via cancel_delayed_work_sync() in batadv_v_elp_iface_disable(). In this case, an rtnl_lock() would cause a deadlock.
To avoid this, rtnl_trylock() was used in this function to skip the retrieval of the ethtool information in case the RTNL lock was already held.
But for cfg80211 interfaces, batadv_get_real_netdev() was called - which also uses rtnl_lock(). The approach for __ethtool_get_link_ksettings() must also be used instead and the lockless version __batadv_get_real_netdev() has to be called.
--- net/batman-adv/bat_v_elp.c | 10 +++++++++- net/batman-adv/hard-interface.c | 8 ++++---- net/batman-adv/hard-interface.h | 1 + 3 files changed, 14 insertions(+), 5 deletions(-)
net/batman-adv/bat_v_elp.c +9 -1
@@ -113,7 +113,15 @@ static bool batadv_v_elp_get_throughput(/* unsupported WiFi driver version */ goto default_throughput; - real_netdev =batadv_get_real_netdev (hard_iface->net_dev); +/* only use rtnl_trylock because the elp worker will be cancelled while +* the rntl_lock is held. the cancel_delayed_work_sync() would otherwise +* wait forever when the elp work_item was started and it is then also +* trying to rtnl_lock +*/ +if (!rtnl_trylock ()) +return false; + real_netdev =__batadv_get_real_netdev (hard_iface->net_dev); +rtnl_unlock ();if (!real_netdev) goto default_throughput;
net/batman-adv/hard-interface.c +4 -4
@@ -201,7 +201,7 @@ static bool batadv_is_valid_iface(const }/** -* batadv_get_real_netdevice() - check if the given netdev struct is a virtual +* __batadv_get_real_netdev() - check if the given netdev struct is a virtual * interface on top of another 'real' interface * @netdev: the device to check *
@@ -211,7 +211,7 @@ static bool batadv_is_valid_iface(const* Return: the 'real' net device or the original net device and NULL in case * of an error. */ -static struct net_device *batadv_get_real_netdevice (struct net_device *netdev) +struct net_device *__batadv_get_real_netdev (struct net_device *netdev) {struct batadv_hard_iface *hard_iface =NULL ;struct net_device *real_netdev =NULL ;
@@ -264,7 +264,7 @@ struct net_device *batadv_get_real_netdestruct net_device *real_netdev;rtnl_lock (); - real_netdev =batadv_get_real_netdevice (net_device); + real_netdev =__batadv_get_real_netdev (net_device);rtnl_unlock ();return real_netdev;
@@ -331,7 +331,7 @@ static u32 batadv_wifi_flags_evaluate(stif (batadv_is_cfg80211_netdev (net_device)) wifi_flags |=BATADV_HARDIF_WIFI_CFG80211_DIRECT ; - real_netdev =batadv_get_real_netdevice (net_device); + real_netdev =__batadv_get_real_netdev (net_device);if (!real_netdev)return wifi_flags;
net/batman-adv/hard-interface.h +1 -0
@@ -68,6 +68,7 @@ enum batadv_hard_if_bcast {extern struct notifier_block batadv_hard_if_notifier; +struct net_device *__batadv_get_real_netdev (struct net_device *net_device);struct net_device *batadv_get_real_netdev (struct net_device *net_device);bool batadv_is_cfg80211_hardif (struct batadv_hard_iface *hard_iface);bool batadv_is_wifi_hardif (struct batadv_hard_iface *hard_iface);
Greg Kroah-Hartman
maintainerPATCH 167/570 parisc: Increase initial mapping to 64 MB with KALLSYMS
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Helge Deller <[email protected]>
commit 8e732934fb81282be41602550e7e07baf265e972 upstream.
The 32MB initial kernel mapping can become too small when CONFIG_KALLSYMS is used. Increase the mapping to 64 MB in this case.
--- arch/parisc/include/asm/pgtable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/include/asm/pgtable.h +1 -1
@@ -109,7 +109,7 @@ extern void __update_cache(pte_t pte);printk ("%s:%d: bad pgd %08lx.\n" , __FILE__, __LINE__, (unsigned long )pgd_val (e)) /* This is the size of the initially mapped kernel memory */ -#if defined(CONFIG_64BIT ) +#if defined(CONFIG_64BIT ) || defined(CONFIG_KALLSYMS )#define KERNEL_INITIAL_ORDER 26/* 1<<26 = 64MB */ #else #define KERNEL_INITIAL_ORDER 25/* 1<<25 = 32MB */
Greg Kroah-Hartman
maintainerPATCH 168/570 nouveau/dpcd: return EBUSY for aux xfer if the device is asleep
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Airlie <[email protected]>
commit 8f3c6f08ababad2e3bdd239728cf66a9949446b4 upstream.
If we have runtime suspended, and userspace wants to use /dev/drm_dp_* then just tell it the device is busy instead of crashing in the GSP code.
WARNING: CPU: 2 PID: 565741 at drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/rpc.c:164 r535_gsp_msgq_wait+0x9a/0xb0 [nouveau] CPU: 2 UID: 0 PID: 565741 Comm: fwupd Not tainted 6.18.10-200.fc43.x86_64 #1 PREEMPT(lazy) Hardware name: LENOVO 20QTS0PQ00/20QTS0PQ00, BIOS N2OET65W (1.52 ) 08/05/2024 RIP: 0010:r535_gsp_msgq_wait+0x9a/0xb0 [nouveau]
This is a simple fix to get backported. We should probably engineer a proper power domain solution to wake up devices and keep them awake while fw updates are happening.
--- drivers/gpu/drm/nouveau/nouveau_connector.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/nouveau/nouveau_connector.c +3 -0
@@ -1195,6 +1195,9 @@ nouveau_connector_aux_xfer(struct drm_dpu8 size = msg->size;int ret; +if (pm_runtime_suspended (nv_connector->base.dev->dev)) +return -EBUSY ; + nv_encoder =find_encoder (&nv_connector->base,DCB_OUTPUT_DP );if (!nv_encoder || !(aux = nv_encoder->aux))return -ENODEV ;
Greg Kroah-Hartman
maintainerPATCH 169/570 hwmon: (pmbus/q54sj108a2) fix stack overflow in debugfs read
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanman Pradhan <[email protected]>
commit 25dd70a03b1f5f3aa71e1a5091ecd9cd2a13ee43 upstream.
The q54sj108a2_debugfs_read function suffers from a stack buffer overflow due to incorrect arguments passed to bin2hex(). The function currently passes 'data' as the destination and 'data_char' as the source.
Because bin2hex() converts each input byte into two hex characters, a 32-byte block read results in 64 bytes of output. Since 'data' is only 34 bytes (I2C_SMBUS_BLOCK_MAX + 2), this writes 30 bytes past the end of the buffer onto the stack.
Additionally, the arguments were swapped: it was reading from the zero-initialized 'data_char' and writing to 'data', resulting in all-zero output regardless of the actual I2C read.
Fix this by:
1. Expanding 'data_char' to 66 bytes to safely hold the hex output.
2. Correcting the bin2hex() argument order and using the actual read count.
3. Using a pointer to select the correct output buffer for the final simple_read_from_buffer call.
--- drivers/hwmon/pmbus/q54sj108a2.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/hwmon/pmbus/q54sj108a2.c +10 -9
@@ -77,7 +77,8 @@ static ssize_t q54sj108a2_debugfs_read(sint idx = *idxp;struct q54sj108a2_data *psu =to_psu (idxp, idx);char data[I2C_SMBUS_BLOCK_MAX +2 ] = {0 }; -char data_char[I2C_SMBUS_BLOCK_MAX +2 ] = {0 }; +char data_char[I2C_SMBUS_BLOCK_MAX *2 +2 ] = {0 }; +char *out = data;char *res;switch (idx) {
@@ -148,27 +149,27 @@ static ssize_t q54sj108a2_debugfs_read(sif (rc <0 )return rc; - res =bin2hex (data, data_char,32 ); - rc = res - data; - + res =bin2hex (data_char, data, rc); + rc = res - data_char; + out = data_char;break ;case Q54SJ108A2_DEBUGFS_FLASH_KEY : rc =i2c_smbus_read_block_data (psu->client,PMBUS_FLASH_KEY_WRITE , data);if (rc <0 )return rc; - res =bin2hex (data, data_char,4 ); - rc = res - data; - + res =bin2hex (data_char, data, rc); + rc = res - data_char; + out = data_char;break ;default :return -EINVAL ; } - data[rc] ='\n' ; + out[rc] ='\n' ; rc +=2 ; -return simple_read_from_buffer (buf, count, ppos, data, rc); +return simple_read_from_buffer (buf, count, ppos, out, rc); } static ssize_t q54sj108a2_debugfs_write(struct file *file, const char __user *buf,
Greg Kroah-Hartman
maintainerPATCH 170/570 parisc: Fix initial page table creation for boot
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Helge Deller <[email protected]>
commit 8475d8fe21ec9c7eb2faca555fbc5b68cf0d2597 upstream.
The KERNEL_INITIAL_ORDER value defines the initial size (usually 32 or 64 MB) of the page table during bootup. Up until now the whole area was initialized with PTE entries, but there was no check if we filled too many entries. Change the code to fill up with so many entries that the "_end" symbol can be reached by the kernel, but not more entries than actually fit into the initial PTE tables.
--- arch/parisc/kernel/head.S | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/parisc/kernel/head.S +6 -1
@@ -55,6 +55,7 @@ ENTRY(parisc_kernel_start) .import __bss_start,data .import __bss_stop,data + .import __end,data load32 PA(__bss_start),%r3 load32 PA(__bss_stop),%r4
@@ -148,7 +149,11 @@ $cpu_ok: * everything ... it will get remapped correctly later */ ldo 0+_PAGE_KERNEL_RWX(%r0),%r3 /* Hardwired 0 phys addr start */ load32 (1<<(KERNEL_INITIAL_ORDER-PAGE_SHIFT)),%r11 /* PFN count */ - load32 PA(pg0),%r1 + load32 PA(_end),%r1 + SHRREG %r1,PAGE_SHIFT,%r1 /* %r1 is PFN count for _end symbol */ + cmpb,<<,n %r11,%r1,1f + copy %r1,%r11 /* %r1 PFN count smaller than %r11 */ +1: load32 PA(pg0),%r1 $pgt_fill_loop: STREGM %r3,ASM_PTE_ENTRY_SIZE(%r1)
Greg Kroah-Hartman
maintainerPATCH 171/570 net: ncsi: fix skb leak in error paths
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jian Zhang <[email protected]>
commit 5c3398a54266541610c8d0a7082e654e9ff3e259 upstream.
Early return paths in NCSI RX and AEN handlers fail to release the received skb, resulting in a memory leak.
Specifically, ncsi_aen_handler() returns on invalid AEN packets without consuming the skb. Similarly, ncsi_rcv_rsp() exits early when failing to resolve the NCSI device, response handler, or request, leaving the skb unfreed.
--- net/ncsi/ncsi-aen.c | 3 ++- net/ncsi/ncsi-rsp.c | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-)
net/ncsi/ncsi-aen.c +2 -1
@@ -224,7 +224,8 @@ int ncsi_aen_handler(struct ncsi_dev_priif (!nah) {netdev_warn (ndp->ndev.dev,"Invalid AEN (0x%x) received\n" , h->type); -return -ENOENT ; + ret = -ENOENT ; + goto out; } ret =ncsi_validate_aen_pkt (h, nah->payload);
net/ncsi/ncsi-rsp.c +12 -4
@@ -1176,8 +1176,10 @@ int ncsi_rcv_rsp(struct sk_buff *skb, st/* Find the NCSI device */ nd =ncsi_find_dev (orig_dev); ndp = nd ?TO_NCSI_DEV_PRIV (nd) :NULL ; -if (!ndp) -return -ENODEV ; +if (!ndp) { + ret = -ENODEV ; + goto err_free_skb; + }/* Check if it is AEN packet */ hdr = (struct ncsi_pkt_hdr *)skb_network_header (skb);
@@ -1199,7 +1201,8 @@ int ncsi_rcv_rsp(struct sk_buff *skb, stif (!nrh) {netdev_err (nd->dev,"Received unrecognized packet (0x%x)\n" , hdr->type); -return -ENOENT ; + ret = -ENOENT ; + goto err_free_skb; }/* Associate with the request */
@@ -1207,7 +1210,8 @@ int ncsi_rcv_rsp(struct sk_buff *skb, st nr = &ndp->requests[hdr->id];if (!nr->used) {spin_unlock_irqrestore (&ndp->lock, flags); -return -ENODEV ; + ret = -ENODEV ; + goto err_free_skb; } nr->rsp = skb;
@@ -1261,4 +1265,8 @@ out_netlink: out:ncsi_free_request (nr);return ret; + +err_free_skb: +kfree_skb (skb); +return ret; }
Greg Kroah-Hartman
maintainerPATCH 172/570 net: ethernet: arc: emac: quiesce interrupts before requesting IRQ
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit 2503d08f8a2de618e5c3a8183b250ff4a2e2d52c upstream.
Normal RX/TX interrupts are enabled later, in arc_emac_open(), so probe should not see interrupt delivery in the usual case. However, hardware may still present stale or latched interrupt status left by firmware or the bootloader.
If probe later unwinds after devm_request_irq() has installed the handler, such a stale interrupt can still reach arc_emac_intr() during teardown and race with release of the associated net_device.
Avoid that window by putting the device into a known quiescent state before requesting the IRQ: disable all EMAC interrupt sources and clear any pending EMAC interrupt status bits. This keeps the change hardware-focused and minimal, while preventing spurious IRQ delivery from leftover state.
--- drivers/net/ethernet/arc/emac_main.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/ethernet/arc/emac_main.c +11 -0
@@ -934,6 +934,17 @@ int arc_emac_probe(struct net_device *nd/* Set poll rate so that it polls every 1 ms */ arc_reg_set (priv,R_POLLRATE , clock_frequency /1000000 ); +/* +* Put the device into a known quiescent state before requesting +* the IRQ. Clear only EMAC interrupt status bits here; leave the +* MDIO completion bit alone and avoid writing TXPL_MASK, which is +* used to force TX polling rather than acknowledge interrupts. +*/ +arc_reg_set (priv,R_ENABLE ,0 ); +arc_reg_set (priv,R_STATUS ,RXINT_MASK |TXINT_MASK |ERR_MASK | +TXCH_MASK |MSER_MASK |RXCR_MASK | +RXFR_MASK |RXFL_MASK ); + ndev->irq = irq;dev_info (dev,"IRQ is %d\n" , ndev->irq);
Greg Kroah-Hartman
maintainerPATCH 173/570 drm/amdgpu: Fix use-after-free race in VM acquire
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alysa Liu <[email protected]>
commit 2c1030f2e84885cc58bffef6af67d5b9d2e7098f upstream.
Replace non-atomic vm->process_info assignment with cmpxchg() to prevent race when parent/child processes sharing a drm_file both try to acquire the same VM after fork().
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +5 -1
@@ -1218,7 +1218,10 @@ static int init_kfd_vm(struct amdgpu_vm *ef =dma_fence_get (&info->eviction_fence->base); } - vm->process_info = *process_info; +if (cmpxchg (&vm->process_info,NULL , *process_info) !=NULL ) { + ret = -EINVAL ; + goto already_acquired; + }/* Validate page directory and attach eviction fence */ ret =amdgpu_bo_reserve (vm->root.bo, true);
@@ -1255,6 +1258,7 @@ validate_pd_fail:amdgpu_bo_unreserve (vm->root.bo); reserve_pd_fail: vm->process_info =NULL ; +already_acquired:if (info) {/* Two fence references: one in info and one in *ef */ dma_fence_put (&info->eviction_fence->base);
Greg Kroah-Hartman
maintainerPATCH 174/570 tracing: Fix trace_buf_size= cmdline parameter with sizes >= 2G
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Calvin Owens <[email protected]>
commit d008ba8be8984760e36d7dcd4adbd5a41a645708 upstream.
Some of the sizing logic through tracer_alloc_buffers() uses int internally, causing unexpected behavior if the user passes a value that does not fit in an int (on my x86 machine, the result is uselessly tiny buffers).
Fix by plumbing the parameter's real type (unsigned long) through to the ring buffer allocation functions, which already use unsigned long.
It has always been possible to create larger ring buffers via the sysfs
interface: this only affects the cmdline parameter.
--- kernel/trace/trace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/trace/trace.c +3 -3
@@ -9244,7 +9244,7 @@ static void init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer);static int -allocate_trace_buffer (struct trace_array *tr,struct array_buffer *buf,int size) +allocate_trace_buffer (struct trace_array *tr,struct array_buffer *buf,unsigned long size) {enum ring_buffer_flags rb_flags;
@@ -9270,7 +9270,7 @@ allocate_trace_buffer(struct trace_arrayreturn 0 ; } -static int allocate_trace_buffers (struct trace_array *tr,int size) +static int allocate_trace_buffers (struct trace_array *tr,unsigned long size) {int ret;
@@ -10213,7 +10213,7 @@ out:__init static int tracer_alloc_buffers (void ) { -int ring_buf_size; +unsigned long ring_buf_size;int ret = -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 175/570 xfs: fix undersized l_iclog_roundoff values
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit 52a8a1ba883defbfe3200baa22cf4cd21985d51a upstream.
If the superblock doesn't list a log stripe unit, we set the incore log roundoff value to 512. This leads to corrupt logs and unmountable filesystems in generic/617 on a disk with 4k physical sectors...
XFS (sda1): Mounting V5 Filesystem ff3121ca-26e6-4b77-b742-aaff9a449e1c
XFS (sda1): Torn write (CRC failure) detected at log block 0x318e. Truncating head block from 0x3197. XFS (sda1): failed to locate log tail
XFS (sda1): log mount/recovery failed: error -74
XFS (sda1): log mount failed
XFS (sda1): Mounting V5 Filesystem ff3121ca-26e6-4b77-b742-aaff9a449e1c
XFS (sda1): Ending clean mount
...on the current xfsprogs for-next which has a broken mkfs. xfs_info shows this...
meta-data=/dev/sda1 isize=512 agcount=4, agsize=644992 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=1
= reflink=1 bigtime=1 inobtcount=1 nrext64=1
= exchange=1 metadir=1
data = bsize=4096 blocks=2579968, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1, parent=1
log =internal log bsize=4096 blocks=16384, version=2
= sectsz=4096 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
= rgcount=0 rgsize=268435456 extents
= zoned=0 start=0 reserved=0...observe that the log section has sectsz=4096 sunit=0, which means that the roundoff factor is 512, not 4096 as you'd expect. We should fix mkfs not to generate broken filesystems, but anyone can fuzz the ondisk superblock so we should be more cautious. I think the inadequate logic predates commit a6a65fef5ef8d0, but that's clearly going to require a different backport.
--- fs/xfs/xfs_log.c | 2 ++ 1 file changed, 2 insertions(+)
fs/xfs/xfs_log.c +2 -0
@@ -1503,6 +1503,8 @@ xlog_alloc_log(if (xfs_has_logv2 (mp) && mp->m_sb.sb_logsunit >1 ) log->l_iclog_roundoff = mp->m_sb.sb_logsunit; +else if (mp->m_sb.sb_logsectsize >0 ) + log->l_iclog_roundoff = mp->m_sb.sb_logsectsize;else log->l_iclog_roundoff =BBSIZE ;
Greg Kroah-Hartman
maintainerPATCH 176/570 lib/bootconfig: fix off-by-one in xbc_verify_tree() unclosed brace error
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josh Law <[email protected]>
commit 39ebc8d7f561e1b64eca87353ef9b18e2825e591 upstream.
__xbc_open_brace() pushes entries with post-increment (open_brace[brace_index++]), so brace_index always points one past the last valid entry. xbc_verify_tree() reads open_brace[brace_index] to report which brace is unclosed, but this is one past the last pushed entry and contains stale/zero data, causing the error message to reference the wrong node.
Use open_brace[brace_index - 1] to correctly identify the unclosed brace. brace_index is known to be > 0 here since we are inside the if (brace_index) guard.
--- lib/bootconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bootconfig.c +1 -1
@@ -725,7 +725,7 @@ static int __init xbc_verify_tree(void)/* Brace closing */ if (brace_index) { - n = &xbc_nodes[open_brace[brace_index]]; + n = &xbc_nodes[open_brace[brace_index -1 ]];return xbc_parse_error ("Brace is not closed" ,xbc_node_get_data (n)); }
Greg Kroah-Hartman
maintainerPATCH 177/570 scsi: core: Fix error handling for scsi_alloc_sdev()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junxiao Bi <[email protected]>
commit 4ce7ada40c008fa21b7e52ab9d04e8746e2e9325 upstream.
After scsi_sysfs_device_initialize() was called, error paths must call __scsi_remove_device().
--- drivers/scsi/scsi_scan.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/scsi/scsi_scan.c +2 -6
@@ -339,12 +339,8 @@ static struct scsi_device *scsi_alloc_sd* default device queue depth to figure out sbitmap shift * since we use this queue depth most of times. */ -if (scsi_realloc_sdev_budget_map (sdev, depth)) { -kref_put (&sdev->host->tagset_refcnt, scsi_mq_free_tags); -put_device (&starget->dev); -kfree (sdev); - goto out; - } +if (scsi_realloc_sdev_budget_map (sdev, depth)) + goto out_device_destroy;scsi_change_queue_depth (sdev, depth);
Re: [PATCH 5.15 177/570] scsi: core: Fix error handling for scsi_alloc_sdev()
Hi,
Quoted 28 lines · Greg Kroah-Hartman
5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junxiao Bi <[email protected]>
commit
4ce7ada40c008fa21b7e52ab9d04e8746e2e9325upstream.After
scsi_sysfs_device_initialize()was called, error paths must call__scsi_remove_device().Fixes 1ac22c8eae81 ("scsi: core: Fix refcount leak for tagset_refcnt")Signed-off-by Junxiao Bi <[email protected]>Reviewed-by John Garry <[email protected]>Reviewed-by Bart Van Assche <[email protected]>Signed-off-by Martin K. Petersen <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- drivers/scsi/scsi_scan.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/scsi/scsi_scan.c +0
-0@@ -339,12 +339,8 @@ static struct scsi_device *scsi_alloc_sd* default device queue depth to figure out sbitmap shift * since we use this queue depth most of times.
drivers/scsi/scsi_scan.c static struct scsi_device *scsi_alloc_sd · line 344
Quoted 10 lines
drivers/scsi/scsi_scan.c +2
-6*/ -if (scsi_realloc_sdev_budget_map (sdev, depth)) { -kref_put (&sdev->host->tagset_refcnt, scsi_mq_free_tags); -put_device (&starget->dev); -kfree (sdev); - goto out; - } +if (scsi_realloc_sdev_budget_map (sdev, depth)) + goto out_device_destroy;
I have run an AI assisted backport review and it spotted an issue: I have taken a look and the issue is:
5.15.y doesn't have commit: 21008cabc5d9 ("scsi: core: Move two statements") - v6.19-rc1 based so backporting this patch introduces something like:
if (scsi_realloc_sdev_budget_map(sdev, depth))
goto out_device_destroy;
scsi_change_queue_depth(sdev, depth);
scsi_sysfs_device_initialize(sdev);
...
out_device_destroy:
__scsi_remove_device(sdev);calling put_device() before device_initialize(), so I think we should drop this patch in stable branches which don't have commit: 21008cabc5d9 ("scsi: core: Move two statements") in them. Upstream moved scsi_sysfs_device_initialize() above the budget_map() call.
Thoughts ?
I see the same problem in other stable branches as well.
Thanks,
Harshit
Quoted 5 lines
drivers/scsi/scsi_scan.c +0
-0scsi_change_queue_depth (sdev, depth);
Re: [PATCH 5.15 177/570] scsi: core: Fix error handling for scsi_alloc_sdev()
Quoted 53 lines · Harshit Mogalapalli
Hi,
Quoted 27 lines · Greg Kroah-Hartman
5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junxiao Bi <[email protected]>
commit
4ce7ada40c008fa21b7e52ab9d04e8746e2e9325upstream.After
scsi_sysfs_device_initialize()was called, error paths must call__scsi_remove_device().Fixes 1ac22c8eae81 ("scsi: core: Fix refcount leak for tagset_refcnt")Signed-off-by Junxiao Bi <[email protected]>Reviewed-by John Garry <[email protected]>Reviewed-by Bart Van Assche <[email protected]>Signed-off-by Martin K. Petersen <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>---
drivers/scsi/scsi_scan.c| 8 ++------1 file changed, 2 insertions(+), 6 deletions(-)drivers/scsi/scsi_scan.c +0
-0@@ -339,12 +339,8 @@ static struct scsi_device *scsi_alloc_sd * default device queue depth to figure out sbitmap shiftdrivers/scsi/scsi_scan.c static struct scsi_device *scsi_alloc_sd · line 343
Quoted 10 lines
drivers/scsi/scsi_scan.c +2
-6* since we use this queue depth most of times. */ - if (scsi_realloc_sdev_budget_map(sdev, depth)) { - kref_put(&sdev->host->tagset_refcnt, scsi_mq_free_tags); - put_device(&starget->dev); - kfree(sdev); - goto out; - } + if (scsi_realloc_sdev_budget_map(sdev, depth)) + goto out_device_destroy;I have run an AI assisted backport review and it spotted an issue: I have taken a look and the issue is:
5.15.y doesn't have commit:
21008cabc5d9("scsi: core: Move two statements") - v6.19-rc1 based so backporting this patch introduces something like:if (
scsi_realloc_sdev_budget_map(sdev, depth))
gotoout_device_destroy;
scsi_change_queue_depth(sdev, depth);
scsi_sysfs_device_initialize(sdev);
Quoted 9 lines
...
out_device_destroy:
__scsi_remove_device(sdev);calling
put_device()beforedevice_initialize(), so I think we should drop this patch in stable branches which don't have commit:21008cabc5d9("scsi: core: Move two statements") in them. Upstream movedscsi_sysfs_device_initialize()above thebudget_map()call.Thoughts ?
Right, this commit should be backported as well. Otherwise we could see this warning.
"kobject: '%s' (%p): is not initialized, yet kobject_put() is being called.\n"
Thanks,
Junxiao.
Quoted 11 lines
I see the same problem in other stable branches as well.
Thanks,
HarshitQuoted 4 lines
drivers/scsi/scsi_scan.c +0
-0scsi_change_queue_depth(sdev, depth);
Re: [PATCH 5.15 177/570] scsi: core: Fix error handling for scsi_alloc_sdev()
Hi Junxiao,
Quoted 26 lines
Quoted 26 lines
Quoted 8 lines
- if (
scsi_realloc_sdev_budget_map(sdev, depth)) {
-kref_put(&sdev->host->tagset_refcnt, scsi_mq_free_tags); -put_device(&starget->dev);
- kfree(sdev);
- goto out;
- }
+ if (scsi_realloc_sdev_budget_map(sdev, depth))
+ gotoout_device_destroy;I have run an AI assisted backport review and it spotted an issue: I have taken a look and the issue is:
5.15.y doesn't have commit:
21008cabc5d9("scsi: core: Move two statements") - v6.19-rc1 based so backporting this patch introduces something like:if (
scsi_realloc_sdev_budget_map(sdev, depth))
gotoout_device_destroy;
scsi_change_queue_depth(sdev, depth);
scsi_sysfs_device_initialize(sdev);...
out_device_destroy:
__scsi_remove_device(sdev);
Quoted 8 lines
Quoted 4 lines
calling
put_device()beforedevice_initialize(), so I think we should drop this patch in stable branches which don't have commit:21008cabc5d9("scsi: core: Move two statements") in them. Upstream movedscsi_sysfs_device_initialize()above thebudget_map()call.Thoughts ?
Right, this commit should be backported as well. Otherwise we could see this warning.
"kobject: '%s' (%p): is not initialized, yet
kobject_put()is being called.\n"
Thanks for confirming, Sasha dropped it from the stable queue for this release.
Thanks,
Harshit
Quoted 15 lines
Thanks,
Junxiao.
Quoted 11 lines
I see the same problem in other stable branches as well.
Thanks,
HarshitQuoted 4 lines
scsi_change_queue_depth(sdev, depth);
Sasha Levin
maintainerRe: scsi: core: Move two statements (prerequisite for already-backported 4ce7ada40c00)
In reply to Harshit MogalapalliQuoted 3 lines · Harshit Mogalapalli
21008cabc5d9("scsi: core: Move two statements") is a prerequisite for the already-backported4ce7ada40c00and should land on 6.18/6.12/6.6/6.1 (and 5.15).
I tried queuing 21008cabc5d9 on 6.12 but it causes a build break: the prerequisite ed638918f4df ("scsi: Rename .slave_alloc() and .slave_destroy()") renames the scsi_host_template fields (.slave_alloc -> .sdev_init, .slave_destroy -> .sdev_destroy) while drivers/staging/rts5208/rtsx.c still uses the old names and fails to build with:
error: 'const struct scsi_host_template' has no member named 'slave_alloc'
The same rts5208 driver exists on 6.6/6.1/5.15 so those trees hit the same wall.
--
Thanks,
Sasha
Greg Kroah-Hartman
maintainerPATCH 178/570 x86/apic: Disable x2apic on resume if the kernel expects so
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shashank Balaji <[email protected]>
commit 8cc7dd77a1466f0ec58c03478b2e735a5b289b96 upstream.
When resuming from s2ram, firmware may re-enable x2apic mode, which may have been disabled by the kernel during boot either because it doesn't support IRQ remapping or for other reasons. This causes the kernel to continue using the xapic interface, while the hardware is in x2apic mode, which causes hangs. This happens on defconfig + bare metal + s2ram.
Fix this in lapic_resume() by disabling x2apic if the kernel expects it to be disabled, i.e. when x2apic_mode = 0.
The ACPI v6.6 spec, Section 16.3 [1] says firmware restores either the pre-sleep configuration or initial boot configuration for each CPU, including MSR state:
When executing from the power-on reset vector as a result of waking from an S2 or S3 sleep state, the platform firmware performs only the hardware initialization required to restore the system to either the state the platform was in prior to the initial operating system boot, or to the pre-sleep configuration state. In multiprocessor systems, non-boot processors should be placed in the same state as prior to the initial operating system boot.
(further ahead)
If this is an S2 or S3 wake, then the platform runtime firmware restores minimum context of the system before jumping to the waking vector. This includes:
CPU configuration. Platform runtime firmware restores the pre-sleep configuration or initial boot configuration of each CPU (MSR, MTRR, firmware update, SMBase, and so on). Interrupts must be disabled (for IA-32 processors, disabled by CLI instruction).
(and other things)
So at least as per the spec, re-enablement of x2apic by the firmware is allowed if "x2apic on" is a part of the initial boot configuration.
[1] https://uefi.org/specs/ACPI/6.6/16_Waking_and_Sleeping.html#initialization
[ bp: Massage. ]
--- arch/x86/kernel/apic/apic.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/x86/kernel/apic/apic.c +6 -0
@@ -1916,6 +1916,7 @@ early_initcall(validate_x2apic);static inline void try_to_enable_x2apic (int remap_mode) { }static inline void __x2apic_enable (void ) { } +static inline void __x2apic_disable (void ) { }#endif /* !CONFIG_X86_X2APIC */ void __init enable_IR_x2apic (void )
@@ -2726,6 +2727,11 @@ static void lapic_resume(void)if (x2apic_mode) {__x2apic_enable (); }else { +if (x2apic_enabled ()) { +pr_warn_once ("x2apic: re-enabled by firmware during resume. Disabling\n" ); +__x2apic_disable (); + } +/* * Make sure the APICBASE points to the right address *
Greg Kroah-Hartman
maintainerPATCH 179/570 lib/bootconfig: fix snprintf truncation check in xbc_node_compose_key_after()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josh Law <[email protected]>
commit 1120a36bb1e9b9e22de75ecb4ef0b998f73a97f1 upstream.
snprintf() returns the number of characters that would have been written excluding the NUL terminator. Output is truncated when the return value is >= the buffer size, not just > the buffer size.
When ret == size, the current code takes the non-truncated path, advancing buf by ret and reducing size to 0. This is wrong because the output was actually truncated (the last character was replaced by NUL). Fix by using >= so the truncation path is taken correctly.
--- lib/bootconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bootconfig.c +1 -1
@@ -250,7 +250,7 @@ int __init xbc_node_compose_key_after(st depth ? "." : "");if (ret <0 )return ret; -if (ret > size) { +if (ret >= size) { size =0 ; }else { size -= ret;
Greg Kroah-Hartman
maintainerPATCH 180/570 lib/bootconfig: check bounds before writing in __xbc_open_brace()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josh Law <[email protected]>
commit 560f763baa0f2c9a44da4294c06af071405ac46f upstream.
The bounds check for brace_index happens after the array write. While the current call pattern prevents an actual out-of-bounds access (the previous call would have returned an error), the write-before-check pattern is fragile and would become a real out-of-bounds write if the error return were ever not propagated.
Move the bounds check before the array write so the function is self-contained and safe regardless of caller behavior.
--- lib/bootconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bootconfig.c +1 -1
@@ -466,9 +466,9 @@ static char *skip_spaces_until_newline(cstatic int __init __xbc_open_brace (char *p) {/* Push the last key as open brace */ - open_brace[brace_index++] =xbc_node_index (last_parent);if (brace_index >=XBC_DEPTH_MAX )return xbc_parse_error ("Exceed max depth of braces" , p); + open_brace[brace_index++] =xbc_node_index (last_parent);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 181/570 btrfs: abort transaction on failure to update root in the received subvol ioctl
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
commit 0f475ee0ebce5c9492b260027cd95270191675fa upstream.
If we failed to update the root we don't abort the transaction, which is wrong since we already used the transaction to remove an item from the uuid tree.
--- fs/btrfs/ioctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/ioctl.c +2 -1
@@ -4545,7 +4545,8 @@ static long _btrfs_ioctl_set_received_su ret =btrfs_update_root (trans, fs_info->tree_root, &root->root_key, &root->root_item); -if (ret <0 ) { +if (unlikely (ret <0 )) { +btrfs_abort_transaction (trans, ret);btrfs_end_transaction (trans); goto out; }
Greg Kroah-Hartman
maintainerPATCH 182/570 iio: dac: ds4424: reject -128 RAW value
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oleksij Rempel <[email protected]>
commit 5187e03b817c26c1c3bcb2645a612ea935c4be89 upstream.
The DS442x DAC uses sign-magnitude encoding, so -128 cannot be represented in hardware (7-bit magnitude).
Previously, passing -128 resulted in a truncated value that programmed 0mA (magnitude 0) instead of the expected maximum negative current, effectively failing silently.
Reject -128 to avoid producing the wrong current.
--- drivers/iio/dac/ds4424.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/dac/ds4424.c +1 -1
@@ -141,7 +141,7 @@ static int ds4424_write_raw(struct iio_dswitch (mask) {case IIO_CHAN_INFO_RAW : -if (val <S8_MIN || val >S8_MAX ) +if (val <=S8_MIN || val >S8_MAX )return -EINVAL ;if (val >0 ) {
Greg Kroah-Hartman
maintainerPATCH 183/570 iio: chemical: sps30_serial: fix buffer size in sps30_serial_read_meas()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antoniu Miclaus <[email protected]>
commit c3914ce1963c4db25e186112c90fa5d2361e9e0a upstream.
sizeof(num) evaluates to sizeof(size_t) which is 8 bytes on 64-bit, but the buffer elements are only 4 bytes. The same function already uses sizeof(*meas) on line 312, making the mismatch evident. Use sizeof(*meas) consistently.
--- drivers/iio/chemical/sps30_serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/sps30_serial.c +1 -1
@@ -303,7 +303,7 @@ static int sps30_serial_read_meas(structif (msleep_interruptible (1000 ))return -EINTR ; - ret =sps30_serial_command (state,SPS30_SERIAL_READ_MEAS ,NULL ,0 , meas, num *sizeof (num)); + ret =sps30_serial_command (state,SPS30_SERIAL_READ_MEAS ,NULL ,0 , meas, num *sizeof (*meas));if (ret <0 )return ret;/* if measurements aren't ready sensor returns empty frame */
Greg Kroah-Hartman
maintainerPATCH 184/570 iio: chemical: sps30_i2c: fix buffer size in sps30_i2c_read_meas()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antoniu Miclaus <[email protected]>
commit 216345f98cae7fcc84f49728c67478ac00321c87 upstream.
sizeof(num) evaluates to sizeof(size_t) (8 bytes on 64-bit) instead of the intended __be32 element size (4 bytes). Use sizeof(*meas) to correctly match the buffer element type.
--- drivers/iio/chemical/sps30_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/sps30_i2c.c +1 -1
@@ -171,7 +171,7 @@ static int sps30_i2c_read_meas(struct spif (!sps30_i2c_meas_ready (state))return -ETIMEDOUT ; -return sps30_i2c_command (state,SPS30_I2C_READ_MEAS ,NULL ,0 , meas,sizeof (num) * num); +return sps30_i2c_command (state,SPS30_I2C_READ_MEAS ,NULL ,0 , meas,sizeof (*meas) * num); }static int sps30_i2c_clean_fan (struct sps30_state *state)
Greg Kroah-Hartman
maintainerPATCH 185/570 iio: potentiometer: mcp4131: fix double application of wiper shift
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Schmid <[email protected]>
commit 85e4614524dca6c0a43874f475a17de2b9725648 upstream.
The MCP4131 wiper address is shifted twice when preparing the SPI command in mcp4131_write_raw().
The address is already shifted when assigned to the local variable "address", but is then shifted again when written to data->buf[0]. This results in an incorrect command being sent to the device and breaks wiper writes to the second channel.
Remove the second shift and use the pre-shifted address directly when composing the SPI transfer.
--- drivers/iio/potentiometer/mcp4131.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/potentiometer/mcp4131.c +1 -1
@@ -222,7 +222,7 @@ static int mcp4131_write_raw(struct iio_mutex_lock (&data->lock); - data->buf[0 ] = address <<MCP4131_WIPER_SHIFT ; + data->buf[0 ] = address; data->buf[0 ] |=MCP4131_WRITE | (val >>8 ); data->buf[1 ] = val &0xFF ;/* 8 bits here */
Greg Kroah-Hartman
maintainerPATCH 186/570 iio: chemical: bme680: Fix measurement wait duration calculation
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Spencer <[email protected]>
commit f55b9510cd9437da3a0efa08b089caeb47595ff1 upstream.
This function refers to the Bosch BME680 API as the source of the calculation, but one of the constants does not match the Bosch implementation. This appears to be a simple transposition of two digits, resulting in a wait time that is too short. This can cause the following 'device measurement cycle incomplete' check to occasionally fail, returning EBUSY to user space.
Adjust the constant to match the Bosch implementation and resolve the EBUSY errors.
--- drivers/iio/chemical/bme680_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/bme680_core.c +1 -1
@@ -548,7 +548,7 @@ static int bme680_wait_for_eoc(struct bm* + heater duration */ int wait_eoc_us = ((data->oversampling_temp + data->oversampling_press + - data->oversampling_humid) *1936 ) + (477 *4 ) + + data->oversampling_humid) *1963 ) + (477 *4 ) + (477 *5 ) +1000 + (data->heater_dur *1000 );usleep_range (wait_eoc_us, wait_eoc_us +100 );
Greg Kroah-Hartman
maintainerPATCH 187/570 iio: gyro: mpu3050-core: fix pm_runtime error handling
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antoniu Miclaus <[email protected]>
commit acc3949aab3e8094641a9c7c2768de1958c88378 upstream.
The return value of pm_runtime_get_sync() is not checked, allowing the driver to access hardware that may fail to resume. The device usage count is also unconditionally incremented. Use pm_runtime_resume_and_get() which propagates errors and avoids incrementing the usage count on failure.
In preenable, add pm_runtime_put_autosuspend() on set_8khz_samplerate() failure since postdisable does not run when preenable fails.
--- drivers/iio/gyro/mpu3050-core.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/iio/gyro/mpu3050-core.c +13 -5
@@ -321,7 +321,9 @@ static int mpu3050_read_raw(struct iio_d }case IIO_CHAN_INFO_RAW :/* Resume device */ -pm_runtime_get_sync (mpu3050->dev); + ret =pm_runtime_resume_and_get (mpu3050->dev); +if (ret) +return ret;mutex_lock (&mpu3050->lock); ret =mpu3050_set_8khz_samplerate (mpu3050);
@@ -652,14 +654,20 @@ out_trigger_unlock:static int mpu3050_buffer_preenable (struct iio_dev *indio_dev) {struct mpu3050 *mpu3050 =iio_priv (indio_dev); +int ret; -pm_runtime_get_sync (mpu3050->dev); + ret =pm_runtime_resume_and_get (mpu3050->dev); +if (ret) +return ret;/* Unless we have OUR trigger active, run at full speed */ -if (!mpu3050->hw_irq_trigger) -return mpu3050_set_8khz_samplerate (mpu3050); +if (!mpu3050->hw_irq_trigger) { + ret =mpu3050_set_8khz_samplerate (mpu3050); +if (ret) +pm_runtime_put_autosuspend (mpu3050->dev); + } -return 0 ; +return ret; }static int mpu3050_buffer_postdisable (struct iio_dev *indio_dev)
Greg Kroah-Hartman
maintainerPATCH 188/570 iio: gyro: mpu3050-i2c: fix pm_runtime error handling
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antoniu Miclaus <[email protected]>
commit 91f950b4cbb1aa9ea4eb3999f1463e8044b717fb upstream.
The return value of pm_runtime_get_sync() is not checked, and the function always returns success. This allows I2C mux operations to proceed even when the device fails to resume.
Use pm_runtime_resume_and_get() and propagate its return value to properly handle resume failures.
--- drivers/iio/gyro/mpu3050-i2c.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/gyro/mpu3050-i2c.c +1 -2
@@ -19,8 +19,7 @@ static int mpu3050_i2c_bypass_select(strstruct mpu3050 *mpu3050 =i2c_mux_priv (mux);/* Just power up the device, that is all that is needed */ -pm_runtime_get_sync (mpu3050->dev); -return 0 ; +return pm_runtime_resume_and_get (mpu3050->dev); }static int mpu3050_i2c_bypass_deselect (struct i2c_mux_core *mux,u32 chan_id)
Greg Kroah-Hartman
maintainerPATCH 189/570 iio: imu: inv_icm42600: fix odr switch to the same value
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jean-Baptiste Maneyrol <[email protected]>
commit c9f3a593137d862d424130343e77d4b5260a4f5a upstream.
ODR switch is done in 2 steps when FIFO is on : change the ODR register value and acknowledge change when reading the FIFO ODR change flag. When we are switching to the same odr value, we end up waiting for a FIFO ODR flag that is never happening.
Fix the issue by doing nothing and exiting properly when we are switching to the same ODR value.
--- drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 2 ++ drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c | 2 ++ 2 files changed, 4 insertions(+)
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +2 -0
@@ -322,6 +322,8 @@ static int inv_icm42600_accel_write_odr(return -EINVAL ; conf.odr = inv_icm42600_accel_odr_conv[idx /2 ]; +if (conf.odr == st->conf.accel.odr) +return 0 ;pm_runtime_get_sync (dev);mutex_lock (&st->lock);
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +2 -0
@@ -334,6 +334,8 @@ static int inv_icm42600_gyro_write_odr(sreturn -EINVAL ; conf.odr = inv_icm42600_gyro_odr_conv[idx /2 ]; +if (conf.odr == st->conf.gyro.odr) +return 0 ;pm_runtime_get_sync (dev);mutex_lock (&st->lock);
Greg Kroah-Hartman
maintainerPATCH 190/570 i3c: mipi-i3c-hci: Use ETIMEDOUT instead of ETIME for timeout errors
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
commit 4167b8914463132654e01e16259847d097f8a7f7 upstream.
The MIPI I3C HCI driver currently returns -ETIME for various timeout conditions, while other I3C master drivers consistently use -ETIMEDOUT for the same class of errors. Align the HCI driver with the rest of the subsystem by replacing all uses of -ETIME with -ETIMEDOUT.
--- drivers/i3c/master/mipi-i3c-hci/cmd_v1.c | 2 +- drivers/i3c/master/mipi-i3c-hci/cmd_v2.c | 2 +- drivers/i3c/master/mipi-i3c-hci/core.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/i3c/master/mipi-i3c-hci/cmd_v1.c +1 -1
@@ -335,7 +335,7 @@ static int hci_cmd_v1_daa(struct i3c_hci hci->io->queue_xfer (hci, xfer,1 );if (!wait_for_completion_timeout (&done,HZ ) && hci->io->dequeue_xfer (hci, xfer,1 )) { - ret = -ETIME ; + ret = -ETIMEDOUT ;break ; } if (RESP_STATUS(xfer[0].response) == RESP_ERR_NACK &&
drivers/i3c/master/mipi-i3c-hci/cmd_v2.c +1 -1
@@ -277,7 +277,7 @@ static int hci_cmd_v2_daa(struct i3c_hci hci->io->queue_xfer (hci, xfer,2 );if (!wait_for_completion_timeout (&done,HZ ) && hci->io->dequeue_xfer (hci, xfer,2 )) { - ret = -ETIME ; + ret = -ETIMEDOUT ;break ; }if (RESP_STATUS (xfer[0 ].response) !=RESP_SUCCESS ) {
drivers/i3c/master/mipi-i3c-hci/core.c +3 -3
@@ -237,7 +237,7 @@ static int i3c_hci_send_ccc_cmd(struct i goto out;if (!wait_for_completion_timeout (&done,HZ ) && hci->io->dequeue_xfer (hci, xfer, nxfers)) { - ret = -ETIME ; + ret = -ETIMEDOUT ; goto out; }for (i = prefixed; i < nxfers; i++) {
@@ -311,7 +311,7 @@ static int i3c_hci_priv_xfers(struct i3c goto out;if (!wait_for_completion_timeout (&done,HZ ) && hci->io->dequeue_xfer (hci, xfer, nxfers)) { - ret = -ETIME ; + ret = -ETIMEDOUT ; goto out; }for (i =0 ; i < nxfers; i++) {
@@ -359,7 +359,7 @@ static int i3c_hci_i2c_xfers(struct i2c_ goto out;if (!wait_for_completion_timeout (&done,HZ ) && hci->io->dequeue_xfer (hci, xfer, nxfers)) { - ret = -ETIME ; + ret = -ETIMEDOUT ; goto out; }for (i =0 ; i < nxfers; i++) {
Greg Kroah-Hartman
maintainerPATCH 191/570 i3c: mipi-i3c-hci: Restart DMA ring correctly after dequeue abort
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
commit b6d586431ae20d5157ee468d0ef62ad26798ef13 upstream.
The DMA dequeue path attempts to restart the ring after aborting an in-flight transfer, but the current sequence is incomplete. The controller must be brought out of the aborted state and the ring control registers must be programmed in the correct order: first clearing ABORT, then re-enabling the ring and asserting RUN_STOP to resume operation.
Add the missing controller resume step and update the ring control writes so that the ring is restarted using the proper sequence.
--- drivers/i3c/master/mipi-i3c-hci/dma.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/i3c/master/mipi-i3c-hci/dma.c +2 -0
@@ -491,7 +491,9 @@ static bool hci_dma_dequeue_xfer(struct }/* restart the ring */ +mipi_i3c_hci_resume (hci);rh_reg_write (RING_CONTROL ,RING_CTRL_ENABLE ); +rh_reg_write (RING_CONTROL ,RING_CTRL_ENABLE |RING_CTRL_RUN_STOP );return did_unqueue; }
Greg Kroah-Hartman
maintainerPATCH 192/570 i3c: mipi-i3c-hci: Add missing TID field to no-op command descriptor
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
commit ec3cfd835f7c4bbd23bc9ad909d2fdc772a578bb upstream.
The internal control command descriptor used for no-op commands includes a Transaction ID (TID) field, but the no-op command constructed in hci_dma_dequeue_xfer() omitted it. As a result, the hardware receives a no-op descriptor without the expected TID.
This bug has gone unnoticed because the TID is currently not validated in the no-op completion path, but the descriptor format requires it to be present.
Add the missing TID field when generating a no-op descriptor so that its layout matches the defined command structure.
--- drivers/i3c/master/mipi-i3c-hci/cmd.h | 1 + drivers/i3c/master/mipi-i3c-hci/dma.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/i3c/master/mipi-i3c-hci/cmd.h +1 -0
@@ -17,6 +17,7 @@#define CMD_0_TOC W0_BIT_(31)#define CMD_0_ROC W0_BIT_(30)#define CMD_0_ATTR W0_MASK(2, 0) +#define CMD_0_TID W0_MASK(6, 3)/* * Response Descriptor Structure
drivers/i3c/master/mipi-i3c-hci/dma.c +1 -1
@@ -473,7 +473,7 @@ static bool hci_dma_dequeue_xfer(structu32 *ring_data = rh->xfer + rh->xfer_struct_sz * idx;/* store no-op cmd descriptor */ - *ring_data++ =FIELD_PREP (CMD_0_ATTR ,0x7 ); + *ring_data++ =FIELD_PREP (CMD_0_ATTR ,0x7 ) |FIELD_PREP (CMD_0_TID , xfer->cmd_tid); *ring_data++ =0 ;if (hci->cmd == &mipi_i3c_hci_cmd_v2) { *ring_data++ =0 ;
Greg Kroah-Hartman
maintainerPATCH 193/570 bpf: Forget ranges when refining tnum after JSET
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Chaignon <[email protected]>
commit 6279846b9b2532e1b04559ef8bd0dec049f29383 upstream.
Syzbot reported a kernel warning due to a range invariant violation on the following BPF program.
0: call bpf_get_netns_cookie
1: if r0 == 0 goto <exit>
2: if r0 & Oxffffffff goto <exit>
The issue is on the path where we fall through both jumps.
That path is unreachable at runtime: after insn 1, we know r0 != 0, but with the sign extension on the jset, we would only fallthrough insn 2 if r0 == 0. Unfortunately, is_branch_taken() isn't currently able to figure this out, so the verifier walks all branches. The verifier then refines the register bounds using the second condition and we end up with inconsistent bounds on this unreachable path:
1: if r0 == 0 goto <exit>
r0: u64=[0x1, 0xffffffffffffffff] var_off=(0, 0xffffffffffffffff)
2: if r0 & 0xffffffff goto <exit>
r0 before reg_bounds_sync: u64=[0x1, 0xffffffffffffffff] var_off=(0, 0)
r0 after reg_bounds_sync: u64=[0x1, 0] var_off=(0, 0)Improving the range refinement for JSET to cover all cases is tricky. We also don't expect many users to rely on JSET given LLVM doesn't generate those instructions. So instead of improving the range refinement for JSETs, Eduard suggested we forget the ranges whenever we're narrowing tnums after a JSET. This patch implements that approach.
[ shung-hsi.yu: no detection or kernel warning for invariant violation before
6.8, but the same umin=1,umax=0 state can occur when jset is preceed by r0 < 1. Changes were made to adapt to older range refinement logic before commit 67420501e868 ("bpf: generalize reg_set_min_max() to handle non-const register comparisons"). ]
--- kernel/bpf/verifier.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/bpf/verifier.c +4 -0
@@ -8906,6 +8906,10 @@ static void reg_set_min_max(struct bpf_r }break ;case BPF_JSET : +/* Forget the ranges before narrowing tnums, to avoid invariant +* violations if we're on a dead branch. +*/ +__mark_reg_unbounded (false_reg);if (is_jmp32) { false_32off =tnum_and (false_32off,tnum_const (~val32));if (is_power_of_2 (val32))
Greg Kroah-Hartman
maintainerPATCH 194/570 l2tp: do not use sock_hold() in pppol2tp_session_get_sock()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 9b8c88f875c04d4cb9111bd5dd9291c7e9691bf5 upstream.
pppol2tp_session_get_sock() is using RCU, it must be ready for sk_refcnt being zero.
Commit ee40fb2e1eb5 ("l2tp: protect sock pointer of
struct pppol2tp_session with RCU") was correct because it
had a call_rcu(..., pppol2tp_put_sk) which was later removed in blamed commit.
pppol2tp_recv() can use pppol2tp_session_get_sock() as well.
--- net/l2tp/l2tp_ppp.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-)
net/l2tp/l2tp_ppp.c +8 -17
@@ -130,22 +130,12 @@ static const struct ppp_channel_ops pppostatic const struct proto_ops pppol2tp_ops; -/* Retrieves the pppol2tp socket associated to a session. -* A reference is held on the returned socket, so this function must be paired -* with sock_put(). -*/ +/* Retrieves the pppol2tp socket associated to a session. */ static struct sock *pppol2tp_session_get_sock (struct l2tp_session *session) {struct pppol2tp_session *ps =l2tp_session_priv (session); -struct sock *sk; -rcu_read_lock (); - sk =rcu_dereference (ps->sk); -if (sk) -sock_hold (sk); -rcu_read_unlock (); - -return sk; +return rcu_dereference (ps->sk); }/* Helpers to obtain tunnel/session contexts from sockets.
@@ -212,14 +202,13 @@ end:static void pppol2tp_recv (struct l2tp_session *session,struct sk_buff *skb,int data_len) { -struct pppol2tp_session *ps =l2tp_session_priv (session); -struct sock *sk =NULL ; +struct sock *sk;/* If the socket is bound, send it in to PPP's input queue. Otherwise * queue it on the session socket. */ rcu_read_lock (); - sk =rcu_dereference (ps->sk); + sk =pppol2tp_session_get_sock (session);if (!sk) goto no_sock;
@@ -529,13 +518,14 @@ static void pppol2tp_show(struct seq_filstruct l2tp_session *session = arg;struct sock *sk; +rcu_read_lock (); sk =pppol2tp_session_get_sock (session);if (sk) {struct pppox_sock *po =pppox_sk (sk);seq_printf (m," interface %s\n" ,ppp_dev_name (&po->chan)); -sock_put (sk); } +rcu_read_unlock (); }static void pppol2tp_session_init (struct l2tp_session *session)
@@ -1541,6 +1531,7 @@ static void pppol2tp_seq_session_show(st port =ntohs (inet->inet_sport); } +rcu_read_lock (); sk =pppol2tp_session_get_sock (session);if (sk) { state = sk->sk_state;
@@ -1576,8 +1567,8 @@ static void pppol2tp_seq_session_show(ststruct pppox_sock *po =pppox_sk (sk);seq_printf (m," interface %s\n" ,ppp_dev_name (&po->chan)); -sock_put (sk); } +rcu_read_unlock (); }static int pppol2tp_seq_show (struct seq_file *m,void *v)
Greg Kroah-Hartman
maintainerPATCH 195/570 io_uring/io-wq: check IO_WQ_BIT_EXIT inside work run loop
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Axboe <[email protected]>
commit 10dc959398175736e495f71c771f8641e1ca1907 upstream.
Currently this is checked before running the pending work. Normally this is quite fine, as work items either end up blocking (which will create a new worker for other items), or they complete fairly quickly. But syzbot reports an issue where io-wq takes seemingly forever to exit, and with a bit of debugging, this turns out to be because it queues a bunch of big (2GB - 4096b) reads with a /dev/msr* file. Since this file type doesn't support ->read_iter(), loop_rw_iter() ends up handling them. Each read returns 16MB of data read, which takes 20 (!!) seconds. With a bunch of these pending, processing the whole chain can take a long time. Easily longer than the syzbot uninterruptible sleep timeout of 140 seconds. This then triggers a complaint off the io-wq exit path:
INFO: task syz.4.135:6326 blocked for more than 143 seconds.
Not tainted syzkaller #0
Blocked by coredump.
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:syz.4.135 state:D stack:26824 pid:6326 tgid:6324 ppid:5957 task_flags:0x400548 flags:0x00080000
Call Trace:
<TASK>
context_switch kernel/sched/core.c:5256 [inline]
__schedule+0x1139/0x6150 kernel/sched/core.c:6863
__schedule_loop kernel/sched/core.c:6945 [inline]
schedule+0xe7/0x3a0 kernel/sched/core.c:6960
schedule_timeout+0x257/0x290 kernel/time/sleep_timeout.c:75
do_wait_for_common kernel/sched/completion.c:100 [inline]
__wait_for_common+0x2fc/0x4e0 kernel/sched/completion.c:121
io_wq_exit_workers io_uring/io-wq.c:1328 [inline]
io_wq_put_and_exit+0x271/0x8a0 io_uring/io-wq.c:1356
io_uring_clean_tctx+0x10d/0x190 io_uring/tctx.c:203
io_uring_cancel_generic+0x69c/0x9a0 io_uring/cancel.c:651
io_uring_files_cancel include/linux/io_uring.h:19 [inline]
do_exit+0x2ce/0x2bd0 kernel/exit.c:911
do_group_exit+0xd3/0x2a0 kernel/exit.c:1112
get_signal+0x2671/0x26d0 kernel/signal.c:3034
arch_do_signal_or_restart+0x8f/0x7e0 arch/x86/kernel/signal.c:337
__exit_to_user_mode_loop kernel/entry/common.c:41 [inline]
exit_to_user_mode_loop+0x8c/0x540 kernel/entry/common.c:75
__exit_to_user_mode_prepare include/linux/irq-entry-common.h:226 [inline]
syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:256 [inline]
syscall_exit_to_user_mode_work include/linux/entry-common.h:159 [inline]
syscall_exit_to_user_mode include/linux/entry-common.h:194 [inline]
do_syscall_64+0x4ee/0xf80 arch/x86/entry/syscall_64.c:100
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fa02738f749
RSP: 002b:00007fa0281ae0e8 EFLAGS: 00000246 ORIG_RAX: 00000000000000ca
RAX: fffffffffffffe00 RBX: 00007fa0275e6098 RCX: 00007fa02738f749
RDX: 0000000000000000 RSI: 0000000000000080 RDI: 00007fa0275e6098
RBP: 00007fa0275e6090 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fa0275e6128 R14: 00007fff14e4fcb0 R15: 00007fff14e4fd98There's really nothing wrong here, outside of processing these reads will take a LONG time. However, we can speed up the exit by checking the IO_WQ_BIT_EXIT inside the io_worker_handle_work() loop, as syzbot will exit the ring after queueing up all of these reads. Then once the first item is processed, io-wq will simply cancel the rest. That should avoid syzbot running into this complaint again.
--- io_uring/io-wq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/io-wq.c +1 -1
@@ -554,9 +554,9 @@ static void io_worker_handle_work(structstruct io_wqe_acct *acct =io_wqe_get_acct (worker);struct io_wqe *wqe = worker->wqe;struct io_wq *wq = wqe->wq; -bool do_kill =test_bit (IO_WQ_BIT_EXIT , &wq->state); do { + bool do_kill = test_bit(IO_WQ_BIT_EXIT, &wq->state); struct io_wq_work *work; get_next: /*
Greg Kroah-Hartman
maintainerPATCH 196/570 driver: iio: add missing checks on iio_infos callback access
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julien Stephan <[email protected]>
commit c4ec8dedca961db056ec85cb7ca8c9f7e2e92252 upstream.
Some callbacks from iio_info structure are accessed without any check, so if a driver doesn't implement them trying to access the corresponding sysfs entries produce a kernel oops such as:
[ 2203.527791] Unable to handle kernel NULL pointer dereference at virtual address 00000000 when execute [...] [ 2203.783416] Call trace: [ 2203.783429] iio_read_channel_info_avail from dev_attr_show+0x18/0x48 [ 2203.789807] dev_attr_show from sysfs_kf_seq_show+0x90/0x120 [ 2203.794181] sysfs_kf_seq_show from seq_read_iter+0xd0/0x4e4 [ 2203.798555] seq_read_iter from vfs_read+0x238/0x2a0 [ 2203.802236] vfs_read from ksys_read+0xa4/0xd4 [ 2203.805385] ksys_read from ret_fast_syscall+0x0/0x54 [ 2203.809135] Exception stack(0xe0badfa8 to 0xe0badff0) [ 2203.812880] dfa0: 00000003 b6f10f80 00000003 b6eab000 00020000 00000000 [ 2203.819746] dfc0: 00000003 b6f10f80 7ff00000 00000003 00000003 00000000 00020000 00000000 [ 2203.826619] dfe0: b6e1bc88 bed80958 b6e1bc94 b6e1bcb0 [ 2203.830363] Code: bad PC value [ 2203.832695] ---[ end trace 0000000000000000 ]---
--- drivers/iio/industrialio-core.c | 7 ++++++- drivers/iio/industrialio-event.c | 9 +++++++++ drivers/iio/inkern.c | 35 ++++++++++++++++++++++++----------- 3 files changed, 39 insertions(+), 12 deletions(-)
drivers/iio/industrialio-core.c +6 -1
@@ -776,9 +776,11 @@ static ssize_t iio_read_channel_info(strINDIO_MAX_RAW_ELEMENTS , vals, &val_len, this_attr->address); - else + else if (indio_dev->info->read_raw) ret = indio_dev->info->read_raw (indio_dev, this_attr->c, &vals[0 ], &vals[1 ], this_attr->address); + else + return -EINVAL;if (ret <0 )return ret;
@@ -860,6 +862,9 @@ static ssize_t iio_read_channel_info_avaint length;int type; +if (!indio_dev->info->read_avail) +return -EINVAL ; + ret = indio_dev->info->read_avail (indio_dev, this_attr->c, &vals, &type, &length, this_attr->address);
drivers/iio/industrialio-event.c +9 -0
@@ -277,6 +277,9 @@ static ssize_t iio_ev_state_store(structif (ret <0 )return ret; +if (!indio_dev->info->write_event_config) +return -EINVAL ; + ret = indio_dev->info->write_event_config (indio_dev, this_attr->c,iio_ev_attr_type (this_attr),iio_ev_attr_dir (this_attr), val);
@@ -292,6 +295,9 @@ static ssize_t iio_ev_state_show(structstruct iio_dev_attr *this_attr =to_iio_dev_attr (attr);int val; +if (!indio_dev->info->read_event_config) +return -EINVAL ; + val = indio_dev->info->read_event_config (indio_dev, this_attr->c,iio_ev_attr_type (this_attr),iio_ev_attr_dir (this_attr));
@@ -310,6 +316,9 @@ static ssize_t iio_ev_value_show(structint val, val2, val_arr[2 ];int ret; +if (!indio_dev->info->read_event_value) +return -EINVAL ; + ret = indio_dev->info->read_event_value(indio_dev, this_attr->c, iio_ev_attr_type(this_attr), iio_ev_attr_dir(this_attr), iio_ev_attr_info(this_attr),
drivers/iio/inkern.c +24 -11
@@ -517,6 +517,7 @@ EXPORT_SYMBOL_GPL(devm_iio_channel_get_astatic int iio_channel_read (struct iio_channel *chan,int *val,int *val2,enum iio_chan_info_enum info) { +const struct iio_info *iio_info = chan->indio_dev->info;int unused;int vals[INDIO_MAX_RAW_ELEMENTS ];int ret;
@@ -528,15 +529,19 @@ static int iio_channel_read(struct iio_cif (!iio_channel_has_info (chan->channel, info))return -EINVAL ; -if (chan->indio_dev->info->read_raw_multi) { - ret = chan->indio_dev->info->read_raw_multi (chan->indio_dev, - chan->channel,INDIO_MAX_RAW_ELEMENTS , - vals, &val_len, info); +if (iio_info->read_raw_multi) { + ret = iio_info->read_raw_multi (chan->indio_dev, + chan->channel, +INDIO_MAX_RAW_ELEMENTS , + vals, &val_len, info); *val = vals[0 ]; *val2 = vals[1 ]; - }else - ret = chan->indio_dev->info->read_raw (chan->indio_dev, - chan->channel, val, val2, info); + }else if (iio_info->read_raw) { + ret = iio_info->read_raw (chan->indio_dev, + chan->channel, val, val2, info); + }else { +return -EINVAL ; + }return ret; }
@@ -754,11 +759,15 @@ static int iio_channel_read_avail(struct const int **vals, int *type, int *length, enum iio_chan_info_enum info) { + const struct iio_info *iio_info = chan->indio_dev->info; +if (!iio_channel_has_available (chan->channel, info))return -EINVAL ; -return chan->indio_dev->info->read_avail (chan->indio_dev, chan->channel, - vals, type, length, info); +if (iio_info->read_avail) +return iio_info->read_avail (chan->indio_dev, chan->channel, + vals, type, length, info); +return -EINVAL ; } int iio_read_avail_channel_attribute(struct iio_channel *chan,
@@ -889,8 +898,12 @@ EXPORT_SYMBOL_GPL(iio_get_channel_type);static int iio_channel_write (struct iio_channel *chan,int val,int val2,enum iio_chan_info_enum info) { -return chan->indio_dev->info->write_raw (chan->indio_dev, - chan->channel, val, val2, info); +const struct iio_info *iio_info = chan->indio_dev->info; + +if (iio_info->write_raw) +return iio_info->write_raw (chan->indio_dev, + chan->channel, val, val2, info); +return -EINVAL ; } int iio_write_channel_attribute(struct iio_channel *chan, int val, int val2,
Greg Kroah-Hartman
maintainerPATCH 197/570 sunrpc: fix cache_request leak in cache_release
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
commit 17ad31b3a43b72aec3a3d83605891e1397d0d065 upstream.
When a reader's file descriptor is closed while in the middle of reading a cache_request (rp->offset != 0), cache_release() decrements the request's readers count but never checks whether it should free the request.
In cache_read(), when readers drops to 0 and CACHE_PENDING is clear, the cache_request is removed from the queue and freed along with its buffer and cache_head reference. cache_release() lacks this cleanup.
The only other path that frees requests with readers == 0 is cache_dequeue(), but it runs only when CACHE_PENDING transitions from set to clear. If that transition already happened while readers was still non-zero, cache_dequeue() will have skipped the request, and no subsequent call will clean it up.
Add the same cleanup logic from cache_read() to cache_release(): after decrementing readers, check if it reached 0 with CACHE_PENDING clear, and if so, dequeue and free the cache_request.
--- net/sunrpc/cache.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
net/sunrpc/cache.c +21 -5
@@ -1037,14 +1037,25 @@ static int cache_release(struct inode *istruct cache_reader *rp = filp->private_data;if (rp) { +struct cache_request *rq =NULL ; +spin_lock (&queue_lock);if (rp->offset) {struct cache_queue *cq; -for (cq= &rp->q; &cq->list != &cd->queue; - cq = list_entry(cq->list.next, struct cache_queue, list)) +for (cq = &rp->q; &cq->list != &cd->queue; + cq =list_entry (cq->list.next, + struct cache_queue, list))if (!cq->reader) { - container_of(cq, struct cache_request, q) - ->readers--; +struct cache_request *cr = +container_of (cq, + struct cache_request, q); + cr->readers--; +if (cr->readers ==0 && + !test_bit (CACHE_PENDING , + &cr->item->flags)) { +list_del (&cr->q.list); + rq = cr; + }break ; } rp->offset =0 ;
@@ -1052,9 +1063,14 @@ static int cache_release(struct inode *ilist_del (&rp->q.list);spin_unlock (&queue_lock); +if (rq) { +cache_put (rq->item, cd); +kfree (rq->buf); +kfree (rq); + } + filp->private_data =NULL ;kfree (rp); - }if (filp->f_mode &FMODE_WRITE ) {atomic_dec (&cd->writers);
Greg Kroah-Hartman
maintainerPATCH 198/570 nvdimm/bus: Fix potential use after free in asynchronous initialization
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ira Weiny <[email protected]>
commit a8aec14230322ed8f1e8042b6d656c1631d41163 upstream.
Dingisoul with KASAN reports a use after free if device_add() fails in nd_async_device_register().
Commit b6eae0f61db2 ("libnvdimm: Hold reference on parent while scheduling async init") correctly added a reference on the parent device to be held until asynchronous initialization was complete. However, if device_add() results in an allocation failure the ref count of the device drops to 0 prior to the parent pointer being accessed. Thus resulting in use after free.
The bug bot AI correctly identified the fix. Save a reference to the parent pointer to be used to drop the parent reference regardless of the outcome of device_add().
--- drivers/nvdimm/bus.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvdimm/bus.c +3 -2
@@ -492,14 +492,15 @@ EXPORT_SYMBOL_GPL(nd_synchronize);static void nd_async_device_register (void *d,async_cookie_t cookie) {struct device *dev = d; +struct device *parent = dev->parent;if (device_add (dev) !=0 ) {dev_err (dev,"%s: failed\n" , __func__);put_device (dev); }put_device (dev); -if (dev->parent) -put_device (dev->parent); +if (parent) +put_device (parent); }static void nd_async_device_unregister (void *d,async_cookie_t cookie)
Greg Kroah-Hartman
maintainerPATCH 199/570 NFC: nxp-nci: allow GPIOs to sleep
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Ray <[email protected]>
commit 55dc632ab2ac2889b15995a9eef56c753d48ebc7 upstream.
Allow the firmware and enable GPIOs to sleep.
This fixes a `WARN_ON' and allows the driver to operate GPIOs which are connected to I2C GPIO expanders.
-- >8 --
kernel: WARNING: CPU: 3 PID: 2636 at drivers/gpio/gpiolib.c:3880 gpiod_set_value+0x88/0x98 -- >8 --
--- drivers/nfc/nxp-nci/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nfc/nxp-nci/i2c.c +2 -2
@@ -47,8 +47,8 @@ static int nxp_nci_i2c_set_mode(void *ph {struct nxp_nci_i2c_phy *phy = (struct nxp_nci_i2c_phy *) phy_id; -gpiod_set_value (phy->gpiod_fw, (mode ==NXP_NCI_MODE_FW ) ?1 :0 ); -gpiod_set_value (phy->gpiod_en, (mode !=NXP_NCI_MODE_COLD ) ?1 :0 ); +gpiod_set_value_cansleep (phy->gpiod_fw, (mode ==NXP_NCI_MODE_FW ) ?1 :0 ); +gpiod_set_value_cansleep (phy->gpiod_en, (mode !=NXP_NCI_MODE_COLD ) ?1 :0 );usleep_range (10000 ,15000 );if (mode ==NXP_NCI_MODE_COLD )
Greg Kroah-Hartman
maintainerPATCH 200/570 net: macb: fix use-after-free access to PTP clock
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fedor Pchelkin <[email protected]>
commit 8da13e6d63c1a97f7302d342c89c4a56a55c7015 upstream.
PTP clock is registered on every opening of the interface and destroyed on every closing. However it may be accessed via get_ts_info ethtool call which is possible while the interface is just present in the kernel.
BUG: KASAN: use-after-free in ptp_clock_index+0x47/0x50 drivers/ptp/ptp_clock.c:426 Read of size 4 at addr ffff8880194345cc by task syz.0.6/948 CPU: 1 PID: 948 Comm: syz.0.6 Not tainted 6.1.164+ #109 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.1-0-g3208b098f51a-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x8d/0xba lib/dump_stack.c:106 print_address_description mm/kasan/report.c:316 [inline] print_report+0x17f/0x496 mm/kasan/report.c:420 kasan_report+0xd9/0x180 mm/kasan/report.c:524 ptp_clock_index+0x47/0x50 drivers/ptp/ptp_clock.c:426 gem_get_ts_info+0x138/0x1e0 drivers/net/ethernet/cadence/macb_main.c:3349 macb_get_ts_info+0x68/0xb0 drivers/net/ethernet/cadence/macb_main.c:3371 __ethtool_get_ts_info+0x17c/0x260 net/ethtool/common.c:558 ethtool_get_ts_info net/ethtool/ioctl.c:2367 [inline] __dev_ethtool net/ethtool/ioctl.c:3017 [inline] dev_ethtool+0x2b05/0x6290 net/ethtool/ioctl.c:3095 dev_ioctl+0x637/0x1070 net/core/dev_ioctl.c:510 sock_do_ioctl+0x20d/0x2c0 net/socket.c:1215 sock_ioctl+0x577/0x6d0 net/socket.c:1320 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:870 [inline] __se_sys_ioctl fs/ioctl.c:856 [inline] __x64_sys_ioctl+0x18c/0x210 fs/ioctl.c:856 do_syscall_x64 arch/x86/entry/common.c:46 [inline] do_syscall_64+0x35/0x80 arch/x86/entry/common.c:76 entry_SYSCALL_64_after_hwframe+0x6e/0xd8 </TASK> Allocated by task 457: kmalloc include/linux/slab.h:563 [inline] kzalloc include/linux/slab.h:699 [inline] ptp_clock_register+0x144/0x10e0 drivers/ptp/ptp_clock.c:235 gem_ptp_init+0x46f/0x930 drivers/net/ethernet/cadence/macb_ptp.c:375 macb_open+0x901/0xd10 drivers/net/ethernet/cadence/macb_main.c:2920 __dev_open+0x2ce/0x500 net/core/dev.c:1501 __dev_change_flags+0x56a/0x740 net/core/dev.c:8651 dev_change_flags+0x92/0x170 net/core/dev.c:8722 do_setlink+0xaf8/0x3a80 net/core/rtnetlink.c:2833 __rtnl_newlink+0xbf4/0x1940 net/core/rtnetlink.c:3608 rtnl_newlink+0x63/0xa0 net/core/rtnetlink.c:3655 rtnetlink_rcv_msg+0x3c6/0xed0 net/core/rtnetlink.c:6150 netlink_rcv_skb+0x15d/0x430 net/netlink/af_netlink.c:2511 netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline] netlink_unicast+0x6d7/0xa30 net/netlink/af_netlink.c:1344 netlink_sendmsg+0x97e/0xeb0 net/netlink/af_netlink.c:1872 sock_sendmsg_nosec net/socket.c:718 [inline] __sock_sendmsg+0x14b/0x180 net/socket.c:730 __sys_sendto+0x320/0x3b0 net/socket.c:2152 __do_sys_sendto net/socket.c:2164 [inline] __se_sys_sendto net/socket.c:2160 [inline] __x64_sys_sendto+0xdc/0x1b0 net/socket.c:2160 do_syscall_x64 arch/x86/entry/common.c:46 [inline] do_syscall_64+0x35/0x80 arch/x86/entry/common.c:76 entry_SYSCALL_64_after_hwframe+0x6e/0xd8 Freed by task 938: kasan_slab_free include/linux/kasan.h:177 [inline] slab_free_hook mm/slub.c:1729 [inline] slab_free_freelist_hook mm/slub.c:1755 [inline] slab_free mm/slub.c:3687 [inline] __kmem_cache_free+0xbc/0x320 mm/slub.c:3700 device_release+0xa0/0x240 drivers/base/core.c:2507 kobject_cleanup lib/kobject.c:681 [inline] kobject_release lib/kobject.c:712 [inline] kref_put include/linux/kref.h:65 [inline] kobject_put+0x1cd/0x350 lib/kobject.c:729 put_device+0x1b/0x30 drivers/base/core.c:3805 ptp_clock_unregister+0x171/0x270 drivers/ptp/ptp_clock.c:391 gem_ptp_remove+0x4e/0x1f0 drivers/net/ethernet/cadence/macb_ptp.c:404 macb_close+0x1c8/0x270 drivers/net/ethernet/cadence/macb_main.c:2966 __dev_close_many+0x1b9/0x310 net/core/dev.c:1585 __dev_close net/core/dev.c:1597 [inline] __dev_change_flags+0x2bb/0x740 net/core/dev.c:8649 dev_change_flags+0x92/0x170 net/core/dev.c:8722 dev_ifsioc+0x151/0xe00 net/core/dev_ioctl.c:326 dev_ioctl+0x33e/0x1070 net/core/dev_ioctl.c:572 sock_do_ioctl+0x20d/0x2c0 net/socket.c:1215 sock_ioctl+0x577/0x6d0 net/socket.c:1320 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:870 [inline] __se_sys_ioctl fs/ioctl.c:856 [inline] __x64_sys_ioctl+0x18c/0x210 fs/ioctl.c:856 do_syscall_x64 arch/x86/entry/common.c:46 [inline] do_syscall_64+0x35/0x80 arch/x86/entry/common.c:76 entry_SYSCALL_64_after_hwframe+0x6e/0xd8
Set the PTP clock pointer to NULL after unregistering.
--- drivers/net/ethernet/cadence/macb_ptp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_ptp.c +3 -1
@@ -395,8 +395,10 @@ void gem_ptp_remove(struct net_device *n {struct macb *bp =netdev_priv (ndev); -if (bp->ptp_clock) +if (bp->ptp_clock) {ptp_clock_unregister (bp->ptp_clock); + bp->ptp_clock =NULL ; + }gem_ptp_clear_timer (bp);
Greg Kroah-Hartman
maintainerPATCH 201/570 Bluetooth: L2CAP: Fix type confusion in l2cap_ecred_reconf_rsp()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Johannes Möller <[email protected]>
commit 15145675690cab2de1056e7ed68e59cbd0452529 upstream.
l2cap_ecred_reconf_rsp() casts the incoming data to struct l2cap_ecred_conn_rsp (the ECRED *connection* response, 8 bytes with result at offset 6) instead of struct l2cap_ecred_reconf_rsp (2 bytes with result at offset 0).
This causes two problems:
- The sizeof(*rsp) length check requires 8 bytes instead of the correct 2, so valid L2CAP_ECRED_RECONF_RSP packets are rejected with -EPROTO.
- rsp->result reads from offset 6 instead of offset 0, returning wrong data when the packet is large enough to pass the check.
Fix by using the correct type. Also pass the already byte-swapped result variable to BT_DBG instead of the raw __le16 field.
--- net/bluetooth/l2cap_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/bluetooth/l2cap_core.c +2 -2
@@ -6397,7 +6397,7 @@ static inline int l2cap_ecred_reconf_rsp u8 *data) {struct l2cap_chan *chan, *tmp; -struct l2cap_ecred_conn_rsp *rsp = (void *) data; +struct l2cap_ecred_reconf_rsp *rsp = (void *)data;u16 result;if (cmd_len <sizeof (*rsp))
@@ -6405,7 +6405,7 @@ static inline int l2cap_ecred_reconf_rsp result =__le16_to_cpu (rsp->result); -BT_DBG ("result 0x%4.4x" , rsp->result); +BT_DBG ("result 0x%4.4x" , result);if (!result)return 0 ;
Greg Kroah-Hartman
maintainerPATCH 202/570 Bluetooth: L2CAP: Validate L2CAP_INFO_RSP payload length before access
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Johannes Möller <[email protected]>
commit dd815e6e3918dc75a49aaabac36e4f024d675101 upstream.
l2cap_information_rsp() checks that cmd_len covers the fixed l2cap_info_rsp header (type + result, 4 bytes) but then reads rsp->data without verifying that the payload is present:
- L2CAP_IT_FEAT_MASK calls get_unaligned_le32(rsp->data), which reads 4 bytes past the header (needs cmd_len >= 8).
- L2CAP_IT_FIXED_CHAN reads rsp->data[0], 1 byte past the header (needs cmd_len >= 5).
A truncated L2CAP_INFO_RSP with result == L2CAP_IR_SUCCESS triggers an out-of-bounds read of adjacent skb data.
Guard each data access with the required payload length check. If the payload is too short, skip the read and let the state machine complete with safe defaults (feat_mask and remote_fixed_chan remain zero from kzalloc), so the info timer cleanup and l2cap_conn_start() still run and the connection is not stalled.
--- net/bluetooth/l2cap_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/bluetooth/l2cap_core.c +4 -2
@@ -4837,7 +4837,8 @@ static inline int l2cap_information_rsp(switch (type) {case L2CAP_IT_FEAT_MASK : - conn->feat_mask =get_unaligned_le32 (rsp->data); +if (cmd_len >=sizeof (*rsp) +sizeof (u32)) + conn->feat_mask =get_unaligned_le32 (rsp->data);if (conn->feat_mask &L2CAP_FEAT_FIXED_CHAN ) {struct l2cap_info_req req;
@@ -4856,7 +4857,8 @@ static inline int l2cap_information_rsp(break ;case L2CAP_IT_FIXED_CHAN : - conn->remote_fixed_chan = rsp->data[0 ]; +if (cmd_len >=sizeof (*rsp) +sizeof (rsp->data[0 ])) + conn->remote_fixed_chan = rsp->data[0 ]; conn->info_state |=L2CAP_INFO_FEAT_MASK_REQ_DONE ; conn->info_ident =0 ;
Greg Kroah-Hartman
maintainerPATCH 203/570 mmc: sdhci-pci-gli: fix GL9750 DMA write corruption
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Schwartz <[email protected]>
commit 2b76e0cc7803e5ab561c875edaba7f6bbd87fbb0 upstream.
The GL9750 SD host controller has intermittent data corruption during DMA write operations. The GM_BURST register's R_OSRC_Lmt field (bits 17:16), which limits outstanding DMA read requests from system memory, is not being cleared during initialization. The Windows driver sets R_OSRC_Lmt to zero, limiting requests to the smallest unit.
Clear R_OSRC_Lmt to match the Windows driver behavior. This eliminates write corruption verified with f3write/f3read tests while maintaining DMA performance.
--- drivers/mmc/host/sdhci-pci-gli.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/mmc/host/sdhci-pci-gli.c +9 -0
@@ -70,6 +70,9 @@#define GLI_9750_MISC_RX_INV_VALUE GLI_9750_MISC_RX_INV_OFF#define GLI_9750_MISC_TX1_DLY_VALUE 0x5 +#define SDHCI_GLI_9750_GM_BURST_SIZE 0x510 +#define SDHCI_GLI_9750_GM_BURST_SIZE_R_OSRC_LMT GENMASK(17, 16) +#define SDHCI_GLI_9750_TUNING_CONTROL 0x540#define SDHCI_GLI_9750_TUNING_CONTROL_EN BIT(4)#define GLI_9750_TUNING_CONTROL_EN_ON 0x1
@@ -188,10 +191,16 @@ static void gli_set_9750(struct sdhci_hou32 misc_value;u32 parameter_value;u32 control_value; +u32 burst_value;u16 ctrl2;gl9750_wt_on (host); +/* clear R_OSRC_Lmt to avoid DMA write corruption */ + burst_value =sdhci_readl (host,SDHCI_GLI_9750_GM_BURST_SIZE ); + burst_value &= ~SDHCI_GLI_9750_GM_BURST_SIZE_R_OSRC_LMT ; +sdhci_writel (host, burst_value,SDHCI_GLI_9750_GM_BURST_SIZE ); + driving_value =sdhci_readl (host,SDHCI_GLI_9750_DRIVING ); pll_value =sdhci_readl (host,SDHCI_GLI_9750_PLL ); sw_ctrl_value =sdhci_readl (host,SDHCI_GLI_9750_SW_CTRL );
Greg Kroah-Hartman
maintainerPATCH 204/570 mmc: sdhci: fix timing selection for 1-bit bus width
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luke Wang <[email protected]>
commit 5e3486e64094c28a526543f1e8aa0d5964b7f02d upstream.
When 1-bit bus width is used with HS200/HS400 capabilities set, mmc_select_hs200() returns 0 without actually switching. This causes mmc_select_timing() to skip mmc_select_hs(), leaving eMMC in legacy mode (26MHz) instead of High Speed SDR (52MHz).
Per JEDEC eMMC spec section 5.3.2, 1-bit mode supports High Speed SDR. Drop incompatible HS200/HS400/UHS/DDR caps early so timing selection falls through to mmc_select_hs() correctly.
--- drivers/mmc/host/sdhci.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +8 -1
@@ -4454,8 +4454,15 @@ int sdhci_setup_host(struct sdhci_host ** their platform code before calling sdhci_add_host(), and we * won't assume 8-bit width for hosts without that CAP. */ -if (!(host->quirks &SDHCI_QUIRK_FORCE_1_BIT_DATA )) +if (host->quirks &SDHCI_QUIRK_FORCE_1_BIT_DATA ) { + host->caps1 &= ~(SDHCI_SUPPORT_SDR104 |SDHCI_SUPPORT_SDR50 |SDHCI_SUPPORT_DDR50 ); +if (host->quirks2 &SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 ) + host->caps1 &= ~SDHCI_SUPPORT_HS400 ; + mmc->caps2 &= ~(MMC_CAP2_HS200 |MMC_CAP2_HS400 |MMC_CAP2_HS400_ES ); + mmc->caps &= ~(MMC_CAP_DDR |MMC_CAP_UHS ); + }else { mmc->caps |=MMC_CAP_4_BIT_DATA ; + }if (host->quirks2 &SDHCI_QUIRK2_HOST_NO_CMD23 ) mmc->caps &= ~MMC_CAP_CMD23 ;
Greg Kroah-Hartman
maintainerPATCH 205/570 mtd: rawnand: pl353: make sure optimal timings are applied
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Olivier Sobrie <[email protected]>
commit b9465b04de4b90228de03db9a1e0d56b00814366 upstream.
Timings of the nand are adjusted by pl35x_nfc_setup_interface() but actually applied by the pl35x_nand_select_target() function. If there is only one nand chip, the pl35x_nand_select_target() will only apply the timings once since the test at its beginning will always be true after the first call to this function. As a result, the hardware will keep using the default timings set at boot to detect the nand chip, not the optimal ones.
With this patch, we program directly the new timings when pl35x_nfc_setup_interface() is called.
--- drivers/mtd/nand/raw/pl35x-nand-controller.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mtd/nand/raw/pl35x-nand-controller.c +3 -0
@@ -864,6 +864,9 @@ static int pl35x_nfc_setup_interface(strPL35X_SMC_NAND_TAR_CYCLES (tmgs.t_ar) |PL35X_SMC_NAND_TRR_CYCLES (tmgs.t_rr); +writel (plnand->timings, nfc->conf_regs +PL35X_SMC_CYCLES ); +pl35x_smc_update_regs (nfc); +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 206/570 mtd: rawnand: cadence: Fix error check for dma_alloc_coherent() in cadence_nand_init()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Ni <[email protected]>
commit 0410e1a4c545c769c59c6eda897ad5d574d0c865 upstream.
Fix wrong variable used for error checking after dma_alloc_coherent() call. The function checks cdns_ctrl->dma_cdma_desc instead of cdns_ctrl->cdma_desc, which could lead to incorrect error handling.
--- drivers/mtd/nand/raw/cadence-nand-controller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/cadence-nand-controller.c +1 -1
@@ -2840,7 +2840,7 @@ static int cadence_nand_init(struct cdnssizeof (*cdns_ctrl->cdma_desc), &cdns_ctrl->dma_cdma_desc, GFP_KERNEL); -if (!cdns_ctrl->dma_cdma_desc) +if (!cdns_ctrl->cdma_desc)return -ENOMEM ; cdns_ctrl->buf_size =SZ_16K ;
Greg Kroah-Hartman
maintainerPATCH 207/570 mtd: Avoid boot crash in RedBoot partition table parser
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Finn Thain <[email protected]>
commit 8e2f8020270af7777d49c2e7132260983e4fc566 upstream.
Given CONFIG_FORTIFY_SOURCE=y and a recent compiler,
commit 439a1bcac648 ("fortify: Use __builtin_dynamic_object_size() when available") produces the warning below and an oops.
Searching for RedBoot partition table in 50000000.flash at offset 0x7e0000
------------[ cut here ]------------
WARNING: lib/string_helpers.c:1035 at 0xc029e04c, CPU#0: swapper/0/1
memcmp: detected buffer overflow: 15 byte read of buffer size 14
Modules linked in:
CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.19.0 #1 NONEAs Kees said, "'names' is pointing to the final 'namelen' many bytes of the allocation ... 'namelen' could be basically any length at all. This fortify warning looks legit to me -- this code used to be reading beyond the end of the allocation."
Since the size of the dynamic allocation is calculated with strlen() we can use strcmp() instead of memcmp() and remain within bounds.
--- drivers/mtd/parsers/redboot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mtd/parsers/redboot.c +3 -3
@@ -270,9 +270,9 @@ nogood:strcpy (names, fl->img->name);#ifdef CONFIG_MTD_REDBOOT_PARTS_READONLY -if (!memcmp (names,"RedBoot" ,8 ) || - !memcmp (names,"RedBoot config" ,15 ) || - !memcmp (names,"FIS directory" ,14 )) { +if (!strcmp (names,"RedBoot" ) || + !strcmp (names,"RedBoot config" ) || + !strcmp (names,"FIS directory" )) { parts[i].mask_flags =MTD_WRITEABLE ; }#endif
Greg Kroah-Hartman
maintainerPATCH 208/570 iommu/vt-d: Fix intel iommu iotlb sync hardlockup and retry
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guanghui Feng <[email protected]>
commit fe89277c9ceb0d6af0aa665bcf24a41d8b1b79cd upstream.
During the qi_check_fault process after an IOMMU ITE event, requests at odd-numbered positions in the queue are set to QI_ABORT, only satisfying single-request submissions. However, qi_submit_sync now supports multiple simultaneous submissions, and can't guarantee that the wait_desc will be at an odd-numbered position. Therefore, if an item times out, IOMMU can't re-initiate the request, resulting in an infinite polling wait.
This modifies the process by setting the status of all requests already fetched by IOMMU and recorded as QI_IN_USE status (including wait_desc requests) to QI_ABORT, thus enabling multiple requests to be resubmitted.
--- drivers/iommu/intel/dmar.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iommu/intel/dmar.c +1 -2
@@ -1305,7 +1305,6 @@ static int qi_check_fault(struct intel_iif (fault &DMA_FSTS_ITE ) { head =readl (iommu->reg +DMAR_IQH_REG ); head = ((head >> shift) -1 +QI_LENGTH ) %QI_LENGTH ; - head |=1 ; tail =readl (iommu->reg +DMAR_IQT_REG ); tail = ((tail >> shift) -1 +QI_LENGTH ) %QI_LENGTH ;
@@ -1315,7 +1314,7 @@ static int qi_check_fault(struct intel_ido {if (qi->desc_status[head] ==QI_IN_USE ) qi->desc_status[head] =QI_ABORT ; - head = (head -2 +QI_LENGTH ) %QI_LENGTH ; + head = (head -1 +QI_LENGTH ) %QI_LENGTH ; }while (head != tail);if (qi->desc_status[wait_index] ==QI_ABORT )
Greg Kroah-Hartman
maintainerPATCH 209/570 serial: 8250_pci: add support for the AX99100
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Roukala (né Peres) <[email protected]>
commit 9c0072bc33d349c83d223e64be30794e11938a6b upstream.
This is found in popular brands such as StarTech.com or Delock, and has been a source of frustration to quite a few people, if I can trust Amazon comments complaining about Linux support via the official out-of-the-tree driver.
--- drivers/tty/serial/8250/8250_pci.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/tty/serial/8250/8250_pci.c +17 -0
@@ -58,6 +58,8 @@ struct serial_private { };#define PCI_DEVICE_ID_HPE_PCI_SERIAL 0x37e +#define PCIE_VENDOR_ID_ASIX 0x125B +#define PCIE_DEVICE_ID_AX99100 0x9100static const struct pci_device_id pci_use_msi[] = { { PCI_DEVICE_SUB(PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9900,
@@ -70,6 +72,8 @@ static const struct pci_device_id pci_us 0xA000, 0x1000) }, {PCI_DEVICE_SUB (PCI_VENDOR_ID_HP_3PAR ,PCI_DEVICE_ID_HPE_PCI_SERIAL , PCI_ANY_ID, PCI_ANY_ID) }, + { PCI_DEVICE_SUB(PCIE_VENDOR_ID_ASIX, PCIE_DEVICE_ID_AX99100, + 0xA000, 0x1000) }, { } };
@@ -854,6 +858,7 @@ static int pci_netmos_init(struct pci_decase PCI_DEVICE_ID_NETMOS_9912 :case PCI_DEVICE_ID_NETMOS_9922 :case PCI_DEVICE_ID_NETMOS_9900 : +case PCIE_DEVICE_ID_AX99100 : num_serial =pci_netmos_9900_numports (dev);break ;
@@ -2688,6 +2693,14 @@ static struct pci_serial_quirk pci_seria .init = pci_netmos_init, .setup = pci_netmos_9900_setup, }, + { + .vendor = PCIE_VENDOR_ID_ASIX, + .device = PCI_ANY_ID, + .subvendor = PCI_ANY_ID, + .subdevice = PCI_ANY_ID, + .init = pci_netmos_init, + .setup = pci_netmos_9900_setup, + },/* * EndRun Technologies */
@@ -6369,6 +6382,10 @@ static const struct pci_device_id serial0xA000 ,0x3002 , 0, 0, pbn_NETMOS9900_2s_115200 }, + { PCIE_VENDOR_ID_ASIX, PCIE_DEVICE_ID_AX99100, +0xA000 ,0x1000 , + 0, 0, pbn_b0_1_115200 }, +/* * Best Connectivity and Rosewill PCI Multi I/O cards */
Greg Kroah-Hartman
maintainerPATCH 210/570 serial: 8250: Fix TX deadlock when using DMA
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raul E Rangel <[email protected]>
commit a424a34b8faddf97b5af41689087e7a230f79ba7 upstream.
dmaengine_terminate_async does not guarantee that the __dma_tx_complete callback will run. The callback is currently the only place where dma->tx_running gets cleared. If the transaction is canceled and the callback never runs, then dma->tx_running will never get cleared and we will never schedule new TX DMA transactions again.
This change makes it so we clear dma->tx_running after we terminate the DMA transaction. This is "safe" because serial8250_tx_dma_flush is holding the UART port lock. The first thing the callback does is also grab the UART port lock, so access to dma->tx_running is serialized.
--- drivers/tty/serial/8250/8250_dma.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/tty/serial/8250/8250_dma.c +15 -0
@@ -150,7 +150,22 @@ void serial8250_tx_dma_flush(struct uart*/ dma->tx_size =0 ; +/* +* We can't use `dmaengine_terminate_sync` because `uart_flush_buffer` is +* holding the uart port spinlock. +*/ dmaengine_terminate_async (dma->txchan); + +/* +* The callback might or might not run. If it doesn't run, we need to ensure +* that `tx_running` is cleared so that we can schedule new transactions. +* If it does run, then the zombie callback will clear `tx_running` again +* and perform a no-op since `tx_size` was cleared above. +* +* In either case, we ASSUME the DMA transaction will terminate before we +* issue a new `serial8250_tx_dma`. +*/ + dma->tx_running =0 ; }int serial8250_rx_dma (struct uart_8250_port *p)
Greg Kroah-Hartman
maintainerPATCH 211/570 serial: 8250: Add late synchronize_irq() to shutdown to handle DW UART BUSY
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilpo Järvinen <[email protected]>
commit e0a368ae79531ff92105a2692f10d83052055856 upstream.
When DW UART is !uart_16550_compatible, it can indicate BUSY at any point (when under constant Rx pressure) unless a complex sequence of steps is performed. Any LCR write can run a foul with the condition that prevents writing LCR while the UART is BUSY, which triggers BUSY_DETECT interrupt that seems unmaskable using IER bits.
Normal flow is that dw8250_handle_irq() handles BUSY_DETECT condition by reading USR register. This BUSY feature, however, breaks the assumptions made in serial8250_do_shutdown(), which runs synchronize_irq() after clearing IER and assumes no interrupts can occur after that point but then proceeds to update LCR, which on DW UART can trigger an interrupt.
If serial8250_do_shutdown() releases the interrupt handler before the handler has run and processed the BUSY_DETECT condition by read the USR register, the IRQ is not deasserted resulting in interrupt storm that triggers "irq x: nobody cared" warning leading to disabling the IRQ.
Add late synchronize_irq() into serial8250_do_shutdown() to ensure BUSY_DETECT from DW UART is handled before port's interrupt handler is released. Alternative would be to add DW UART specific shutdown function but it would mostly duplicate the generic code and the extra synchronize_irq() seems pretty harmless in serial8250_do_shutdown().
--- drivers/tty/serial/8250/8250_port.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/tty/serial/8250/8250_port.c +6 -0
@@ -2488,6 +2488,12 @@ void serial8250_do_shutdown(struct uart_* the IRQ chain. */ serial_port_in (port,UART_RX ); +/* +* LCR writes on DW UART can trigger late (unmaskable) IRQs. +* Handle them before releasing the handler. +*/ +synchronize_irq (port->irq); +serial8250_rpm_put (up); up->ops->release_irq (up);
Greg Kroah-Hartman
maintainerPATCH 212/570 serial: uartlite: fix PM runtime usage count underflow on probe
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Andrzejewski ICEYE <[email protected]>
commit d54801cd509515f674a5aac1d3ea1401d2a05863 upstream.
ulite_probe() calls pm_runtime_put_autosuspend() at the end of probe without holding a corresponding PM runtime reference for non-console ports.
During ulite_assign(), uart_add_one_port() triggers uart_configure_port() which calls ulite_pm() via uart_change_pm(). For non-console ports, the UART core performs a balanced get/put cycle:
uart_change_pm(ON) -> ulite_pm() -> pm_runtime_get_sync() +1
uart_change_pm(OFF) -> ulite_pm() -> pm_runtime_put_autosuspend() -1
This leaves no spare reference for the pm_runtime_put_autosuspend() at the end of probe. The PM runtime core prevents the count from actually going below zero, and instead triggers a
"Runtime PM usage count underflow!" warning.
For console ports the bug is masked: the UART core skips the uart_change_pm(OFF) call, so the UART core's unbalanced get happens to pair with probe's trailing put.
Add pm_runtime_get_noresume() before pm_runtime_enable() to take an explicit probe-owned reference that the trailing pm_runtime_put_autosuspend() can release. This ensures a correct usage count regardless of whether the port is a console.
--- drivers/tty/serial/uartlite.c | 1 + 1 file changed, 1 insertion(+)
drivers/tty/serial/uartlite.c +1 -0
@@ -806,6 +806,7 @@ static int ulite_probe(struct platform_dpm_runtime_use_autosuspend (&pdev->dev);pm_runtime_set_autosuspend_delay (&pdev->dev,UART_AUTOSUSPEND_TIMEOUT );pm_runtime_set_active (&pdev->dev); +pm_runtime_get_noresume (&pdev->dev);pm_runtime_enable (&pdev->dev); ret =ulite_assign (&pdev->dev, id, res->start, irq, pdata);
Greg Kroah-Hartman
maintainerPATCH 213/570 drm/radeon: apply state adjust rules to some additional HAINAN vairants
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
commit 86650ee2241ff84207eaa298ab318533f3c21a38 upstream.
They need a similar workaround.
--- drivers/gpu/drm/radeon/si_dpm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/si_dpm.c +3 -1
@@ -2959,9 +2959,11 @@ static void si_apply_state_adjust_rules(if (rdev->family ==CHIP_HAINAN ) {if ((rdev->pdev->revision ==0x81 ) || (rdev->pdev->revision ==0xC3 ) || + (rdev->pdev->device ==0x6660 ) || (rdev->pdev->device ==0x6664 ) || (rdev->pdev->device ==0x6665 ) || - (rdev->pdev->device ==0x6667 )) { + (rdev->pdev->device ==0x6667 ) || + (rdev->pdev->device ==0x666F )) { max_sclk =75000 ; } if ((rdev->pdev->revision == 0xC3) ||
Greg Kroah-Hartman
maintainerPATCH 214/570 mm/hugetlb: make detecting shared pte more reliable
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miaohe Lin <[email protected]>
commit 3aa4ed8040e1535d95c03cef8b52cf11bf0d8546 upstream.
If the pagetables are shared, we shouldn't copy or take references. Since src could have unshared and dst shares with another vma, huge_pte_none() is thus used to determine whether dst_pte is shared. But this check isn't reliable. A shared pte could have pte none in pagetable in fact. The page count of ptep page should be checked here in order to reliably determine whether pte is shared.
--- mm/hugetlb.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
mm/hugetlb.c +8 -13
@@ -4304,7 +4304,7 @@ hugetlb_install_page(struct vm_area_struint copy_hugetlb_page_range (struct mm_struct *dst,struct mm_struct *src,struct vm_area_struct *vma) { -pte_t *src_pte, *dst_pte, entry, dst_entry; +pte_t *src_pte, *dst_pte, entry;struct page *ptepage;unsigned long addr;bool cow =is_cow_mapping (vma->vm_flags);
@@ -4343,28 +4343,23 @@ int copy_hugetlb_page_range(struct mm_st/* * If the pagetables are shared don't copy or take references. -* dst_pte == src_pte is the common case of src/dest sharing. * +* dst_pte == src_pte is the common case of src/dest sharing. * However, src could have 'unshared' and dst shares with -* another vma. If dst_pte !none, this implies sharing. -* Check here before taking page table lock, and once again -* after taking the lock below. +* another vma. So page_count of ptep page is checked instead +* to reliably determine whether pte is shared. */ - dst_entry =huge_ptep_get (dst_pte); -if ((dst_pte == src_pte) || !huge_pte_none (dst_entry)) +if (page_count (virt_to_page (dst_pte)) >1 )continue ; dst_ptl =huge_pte_lock (h, dst, dst_pte); src_ptl =huge_pte_lockptr (h, src, src_pte);spin_lock_nested (src_ptl,SINGLE_DEPTH_NESTING ); entry =huge_ptep_get (src_pte); - dst_entry =huge_ptep_get (dst_pte); again: -if (huge_pte_none (entry) || !huge_pte_none (dst_entry)) { +if (huge_pte_none (entry)) {/* -* Skip if src entry none. Also, skip in the -* unlikely case dst entry !none as this implies -* sharing with another vma. +* Skip if src entry none. */ ; } else if (unlikely(is_hugetlb_entry_migration(entry) ||
@@ -4423,7 +4418,7 @@ again:restore_reserve_on_error (h, vma, addr, new);put_page (new); -/* dst_entry won't change as in child */ +/* huge_ptep of dst_pte won't change as in child */ goto again; }hugetlb_install_page (vma, dst_pte, addr, new);
Greg Kroah-Hartman
maintainerPATCH 215/570 mm/hugetlb: fix copy_hugetlb_page_range() to use ->pt_share_count
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jane Chu <[email protected]>
commit 14967a9c7d247841b0312c48dcf8cd29e55a4cc8 upstream.
commit 59d9094df3d79 ("mm: hugetlb: independent PMD page table shared count") introduced ->pt_share_count dedicated to hugetlb PMD share count tracking, but omitted fixing copy_hugetlb_page_range(), leaving the function relying on page_count() for tracking that no longer works.
When lazy page table copy for hugetlb is disabled, that is, revert commit bcd51a3c679d ("hugetlb: lazy page table copies in fork()") fork()'ing with hugetlb PMD sharing quickly lockup -
[ 239.446559] watchdog: BUG: soft lockup - CPU#75 stuck for 27s! [ 239.446611] RIP: 0010:native_queued_spin_lock_slowpath+0x7e/0x2e0 [ 239.446631] Call Trace: [ 239.446633] <TASK> [ 239.446636] _raw_spin_lock+0x3f/0x60 [ 239.446639] copy_hugetlb_page_range+0x258/0xb50 [ 239.446645] copy_page_range+0x22b/0x2c0 [ 239.446651] dup_mmap+0x3e2/0x770 [ 239.446654] dup_mm.constprop.0+0x5e/0x230 [ 239.446657] copy_process+0xd17/0x1760 [ 239.446660] kernel_clone+0xc0/0x3e0 [ 239.446661] __do_sys_clone+0x65/0xa0 [ 239.446664] do_syscall_64+0x82/0x930 [ 239.446668] ? count_memcg_events+0xd2/0x190 [ 239.446671] ? syscall_trace_enter+0x14e/0x1f0 [ 239.446676] ? syscall_exit_work+0x118/0x150 [ 239.446677] ? arch_exit_to_user_mode_prepare.constprop.0+0x9/0xb0 [ 239.446681] ? clear_bhb_loop+0x30/0x80 [ 239.446684] ? clear_bhb_loop+0x30/0x80 [ 239.446686] entry_SYSCALL_64_after_hwframe+0x76/0x7e
There are two options to resolve the potential latent issue:
1. warn against PMD sharing in copy_hugetlb_page_range(),
2. fix it.
This patch opts for the second option.
While at it, simplify the comment, the details are not actually relevant anymore.
[ David: We don't have ptdesc and the wrappers, so work directly on the
page->pt_share_count. CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING is still called CONFIG_ARCH_WANT_HUGE_PMD_SHARE. ]
--- mm/hugetlb.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
mm/hugetlb.c +4 -9
@@ -4341,16 +4341,11 @@ int copy_hugetlb_page_range(struct mm_stbreak ; } -/* -* If the pagetables are shared don't copy or take references. -* -* dst_pte == src_pte is the common case of src/dest sharing. -* However, src could have 'unshared' and dst shares with -* another vma. So page_count of ptep page is checked instead -* to reliably determine whether pte is shared. -*/ -if (page_count (virt_to_page (dst_pte)) >1 ) +#ifdef CONFIG_ARCH_WANT_HUGE_PMD_SHARE +/* If the pagetables are shared, there is nothing to do */ +if (atomic_read (&virt_to_page (dst_pte)->pt_share_count))continue ; +#endif dst_ptl =huge_pte_lock (h, dst, dst_pte); src_ptl =huge_pte_lockptr (h, src, src_pte);
Greg Kroah-Hartman
maintainerPATCH 216/570 mm/hugetlb: fix hugetlb_pmd_shared()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Red Hat) <[email protected]>
commit ca1a47cd3f5f4c46ca188b1c9a27af87d1ab2216 upstream.
Patch series "mm/hugetlb: fixes for PMD table sharing (incl. using mmu_gather)", v3.
One functional fix, one performance regression fix, and two related comment fixes.
I cleaned up my prototype I recently shared [1] for the performance fix, deferring most of the cleanups I had in the prototype to a later point. While doing that I identified the other things.
The goal of this patch set is to be backported to stable trees "fairly" easily. At least patch #1 and #4.
Patch #1 fixes hugetlb_pmd_shared() not detecting any sharing Patch #2 + #3 are simple comment fixes that patch #4 interacts with. Patch #4 is a fix for the reported performance regression due to excessive IPI broadcasts during fork()+exit().
The last patch is all about TLB flushes, IPIs and mmu_gather.
Read: complicated
There are plenty of cleanups in the future to be had + one reasonable optimization on x86. But that's all out of scope for this series.
Runtime tested, with a focus on fixing the performance regression using the original reproducer [2] on x86.
This patch (of 4):
We switched from (wrongly) using the page count to an independent shared count. Now, shared page tables have a refcount of 1 (excluding speculative references) and instead use ptdesc->pt_share_count to identify sharing.
We didn't convert hugetlb_pmd_shared(), so right now, we would never detect a shared PMD table as such, because sharing/unsharing no longer touches the refcount of a PMD table.
Page migration, like mbind() or migrate_pages() would allow for migrating folios mapped into such shared PMD tables, even though the folios are not exclusive. In smaps we would account them as "private" although they are "shared", and we would be wrongly setting the PM_MMAP_EXCLUSIVE in the pagemap interface.
Fix it by properly using ptdesc_pmd_is_shared() in hugetlb_pmd_shared().
[ David: We don't have ptdesc and the wrappers, so work directly on
page->pt_share_count. ]
--- include/linux/hugetlb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/hugetlb.h +1 -1
@@ -1110,7 +1110,7 @@ static inline __init void hugetlb_cma_ch#ifdef CONFIG_ARCH_WANT_HUGE_PMD_SHARE static inline bool hugetlb_pmd_shared (pte_t *pte) { -return page_count (virt_to_page (pte)) >1 ; +return atomic_read (&virt_to_page (pte)->pt_share_count); }#else static inline bool hugetlb_pmd_shared (pte_t *pte)
Greg Kroah-Hartman
maintainerPATCH 217/570 mm/hugetlb: fix two comments related to huge_pmd_unshare()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Red Hat) <[email protected]>
commit 3937027caecb4f8251e82dd857ba1d749bb5a428 upstream.
Ever since we stopped using the page count to detect shared PMD page tables, these comments are outdated.
The only reason we have to flush the TLB early is because once we drop the i_mmap_rwsem, the previously shared page table could get freed (to then get reallocated and used for other purpose). So we really have to flush the TLB before that could happen.
So let's simplify the comments a bit.
The "If we unshared PMDs, the TLB flush was not recorded in mmu_gather." part introduced as in commit a4a118f2eead ("hugetlbfs: flush TLBs correctly after huge_pmd_unshare") was confusing: sure it is recorded in the mmu_gather, otherwise tlb_flush_mmu_tlbonly() wouldn't do anything. So let's drop that comment while at it as well.
We'll centralize these comments in a single helper as we rework the code next.
--- mm/hugetlb.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)
mm/hugetlb.c +8 -16
@@ -4552,17 +4552,10 @@ void __unmap_hugepage_range(struct mmu_gtlb_end_vma (tlb, vma);/* -* If we unshared PMDs, the TLB flush was not recorded in mmu_gather. We -* could defer the flush until now, since by holding i_mmap_rwsem we -* guaranteed that the last refernece would not be dropped. But we must -* do the flushing before we return, as otherwise i_mmap_rwsem will be -* dropped and the last reference to the shared PMDs page might be -* dropped as well. -* -* In theory we could defer the freeing of the PMD pages as well, but -* huge_pmd_unshare() relies on the exact page_count for the PMD page to -* detect sharing, so we cannot defer the release of the page either. -* Instead, do flush now. +* There is nothing protecting a previously-shared page table that we +* unshared through huge_pmd_unshare() from getting freed after we +* release i_mmap_rwsem, so flush the TLB now. If huge_pmd_unshare() +* succeeded, flush the range corresponding to the pud. */ if (force_flush)tlb_flush_mmu_tlbonly (tlb);
@@ -5708,11 +5701,10 @@ unsigned long hugetlb_change_protection(cond_resched (); }/* -* Must flush TLB before releasing i_mmap_rwsem: x86's huge_pmd_unshare -* may have cleared our pud entry and done put_page on the page table: -* once we release i_mmap_rwsem, another task can do the final put_page -* and that page table be reused and filled with junk. If we actually -* did unshare a page of pmds, flush the range corresponding to the pud. +* There is nothing protecting a previously-shared page table that we +* unshared through huge_pmd_unshare() from getting freed after we +* release i_mmap_rwsem, so flush the TLB now. If huge_pmd_unshare() +* succeeded, flush the range corresponding to the pud. */ if (shared_pmd)flush_hugetlb_tlb_range (vma, range.start, range.end);
Greg Kroah-Hartman
maintainerPATCH 218/570 mm/rmap: fix two comments related to huge_pmd_unshare()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Red Hat) <[email protected]>
commit a8682d500f691b6dfaa16ae1502d990aeb86e8be upstream.
PMD page table unsharing no longer touches the refcount of a PMD page table. Also, it is not about dropping the refcount of a "PMD page" but the "PMD page table".
Let's just simplify by saying that the PMD page table was unmapped, consequently also unmapping the folio that was mapped into this page.
This code should be deduplicated in the future.
[ David: We don't have 40549ba8f8e0 ("hugetlb: use new vma_lock
for pmd sharing synchronization") so there are some contextual differences. ]
--- mm/rmap.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
mm/rmap.c +4 -14
@@ -1489,13 +1489,8 @@ static bool try_to_unmap_one(struct page range.end);/* -* The ref count of the PMD page was dropped -* which is part of the way map counting -* is done for shared PMDs. Return 'true' -* here. When there is no other sharing, -* huge_pmd_unshare returns false and we will -* unmap the actual page and drop map count -* to zero. +* The PMD table was unmapped, +* consequently unmapping the folio. */ page_vma_mapped_walk_done (&pvmw);break ;
@@ -1808,13 +1803,8 @@ static bool try_to_migrate_one(struct pa range.end);/* -* The ref count of the PMD page was dropped -* which is part of the way map counting -* is done for shared PMDs. Return 'true' -* here. When there is no other sharing, -* huge_pmd_unshare returns false and we will -* unmap the actual page and drop map count -* to zero. +* The PMD table was unmapped, +* consequently unmapping the folio. */ page_vma_mapped_walk_done (&pvmw);break ;
Greg Kroah-Hartman
maintainerPATCH 219/570 mm/hugetlb: fix excessive IPI broadcasts when unsharing PMD tables using mmu_gather
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Red Hat) <[email protected]>
commit 8ce720d5bd91e9dc16db3604aa4b1bf76770a9a1 upstream.
As reported, ever since commit 1013af4f585f ("mm/hugetlb: fix huge_pmd_unshare() vs GUP-fast race") we can end up in some situations where we perform so many IPI broadcasts when unsharing hugetlb PMD page tables that it severely regresses some workloads.
In particular, when we fork()+exit(), or when we munmap() a large area backed by many shared PMD tables, we perform one IPI broadcast per unshared PMD table.
There are two optimizations to be had:
(1) When we process (unshare) multiple such PMD tables, such as during exit(), it is sufficient to send a single IPI broadcast (as long as we respect locking rules) instead of one per PMD table.
Locking prevents that any of these PMD tables could get reused before we drop the lock.
(2) When we are not the last sharer (> 2 users including us), there is no need to send the IPI broadcast. The shared PMD tables cannot become exclusive (fully unshared) before an IPI will be broadcasted by the last sharer.
Concurrent GUP-fast could walk into a PMD table just before we unshared it. It could then succeed in grabbing a page from the shared page table even after munmap() etc succeeded (and supressed an IPI). But there is not difference compared to GUP-fast just sleeping for a while after grabbing the page and re-enabling IRQs.
Most importantly, GUP-fast will never walk into page tables that are no-longer shared, because the last sharer will issue an IPI broadcast.
(if ever required, checking whether the PUD changed in GUP-fast
after grabbing the page like we do in the PTE case could handle this)
So let's rework PMD sharing TLB flushing + IPI sync to use the mmu_gather infrastructure so we can implement these optimizations and demystify the code at least a bit. Extend the mmu_gather infrastructure to be able to deal with our special hugetlb PMD table sharing implementation.
To make initialization of the mmu_gather easier when working on a single VMA (in particular, when dealing with hugetlb), provide tlb_gather_mmu_vma().
We'll consolidate the handling for (full) unsharing of PMD tables in tlb_unshare_pmd_ptdesc() and tlb_flush_unshared_tables(), and track in "struct mmu_gather" whether we had (full) unsharing of PMD tables.
Because locking is very special (concurrent unsharing+reuse must be prevented), we disallow deferring flushing to tlb_finish_mmu() and instead require an explicit earlier call to tlb_flush_unshared_tables().
Quoted 1 line
From hugetlb code, we call
huge_pmd_unshare_flush()where we make sure
that the expected lock protecting us from concurrent unsharing+reuse is still held.
Check with a VM_WARN_ON_ONCE() in tlb_finish_mmu() that tlb_flush_unshared_tables() was properly called earlier.
Document it all properly.
Notes about tlb_remove_table_sync_one() interaction with unsharing:
There are two fairly tricky things:
(1) tlb_remove_table_sync_one() is a NOP on architectures without CONFIG_MMU_GATHER_RCU_TABLE_FREE.
Here, the assumption is that the previous TLB flush would send an IPI to all relevant CPUs. Careful: some architectures like x86 only send IPIs to all relevant CPUs when tlb->freed_tables is set.
The relevant architectures should be selecting MMU_GATHER_RCU_TABLE_FREE, but x86 might not do that in stable kernels and it might have been problematic before this patch.
Also, the arch flushing behavior (independent of IPIs) is different when tlb->freed_tables is set. Do we have to enlighten them to also take care of tlb->unshared_tables? So far we didn't care, so hopefully we are fine. Of course, we could be setting tlb->freed_tables as well, but that might then unnecessarily flush too much, because the semantics of tlb->freed_tables are a bit fuzzy.
This patch changes nothing in this regard.
(2) tlb_remove_table_sync_one() is not a NOP on architectures with CONFIG_MMU_GATHER_RCU_TABLE_FREE that actually don't need a sync.
Take x86 as an example: in the common case (!pv, !X86_FEATURE_INVLPGB) we still issue IPIs during TLB flushes and don't actually need the second tlb_remove_table_sync_one().
This optimized can be implemented on top of this, by checking e.g., in tlb_remove_table_sync_one() whether we really need IPIs. But as described in (1), it really must honor tlb->freed_tables then to send IPIs to all relevant CPUs.
Notes on TLB flushing changes:
(1) Flushing for non-shared PMD tables
We're converting from flush_hugetlb_tlb_range() to tlb_remove_huge_tlb_entry(). Given that we properly initialize the MMU gather in tlb_gather_mmu_vma() to be hugetlb aware, similar to __unmap_hugepage_range(), that should be fine.
(2) Flushing for shared PMD tables
We're converting from various things (flush_hugetlb_tlb_range(), tlb_flush_pmd_range(), flush_tlb_range()) to tlb_flush_pmd_range().
tlb_flush_pmd_range() achieves the same that tlb_remove_huge_tlb_entry() would achieve in these scenarios. Note that tlb_remove_huge_tlb_entry() also calls __tlb_remove_tlb_entry(), however that is only implemented on powerpc, which does not support PMD table sharing.
Similar to (1), tlb_gather_mmu_vma() should make sure that TLB flushing keeps on working as expected.
Further, note that the ptdesc_pmd_pts_dec() in huge_pmd_share() is not a concern, as we are holding the i_mmap_lock the whole time, preventing concurrent unsharing. That ptdesc_pmd_pts_dec() usage will be removed separately as a cleanup later.
There are plenty more cleanups to be had, but they have to wait until this is fixed.
[ David: We don't have ptdesc and the wrappers, so work directly on
page->pt_share_count and pass "struct page" instead of "struct ptdesc". CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING is still called CONFIG_ARCH_WANT_HUGE_PMD_SHARE and is set even without CONFIG_HUGETLB_PAGE. We don't have 550a7d60bd5e ("mm, hugepages: add mremap() support for hugepage backed vma"), so move_hugetlb_page_tables() does not exist. We don't have 40549ba8f8e0 ("hugetlb: use new vma_lock for pmd sharing synchronization") so changes in mm/rmap.c looks quite different. We don't have 4ddb4d91b82f ("hugetlb: do not update address in huge_pmd_unshare"), so huge_pmd_unshare() still gets a pointer to an address. Some smaller contextual stuff. ]
--- include/asm-generic/tlb.h | 77 ++++++++++++++++++++++++++++++++- include/linux/hugetlb.h | 15 ++++-- include/linux/mm_types.h | 1 mm/hugetlb.c | 107 +++++++++++++++++++++++++++------------------- mm/mmu_gather.c | 33 ++++++++++++++ mm/rmap.c | 20 ++++++-- 6 files changed, 197 insertions(+), 56 deletions(-)
include/asm-generic/tlb.h +75 -2
@@ -46,7 +46,8 @@* * The mmu_gather API consists of: * -* - tlb_gather_mmu() / tlb_gather_mmu_fullmm() / tlb_finish_mmu() +* - tlb_gather_mmu() / tlb_gather_mmu_fullmm() / tlb_gather_mmu_vma() / +* tlb_finish_mmu() * * start and finish a mmu_gather *
@@ -293,6 +294,20 @@ struct mmu_gather { unsigned int vma_exec : 1; unsigned int vma_huge : 1; +/* +* Did we unshare (unmap) any shared page tables? For now only +* used for hugetlb PMD table sharing. +*/ + unsigned int unshared_tables : 1; + +/* +* Did we unshare any page tables such that they are now exclusive +* and could get reused+modified by the new owner? When setting this +* flag, "unshared_tables" will be set as well. For now only used +* for hugetlb PMD table sharing. +*/ + unsigned int fully_unshared_tables : 1; +unsigned int batch_count;#ifndef CONFIG_MMU_GATHER_NO_GATHER
@@ -329,6 +344,7 @@ static inline void __tlb_reset_range(str tlb->cleared_pmds =0 ; tlb->cleared_puds =0 ; tlb->cleared_p4ds =0 ; + tlb->unshared_tables =0 ;/* * Do not reset mmu_gather::vma_* fields here, we do not * call into tlb_start_vma() again to set them if there is an
@@ -424,7 +440,7 @@ static inline void tlb_flush_mmu_tlbonly* these bits. */ if (!(tlb->freed_tables || tlb->cleared_ptes || tlb->cleared_pmds || - tlb->cleared_puds || tlb->cleared_p4ds)) + tlb->cleared_puds || tlb->cleared_p4ds || tlb->unshared_tables))return ;tlb_flush (tlb);
@@ -662,6 +678,63 @@ static inline void tlb_flush_p4d_range(s } while (0)#endif +#if defined(CONFIG_ARCH_WANT_HUGE_PMD_SHARE ) && defined(CONFIG_HUGETLB_PAGE ) +static inline void tlb_unshare_pmd_ptdesc (struct mmu_gather *tlb,struct page *pt, +unsigned long addr) +{ +/* +* The caller must make sure that concurrent unsharing + exclusive +* reuse is impossible until tlb_flush_unshared_tables() was called. +*/ +VM_WARN_ON_ONCE (!atomic_read (&pt->pt_share_count)); +atomic_dec (&pt->pt_share_count); + +/* Clearing a PUD pointing at a PMD table with PMD leaves. */ +tlb_flush_pmd_range (tlb, addr &PUD_MASK ,PUD_SIZE ); + +/* +* If the page table is now exclusively owned, we fully unshared +* a page table. +*/ +if (!atomic_read (&pt->pt_share_count)) + tlb->fully_unshared_tables = true; + tlb->unshared_tables = true; +} + +static inline void tlb_flush_unshared_tables (struct mmu_gather *tlb) +{ +/* +* As soon as the caller drops locks to allow for reuse of +* previously-shared tables, these tables could get modified and +* even reused outside of hugetlb context, so we have to make sure that +* any page table walkers (incl. TLB, GUP-fast) are aware of that +* change. +* +* Even if we are not fully unsharing a PMD table, we must +* flush the TLB for the unsharer now. +*/ +if (tlb->unshared_tables) +tlb_flush_mmu_tlbonly (tlb); + +/* +* Similarly, we must make sure that concurrent GUP-fast will not +* walk previously-shared page tables that are getting modified+reused +* elsewhere. So broadcast an IPI to wait for any concurrent GUP-fast. +* +* We only perform this when we are the last sharer of a page table, +* as the IPI will reach all CPUs: any GUP-fast. +* +* Note that on configs where tlb_remove_table_sync_one() is a NOP, +* the expectation is that the tlb_flush_mmu_tlbonly() would have issued +* required IPIs already for us. +*/ +if (tlb->fully_unshared_tables) { +tlb_remove_table_sync_one (); + tlb->fully_unshared_tables = false; + } +} +#endif +#endif /* CONFIG_MMU */ #endif /* _ASM_GENERIC__TLB_H */
include/linux/hugetlb.h +10 -5
@@ -190,8 +190,9 @@ pte_t *huge_pte_alloc(struct mm_struct * unsigned long addr, unsigned long sz);pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr,unsigned long sz); -int huge_pmd_unshare (struct mm_struct *mm,struct vm_area_struct *vma, -unsigned long *addr,pte_t *ptep); +int huge_pmd_unshare (struct mmu_gather *tlb,struct vm_area_struct *vma, +unsigned long *addr,pte_t *ptep); +void huge_pmd_unshare_flush (struct mmu_gather *tlb,struct vm_area_struct *vma);void adjust_range_if_pmd_sharing_possible (struct vm_area_struct *vma,unsigned long *start,unsigned long *end); struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
@@ -232,13 +233,17 @@ static inline struct address_space *hugereturn NULL ; } -static inline int huge_pmd_unshare (struct mm_struct *mm, -struct vm_area_struct *vma, -unsigned long *addr,pte_t *ptep) +static inline int huge_pmd_unshare (struct mmu_gather *tlb, +struct vm_area_struct *vma,unsigned long *addr,pte_t *ptep) {return 0 ; } +static inline void huge_pmd_unshare_flush (struct mmu_gather *tlb, +struct vm_area_struct *vma) +{ +} +static inline void adjust_range_if_pmd_sharing_possible (struct vm_area_struct *vma,unsigned long *start,unsigned long *end)
include/linux/mm_types.h +1 -0
@@ -612,6 +612,7 @@ static inline cpumask_t *mm_cpumask(strustruct mmu_gather ;extern void tlb_gather_mmu (struct mmu_gather *tlb,struct mm_struct *mm);extern void tlb_gather_mmu_fullmm (struct mmu_gather *tlb,struct mm_struct *mm); +void tlb_gather_mmu_vma (struct mmu_gather *tlb,struct vm_area_struct *vma);extern void tlb_finish_mmu (struct mmu_gather *tlb);static inline void init_tlb_flush_pending (struct mm_struct *mm)
mm/hugetlb.c +63 -44
223 lines not on this page · raw message
mm/mmu_gather.c +33 -0
@@ -7,6 +7,7 @@#include <linux/rcupdate.h> #include <linux/smp.h> #include <linux/swap.h> +#include <linux/hugetlb.h> #include <asm/pgalloc.h> #include <asm/tlb.h>
@@ -267,6 +268,7 @@ static void __tlb_gather_mmu(struct mmu_ tlb->page_size =0 ;#endif + tlb->fully_unshared_tables =0 ;__tlb_reset_range (tlb);inc_tlb_flush_pending (tlb->mm); }
@@ -301,6 +303,31 @@ void tlb_gather_mmu_fullmm(struct mmu_ga }/** +* tlb_gather_mmu_vma - initialize an mmu_gather structure for operating on a +* single VMA +* @tlb: the mmu_gather structure to initialize +* @vma: the vm_area_struct +* +* Called to initialize an (on-stack) mmu_gather structure for operating on +* a single VMA. In contrast to tlb_gather_mmu(), calling this function will +* not require another call to tlb_start_vma(). In contrast to tlb_start_vma(), +* this function will *not* call flush_cache_range(). +* +* For hugetlb VMAs, this function will also initialize the mmu_gather +* page_size accordingly, not requiring a separate call to +* tlb_change_page_size(). +* +*/ +void tlb_gather_mmu_vma (struct mmu_gather *tlb,struct vm_area_struct *vma) +{ +tlb_gather_mmu (tlb, vma->vm_mm); +tlb_update_vma_flags (tlb, vma); +if (is_vm_hugetlb_page (vma)) +/* All entries have the same size. */ +tlb_change_page_size (tlb,huge_page_size (hstate_vma (vma))); +} + +/** * tlb_finish_mmu - finish an mmu_gather structure * @tlb: the mmu_gather structure to finish *
@@ -310,6 +337,12 @@ void tlb_gather_mmu_fullmm(struct mmu_gavoid tlb_finish_mmu (struct mmu_gather *tlb) {/* +* We expect an earlier huge_pmd_unshare_flush() call to sort this out, +* due to complicated locking requirements with page table unsharing. +*/ +VM_WARN_ON_ONCE (tlb->fully_unshared_tables); + +/* * If there are parallel threads are doing PTE changes on same range * under non-exclusive lock (e.g., mmap_lock read-side) but defer TLB * flush by batching, one thread may end up seeing inconsistent PTEs
mm/rmap.c +15 -5
@@ -74,7 +74,7 @@#include <linux/memremap.h> #include <linux/userfaultfd_k.h> -#include <asm/tlbflush.h> +#include <asm/tlb.h> #include <trace/events/tlb.h>
@@ -1469,13 +1469,16 @@ static bool try_to_unmap_one(struct page address = pvmw.address;if (PageHuge (page) && !PageAnon (page)) { +struct mmu_gather tlb; +/* * To call huge_pmd_unshare, i_mmap_rwsem must be * held in write mode. Caller needs to explicitly * do this outside rmap routines. */ VM_BUG_ON (!(flags &TTU_RMAP_LOCKED )); -if (huge_pmd_unshare (mm, vma, &address, pvmw.pte)) { +tlb_gather_mmu_vma (&tlb, vma); +if (huge_pmd_unshare (&tlb, vma, &address, pvmw.pte)) {/* * huge_pmd_unshare unmapped an entire PMD * page. There is no way of knowing exactly
@@ -1484,9 +1487,10 @@ static bool try_to_unmap_one(struct page* already adjusted above to cover this range. */ flush_cache_range (vma, range.start, range.end); -flush_tlb_range (vma, range.start, range.end); +huge_pmd_unshare_flush (&tlb, vma);mmu_notifier_invalidate_range (mm, range.start, range.end); +tlb_finish_mmu (&tlb);/* * The PMD table was unmapped,
@@ -1495,6 +1499,7 @@ static bool try_to_unmap_one(struct pagepage_vma_mapped_walk_done (&pvmw);break ; } +tlb_finish_mmu (&tlb); }/* Nuke the page table entry. */
@@ -1783,13 +1788,16 @@ static bool try_to_migrate_one(struct pa address = pvmw.address;if (PageHuge (page) && !PageAnon (page)) { +struct mmu_gather tlb; +/* * To call huge_pmd_unshare, i_mmap_rwsem must be * held in write mode. Caller needs to explicitly * do this outside rmap routines. */ VM_BUG_ON (!(flags &TTU_RMAP_LOCKED )); -if (huge_pmd_unshare (mm, vma, &address, pvmw.pte)) { +tlb_gather_mmu_vma (&tlb, vma); +if (huge_pmd_unshare (&tlb, vma, &address, pvmw.pte)) {/* * huge_pmd_unshare unmapped an entire PMD * page. There is no way of knowing exactly
@@ -1798,9 +1806,10 @@ static bool try_to_migrate_one(struct pa* already adjusted above to cover this range. */ flush_cache_range (vma, range.start, range.end); -flush_tlb_range (vma, range.start, range.end); +huge_pmd_unshare_flush (&tlb, vma);mmu_notifier_invalidate_range (mm, range.start, range.end); +tlb_finish_mmu (&tlb);/* * The PMD table was unmapped,
@@ -1809,6 +1818,7 @@ static bool try_to_migrate_one(struct papage_vma_mapped_walk_done (&pvmw);break ; } +tlb_finish_mmu (&tlb); }/* Nuke the page table entry. */
Greg Kroah-Hartman
maintainerPATCH 220/570 net: stmmac: dwmac-loongson: Set clk_csr_i to 100-150MHz
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Huacai Chen <[email protected]>
commit e1aa5ef892fb4fa9014a25e87b64b97347919d37 upstream.
Current clk_csr_i setting of Loongson STMMAC (including LS7A1000/2000 and LS2K1000/2000/3000) are copy & paste from other drivers. In fact, Loongson STMMAC use 125MHz clocks and need 62 freq division to within 2.5MHz, meeting most PHY MDC requirement. So fix by setting clk_csr_i to 100-150MHz, otherwise some PHYs may link fail.
--- drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -1
@@ -11,7 +11,7 @@static int loongson_default_data (struct plat_stmmacenet_data *plat) { - plat->clk_csr =2 ;/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */ + plat->clk_csr =1 ;/* clk_csr_i = 100-150MHz & MDC = clk_csr_i/62 */ plat->has_gmac =1 ; plat->force_sf_dma_mode =1 ;
Greg Kroah-Hartman
maintainerPATCH 221/570 net: Handle napi_schedule() calls from non-interrupt
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frederic Weisbecker <[email protected]>
commit 77e45145e3039a0fb212556ab3f8c87f54771757 upstream.
napi_schedule() is expected to be called either:
* From an interrupt, where raised softirqs are handled on IRQ exit
* From a softirq disabled section, where raised softirqs are handled on the next call to local_bh_enable().
* From a softirq handler, where raised softirqs are handled on the next round in do_softirq(), or further deferred to a dedicated kthread.
Other bare tasks context may end up ignoring the raised NET_RX vector until the next random softirq handling opportunity, which may not happen before a while if the CPU goes idle afterwards with the tick stopped.
Such "misuses" have been detected on several places thanks to messages of the kind:
"NOHZ tick-stop error: local softirq work is pending, handler #08!!!"
For example:
__raise_softirq_irqoff
__napi_schedule
rtl8152_runtime_resume.isra.0
rtl8152_resume
usb_resume_interface.isra.0
usb_resume_both
__rpm_callback
rpm_callback
rpm_resume
__pm_runtime_resume
usb_autoresume_device
usb_remote_wakeup
hub_event
process_one_work
worker_thread
kthread
ret_from_fork
ret_from_fork_asmAnd also:
* drivers/net/usb/r8152.c::rtl_work_func_t
* drivers/net/netdevsim/netdev.c::nsim_start_xmit
There is a long history of issues of this kind:
019edd01d174 ("ath10k: sdio: Add missing BH locking around napi_schdule()")
330068589389 ("idpf: disable local BH when scheduling napi for marker packets")
e3d5d70cb483 ("net: lan78xx: fix "softirq work is pending" error")
e55c27ed9ccf ("mt76: mt7615: add missing bh-disable around rx napi schedule")
c0182aa98570 ("mt76: mt7915: add missing bh-disable around tx napi enable/schedule")
970be1dff26d ("mt76: disable BH around napi_schedule() calls")
019edd01d174 ("ath10k: sdio: Add missing BH locking around napi_schdule()")
30bfec4fec59 ("can: rx-offload: can_rx_offload_threaded_irq_finish(): add new function to be called from threaded interrupt")
e63052a5dd3c ("mlx5e: add add missing BH locking around napi_schdule()")
83a0c6e58901 ("i40e: Invoke softirqs after napi_reschedule")
bd4ce941c8d5 ("mlx4: Invoke softirqs after napi_reschedule")
8cf699ec849f ("mlx4: do not call napi_schedule() without care")
ec13ee80145c ("virtio_net: invoke softirqs after __napi_schedule")This shows that relying on the caller to arrange a proper context for the softirqs to be handled while calling napi_schedule() is very fragile and error prone. Also fixing them can also prove challenging if the caller may be called from different kinds of contexts.
Therefore fix this from napi_schedule() itself with waking up ksoftirqd when softirqs are raised from task contexts.
--- net/core/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
@@ -4439,7 +4439,7 @@ static inline void ____napi_schedule(str }list_add_tail (&napi->poll_list, &sd->poll_list); -__raise_softirq_irqoff (NET_RX_SOFTIRQ ); +raise_softirq_irqoff (NET_RX_SOFTIRQ ); }#ifdef CONFIG_RPS
Greg Kroah-Hartman
maintainerPATCH 222/570 gve: defer interrupt enabling until NAPI registration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ankit Garg <[email protected]>
commit 3d970eda003441f66551a91fda16478ac0711617 upstream.
Currently, interrupts are automatically enabled immediately upon request. This allows interrupt to fire before the associated NAPI context is fully initialized and cause failures like below:
[ 0.946369] Call Trace: [ 0.946369] <IRQ> [ 0.946369] __napi_poll+0x2a/0x1e0 [ 0.946369] net_rx_action+0x2f9/0x3f0 [ 0.946369] handle_softirqs+0xd6/0x2c0 [ 0.946369] ? handle_edge_irq+0xc1/0x1b0 [ 0.946369] __irq_exit_rcu+0xc3/0xe0 [ 0.946369] common_interrupt+0x81/0xa0 [ 0.946369] </IRQ> [ 0.946369] <TASK> [ 0.946369] asm_common_interrupt+0x22/0x40 [ 0.946369] RIP: 0010:pv_native_safe_halt+0xb/0x10
Use the IRQF_NO_AUTOEN flag when requesting interrupts to prevent auto enablement and explicitly enable the interrupt in NAPI initialization path (and disable it during NAPI teardown).
This ensures that interrupt lifecycle is strictly coupled with readiness of NAPI context.
[ modified to re-introduce the irq member to struct gve_notify_block,
which was introuduced in commit 9a5e0776d11f ("gve: Avoid rescheduling napi if on wrong cpu"). ]
--- drivers/net/ethernet/google/gve/gve.h | 1 + drivers/net/ethernet/google/gve/gve_main.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/google/gve/gve.h +1 -0
@@ -441,6 +441,7 @@ struct gve_notify_block {struct gve_priv *priv;struct gve_tx_ring *tx;/* tx rings on this block */ struct gve_rx_ring *rx;/* rx rings on this block */ +u32 irq; }____cacheline_aligned ;/* Tracks allowed and current queue settings */
drivers/net/ethernet/google/gve/gve_main.c +4 -1
@@ -339,9 +339,10 @@ static int gve_alloc_notify_blocks(strucsnprintf (block->name,sizeof (block->name),"%s-ntfy-block.%d" , name, i); block->priv = priv; + block->irq = priv->msix_vectors[msix_idx].vector; err =request_irq (priv->msix_vectors[msix_idx].vector,gve_is_gqi (priv) ? gve_intr : gve_intr_dqo, -0 , block->name, block); +IRQF_NO_AUTOEN , block->name, block);if (err) {dev_err (&priv->pdev->dev,"Failed to receive msix vector %d\n" , i);
@@ -502,6 +503,7 @@ static void gve_add_napi(struct gve_privnetif_napi_add (priv->dev, &block->napi, gve_poll,NAPI_POLL_WEIGHT ); +enable_irq (block->irq); }static void gve_remove_napi (struct gve_priv *priv,int ntfy_idx)
@@ -509,6 +511,7 @@ static void gve_remove_napi(struct gve_pstruct gve_notify_block *block = &priv->ntfy_blocks[ntfy_idx];netif_napi_del (&block->napi); +disable_irq (block->irq); }static int gve_register_qpls (struct gve_priv *priv)
Greg Kroah-Hartman
maintainerPATCH 223/570 drm/exynos: vidi: use priv->vidi_dev for ctx lookup in vidi_connection_ioctl()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeongjun Park <[email protected]>
commit d3968a0d85b211e197f2f4f06268a7031079e0d0 upstream.
vidi_connection_ioctl() retrieves the driver_data from drm_dev->dev to obtain a struct vidi_context pointer. However, drm_dev->dev is the exynos-drm master device, and the driver_data contained therein is not the vidi component device, but a completely different device.
This can lead to various bugs, ranging from null pointer dereferences and garbage value accesses to, in unlucky cases, out-of-bounds errors, use-after-free errors, and more.
To resolve this issue, we need to store/delete the vidi device pointer in exynos_drm_private->vidi_dev during bind/unbind, and then read this exynos_drm_private->vidi_dev within ioctl() to obtain the correct struct vidi_context pointer.
--- drivers/gpu/drm/exynos/exynos_drm_drv.h | 1 + drivers/gpu/drm/exynos/exynos_drm_vidi.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-)
drivers/gpu/drm/exynos/exynos_drm_drv.h +1 -0
@@ -201,6 +201,7 @@ struct exynos_drm_private {struct device *g2d_dev;struct device *dma_dev; +struct device *vidi_dev;void *mapping;/* for atomic commit */
drivers/gpu/drm/exynos/exynos_drm_vidi.c +13 -1
@@ -223,9 +223,14 @@ ATTRIBUTE_GROUPS(vidi);int vidi_connection_ioctl (struct drm_device *drm_dev,void *data,struct drm_file *file_priv) { -struct vidi_context *ctx =dev_get_drvdata (drm_dev->dev); +struct exynos_drm_private *priv = drm_dev->dev_private; +struct device *dev = priv ? priv->vidi_dev :NULL ; +struct vidi_context *ctx = dev ?dev_get_drvdata (dev) :NULL ;struct drm_exynos_vidi_connection *vidi = data; +if (!ctx) +return -ENODEV ; +if (!vidi) {DRM_DEV_DEBUG_KMS (ctx->dev,"user data for vidi is null.\n" );
@@ -385,6 +390,7 @@ static int vidi_bind(struct device *dev, {struct vidi_context *ctx =dev_get_drvdata (dev);struct drm_device *drm_dev = data; +struct exynos_drm_private *priv = drm_dev->dev_private;struct drm_encoder *encoder = &ctx->encoder;struct exynos_drm_plane *exynos_plane;struct exynos_drm_plane_config plane_config = {0 };
@@ -392,6 +398,8 @@ static int vidi_bind(struct device *dev,int ret; ctx->drm_dev = drm_dev; +if (priv) + priv->vidi_dev = dev; plane_config.pixel_formats = formats; plane_config.num_pixel_formats =ARRAY_SIZE (formats);
@@ -437,8 +445,12 @@ static int vidi_bind(struct device *dev,static void vidi_unbind (struct device *dev,struct device *master,void *data) {struct vidi_context *ctx =dev_get_drvdata (dev); +struct drm_device *drm_dev = data; +struct exynos_drm_private *priv = drm_dev->dev_private;del_timer_sync (&ctx->timer); +if (priv) + priv->vidi_dev =NULL ; }static const struct component_ops vidi_component_ops = {
Greg Kroah-Hartman
maintainerPATCH 224/570 drm/exynos: vidi: fix to avoid directly dereferencing user pointer
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeongjun Park <[email protected]>
commit d4c98c077c7fb2dfdece7d605e694b5ea2665085 upstream.
In vidi_connection_ioctl(), vidi->edid(user pointer) is directly dereferenced in the kernel.
This allows arbitrary kernel memory access from the user space, so instead of directly accessing the user pointer in the kernel, we should modify it to copy edid to kernel memory using copy_from_user() and use it.
--- drivers/gpu/drm/exynos/exynos_drm_vidi.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_vidi.c +11 -4
@@ -251,19 +251,26 @@ int vidi_connection_ioctl(struct drm_devif (vidi->connection) {struct edid *raw_edid; +struct edid edid_buf; +void *edid_userptr =u64_to_user_ptr (vidi->edid); - raw_edid = (struct edid *)(unsigned long )vidi->edid; -if (!drm_edid_is_valid (raw_edid)) { +if (copy_from_user (&edid_buf, edid_userptr,sizeof (struct edid ))) +return -EFAULT ; + +if (!drm_edid_is_valid (&edid_buf)) {DRM_DEV_DEBUG_KMS (ctx->dev,"edid data is invalid.\n" );return -EINVAL ; } - ctx->raw_edid =drm_edid_duplicate (raw_edid); -if (!ctx->raw_edid) { + + raw_edid =drm_edid_duplicate (&edid_buf); + +if (!raw_edid) {DRM_DEV_DEBUG_KMS (ctx->dev,"failed to allocate raw_edid.\n" );return -ENOMEM ; } + ctx->raw_edid = raw_edid; }else {/* * with connection = 0, free raw_edid
Greg Kroah-Hartman
maintainerPATCH 225/570 drm/exynos: vidi: use ctx->lock to protect struct vidi_context member variables related to memory alloc/free
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeongjun Park <[email protected]>
commit 52b330799e2d6f825ae2bb74662ec1b10eb954bb upstream.
Exynos Virtual Display driver performs memory alloc/free operations without lock protection, which easily causes concurrency problem.
For example, use-after-free can occur in race scenario like this:
```
CPU0 CPU1 CPU2
---- ---- ----
vidi_connection_ioctl()
if (vidi->connection) // true
drm_edid = drm_edid_alloc(); // alloc drm_edid
...
ctx->raw_edid = drm_edid;
...
drm_mode_getconnector()
drm_helper_probe_single_connector_modes()
vidi_get_modes()
if (ctx->raw_edid) // true
drm_edid_dup(ctx->raw_edid);
if (!drm_edid) // false
...
vidi_connection_ioctl()
if (vidi->connection) // false
drm_edid_free(ctx->raw_edid); // free drm_edid
...
drm_edid_alloc(drm_edid->edid)
kmemdup(edid); // UAF!!
...
```To prevent these vulns, at least in vidi_context, member variables related to memory alloc/free should be protected with ctx->lock.
--- drivers/gpu/drm/exynos/exynos_drm_vidi.c | 43 +++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_vidi.c +35 -8
@@ -185,15 +185,17 @@ static ssize_t vidi_store_connection(str const char *buf, size_t len) {struct vidi_context *ctx =dev_get_drvdata (dev); -int ret; +int ret, new_connected; - ret =kstrtoint (buf,0 , &ctx->connected); + ret =kstrtoint (buf,0 , &new_connected);if (ret)return ret; -if (ctx->connected >1 ) +if (new_connected >1 )return -EINVAL ; +mutex_lock (&ctx->lock); +/* use fake edid data for test. */ if (!ctx->raw_edid) ctx->raw_edid = (struct edid *)fake_edid_info;
@@ -201,14 +203,21 @@ static ssize_t vidi_store_connection(str/* if raw_edid isn't same as fake data then it can't be tested. */ if (ctx->raw_edid != (struct edid *)fake_edid_info) {DRM_DEV_DEBUG_KMS (dev,"edid data is not fake data.\n" ); -return -EINVAL ; + ret = -EINVAL ; + goto fail; } + ctx->connected = new_connected; +mutex_unlock (&ctx->lock); +DRM_DEV_DEBUG_KMS (dev,"requested connection.\n" );drm_helper_hpd_irq_event (ctx->drm_dev);return len; +fail: +mutex_unlock (&ctx->lock); +return ret; } static DEVICE_ATTR(connection, 0644, vidi_show_connection,
@@ -243,11 +252,14 @@ int vidi_connection_ioctl(struct drm_devreturn -EINVAL ; } +mutex_lock (&ctx->lock);if (ctx->connected == vidi->connection) { +mutex_unlock (&ctx->lock);DRM_DEV_DEBUG_KMS (ctx->dev,"same connection request.\n" );return -EINVAL ; } +mutex_unlock (&ctx->lock);if (vidi->connection) {struct edid *raw_edid;
@@ -270,20 +282,27 @@ int vidi_connection_ioctl(struct drm_dev "failed to allocate raw_edid.\n");return -ENOMEM ; } +mutex_lock (&ctx->lock); ctx->raw_edid = raw_edid; +mutex_unlock (&ctx->lock); }else {/* * with connection = 0, free raw_edid * only if raw edid data isn't same as fake data. */ +mutex_lock (&ctx->lock);if (ctx->raw_edid && ctx->raw_edid != (struct edid *)fake_edid_info) {kfree (ctx->raw_edid); ctx->raw_edid =NULL ; } +mutex_unlock (&ctx->lock); } +mutex_lock (&ctx->lock); ctx->connected = vidi->connection; +mutex_unlock (&ctx->lock); +drm_helper_hpd_irq_event (ctx->drm_dev);return 0 ;
@@ -298,7 +317,7 @@ static enum drm_connector_status vidi_de* connection request would come from user side * to do hotplug through specific ioctl. */ -return ctx->connected ? connector_status_connected : +return READ_ONCE (ctx->connected) ? connector_status_connected : connector_status_disconnected; }
@@ -320,22 +339,24 @@ static int vidi_get_modes(struct drm_construct vidi_context *ctx =ctx_from_connector (connector);struct edid *edid;int edid_len; -int count; +int count =0 ;/* * the edid data comes from user side and it would be set * to ctx->raw_edid through specific ioctl. */ + +mutex_lock (&ctx->lock);if (!ctx->raw_edid) {DRM_DEV_DEBUG_KMS (ctx->dev,"raw_edid is null.\n" ); -return 0 ; + goto fail; } edid_len = (1 + ctx->raw_edid->extensions) *EDID_LENGTH ; edid =kmemdup (ctx->raw_edid, edid_len,GFP_KERNEL );if (!edid) {DRM_DEV_DEBUG_KMS (ctx->dev,"failed to allocate edid\n" ); -return 0 ; + goto fail; }drm_connector_update_edid_property (connector, edid);
@@ -344,6 +365,8 @@ static int vidi_get_modes(struct drm_conkfree (edid); +fail: +mutex_unlock (&ctx->lock);return count; }
@@ -489,11 +512,15 @@ static int vidi_remove(struct platform_d {struct vidi_context *ctx =platform_get_drvdata (pdev); +mutex_lock (&ctx->lock); +if (ctx->raw_edid != (struct edid *)fake_edid_info) {kfree (ctx->raw_edid); ctx->raw_edid =NULL ; } +mutex_unlock (&ctx->lock); +component_del (&pdev->dev, &vidi_component_ops);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 226/570 ksmbd: call ksmbd_vfs_kern_path_end_removing() on some error paths
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fedor Pchelkin <[email protected]>
[ Upstream commit a09dc10d1353f0e92c21eae2a79af1c2b1ddcde8 ]
There are two places where ksmbd_vfs_kern_path_end_removing() needs to be called in order to balance what the corresponding successful call to ksmbd_vfs_kern_path_start_removing() has done, i.e. drop inode locks and put the taken references. Otherwise there might be potential deadlocks and unbalanced locks which are caught like:
BUG: workqueue leaked lock or atomic: kworker/5:21/0x00000000/7596
last function: handle_ksmbd_work
2 locks held by kworker/5:21/7596:
#0: ffff8881051ae448 (sb_writers#3){.+.+}-{0:0}, at: ksmbd_vfs_kern_path_locked+0x142/0x660
#1: ffff888130e966c0 (&type->i_mutex_dir_key#3/1){+.+.}-{4:4}, at: ksmbd_vfs_kern_path_locked+0x17d/0x660
CPU: 5 PID: 7596 Comm: kworker/5:21 Not tainted 6.1.162-00456-gc29b353f383b #138
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1 04/01/2014
Workqueue: ksmbd-io handle_ksmbd_work
Call Trace:
<TASK>
dump_stack_lvl+0x44/0x5b
process_one_work.cold+0x57/0x5c
worker_thread+0x82/0x600
kthread+0x153/0x190
ret_from_fork+0x22/0x30
</TASK>Found by Linux Verification Center (linuxtesting.org).
--- fs/ksmbd/smb2pdu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ksmbd/smb2pdu.c +2 -2
@@ -5652,14 +5652,14 @@ static int smb2_create_link(struct ksmbd rc = -EINVAL ;ksmbd_debug (SMB ,"cannot delete %s\n" , link_name); - goto out; } }else { rc = -EEXIST ;ksmbd_debug (SMB ,"link already exists\n" ); - goto out; }ksmbd_vfs_kern_path_unlock (&parent_path, &path); +if (rc) + goto out; } rc =ksmbd_vfs_link (work, target_name, link_name);if (rc)
Greg Kroah-Hartman
maintainerPATCH 227/570 ext4: dont set EXT4_GET_BLOCKS_CONVERT when splitting before submitting I/O
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Yi <[email protected]>
[ Upstream commit feaf2a80e78f89ee8a3464126077ba8683b62791 ]
When allocating blocks during within-EOF DIO and writeback with dioread_nolock enabled, EXT4_GET_BLOCKS_PRE_IO was set to split an existing large unwritten extent. However, EXT4_GET_BLOCKS_CONVERT was set when calling ext4_split_convert_extents(), which may potentially result in stale data issues.
Assume we have an unwritten extent, and then DIO writes the second half.
[UUUUUUUUUUUUUUUU] on-disk extent U: unwritten extent
[UUUUUUUUUUUUUUUU] extent status tree
|<- ->| ----> dio write this range
First, ext4_iomap_alloc() call ext4_map_blocks() with EXT4_GET_BLOCKS_PRE_IO, EXT4_GET_BLOCKS_UNWRIT_EXT and EXT4_GET_BLOCKS_CREATE flags set. ext4_map_blocks() find this extent and call ext4_split_convert_extents() with EXT4_GET_BLOCKS_CONVERT and the above flags set.
Then, ext4_split_convert_extents() calls ext4_split_extent() with EXT4_EXT_MAY_ZEROOUT, EXT4_EXT_MARK_UNWRIT2 and EXT4_EXT_DATA_VALID2 flags set, and it calls ext4_split_extent_at() to split the second half with EXT4_EXT_DATA_VALID2, EXT4_EXT_MARK_UNWRIT1, EXT4_EXT_MAY_ZEROOUT and EXT4_EXT_MARK_UNWRIT2 flags set. However, ext4_split_extent_at() failed to insert extent since a temporary lack -ENOSPC. It zeroes out the first half but convert the entire on-disk extent to written since the EXT4_EXT_DATA_VALID2 flag set, but left the second half as unwritten in the extent status tree.
[0000000000SSSSSS] data S: stale data, 0: zeroed [WWWWWWWWWWWWWWWW] on-disk extent W: written extent [WWWWWWWWWWUUUUUU] extent status tree
Finally, if the DIO failed to write data to the disk, the stale data in the second half will be exposed once the cached extent entry is gone.
Fix this issue by not passing EXT4_GET_BLOCKS_CONVERT when splitting an unwritten extent before submitting I/O, and make ext4_split_convert_extents() to zero out the entire extent range to zero for this case, and also mark the extent in the extent status tree for consistency.
Message-ID: <[email protected]>
--- fs/ext4/extents.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
fs/ext4/extents.c +8 -4
@@ -3711,11 +3711,15 @@ static int ext4_split_convert_extents(ha/* Convert to unwritten */ if (flags &EXT4_GET_BLOCKS_CONVERT_UNWRITTEN ) { split_flag |=EXT4_EXT_DATA_VALID1 ; -/* Convert to initialized */ - }else if (flags &EXT4_GET_BLOCKS_CONVERT ) { +/* Split the existing unwritten extent */ + }else if (flags & (EXT4_GET_BLOCKS_UNWRIT_EXT | +EXT4_GET_BLOCKS_CONVERT )) { split_flag |= ee_block + ee_len <= eof_block ?EXT4_EXT_MAY_ZEROOUT :0 ; - split_flag |= (EXT4_EXT_MARK_UNWRIT2 |EXT4_EXT_DATA_VALID2 ); + split_flag |=EXT4_EXT_MARK_UNWRIT2 ; +/* Convert to initialized */ +if (flags &EXT4_GET_BLOCKS_CONVERT ) + split_flag |=EXT4_EXT_DATA_VALID2 ; } flags |=EXT4_GET_BLOCKS_PRE_IO ;return ext4_split_extent (handle, inode, ppath, map, split_flag, flags);
@@ -3880,7 +3884,7 @@ ext4_ext_handle_unwritten_extents(handle/* get_block() before submitting IO, split the extent */ if (flags &EXT4_GET_BLOCKS_PRE_IO ) { ret =ext4_split_convert_extents (handle, inode, map, ppath, - flags |EXT4_GET_BLOCKS_CONVERT ); + flags);if (ret <0 ) { err = ret; goto out2;
Greg Kroah-Hartman
maintainerPATCH 228/570 ext4: drop extent cache when splitting extent fails
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Yi <[email protected]>
[ Upstream commit 79b592e8f1b435796cbc2722190368e3e8ffd7a1 ]
When the split extent fails, we might leave some extents still being processed and return an error directly, which will result in stale extent entries remaining in the extent status tree. So drop all of the remaining potentially stale extents if the splitting fails.
Message-ID: <[email protected]>
--- fs/ext4/extents.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/ext4/extents.c +8 -2
@@ -3236,7 +3236,9 @@ static int ext4_split_extent_at(handle_text4_ext_mark_unwritten (ex2); err =ext4_ext_insert_extent (handle, inode, ppath, &newex, flags); -if (err != -ENOSPC && err != -EDQUOT && err != -ENOMEM ) +if (err && err != -ENOSPC && err != -EDQUOT && err != -ENOMEM ) + goto out_err; +if (!err) goto out;/*
@@ -3252,7 +3254,8 @@ static int ext4_split_extent_at(handle_tif (IS_ERR (path)) {EXT4_ERROR_INODE (inode,"Failed split extent on %u, err %ld" , split,PTR_ERR (path)); -return PTR_ERR (path); + err =PTR_ERR (path); + goto out_err; } depth =ext_depth (inode); ex = path[depth].p_ext;
@@ -3308,6 +3311,9 @@ fix_extent_len:*/ ext4_ext_dirty (handle, inode, path + path->p_depth);return err; +out_err: +/* Remove all remaining potentially stale extents. */ +ext4_es_remove_extent (inode, ee_block, ee_len); out:ext4_ext_show_leaf (inode, *ppath);return err;
Greg Kroah-Hartman
maintainerPATCH 229/570 ext4: fix dirtyclusters double decrement on fs shutdown
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Brian Foster <[email protected]>
[ Upstream commit 94a8cea54cd935c54fa2fba70354757c0fc245e3 ]
fstests test generic/388 occasionally reproduces a warning in ext4_put_super() associated with the dirty clusters count:
WARNING: CPU: 7 PID: 76064 at fs/ext4/super.c:1324 ext4_put_super+0x48c/0x590 [ext4]
Tracing the failure shows that the warning fires due to an s_dirtyclusters_counter value of -1. IOW, this appears to be a spurious decrement as opposed to some sort of leak. Further tracing of the dirty cluster count deltas and an LLM scan of the resulting output identified the cause as a double decrement in the error path between ext4_mb_mark_diskspace_used() and the caller ext4_mb_new_blocks().
First, note that generic/388 is a shutdown vs. fsstress test and so produces a random set of operations and shutdown injections. In the problematic case, the shutdown triggers an error return from the ext4_handle_dirty_metadata() call(s) made from ext4_mb_mark_context(). The changed value is non-zero at this point, so ext4_mb_mark_diskspace_used() does not exit after the error bubbles up from ext4_mb_mark_context(). Instead, the former decrements both cluster counters and returns the error up to ext4_mb_new_blocks(). The latter falls into the !ar->len out path which decrements the dirty clusters counter a second time, creating the inconsistency.
To avoid this problem and simplify ownership of the cluster reservation in this codepath, lift the counter reduction to a single place in the caller. This makes it more clear that ext4_mb_new_blocks() is responsible for acquiring cluster reservation (via ext4_claim_free_clusters()) in the !delalloc case as well as releasing it, regardless of whether it ends up consumed or returned due to failure.
--- fs/ext4/mballoc.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)
fs/ext4/mballoc.c +5 -16
@@ -3834,8 +3834,7 @@ void ext4_exit_mballoc(void)* Returns 0 if success or error code */ static noinline_for_stack int -ext4_mb_mark_diskspace_used (struct ext4_allocation_context *ac, -handle_t *handle,unsigned int reserv_clstrs) +ext4_mb_mark_diskspace_used (struct ext4_allocation_context *ac,handle_t *handle) {struct buffer_head *bitmap_bh =NULL ;struct ext4_group_desc *gdp;
@@ -3923,13 +3922,6 @@ ext4_mb_mark_diskspace_used(struct ext4_ext4_unlock_group (sb, ac->ac_b_ex.fe_group);percpu_counter_sub (&sbi->s_freeclusters_counter, ac->ac_b_ex.fe_len); -/* -* Now reduce the dirty block count also. Should not go negative -*/ -if (!(ac->ac_flags &EXT4_MB_DELALLOC_RESERVED )) -/* release all the reserved blocks if non delalloc */ -percpu_counter_sub (&sbi->s_dirtyclusters_counter, - reserv_clstrs);if (sbi->s_log_groups_per_flex) { ext4_group_t flex_group = ext4_flex_group(sbi,
@@ -5801,7 +5793,7 @@ repeat:ext4_mb_pa_free (ac); }if (likely (ac->ac_status ==AC_STATUS_FOUND )) { - *errp =ext4_mb_mark_diskspace_used (ac, handle, reserv_clstrs); + *errp =ext4_mb_mark_diskspace_used (ac, handle);if (*errp) {ext4_discard_allocated_blocks (ac); goto errout;
@@ -5833,12 +5825,9 @@ out:kmem_cache_free (ext4_ac_cachep, ac);if (inquota && ar->len < inquota)dquot_free_block (ar->inode,EXT4_C2B (sbi, inquota - ar->len)); -if (!ar->len) { -if ((ar->flags &EXT4_MB_DELALLOC_RESERVED ) ==0 ) -/* release all the reserved blocks if non delalloc */ -percpu_counter_sub (&sbi->s_dirtyclusters_counter, - reserv_clstrs); - } +/* release any reserved blocks */ +if (reserv_clstrs) +percpu_counter_sub (&sbi->s_dirtyclusters_counter, reserv_clstrs);trace_ext4_allocate_blocks (ar, (unsigned long long )block);
Greg Kroah-Hartman
maintainerPATCH 230/570 ksmbd: fix null pointer dereference error in generate_encryptionkey
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 9b493ab6f35178afd8d619800df9071992f715de ]
If client send two session setups with krb5 authenticate to ksmbd, null pointer dereference error in generate_encryptionkey could happen. sess->Preauth_HashValue is set to NULL if session is valid. So this patch skip generate encryption key if session is valid.
--- fs/ksmbd/smb2pdu.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
fs/ksmbd/smb2pdu.c +16 -2
@@ -1628,11 +1628,24 @@ static int krb5_authenticate(struct ksmb } rsp->SecurityBufferLength =cpu_to_le16 (out_len); -if ((conn->sign || server_conf.enforced_signing) || +/* +* If session state is SMB2_SESSION_VALID, We can assume +* that it is reauthentication. And the user/password +* has been verified, so return it here. +*/ +if (sess->state ==SMB2_SESSION_VALID ) { +if (conn->binding) + goto binding_session; +return 0 ; + } + +if ((rsp->SessionFlags !=SMB2_SESSION_FLAG_IS_GUEST_LE && + (conn->sign || server_conf.enforced_signing)) || (req->SecurityMode &SMB2_NEGOTIATE_SIGNING_REQUIRED )) sess->sign = true; -if (smb3_encryption_negotiated (conn)) { +if (smb3_encryption_negotiated (conn) && + !(req->Flags &SMB2_SESSION_REQ_FLAG_BINDING )) { retval = conn->ops->generate_encryptionkey (conn, sess);if (retval) { ksmbd_debug(SMB,
@@ -1645,6 +1658,7 @@ static int krb5_authenticate(struct ksmb sess->sign = false; } +binding_session:if (conn->dialect >=SMB30_PROT_ID ) { chann =lookup_chann_list (sess, conn);if (!chann) {
Greg Kroah-Hartman
maintainerPATCH 231/570 ext4: always allocate blocks only from groups inode can use
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
[ Upstream commit 4865c768b563deff1b6a6384e74a62f143427b42 ]
For filesystems with more than 2^32 blocks inodes using indirect block based format cannot use blocks beyond the 32-bit limit. ext4_mb_scan_groups_linear() takes care to not select these unsupported groups for such inodes however other functions selecting groups for allocation don't. So far this is harmless because the other selection functions are used only with mb_optimize_scan and this is currently disabled for inodes with indirect blocks however in the following patch we want to enable mb_optimize_scan regardless of inode format.
--- fs/ext4/mballoc.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
fs/ext4/mballoc.c +16 -4
@@ -885,6 +885,21 @@ mb_update_avg_fragment_size(struct superwrite_unlock (&sbi->s_mb_rb_lock); } +static ext4_group_t ext4_get_allocation_groups_count ( +struct ext4_allocation_context *ac) +{ +ext4_group_t ngroups =ext4_get_groups_count (ac->ac_sb); + +/* non-extent files are limited to low blocks/groups */ +if (!(ext4_test_inode_flag (ac->ac_inode,EXT4_INODE_EXTENTS ))) + ngroups =EXT4_SB (ac->ac_sb)->s_blockfile_groups; + +/* Pairs with smp_wmb() in ext4_update_super() */ +smp_rmb (); + +return ngroups; +} +/* * Choose next group by traversing largest_free_order lists. Updates *new_cr if * cr level needs an update.
@@ -2700,10 +2715,7 @@ ext4_mb_regular_allocator(struct ext4_al sb = ac->ac_sb; sbi =EXT4_SB (sb); - ngroups =ext4_get_groups_count (sb); -/* non-extent files are limited to low blocks/groups */ -if (!(ext4_test_inode_flag (ac->ac_inode,EXT4_INODE_EXTENTS ))) - ngroups = sbi->s_blockfile_groups; + ngroups =ext4_get_allocation_groups_count (ac);BUG_ON (ac->ac_status ==AC_STATUS_FOUND );
Greg Kroah-Hartman
maintainerPATCH 232/570 wifi: libertas: fix use-after-free in lbs_free_adapter()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Hodges <[email protected]>
[ Upstream commit 03cc8f90d0537fcd4985c3319b4fafbf2e3fb1f0 ]
The lbs_free_adapter() function uses timer_delete() (non-synchronous) for both command_timer and tx_lockup_timer before the structure is freed. This is incorrect because timer_delete() does not wait for any running timer callback to complete.
If a timer callback is executing when lbs_free_adapter() is called, the callback will access freed memory since lbs_cfg_free() frees the containing structure immediately after lbs_free_adapter() returns.
Both timer callbacks (lbs_cmd_timeout_handler and lbs_tx_lockup_handler) access priv->driver_lock, priv->cur_cmd, priv->dev, and other fields, which would all be use-after-free violations.
Use timer_delete_sync() instead to ensure any running timer callback has completed before returning.
This bug was introduced in commit 8f641d93c38a ("libertas: detect TX lockups and reset hardware") where del_timer() was used instead of del_timer_sync() in the cleanup path. The command_timer has had the same issue since the driver was first written.
--- drivers/net/wireless/marvell/libertas/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/marvell/libertas/main.c +2 -2
@@ -882,8 +882,8 @@ static void lbs_free_adapter(struct lbs_ {lbs_free_cmd_buffer (priv);kfifo_free (&priv->event_fifo); -del_timer (&priv->command_timer); -del_timer (&priv->tx_lockup_timer); +timer_delete_sync (&priv->command_timer); +timer_delete_sync (&priv->tx_lockup_timer);del_timer (&priv->auto_deepsleep_timer); }
Greg Kroah-Hartman
maintainerPATCH 233/570 wifi: cfg80211: move scan done work to wiphy work
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit fe0af9fe54d0ff53aa49eef390c8962355b274e2 ]
Move the scan done work to the new wiphy work to
simplify the code a bit.
Stable-dep-of: 767d23ade706 ("wifi: cfg80211: cancel rfkill_block work in wiphy_unregister()")
--- net/wireless/core.c | 3 +-- net/wireless/core.h | 4 ++-- net/wireless/scan.c | 14 ++++---------- 3 files changed, 7 insertions(+), 14 deletions(-)
net/wireless/core.c +1 -2
@@ -525,7 +525,7 @@ use_default_name:spin_lock_init (&rdev->bss_lock);INIT_LIST_HEAD (&rdev->bss_list);INIT_LIST_HEAD (&rdev->sched_scan_req_list); -INIT_WORK (&rdev->scan_done_wk, __cfg80211_scan_done); +wiphy_work_init (&rdev->scan_done_wk, __cfg80211_scan_done);INIT_DELAYED_WORK (&rdev->dfs_update_channels_wk, cfg80211_dfs_channels_update_work);#ifdef CONFIG_CFG80211_WEXT
@@ -1104,7 +1104,6 @@ void wiphy_unregister(struct wiphy *wiph/* this has nothing to do now but make sure it's gone */ cancel_work_sync (&rdev->wiphy_work); -flush_work (&rdev->scan_done_wk);cancel_work_sync (&rdev->conn_work);flush_work (&rdev->event_work);cancel_delayed_work_sync (&rdev->dfs_update_channels_wk);
net/wireless/core.h +2 -2
@@ -75,7 +75,7 @@ struct cfg80211_registered_device {struct sk_buff *scan_msg;struct list_head sched_scan_req_list;time64_t suspend_at; -struct work_struct scan_done_wk; +struct wiphy_work scan_done_wk;struct genl_info *cur_cmd_info;
@@ -445,7 +445,7 @@ bool cfg80211_valid_key_idx(struct cfg80int cfg80211_validate_key_settings (struct cfg80211_registered_device *rdev,struct key_params *params,int key_idx,bool pairwise,const u8 *mac_addr); -void __cfg80211_scan_done (struct work_struct *wk); +void __cfg80211_scan_done (struct wiphy *wiphy,struct wiphy_work *wk);void ___cfg80211_scan_done (struct cfg80211_registered_device *rdev,bool send_message); void cfg80211_add_sched_scan_req(struct cfg80211_registered_device *rdev,
net/wireless/scan.c +4 -10
@@ -1079,16 +1079,9 @@ void ___cfg80211_scan_done(struct cfg802nl80211_send_scan_msg (rdev, msg); } -void __cfg80211_scan_done (struct work_struct *wk) +void __cfg80211_scan_done (struct wiphy *wiphy,struct wiphy_work *wk) { -struct cfg80211_registered_device *rdev; - - rdev = container_of(wk, struct cfg80211_registered_device, - scan_done_wk); - -wiphy_lock (&rdev->wiphy); -___cfg80211_scan_done (rdev, true); -wiphy_unlock (&rdev->wiphy); +___cfg80211_scan_done (wiphy_to_rdev (wiphy), true); } void cfg80211_scan_done(struct cfg80211_scan_request *request,
@@ -1114,7 +1107,8 @@ void cfg80211_scan_done(struct cfg80211_ } request->notified = true; -queue_work (cfg80211_wq, &wiphy_to_rdev (request->wiphy)->scan_done_wk); +wiphy_work_queue (request->wiphy, + &wiphy_to_rdev (request->wiphy)->scan_done_wk); }EXPORT_SYMBOL (cfg80211_scan_done);
Greg Kroah-Hartman
maintainerPATCH 234/570 wifi: cfg80211: cancel rfkill_block work in wiphy_unregister()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniil Dulov <[email protected]>
[ Upstream commit 767d23ade706d5fa51c36168e92a9c5533c351a1 ]
There is a use-after-free error in cfg80211_shutdown_all_interfaces found by syzkaller:
BUG: KASAN: use-after-free in cfg80211_shutdown_all_interfaces+0x213/0x220 Read of size 8 at addr ffff888112a78d98 by task kworker/0:5/5326 CPU: 0 UID: 0 PID: 5326 Comm: kworker/0:5 Not tainted 6.19.0-rc2 #2 PREEMPT(voluntary) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014 Workqueue: events cfg80211_rfkill_block_work Call Trace: <TASK> dump_stack_lvl+0x116/0x1f0 print_report+0xcd/0x630 kasan_report+0xe0/0x110 cfg80211_shutdown_all_interfaces+0x213/0x220 cfg80211_rfkill_block_work+0x1e/0x30 process_one_work+0x9cf/0x1b70 worker_thread+0x6c8/0xf10 kthread+0x3c5/0x780 ret_from_fork+0x56d/0x700 ret_from_fork_asm+0x1a/0x30 </TASK>
The problem arises due to the rfkill_block work is not cancelled when wiphy is being unregistered. In order to fix the issue cancel the corresponding work in wiphy_unregister().
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
--- net/wireless/core.c | 1 + 1 file changed, 1 insertion(+)
net/wireless/core.c +1 -0
@@ -1104,6 +1104,7 @@ void wiphy_unregister(struct wiphy *wiph/* this has nothing to do now but make sure it's gone */ cancel_work_sync (&rdev->wiphy_work); +cancel_work_sync (&rdev->rfkill_block);cancel_work_sync (&rdev->conn_work);flush_work (&rdev->event_work);cancel_delayed_work_sync (&rdev->dfs_update_channels_wk);
Greg Kroah-Hartman
maintainerPATCH 235/570 RDMA/irdma: Fix kernel stack leak in irdma_create_user_ah()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason Gunthorpe <[email protected]>
[ Upstream commit 74586c6da9ea222a61c98394f2fc0a604748438c ]
struct irdma_create_ah_resp { // 8 bytes, no padding
__u32 ah_id; // offset 0 - SET (uresp.ah_id = ah->sc_ah.ah_info.ah_idx)
__u8 rsvd[4]; // offset 4 - NEVER SET <- LEAK};
rsvd[4]: 4 bytes of stack memory leaked unconditionally. Only ah_id is assigned before ib_respond_udata().
The reserved members of the structure were not zeroed.
--- drivers/infiniband/hw/irdma/verbs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/irdma/verbs.c +1 -1
@@ -4170,7 +4170,7 @@ static int irdma_create_ah(struct ib_ahstruct irdma_sc_ah *sc_ah;u32 ah_id =0 ;struct irdma_ah_info *ah_info; -struct irdma_create_ah_resp uresp; +struct irdma_create_ah_resp uresp = {};union {struct sockaddr saddr;struct sockaddr_in saddr_in;
Greg Kroah-Hartman
maintainerPATCH 236/570 smb: client: Dont log plaintext credentials in cifs_set_cifscreds
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 2f37dc436d4e61ff7ae0b0353cf91b8c10396e4d ]
When debug logging is enabled, cifs_set_cifscreds() logs the key payload and exposes the plaintext username and password. Remove the debug log to avoid exposing credentials.
--- fs/cifs/connect.c | 1 - 1 file changed, 1 deletion(-)
fs/cifs/connect.c +0 -1
@@ -1874,7 +1874,6 @@ cifs_set_cifscreds(struct smb3_fs_contex/* find first : in payload */ payload = upayload->data; delim =strnchr (payload, upayload->datalen,':' ); -cifs_dbg (FYI ,"payload=%s\n" , payload);if (!delim) {cifs_dbg (FYI ,"Unable to find ':' in payload (datalen=%d)\n" , upayload->datalen);
Greg Kroah-Hartman
maintainerPATCH 237/570 net: phy: register phy led_triggers during probe to avoid AB-BA deadlock
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew Lunn <[email protected]>
[ Upstream commit c8dbdc6e380e7e96a51706db3e4b7870d8a9402d ]
There is an AB-BA deadlock when both LEDS_TRIGGER_NETDEV and LED_TRIGGER_PHY are enabled:
[ 1362.049207] [<8054e4b8>] led_trigger_register+0x5c/0x1fc <-- Trying to get lock "triggers_list_lock" via down_write(&triggers_list_lock); [ 1362.054536] [<80662830>] phy_led_triggers_register+0xd0/0x234 [ 1362.060329] [<8065e200>] phy_attach_direct+0x33c/0x40c [ 1362.065489] [<80651fc4>] phylink_fwnode_phy_connect+0x15c/0x23c [ 1362.071480] [<8066ee18>] mtk_open+0x7c/0xba0 [ 1362.075849] [<806d714c>] __dev_open+0x280/0x2b0 [ 1362.080384] [<806d7668>] __dev_change_flags+0x244/0x24c [ 1362.085598] [<806d7698>] dev_change_flags+0x28/0x78 [ 1362.090528] [<807150e4>] dev_ioctl+0x4c0/0x654 <-- Hold lock "rtnl_mutex" by calling rtnl_lock(); [ 1362.094985] [<80694360>] sock_ioctl+0x2f4/0x4e0 [ 1362.099567] [<802e9c4c>] sys_ioctl+0x32c/0xd8c [ 1362.104022] [<80014504>] syscall_common+0x34/0x58
Here LED_TRIGGER_PHY is registering LED triggers during phy_attach while holding RTNL and then taking triggers_list_lock.
[ 1362.191101] [<806c2640>] register_netdevice_notifier+0x60/0x168 <-- Trying to get lock "rtnl_mutex" via rtnl_lock(); [ 1362.197073] [<805504ac>] netdev_trig_activate+0x194/0x1e4 [ 1362.202490] [<8054e28c>] led_trigger_set+0x1d4/0x360 <-- Hold lock "triggers_list_lock" by down_read(&triggers_list_lock); [ 1362.207511] [<8054eb38>] led_trigger_write+0xd8/0x14c [ 1362.212566] [<80381d98>] sysfs_kf_bin_write+0x80/0xbc [ 1362.217688] [<8037fcd8>] kernfs_fop_write_iter+0x17c/0x28c [ 1362.223174] [<802cbd70>] vfs_write+0x21c/0x3c4 [ 1362.227712] [<802cc0c4>] ksys_write+0x78/0x12c [ 1362.232164] [<80014504>] syscall_common+0x34/0x58
Here LEDS_TRIGGER_NETDEV is being enabled on an LED. It first takes triggers_list_lock and then RTNL. A classical AB-BA deadlock.
phy_led_triggers_registers() does not require the RTNL, it does not make any calls into the network stack which require protection. There is also no requirement the PHY has been attached to a MAC, the triggers only make use of phydev state. This allows the call to phy_led_triggers_registers() to be placed elsewhere. PHY probe() and release() don't hold RTNL, so solving the AB-BA deadlock.
--- drivers/net/phy/phy_device.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/phy/phy_device.c +8 -5
@@ -1508,7 +1508,6 @@ int phy_attach_direct(struct net_devicereturn err;phy_resume (phydev); -phy_led_triggers_register (phydev);return err;
@@ -1765,8 +1764,6 @@ void phy_detach(struct phy_device *phyde } phydev->phylink =NULL ; -phy_led_triggers_unregister (phydev); -if (phydev->mdio.dev.driver)module_put (phydev->mdio.dev.driver->owner);
@@ -3120,10 +3117,14 @@ static int phy_probe(struct device *dev)/* Set the state to READY by default */ phydev->state =PHY_READY ; +/* Register the PHY LED triggers */ +phy_led_triggers_register (phydev); + +return 0 ; + out:/* Re-assert the reset signal on error */ -if (err) -phy_device_reset (phydev,1 ); +phy_device_reset (phydev,1 );return err; }
@@ -3134,6 +3135,8 @@ static int phy_remove(struct device *devcancel_delayed_work_sync (&phydev->state_queue); +phy_led_triggers_unregister (phydev); + phydev->state =PHY_DOWN ;sfp_bus_del_upstream (phydev->sfp_bus);
Greg Kroah-Hartman
maintainerPATCH 238/570 drm/amd/display: Use GFP_ATOMIC in dc_create_stream_for_sink
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Natalie Vock <[email protected]>
[ Upstream commit 28dfe4317541e57fe52f9a290394cd29c348228b ]
This can be called while preemption is disabled, for example by dcn32_internal_validate_bw which is called with the FPU active.
Fixes "BUG: scheduling while atomic" messages I encounter on my Navi31 machine.
--- drivers/gpu/drm/amd/display/dc/core/dc_stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/core/dc_stream.c +1 -1
@@ -167,7 +167,7 @@ struct dc_stream_state *dc_create_streamif (sink ==NULL )return NULL ; - stream =kzalloc (sizeof (struct dc_stream_state ),GFP_KERNEL ); + stream =kzalloc (sizeof (struct dc_stream_state ),GFP_ATOMIC );if (stream ==NULL ) goto alloc_fail;
Greg Kroah-Hartman
maintainerPATCH 239/570 mptcp: pm: avoid sending RM_ADDR over same subflow
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Matthieu Baerts (NGI0)" <[email protected]>
[ Upstream commit fb8d0bccb221080630efcd9660c9f9349e53cc9e ]
RM_ADDR are sent over an active subflow, the first one in the subflows list. There is then a high chance the initial subflow is picked. With the in-kernel PM, when an endpoint is removed, a RM_ADDR is sent, then linked subflows are closed. This is done for each active MPTCP connection.
MPTCP endpoints are likely removed because the attached network is no longer available or usable. In this case, it is better to avoid sending this RM_ADDR over the subflow that is going to be removed, but prefer sending it over another active and non stale subflow, if any.
This modification avoids situations where the other end is not notified when a subflow is no longer usable: typically when the endpoint linked to the initial subflow is removed, especially on the server side.
--- net/mptcp/pm.c | 2 - net/mptcp/pm_netlink.c | 57 +++++++++++++++++++++++++++++++++++++++---------- net/mptcp/protocol.h | 2 + 3 files changed, 49 insertions(+), 12 deletions(-)
net/mptcp/pm.c +1 -1
@@ -55,7 +55,7 @@ int mptcp_pm_remove_addr(struct mptcp_so msk->pm.rm_list_tx = *rm_list; rm_addr |=BIT (MPTCP_RM_ADDR_SIGNAL );WRITE_ONCE (msk->pm.addr_signal, rm_addr); -mptcp_pm_nl_addr_send_ack (msk); +mptcp_pm_nl_addr_send_ack_avoid_list (msk, rm_list);return 0 ; }
net/mptcp/pm_netlink.c +46 -11
73 lines not on this page · raw message
net/mptcp/protocol.h +2 -0
@@ -753,6 +753,8 @@ void mptcp_pm_add_addr_send_ack(struct mbool mptcp_pm_nl_is_init_remote_addr (struct mptcp_sock *msk,const struct mptcp_addr_info *remote);void mptcp_pm_nl_addr_send_ack (struct mptcp_sock *msk); +void mptcp_pm_nl_addr_send_ack_avoid_list (struct mptcp_sock *msk, +const struct mptcp_rm_list *rm_list);void mptcp_pm_rm_addr_received (struct mptcp_sock *msk,const struct mptcp_rm_list *rm_list);void mptcp_pm_mp_prio_received (struct sock *sk,u8 bkup);
Greg Kroah-Hartman
maintainerPATCH 240/570 pmdomain: bcm: bcm2835-power: Increase ASB control timeout
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maíra Canal <[email protected]>
[ Upstream commit b826d2c0b0ecb844c84431ba6b502e744f5d919a ]
The bcm2835_asb_control() function uses a tight polling loop to wait for the ASB bridge to acknowledge a request. During intensive workloads, this handshake intermittently fails for V3D's master ASB on BCM2711, resulting in "Failed to disable ASB master for v3d" errors during runtime PM suspend. As a consequence, the failed power-off leaves V3D in a broken state, leading to bus faults or system hangs on later accesses.
As the timeout is insufficient in some scenarios, increase the polling timeout from 1us to 5us, which is still negligible in the context of a power domain transition. Also, replace the open-coded ktime_get_ns()/ cpu_relax() polling loop with readl_poll_timeout_atomic().
--- drivers/soc/bcm/bcm2835-power.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)
drivers/soc/bcm/bcm2835-power.c +11 -16
@@ -9,6 +9,7 @@#include <linux/clk.h> #include <linux/delay.h> #include <linux/io.h> +#include <linux/iopoll.h> #include <linux/mfd/bcm2835-pm.h> #include <linux/module.h> #include <linux/platform_device.h>
@@ -150,40 +151,34 @@ struct bcm2835_power {static int bcm2835_asb_enable (struct bcm2835_power *power,u32 reg) { -u64 start; +u32 val;if (!reg)return 0 ; - start =ktime_get_ns (); -/* Enable the module's async AXI bridges. */ ASB_WRITE (reg,ASB_READ (reg) & ~ASB_REQ_STOP ); -while (ASB_READ (reg) &ASB_ACK ) { -cpu_relax (); -if (ktime_get_ns () - start >=1000 ) -return -ETIMEDOUT ; - } + +if (readl_poll_timeout_atomic (power->asb + reg, val, + !(val &ASB_ACK ),0 ,5 )) +return -ETIMEDOUT ;return 0 ; }static int bcm2835_asb_disable (struct bcm2835_power *power,u32 reg) { -u64 start; +u32 val;if (!reg)return 0 ; - start =ktime_get_ns (); -/* Enable the module's async AXI bridges. */ ASB_WRITE (reg,ASB_READ (reg) |ASB_REQ_STOP ); -while (!(ASB_READ (reg) &ASB_ACK )) { -cpu_relax (); -if (ktime_get_ns () - start >=1000 ) -return -ETIMEDOUT ; - } + +if (readl_poll_timeout_atomic (power->asb + reg, val, + !!(val &ASB_ACK ),0 ,5 )) +return -ETIMEDOUT ;return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 241/570 batman-adv: avoid OGM aggregation when skb tailroom is insufficient
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Yang <[email protected]>
commit 0d4aef630be9d5f9c1227d07669c26c4383b5ad0 upstream.
When OGM aggregation state is toggled at runtime, an existing forwarded packet may have been allocated with only packet_len bytes, while a later packet can still be selected for aggregation. Appending in this case can hit skb_put overflow conditions.
Reject aggregation when the target skb tailroom cannot accommodate the new packet. The caller then falls back to creating a new forward packet instead of appending.
--- net/batman-adv/bat_iv_ogm.c | 3 +++ 1 file changed, 3 insertions(+)
net/batman-adv/bat_iv_ogm.c +3 -0
@@ -465,6 +465,9 @@ batadv_iv_ogm_can_aggregate(const struct !time_after_eq(aggregation_end_time, forw_packet->send_time))return false; +if (skb_tailroom (forw_packet->skb) < packet_len) +return false; +if (aggregated_bytes >BATADV_MAX_AGGREGATION_BYTES )return false;
Greg Kroah-Hartman
maintainerPATCH 242/570 btrfs: tree-checker: fix misleading root drop_level error message
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: ZhengYuan Huang <[email protected]>
[ Upstream commit fc1cd1f18c34f91e78362f9629ab9fd43b9dcab9 ]
Fix tree-checker error message to report "invalid root drop_level" instead of the misleading "invalid root level".
--- fs/btrfs/tree-checker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-checker.c +1 -1
@@ -1183,7 +1183,7 @@ static int check_root_item(struct extent_buffer *leaf, struct btrfs_key *key, }if (unlikely (btrfs_root_drop_level (&ri) >=BTRFS_MAX_LEVEL )) {generic_err (leaf, slot, -"invalid root level, have %u expect [0, %u]" , +"invalid root drop_level, have %u expect [0, %u]" ,btrfs_root_drop_level (&ri),BTRFS_MAX_LEVEL -1 );return -EUCLEAN ; }
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 243/570 soc: fsl: qbman: fix race condition in qman_destroy_fq
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Richard Genoud <[email protected]>
[ Upstream commit 014077044e874e270ec480515edbc1cadb976cf2 ]
When QMAN_FQ_FLAG_DYNAMIC_FQID is set, there's a race condition between fq_table[fq->idx] state and freeing/allocating from the pool and WARN_ON(fq_table[fq->idx]) in qman_create_fq() gets triggered.
Indeed, we can have:
Thread A Thread B
qman_destroy_fq() qman_create_fq()
qman_release_fqid()
qman_shutdown_fq()
gen_pool_free()
-- At this point, the fqid is available again --
qman_alloc_fqid()
-- so, we can get the just-freed fqid in thread B --
fq->fqid = fqid;
fq->idx = fqid * 2;
WARN_ON(fq_table[fq->idx]);
fq_table[fq->idx] = fq;
fq_table[fq->idx] = NULL;And adding some logs between qman_release_fqid() and fq_table[fq->idx] = NULL makes the WARN_ON() trigger a lot more.
To prevent that, ensure that fq_table[fq->idx] is set to NULL before gen_pool_free() is called by using smp_wmb().
--- drivers/soc/fsl/qbman/qman.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/soc/fsl/qbman/qman.c +22 -2
@@ -1827,6 +1827,8 @@ EXPORT_SYMBOL(qman_create_fq);void qman_destroy_fq (struct qman_fq *fq) { +int leaked; +/* * We don't need to lock the FQ as it is a pre-condition that the FQ be * quiesced. Instead, run some checks.
@@ -1834,11 +1836,29 @@ void qman_destroy_fq(struct qman_fq *fq)switch (fq->state) {case qman_fq_state_parked:case qman_fq_state_oos: -if (fq_isset (fq,QMAN_FQ_FLAG_DYNAMIC_FQID )) -qman_release_fqid (fq->fqid); +/* +* There's a race condition here on releasing the fqid, +* setting the fq_table to NULL, and freeing the fqid. +* To prevent it, this order should be respected: +*/ +if (fq_isset (fq,QMAN_FQ_FLAG_DYNAMIC_FQID )) { + leaked =qman_shutdown_fq (fq->fqid); +if (leaked) +pr_debug ("FQID %d leaked\n" , fq->fqid); + }DPAA_ASSERT (fq_table[fq->idx]); fq_table[fq->idx] =NULL ; + +if (fq_isset (fq,QMAN_FQ_FLAG_DYNAMIC_FQID ) && !leaked) { +/* +* fq_table[fq->idx] should be set to null before +* freeing fq->fqid otherwise it could by allocated by +* qman_alloc_fqid() while still being !NULL +*/ +smp_wmb (); +gen_pool_free (qm_fqalloc, fq->fqid |DPAA_GENALLOC_OFF ,1 ); + }return ;default :break ;
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 244/570 wifi: mac80211: Fix static_branch_dec() underflow for aql_disable.
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit b94ae8e0d5fe1bdbbfdc3854ff6ce98f6876a828 ]
syzbot reported static_branch_dec() underflow in aql_enable_write(). [0]
The problem is that aql_enable_write() does not serialise concurrent write()s to the debugfs.
aql_enable_write() checks static_key_false(&aql_disable.key) and later calls static_branch_inc() or static_branch_dec(), but the state may change between the two calls.
aql_disable does not need to track inc/dec.
Let's use static_branch_enable() and static_branch_disable().
[0]:
val == 0
WARNING: kernel/jump_label.c:311 at __static_key_slow_dec_cpuslocked.part.0+0x107/0x120 kernel/jump_label.c:311, CPU#0: syz.1.3155/20288 Modules linked in: CPU: 0 UID: 0 PID: 20288 Comm: syz.1.3155 Tainted: G U L syzkaller #0 PREEMPT(full) Tainted: [U]=USER, [L]=SOFTLOCKUP Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/24/2026 RIP: 0010:__static_key_slow_dec_cpuslocked.part.0+0x107/0x120 kernel/jump_label.c:311 Code: f2 c9 ff 5b 5d c3 cc cc cc cc e8 54 f2 c9 ff 48 89 df e8 ac f9 ff ff eb ad e8 45 f2 c9 ff 90 0f 0b 90 eb a2 e8 3a f2 c9 ff 90 <0f> 0b 90 eb 97 48 89 df e8 5c 4b 33 00 e9 36 ff ff ff 0f 1f 80 00 RSP: 0018:ffffc9000b9f7c10 EFLAGS: 00010293 RAX: 0000000000000000 RBX: ffffffff9b3e5d40 RCX: ffffffff823c57b4 RDX: ffff8880285a0000 RSI: ffffffff823c5846 RDI: ffff8880285a0000 RBP: 0000000000000000 R08: 0000000000000005 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000000 R12: 000000000000000a R13: 1ffff9200173ef88 R14: 0000000000000001 R15: ffffc9000b9f7e98 FS: 00007f530dd726c0(0000) GS:ffff8881245e3000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000200000001140 CR3: 000000007cc4a000 CR4: 00000000003526f0 Call Trace: <TASK> __static_key_slow_dec_cpuslocked kernel/jump_label.c:297 [inline] __static_key_slow_dec kernel/jump_label.c:321 [inline] static_key_slow_dec+0x7c/0xc0 kernel/jump_label.c:336 aql_enable_write+0x2b2/0x310 net/mac80211/debugfs.c:343 short_proxy_write+0x133/0x1a0 fs/debugfs/file.c:383 vfs_write+0x2aa/0x1070 fs/read_write.c:684 ksys_pwrite64 fs/read_write.c:793 [inline] __do_sys_pwrite64 fs/read_write.c:801 [inline] __se_sys_pwrite64 fs/read_write.c:798 [inline] __x64_sys_pwrite64+0x1eb/0x250 fs/read_write.c:798 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xc9/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f530cf9aeb9 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f530dd72028 EFLAGS: 00000246 ORIG_RAX: 0000000000000012 RAX: ffffffffffffffda RBX: 00007f530d215fa0 RCX: 00007f530cf9aeb9 RDX: 0000000000000003 RSI: 0000000000000000 RDI: 0000000000000010 RBP: 00007f530d008c1f R08: 0000000000000000 R09: 0000000000000000 R10: 4200000000000005 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f530d216038 R14: 00007f530d215fa0 R15: 00007ffde89fb978 </TASK>
--- net/mac80211/debugfs.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
net/mac80211/debugfs.c +5 -9
@@ -296,7 +296,6 @@ static ssize_t aql_enable_read(struct file *file, char __user *user_buf,static ssize_t aql_enable_write (struct file *file,const char __user *user_buf,size_t count,loff_t *ppos) { -bool aql_disabled =static_key_false (&aql_disable.key);char buf[3 ];size_t len;
@@ -311,15 +310,12 @@ static ssize_t aql_enable_write(struct file *file, const char __user *user_buf,if (len >0 && buf[len -1 ] =='\n' ) buf[len -1 ] =0 ; -if (buf[0 ] =='0' && buf[1 ] =='\0' ) { -if (!aql_disabled) -static_branch_inc (&aql_disable); - }else if (buf[0 ] =='1' && buf[1 ] =='\0' ) { -if (aql_disabled) -static_branch_dec (&aql_disable); - }else { +if (buf[0 ] =='0' && buf[1 ] =='\0' ) +static_branch_enable (&aql_disable); +else if (buf[0 ] =='1' && buf[1 ] =='\0' ) +static_branch_disable (&aql_disable); +else return -EINVAL ; - }return count; }
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 245/570 wifi: cfg80211: cancel pmsr_free_wk in cfg80211_pmsr_wdev_down
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peddolla Harshavardhan Reddy <[email protected]>
[ Upstream commit 6dccbc9f3e1d38565dff7730d2b7d1e8b16c9b09 ]
When the nl80211 socket that originated a PMSR request is closed, cfg80211_release_pmsr() sets the request's nl_portid to zero and schedules pmsr_free_wk to process the abort asynchronously. If the interface is concurrently torn down before that work runs, cfg80211_pmsr_wdev_down() calls cfg80211_pmsr_process_abort() directly. However, the already- scheduled pmsr_free_wk work item remains pending and may run after the interface has been removed from the driver. This could cause the driver's abort_pmsr callback to operate on a torn-down interface, leading to undefined behavior and potential crashes.
Cancel pmsr_free_wk synchronously in cfg80211_pmsr_wdev_down() before calling cfg80211_pmsr_process_abort(). This ensures any pending or in-progress work is drained before interface teardown proceeds, preventing the work from invoking the driver abort callback after the interface is gone.
--- net/wireless/pmsr.c | 1 + 1 file changed, 1 insertion(+)
net/wireless/pmsr.c +1 -0
@@ -642,6 +642,7 @@ void cfg80211_pmsr_wdev_down(struct wireless_dev *wdev) }spin_unlock_bh (&wdev->pmsr_lock); +cancel_work_sync (&wdev->pmsr_free_wk);if (found)cfg80211_pmsr_process_abort (wdev);
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 246/570 of: Add cleanup.h based auto release via __free(device_node) markings
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jonathan Cameron <[email protected]>
[ Upstream commit 9448e55d032d99af8e23487f51a542d51b2f1a48 ]
The recent addition of scope based cleanup support to the kernel provides a convenient tool to reduce the chances of leaking reference counts where of_node_put() should have been called in an error path.
This enables
struct device_node *child __free(device_node) = NULL;
for_each_child_of_node(np, child) {
if (test)
return test;
}with no need for a manual call of of_node_put().
A following patch will reduce the scope of the child variable to the for loop, to avoid an issues with ordering of autocleanup, and make it obvious when this assigned a non NULL value.
In this simple example the gains are small but there are some very complex error handling cases buried in these loops that will be greatly simplified by enabling early returns with out the need for this manual of_node_put() call.
Note that there are coccinelle checks in scripts/coccinelle/iterators/for_each_child.cocci to detect a failure to call of_node_put(). This new approach does not cause false positives. Longer term we may want to add scripting to check this new approach is done correctly with no double of_node_put() calls being introduced due to the auto cleanup. It may also be useful to script finding places this new approach is useful.
Stable-dep-of: 879c001afbac ("firmware: arm_scpi: Fix device_node reference leak in probe path")
--- include/linux/of.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/of.h +2 -0
@@ -13,6 +13,7 @@*/ #include <linux/types.h> #include <linux/bitops.h> +#include <linux/cleanup.h> #include <linux/errno.h> #include <linux/kobject.h> #include <linux/mod_devicetable.h>
@@ -128,6 +129,7 @@ static inline struct device_node *of_node_get(struct device_node *node) }static inline void of_node_put (struct device_node *node) { }#endif /* !CONFIG_OF_DYNAMIC */ +DEFINE_FREE(device_node, struct device_node *, if (_T) of_node_put(_T)) /* Pointer for first entry in chain of all nodes. */extern struct device_node *of_root;
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 247/570 firmware: arm_scpi: Fix device_node reference leak in probe path
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Gu <[email protected]>
[ Upstream commit 879c001afbac3df94160334fe5117c0c83b2cf48 ]
A device_node reference obtained from the device tree is not released on all error paths in the arm_scpi probe path. Specifically, a node returned by of_parse_phandle() could be leaked when the probe failed after the node was acquired. The probe function returns early and the shmem reference is not released.
Use __free(device_node) scope-based cleanup to automatically release the reference when the variable goes out of scope.
Message-Id: <[email protected]>
--- drivers/firmware/arm_scpi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/firmware/arm_scpi.c +3 -2
@@ -18,6 +18,7 @@#include <linux/bitmap.h> #include <linux/bitfield.h> +#include <linux/cleanup.h> #include <linux/device.h> #include <linux/err.h> #include <linux/export.h>
@@ -945,13 +946,13 @@ static int scpi_probe(struct platform_device *pdev)int idx = scpi_drvinfo->num_chans;struct scpi_chan *pchan = scpi_drvinfo->channels + idx;struct mbox_client *cl = &pchan->cl; -struct device_node *shmem =of_parse_phandle (np,"shmem" , idx); + struct device_node *shmem __free(device_node) = +of_parse_phandle (np,"shmem" , idx);if (!of_match_node (shmem_of_match, shmem))return -ENXIO ; ret =of_address_to_resource (shmem,0 , &res); -of_node_put (shmem);if (ret) {dev_err (dev,"failed to get SCPI payload mem resource\n" );return ret;
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 248/570 Bluetooth: LE L2CAP: Disconnect if received packets SDU exceeds IMTU
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Eggers <[email protected]>
[ Upstream commit e1d9a66889867c232657a9b6f25d451d7c3ab96f ]
Core 6.0, Vol 3, Part A, 3.4.3:
"If the SDU length field value exceeds the receiver's MTU, the receiver shall disconnect the channel..."
This fixes L2CAP/LE/CFC/BV-26-C (running together with 'l2test -r -P 0x0027 -V le_public -I 100').
--- net/bluetooth/l2cap_core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/bluetooth/l2cap_core.c +7 -3
@@ -7629,8 +7629,10 @@ static int l2cap_ecred_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)return -ENOBUFS ; } -if (chan->imtu < skb->len) { -BT_ERR ("Too big LE L2CAP PDU" ); +if (skb->len > chan->imtu) { +BT_ERR ("Too big LE L2CAP PDU: len %u > %u" , skb->len, + chan->imtu); +l2cap_send_disconn_req (chan,ECONNRESET );return -ENOBUFS ; }
@@ -7655,7 +7657,9 @@ static int l2cap_ecred_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb) sdu_len, skb->len, chan->imtu);if (sdu_len > chan->imtu) { -BT_ERR ("Too big LE L2CAP SDU length received" ); +BT_ERR ("Too big LE L2CAP SDU length: len %u > %u" , + skb->len, sdu_len); +l2cap_send_disconn_req (chan,ECONNRESET ); err = -EMSGSIZE ; goto failed; }
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 249/570 Bluetooth: LE L2CAP: Disconnect if sum of payload sizes exceed SDU
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Eggers <[email protected]>
[ Upstream commit b6a2bf43aa37670432843bc73ae2a6288ba4d6f8 ]
Core 6.0, Vol 3, Part A, 3.4.3:
"... If the sum of the payload sizes for the K-frames exceeds the specified SDU length, the receiver shall disconnect the channel."
This fixes L2CAP/LE/CFC/BV-27-C (running together with 'l2test -r -P 0x0027 -V le_public').
--- net/bluetooth/l2cap_core.c | 1 + 1 file changed, 1 insertion(+)
net/bluetooth/l2cap_core.c +1 -0
@@ -7695,6 +7695,7 @@ static int l2cap_ecred_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)if (chan->sdu->len + skb->len > chan->sdu_len) {BT_ERR ("Too much LE L2CAP data received" ); +l2cap_send_disconn_req (chan,ECONNRESET ); err = -EINVAL ; goto failed; }
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 250/570 Bluetooth: SMP: make SM/PER/KDU/BI-04-C happy
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Eggers <[email protected]>
[ Upstream commit 0e4d4dcc1a6e82cc6f9abf32193558efa7e1613d ]
The last test step ("Test with Invalid public key X and Y, all set to 0") expects to get an "DHKEY check failed" instead of "unspecified".
--- net/bluetooth/smp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/smp.c +1 -1
@@ -2737,7 +2737,7 @@ static int smp_cmd_public_key(struct l2cap_conn *conn, struct sk_buff *skb)if (!test_bit (SMP_FLAG_DEBUG_KEY , &smp->flags) && !crypto_memneq (key, smp->local_pk,64 )) {bt_dev_err (hdev,"Remote and local public keys are identical" ); -return SMP_UNSPECIFIED ; +return SMP_DHKEY_CHECK_FAILED ; }memcpy (smp->remote_pk, key,64 );
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 251/570 Bluetooth: HIDP: Fix possible UAF
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luiz Augusto von Dentz <[email protected]>
[ Upstream commit dbf666e4fc9bdd975a61bf682b3f75cb0145eedd ]
This fixes the following trace caused by not dropping l2cap_conn reference when user->remove callback is called:
[ 97.809249] l2cap_conn_free: freeing conn ffff88810a171c00 [ 97.809907] CPU: 1 UID: 0 PID: 1419 Comm: repro_standalon Not tainted 7.0.0-rc1-dirty #14 PREEMPT(lazy) [ 97.809935] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1 04/01/2014 [ 97.809947] Call Trace: [ 97.809954] <TASK> [ 97.809961] dump_stack_lvl (lib/dump_stack.c:122) [ 97.809990] l2cap_conn_free (net/bluetooth/l2cap_core.c:1808) [ 97.810017] l2cap_conn_del (./include/linux/kref.h:66 net/bluetooth/l2cap_core.c:1821 net/bluetooth/l2cap_core.c:1798) [ 97.810055] l2cap_disconn_cfm (net/bluetooth/l2cap_core.c:7347 (discriminator 1) net/bluetooth/l2cap_core.c:7340 (discriminator 1)) [ 97.810086] ? __pfx_l2cap_disconn_cfm (net/bluetooth/l2cap_core.c:7341) [ 97.810117] hci_conn_hash_flush (./include/net/bluetooth/hci_core.h:2152 (discriminator 2) net/bluetooth/hci_conn.c:2644 (discriminator 2)) [ 97.810148] hci_dev_close_sync (net/bluetooth/hci_sync.c:5360) [ 97.810180] ? __pfx_hci_dev_close_sync (net/bluetooth/hci_sync.c:5285) [ 97.810212] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 97.810242] ? up_write (./arch/x86/include/asm/atomic64_64.h:87 (discriminator 5) ./include/linux/atomic/atomic-arch-fallback.h:2852 (discriminator 5) ./include/linux/atomic/atomic-long.h:268 (discriminator 5) ./include/linux/atomic/atomic-instrumented.h:3391 (discriminator 5) kernel/locking/rwsem.c:1385 (discriminator 5) kernel/locking/rwsem.c:1643 (discriminator 5)) [ 97.810267] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 97.810290] ? rcu_is_watching (./arch/x86/include/asm/atomic.h:23 ./include/linux/atomic/atomic-arch-fallback.h:457 ./include/linux/context_tracking.h:128 kernel/rcu/tree.c:752) [ 97.810320] hci_unregister_dev (net/bluetooth/hci_core.c:504 net/bluetooth/hci_core.c:2716) [ 97.810346] vhci_release (drivers/bluetooth/hci_vhci.c:691) [ 97.810375] ? __pfx_vhci_release (drivers/bluetooth/hci_vhci.c:678) [ 97.810404] __fput (fs/file_table.c:470) [ 97.810430] task_work_run (kernel/task_work.c:235) [ 97.810451] ? __pfx_task_work_run (kernel/task_work.c:201) [ 97.810472] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 97.810495] ? do_raw_spin_unlock (./include/asm-generic/qspinlock.h:128 (discriminator 5) kernel/locking/spinlock_debug.c:142 (discriminator 5)) [ 97.810527] do_exit (kernel/exit.c:972) [ 97.810547] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 97.810574] ? __pfx_do_exit (kernel/exit.c:897) [ 97.810594] ? lock_acquire (kernel/locking/lockdep.c:470 (discriminator 6) kernel/locking/lockdep.c:5870 (discriminator 6) kernel/locking/lockdep.c:5825 (discriminator 6)) [ 97.810616] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 97.810639] ? do_raw_spin_lock (kernel/locking/spinlock_debug.c:95 (discriminator 4) kernel/locking/spinlock_debug.c:118 (discriminator 4)) [ 97.810664] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 97.810688] ? find_held_lock (kernel/locking/lockdep.c:5350 (discriminator 1)) [ 97.810721] do_group_exit (kernel/exit.c:1093) [ 97.810745] get_signal (kernel/signal.c:3007 (discriminator 1)) [ 97.810772] ? security_file_permission (./arch/x86/include/asm/jump_label.h:37 security/security.c:2366) [ 97.810803] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 97.810826] ? vfs_read (fs/read_write.c:555) [ 97.810854] ? __pfx_get_signal (kernel/signal.c:2800) [ 97.810880] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 97.810905] ? __pfx_vfs_read (fs/read_write.c:555) [ 97.810932] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 97.810960] arch_do_signal_or_restart (arch/x86/kernel/signal.c:337 (discriminator 1)) [ 97.810990] ? __pfx_arch_do_signal_or_restart (arch/x86/kernel/signal.c:334) [ 97.811021] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 97.811055] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 97.811078] ? ksys_read (fs/read_write.c:707) [ 97.811106] ? __pfx_ksys_read (fs/read_write.c:707) [ 97.811137] exit_to_user_mode_loop (kernel/entry/common.c:66 kernel/entry/common.c:98) [ 97.811169] ? rcu_is_watching (./arch/x86/include/asm/atomic.h:23 ./include/linux/atomic/atomic-arch-fallback.h:457 ./include/linux/context_tracking.h:128 kernel/rcu/tree.c:752) [ 97.811192] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 97.811215] ? trace_hardirqs_off (./include/trace/events/preemptirq.h:36 (discriminator 33) kernel/trace/trace_preemptirq.c:95 (discriminator 33) kernel/trace/trace_preemptirq.c:90 (discriminator 33)) [ 97.811240] do_syscall_64 (./include/linux/irq-entry-common.h:226 ./include/linux/irq-entry-common.h:256 ./include/linux/entry-common.h:325 arch/x86/entry/syscall_64.c:100) [ 97.811268] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 97.811292] ? exc_page_fault (arch/x86/mm/fault.c:1480 (discriminator 3) arch/x86/mm/fault.c:1527 (discriminator 3)) [ 97.811318] entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130) [ 97.811338] RIP: 0033:0x445cfe [ 97.811352] Code: Unable to access opcode bytes at 0x445cd4.
Code starting with the faulting instruction
===========================================
[ 97.811360] RSP: 002b:00007f65c41c6dc8 EFLAGS: 00000246 ORIG_RAX: 0000000000000000 [ 97.811378] RAX: fffffffffffffe00 RBX: 00007f65c41c76c0 RCX: 0000000000445cfe [ 97.811391] RDX: 0000000000000400 RSI: 00007f65c41c6e40 RDI: 0000000000000004 [ 97.811403] RBP: 00007f65c41c7250 R08: 0000000000000000 R09: 0000000000000000 [ 97.811415] R10: 0000000000000000 R11: 0000000000000246 R12: ffffffffffffffe8 [ 97.811428] R13: 0000000000000000 R14: 00007fff780a8c00 R15: 00007f65c41c76c0 [ 97.811453] </TASK> [ 98.402453] ================================================================== [ 98.403560] BUG: KASAN: use-after-free in __mutex_lock (kernel/locking/mutex.c:199 kernel/locking/mutex.c:694 kernel/locking/mutex.c:776) [ 98.404541] Read of size 8 at addr ffff888113ee40a8 by task khidpd_00050004/1430 [ 98.405361] [ 98.405563] CPU: 1 UID: 0 PID: 1430 Comm: khidpd_00050004 Not tainted 7.0.0-rc1-dirty #14 PREEMPT(lazy) [ 98.405588] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1 04/01/2014 [ 98.405600] Call Trace: [ 98.405607] <TASK> [ 98.405614] dump_stack_lvl (lib/dump_stack.c:122) [ 98.405641] print_report (mm/kasan/report.c:379 mm/kasan/report.c:482) [ 98.405667] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.405691] ? __virt_addr_valid (arch/x86/mm/physaddr.c:55) [ 98.405724] ? __mutex_lock (kernel/locking/mutex.c:199 kernel/locking/mutex.c:694 kernel/locking/mutex.c:776) [ 98.405748] kasan_report (mm/kasan/report.c:221 mm/kasan/report.c:597) [ 98.405778] ? __mutex_lock (kernel/locking/mutex.c:199 kernel/locking/mutex.c:694 kernel/locking/mutex.c:776) [ 98.405807] __mutex_lock (kernel/locking/mutex.c:199 kernel/locking/mutex.c:694 kernel/locking/mutex.c:776) [ 98.405832] ? do_raw_spin_lock (kernel/locking/spinlock_debug.c:95 (discriminator 4) kernel/locking/spinlock_debug.c:118 (discriminator 4)) [ 98.405859] ? l2cap_unregister_user (./include/linux/list.h:381 (discriminator 2) net/bluetooth/l2cap_core.c:1723 (discriminator 2)) [ 98.405888] ? __pfx_do_raw_spin_lock (kernel/locking/spinlock_debug.c:114) [ 98.405915] ? __pfx___mutex_lock (kernel/locking/mutex.c:775) [ 98.405939] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.405963] ? lock_acquire (kernel/locking/lockdep.c:470 (discriminator 6) kernel/locking/lockdep.c:5870 (discriminator 6) kernel/locking/lockdep.c:5825 (discriminator 6)) [ 98.405984] ? find_held_lock (kernel/locking/lockdep.c:5350 (discriminator 1)) [ 98.406015] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.406038] ? lock_release (kernel/locking/lockdep.c:5536 kernel/locking/lockdep.c:5889 kernel/locking/lockdep.c:5875) [ 98.406061] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.406085] ? _raw_spin_unlock_irqrestore (./arch/x86/include/asm/irqflags.h:42 ./arch/x86/include/asm/irqflags.h:119 ./arch/x86/include/asm/irqflags.h:159 ./include/linux/spinlock_api_smp.h:178 kernel/locking/spinlock.c:194) [ 98.406107] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.406130] ? __timer_delete_sync (kernel/time/timer.c:1592) [ 98.406158] ? l2cap_unregister_user (./include/linux/list.h:381 (discriminator 2) net/bluetooth/l2cap_core.c:1723 (discriminator 2)) [ 98.406186] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.406210] l2cap_unregister_user (./include/linux/list.h:381 (discriminator 2) net/bluetooth/l2cap_core.c:1723 (discriminator 2)) [ 98.406263] hidp_session_thread (./include/linux/instrumented.h:112 ./include/linux/atomic/atomic-instrumented.h:400 ./include/linux/refcount.h:389 ./include/linux/refcount.h:432 ./include/linux/refcount.h:450 ./include/linux/kref.h:64 net/bluetooth/hidp/core.c:996 net/bluetooth/hidp/core.c:1305) [ 98.406293] ? __pfx_hidp_session_thread (net/bluetooth/hidp/core.c:1264) [ 98.406323] ? kthread (kernel/kthread.c:433) [ 98.406340] ? __pfx_hidp_session_wake_function (net/bluetooth/hidp/core.c:1251) [ 98.406370] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.406393] ? find_held_lock (kernel/locking/lockdep.c:5350 (discriminator 1)) [ 98.406424] ? __pfx_hidp_session_wake_function (net/bluetooth/hidp/core.c:1251) [ 98.406453] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.406476] ? trace_hardirqs_on (kernel/trace/trace_preemptirq.c:79 (discriminator 1)) [ 98.406499] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.406523] ? kthread (kernel/kthread.c:433) [ 98.406539] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.406565] ? kthread (kernel/kthread.c:433) [ 98.406581] ? __pfx_hidp_session_thread (net/bluetooth/hidp/core.c:1264) [ 98.406610] kthread (kernel/kthread.c:467) [ 98.406627] ? __pfx_kthread (kernel/kthread.c:412) [ 98.406645] ret_from_fork (arch/x86/kernel/process.c:164) [ 98.406674] ? __pfx_ret_from_fork (arch/x86/kernel/process.c:153) [ 98.406704] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.406728] ? __pfx_kthread (kernel/kthread.c:412) [ 98.406747] ret_from_fork_asm (arch/x86/entry/entry_64.S:258) [ 98.406774] </TASK> [ 98.406780] [ 98.433693] The buggy address belongs to the physical page: [ 98.434405] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff888113ee7c40 pfn:0x113ee4 [ 98.435557] flags: 0x200000000000000(node=0|zone=2) [ 98.436198] raw: 0200000000000000 ffffea0004244308 ffff8881f6f3ebc0 0000000000000000 [ 98.437195] raw: ffff888113ee7c40 0000000000000000 00000000ffffffff 0000000000000000 [ 98.438115] page dumped because: kasan: bad access detected [ 98.438951] [ 98.439211] Memory state around the buggy address: [ 98.439871] ffff888113ee3f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc [ 98.440714] ffff888113ee4000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff [ 98.441580] >ffff888113ee4080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff [ 98.442458] ^ [ 98.443011] ffff888113ee4100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff [ 98.443889] ffff888113ee4180: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff [ 98.444768] ================================================================== [ 98.445719] Disabling lock debugging due to kernel taint [ 98.448074] l2cap_conn_free: freeing conn ffff88810c22b400 [ 98.450012] CPU: 1 UID: 0 PID: 1430 Comm: khidpd_00050004 Tainted: G B 7.0.0-rc1-dirty #14 PREEMPT(lazy) [ 98.450040] Tainted: [B]=BAD_PAGE [ 98.450047] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1 04/01/2014 [ 98.450059] Call Trace: [ 98.450065] <TASK> [ 98.450071] dump_stack_lvl (lib/dump_stack.c:122) [ 98.450099] l2cap_conn_free (net/bluetooth/l2cap_core.c:1808) [ 98.450125] l2cap_conn_put (net/bluetooth/l2cap_core.c:1822) [ 98.450154] session_free (net/bluetooth/hidp/core.c:990) [ 98.450181] hidp_session_thread (net/bluetooth/hidp/core.c:1307) [ 98.450213] ? __pfx_hidp_session_thread (net/bluetooth/hidp/core.c:1264) [ 98.450271] ? kthread (kernel/kthread.c:433) [ 98.450293] ? __pfx_hidp_session_wake_function (net/bluetooth/hidp/core.c:1251) [ 98.450339] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.450368] ? find_held_lock (kernel/locking/lockdep.c:5350 (discriminator 1)) [ 98.450406] ? __pfx_hidp_session_wake_function (net/bluetooth/hidp/core.c:1251) [ 98.450442] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.450471] ? trace_hardirqs_on (kernel/trace/trace_preemptirq.c:79 (discriminator 1)) [ 98.450499] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.450528] ? kthread (kernel/kthread.c:433) [ 98.450547] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.450578] ? kthread (kernel/kthread.c:433) [ 98.450598] ? __pfx_hidp_session_thread (net/bluetooth/hidp/core.c:1264) [ 98.450637] kthread (kernel/kthread.c:467) [ 98.450657] ? __pfx_kthread (kernel/kthread.c:412) [ 98.450680] ret_from_fork (arch/x86/kernel/process.c:164) [ 98.450715] ? __pfx_ret_from_fork (arch/x86/kernel/process.c:153) [ 98.450752] ? srso_alias_return_thunk (arch/x86/lib/retpoline.S:221) [ 98.450782] ? __pfx_kthread (kernel/kthread.c:412) [ 98.450804] ret_from_fork_asm (arch/x86/entry/entry_64.S:258) [ 98.450836] </TASK>
--- net/bluetooth/hidp/core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
net/bluetooth/hidp/core.c +14 -2
@@ -987,7 +987,8 @@ static void session_free(struct kref *ref)skb_queue_purge (&session->intr_transmit);fput (session->intr_sock->file);fput (session->ctrl_sock->file); -l2cap_conn_put (session->conn); +if (session->conn) +l2cap_conn_put (session->conn);kfree (session); }
@@ -1165,6 +1166,15 @@ static void hidp_session_remove(struct l2cap_conn *conn,down_write (&hidp_session_sem); +/* Drop L2CAP reference immediately to indicate that +* l2cap_unregister_user() shall not be called as it is already +* considered removed. +*/ +if (session->conn) { +l2cap_conn_put (session->conn); + session->conn =NULL ; + } +hidp_session_terminate (session);cancel_work_sync (&session->dev_init);
@@ -1302,7 +1312,9 @@ static int hidp_session_thread(void *arg)* Instead, this call has the same semantics as if user-space tried to * delete the session. */ -l2cap_unregister_user (session->conn, &session->user); +if (session->conn) +l2cap_unregister_user (session->conn, &session->user); +hidp_session_put (session);module_put_and_kthread_exit (0 );
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 252/570 Bluetooth: qca: fix ROM version reading on WCN3998 chips
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Baryshkov <[email protected]>
[ Upstream commit 99b2c531e0e797119ae1b9195a8764ee98b00e65 ]
WCN3998 uses a bit different format for rom version:
[ 5.479978] Bluetooth: hci0: setting up wcn399x [ 5.633763] Bluetooth: hci0: QCA Product ID :0x0000000a [ 5.645350] Bluetooth: hci0: QCA SOC Version :0x40010224 [ 5.650906] Bluetooth: hci0: QCA ROM Version :0x00001001 [ 5.665173] Bluetooth: hci0: QCA Patch Version:0x00006699 [ 5.679356] Bluetooth: hci0: QCA controller version 0x02241001 [ 5.691109] Bluetooth: hci0: QCA Downloading qca/crbtfw21.tlv [ 6.680102] Bluetooth: hci0: QCA Downloading qca/crnv21.bin [ 6.842948] Bluetooth: hci0: QCA setup on UART is completed
--- drivers/bluetooth/btqca.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/bluetooth/btqca.c +2 -0
@@ -677,6 +677,8 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,*/ if (soc_type ==QCA_WCN3988 ) rom_ver = ((soc_ver &0x00000f00 ) >>0x05 ) | (soc_ver &0x0000000f ); +else if (soc_type ==QCA_WCN3998 ) + rom_ver = ((soc_ver &0x0000f000 ) >>0x07 ) | (soc_ver &0x0000000f );else rom_ver = ((soc_ver &0x00000f00 ) >>0x04 ) | (soc_ver &0x0000000f );
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 253/570 net/rose: fix NULL pointer dereference in rose_transmit_link on reconnect
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit e1f0a18c9564cdb16523c802e2c6fe5874e3d944 ]
syzkaller reported a bug [1], and the reproducer is available at [2].
ROSE sockets use four sk->sk_state values: TCP_CLOSE, TCP_LISTEN, TCP_SYN_SENT, and TCP_ESTABLISHED. rose_connect() already rejects calls for TCP_ESTABLISHED (-EISCONN) and TCP_CLOSE with SS_CONNECTING (-ECONNREFUSED), but lacks a check for TCP_SYN_SENT.
When rose_connect() is called a second time while the first connection attempt is still in progress (TCP_SYN_SENT), it overwrites rose->neighbour via rose_get_neigh(). If that returns NULL, the socket is left with rose->state == ROSE_STATE_1 but rose->neighbour == NULL. When the socket is subsequently closed, rose_release() sees ROSE_STATE_1 and calls rose_write_internal() -> rose_transmit_link(skb, NULL), causing a NULL pointer dereference.
Per connect(2), a second connect() while a connection is already in progress should return -EALREADY. Add this missing check for TCP_SYN_SENT to complete the state validation in rose_connect().
[1] https://syzkaller.appspot.com/bug?extid=d00f90e0af54102fb271
[2] https://gist.github.com/mrpre/9e6779e0d13e2c66779b1653fef80516
--- net/rose/af_rose.c | 5 +++++ 1 file changed, 5 insertions(+)
net/rose/af_rose.c +5 -0
@@ -808,6 +808,11 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_le goto out_release; } +if (sk->sk_state ==TCP_SYN_SENT ) { + err = -EALREADY ; + goto out_release; + } + sk->sk_state =TCP_CLOSE ; sock->state =SS_UNCONNECTED ;
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 254/570 netfilter: ctnetlink: remove refcounting in expectation dumpers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 1492e3dcb2be3aa46d1963da96aa9593e4e4db5a ]
Same pattern as previous patch: do not keep the expectation object alive via refcount, only store a cookie value and then use that as the skip hint for dump resumption.
AFAICS this has the same issue as the one resolved in the conntrack dumper, when we do
if (!refcount_inc_not_zero(&exp->use))
to increment the refcount, there is a chance that exp == last, which causes a double-increment of the refcount and subsequent memory leak.
Stable-dep-of: 5cb81eeda909 ("netfilter: ctnetlink: fix use-after-free in ctnetlink_dump_exp_ct()")
--- net/netfilter/nf_conntrack_netlink.c | 41 ++++++++++++---------------- 1 file changed, 17 insertions(+), 24 deletions(-)
net/netfilter/nf_conntrack_netlink.c +17 -24
@@ -3160,23 +3160,27 @@ ctnetlink_expect_event(unsigned int events, const struct nf_exp_event *item)return 0 ; }#endif -static int ctnetlink_exp_done (struct netlink_callback *cb) + +static unsigned long ctnetlink_exp_id (const struct nf_conntrack_expect *exp) { -if (cb->args[1 ]) -nf_ct_expect_put ((struct nf_conntrack_expect *)cb->args[1 ]); -return 0 ; +unsigned long id = (unsigned long )exp; + + id +=nf_ct_get_id (exp->master); + id += exp->class; + +return id ? id :1 ; }static int ctnetlink_exp_dump_table (struct sk_buff *skb,struct netlink_callback *cb) {struct net *net =sock_net (skb->sk); -struct nf_conntrack_expect *exp, *last;struct nfgenmsg *nfmsg =nlmsg_data (cb->nlh);u_int8_t l3proto = nfmsg->nfgen_family; +unsigned long last_id = cb->args[1 ]; +struct nf_conntrack_expect *exp;rcu_read_lock (); - last = (struct nf_conntrack_expect *)cb->args[1 ];for (; cb->args[0 ] < nf_ct_expect_hsize; cb->args[0 ]++) { restart: hlist_for_each_entry_rcu(exp, &nf_ct_expect_hash[cb->args[0]],
@@ -3188,7 +3192,7 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb)continue ;if (cb->args[1 ]) { -if (exp != last) +if (ctnetlink_exp_id (exp) != last_id)continue ; cb->args[1 ] =0 ; }
@@ -3197,9 +3201,7 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb) cb->nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW, exp) < 0) { -if (!refcount_inc_not_zero (&exp->use)) -continue ; - cb->args[1 ] = (unsigned long )exp; + cb->args[1 ] =ctnetlink_exp_id (exp); goto out; } }
@@ -3210,32 +3212,30 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb) } out:rcu_read_unlock (); -if (last) -nf_ct_expect_put (last); -return skb->len; }static int ctnetlink_exp_ct_dump_table (struct sk_buff *skb,struct netlink_callback *cb) { -struct nf_conntrack_expect *exp, *last;struct nfgenmsg *nfmsg =nlmsg_data (cb->nlh);struct nf_conn *ct = cb->data;struct nf_conn_help *help =nfct_help (ct);u_int8_t l3proto = nfmsg->nfgen_family; +unsigned long last_id = cb->args[1 ]; +struct nf_conntrack_expect *exp;if (cb->args[0 ])return 0 ;rcu_read_lock (); - last = (struct nf_conntrack_expect *)cb->args[1 ]; + restart:hlist_for_each_entry_rcu (exp, &help->expectations, lnode) {if (l3proto && exp->tuple.src.l3num != l3proto)continue ;if (cb->args[1 ]) { -if (exp != last) +if (ctnetlink_exp_id (exp) != last_id)continue ; cb->args[1 ] =0 ; }
@@ -3243,9 +3243,7 @@ ctnetlink_exp_ct_dump_table(struct sk_buff *skb, struct netlink_callback *cb) cb->nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW, exp) < 0) { -if (!refcount_inc_not_zero (&exp->use)) -continue ; - cb->args[1 ] = (unsigned long )exp; + cb->args[1 ] =ctnetlink_exp_id (exp); goto out; } }
@@ -3256,9 +3254,6 @@ ctnetlink_exp_ct_dump_table(struct sk_buff *skb, struct netlink_callback *cb) cb->args[0 ] =1 ; out:rcu_read_unlock (); -if (last) -nf_ct_expect_put (last); -return skb->len; }
@@ -3277,7 +3272,6 @@ static int ctnetlink_dump_exp_ct(struct net *net, struct sock *ctnl,struct nf_conntrack_zone zone;struct netlink_dump_control c = { .dump = ctnetlink_exp_ct_dump_table, - .done = ctnetlink_exp_done, }; err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER,
@@ -3327,7 +3321,6 @@ static int ctnetlink_get_expect(struct sk_buff *skb,else {struct netlink_dump_control c = { .dump = ctnetlink_exp_dump_table, - .done = ctnetlink_exp_done, };return netlink_dump_start (info->sk, skb, info->nlh, &c); }
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 255/570 netfilter: ctnetlink: fix use-after-free in ctnetlink_dump_exp_ct()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyunwoo Kim <[email protected]>
[ Upstream commit 5cb81eeda909dbb2def209dd10636b51549a3f8a ]
ctnetlink_dump_exp_ct() stores a conntrack pointer in cb->data for the netlink dump callback ctnetlink_exp_ct_dump_table(), but drops the conntrack reference immediately after netlink_dump_start(). When the dump spans multiple rounds, the second recvmsg() triggers the dump callback which dereferences the now-freed conntrack via nfct_help(ct), leading to a use-after-free on ct->ext.
The bug is that the netlink_dump_control has no .start or .done callbacks to manage the conntrack reference across dump rounds. Other dump functions in the same file (e.g. ctnetlink_get_conntrack) properly use .start/.done callbacks for this purpose.
Fix this by adding .start and .done callbacks that hold and release the conntrack reference for the duration of the dump, and move the nfct_help() call after the cb->args[0] early-return check in the dump callback to avoid dereferencing ct->ext unnecessarily.
BUG: KASAN: slab-use-after-free in ctnetlink_exp_ct_dump_table+0x4f/0x2e0 Read of size 8 at addr ffff88810597ebf0 by task ctnetlink_poc/133 CPU: 1 UID: 0 PID: 133 Comm: ctnetlink_poc Not tainted 7.0.0-rc2+ #3 PREEMPTLAZY Call Trace: <TASK> ctnetlink_exp_ct_dump_table+0x4f/0x2e0 netlink_dump+0x333/0x880 netlink_recvmsg+0x3e2/0x4b0 ? aa_sk_perm+0x184/0x450 sock_recvmsg+0xde/0xf0 Allocated by task 133: kmem_cache_alloc_noprof+0x134/0x440 __nf_conntrack_alloc+0xa8/0x2b0 ctnetlink_create_conntrack+0xa1/0x900 ctnetlink_new_conntrack+0x3cf/0x7d0 nfnetlink_rcv_msg+0x48e/0x510 netlink_rcv_skb+0xc9/0x1f0 nfnetlink_rcv+0xdb/0x220 netlink_unicast+0x3ec/0x590 netlink_sendmsg+0x397/0x690 __sys_sendmsg+0xf4/0x180 Freed by task 0: slab_free_after_rcu_debug+0xad/0x1e0 rcu_core+0x5c3/0x9c0
--- net/netfilter/nf_conntrack_netlink.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +25 -1
@@ -3220,7 +3220,7 @@ ctnetlink_exp_ct_dump_table(struct sk_buff *skb, struct netlink_callback *cb) {struct nfgenmsg *nfmsg =nlmsg_data (cb->nlh);struct nf_conn *ct = cb->data; -struct nf_conn_help *help =nfct_help (ct); +struct nf_conn_help *help;u_int8_t l3proto = nfmsg->nfgen_family;unsigned long last_id = cb->args[1 ];struct nf_conntrack_expect *exp;
@@ -3228,6 +3228,10 @@ ctnetlink_exp_ct_dump_table(struct sk_buff *skb, struct netlink_callback *cb)if (cb->args[0 ])return 0 ; + help =nfct_help (ct); +if (!help) +return 0 ; +rcu_read_lock (); restart:
@@ -3257,6 +3261,24 @@ ctnetlink_exp_ct_dump_table(struct sk_buff *skb, struct netlink_callback *cb)return skb->len; } +static int ctnetlink_dump_exp_ct_start (struct netlink_callback *cb) +{ +struct nf_conn *ct = cb->data; + +if (!refcount_inc_not_zero (&ct->ct_general.use)) +return -ENOENT ; +return 0 ; +} + +static int ctnetlink_dump_exp_ct_done (struct netlink_callback *cb) +{ +struct nf_conn *ct = cb->data; + +if (ct) +nf_ct_put (ct); +return 0 ; +} + static int ctnetlink_dump_exp_ct(struct net *net, struct sock *ctnl, struct sk_buff *skb, const struct nlmsghdr *nlh,
@@ -3272,6 +3294,8 @@ static int ctnetlink_dump_exp_ct(struct net *net, struct sock *ctnl,struct nf_conntrack_zone zone;struct netlink_dump_control c = { .dump = ctnetlink_exp_ct_dump_table, + .start = ctnetlink_dump_exp_ct_start, + .done = ctnetlink_dump_exp_ct_done, }; err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER,
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 256/570 netfilter: nf_conntrack_sip: fix Content-Length u32 truncation in sip_help_tcp()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Johannes Möller <[email protected]>
[ Upstream commit fbce58e719a17aa215c724473fd5baaa4a8dc57c ]
sip_help_tcp() parses the SIP Content-Length header with simple_strtoul(), which returns unsigned long, but stores the result in unsigned int clen. On 64-bit systems, values exceeding UINT_MAX are silently truncated before computing the SIP message boundary.
For example, Content-Length 4294967328 (2^32 + 32) is truncated to 32, causing the parser to miscalculate where the current message ends. The loop then treats trailing data in the TCP segment as a second SIP message and processes it through the SDP parser.
Fix this by changing clen to unsigned long to match the return type of simple_strtoul(), and reject Content-Length values that exceed the remaining TCP payload length.
--- net/netfilter/nf_conntrack_sip.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_sip.c +5 -1
@@ -1529,11 +1529,12 @@ static int sip_help_tcp(struct sk_buff *skb, unsigned int protoff, {struct tcphdr *th, _tcph;unsigned int dataoff, datalen; -unsigned int matchoff, matchlen, clen; +unsigned int matchoff, matchlen;unsigned int msglen, origlen;const char *dptr, *end;s16 diff, tdiff =0 ;int ret =NF_ACCEPT ; +unsigned long clen;bool term; if (ctinfo != IP_CT_ESTABLISHED &&
@@ -1568,6 +1569,9 @@ static int sip_help_tcp(struct sk_buff *skb, unsigned int protoff,if (dptr + matchoff == end)break ; +if (clen > datalen) +break ; + term = false;for (; end +strlen ("\r\n\r\n" ) <= dptr + datalen; end++) { if (end[0] == '\r' && end[1] == '\n' &&
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 257/570 netfilter: nf_conntrack_h323: fix OOB read in decode_int() CONS case
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jenny Guanni Qu <[email protected]>
[ Upstream commit 1e3a3593162c96e8a8de48b1e14f60c3b57fca8a ]
In decode_int(), the CONS case calls get_bits(bs, 2) to read a length value, then calls get_uint(bs, len) without checking that len bytes remain in the buffer. The existing boundary check only validates the 2 bits for get_bits(), not the subsequent 1-4 bytes that get_uint() reads. This allows a malformed H.323/RAS packet to cause a 1-4 byte slab-out-of-bounds read.
Add a boundary check for len bytes after get_bits() and before get_uint().
--- net/netfilter/nf_conntrack_h323_asn1.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/nf_conntrack_h323_asn1.c +2 -0
@@ -331,6 +331,8 @@ static int decode_int(struct bitstr *bs, const struct field_t *f,if (nf_h323_error_boundary (bs,0 ,2 ))return H323_ERROR_BOUND ; len =get_bits (bs,2 ) +1 ; +if (nf_h323_error_boundary (bs, len,0 )) +return H323_ERROR_BOUND ;BYTE_ALIGN (bs);if (base && (f->attr &DECODE )) {/* timeToLive */ unsigned int v =get_uint (bs, len) + f->lb;
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 258/570 netfilter: nft_ct: add seqadj extension for natted connections
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrii Melnychenko <[email protected]>
[ Upstream commit 90918e3b6404c2a37837b8f11692471b4c512de2 ]
Sequence adjustment may be required for FTP traffic with PASV/EPSV modes. due to need to re-write packet payload (IP, port) on the ftp control connection. This can require changes to the TCP length and expected seq / ack_seq.
The easiest way to reproduce this issue is with PASV mode. Example ruleset:
table inet ftp_nat {
ct helper ftp_helper {
type "ftp" protocol tcp
l3proto inet
}
chain prerouting {
type filter hook prerouting priority 0; policy accept;
tcp dport 21 ct state new ct helper set "ftp_helper"
}
}
table ip nat {
chain prerouting {
type nat hook prerouting priority -100; policy accept;
tcp dport 21 dnat ip prefix to ip daddr map {
192.168.100.1 : 192.168.13.2/32 }
}
chain postrouting {
type nat hook postrouting priority 100 ; policy accept;
tcp sport 21 snat ip prefix to ip saddr map {
192.168.13.2 : 192.168.100.1/32 }
}
}Note that the ftp helper gets assigned *after* the dnat setup.
The inverse (nat after helper assign) is handled by an existing check in nf_nat_setup_info() and will not show the problem.
Topoloy:
+-------------------+ +----------------------------------+
| FTP: 192.168.13.2 | <-> | NAT: 192.168.13.3, 192.168.100.1 |
+-------------------+ +----------------------------------+
|
+-----------------------+
| Client: 192.168.100.2 |
+-----------------------+ftp nat changes do not work as expected in this case:
Connected to 192.168.100.1.
[..]
ftp> epsv
EPSV/EPRT on IPv4 off.
ftp> ls
227 Entering passive mode (192,168,100,1,209,129). 421 Service not available, remote server has closed connection.
Kernel logs:
Missing nfct_seqadj_ext_add() setup call
WARNING: CPU: 1 PID: 0 at net/netfilter/nf_conntrack_seqadj.c:41 [..] __nf_nat_mangle_tcp_packet+0x100/0x160 [nf_nat] nf_nat_ftp+0x142/0x280 [nf_nat_ftp] help+0x4d1/0x880 [nf_conntrack_ftp] nf_confirm+0x122/0x2e0 [nf_conntrack] nf_hook_slow+0x3c/0xb0 ..
Fix this by adding the required extension when a conntrack helper is assigned to a connection that has a nat binding.
Stable-dep-of: 36eae0956f65 ("netfilter: nft_ct: drop pending enqueued packets on removal")
--- net/netfilter/nft_ct.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nft_ct.c +5 -0
@@ -22,6 +22,7 @@#include <net/netfilter/nf_conntrack_timeout.h> #include <net/netfilter/nf_conntrack_l4proto.h> #include <net/netfilter/nf_conntrack_expect.h> +#include <net/netfilter/nf_conntrack_seqadj.h> struct nft_ct {enum nft_ct_keys key:8 ;
@@ -1109,6 +1110,10 @@ static void nft_ct_helper_obj_eval(struct nft_object *obj,if (help) {rcu_assign_pointer (help->helper, to_assign);set_bit (IPS_HELPER_BIT , &ct->status); + +if ((ct->status &IPS_NAT_MASK ) && !nfct_seqadj (ct)) +if (!nfct_seqadj_ext_add (ct)) + regs->verdict.code =NF_DROP ; } }
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 259/570 netfilter: nft_ct: drop pending enqueued packets on removal
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit 36eae0956f659e48d5366d9b083d9417f3263ddc ]
Packets sitting in nfqueue might hold a reference to:
- templates that specify the conntrack zone, because a percpu area is used and module removal is possible.
- conntrack timeout policies and helper, where object removal leave a stale reference.
Since these objects can just go away, drop enqueued packets to avoid stale reference to them.
If there is a need for finer grain removal, this logic can be revisited to make selective packet drop upon dependencies.
--- net/netfilter/nft_ct.c | 4 ++++ 1 file changed, 4 insertions(+)
net/netfilter/nft_ct.c +4 -0
@@ -23,6 +23,7 @@#include <net/netfilter/nf_conntrack_l4proto.h> #include <net/netfilter/nf_conntrack_expect.h> #include <net/netfilter/nf_conntrack_seqadj.h> +#include "nf_internals.h" struct nft_ct {enum nft_ct_keys key:8 ;
@@ -533,6 +534,7 @@ static void __nft_ct_set_destroy(const struct nft_ctx *ctx, struct nft_ct *priv)#endif #ifdef CONFIG_NF_CONNTRACK_ZONES case NFT_CT_ZONE : +nf_queue_nf_hook_drop (ctx->net);mutex_lock (&nft_ct_pcpu_mutex);if (--nft_ct_pcpu_template_refcnt ==0 )nft_ct_tmpl_put_pcpu ();
@@ -930,6 +932,7 @@ static void nft_ct_timeout_obj_destroy(const struct nft_ctx *ctx,struct nft_ct_timeout_obj *priv =nft_obj_data (obj);struct nf_ct_timeout *timeout = priv->timeout; +nf_queue_nf_hook_drop (ctx->net);nf_ct_untimeout (ctx->net, timeout);nf_ct_netns_put (ctx->net, ctx->family);kfree (priv->timeout);
@@ -1065,6 +1068,7 @@ static void nft_ct_helper_obj_destroy(const struct nft_ctx *ctx, {struct nft_ct_helper_obj *priv =nft_obj_data (obj); +nf_queue_nf_hook_drop (ctx->net);if (priv->helper4)nf_conntrack_helper_put (priv->helper4);if (priv->helper6)
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 260/570 netfilter: xt_CT: drop pending enqueued packets on template removal
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit f62a218a946b19bb59abdd5361da85fa4606b96b ]
Templates refer to objects that can go away while packets are sitting in nfqueue refer to:
- helper, this can be an issue on module removal.
- timeout policy, nfnetlink_cttimeout might remove it.
The use of templates with zone and event cache filter are safe, since this just copies values.
Flush these enqueued packets in case the template rule gets removed.
--- net/netfilter/xt_CT.c | 4 ++++ 1 file changed, 4 insertions(+)
net/netfilter/xt_CT.c +4 -0
@@ -16,6 +16,7 @@#include <net/netfilter/nf_conntrack_ecache.h> #include <net/netfilter/nf_conntrack_timeout.h> #include <net/netfilter/nf_conntrack_zones.h> +#include "nf_internals.h" static inline int xt_ct_target (struct sk_buff *skb,struct nf_conn *ct) {
@@ -269,6 +270,9 @@ static void xt_ct_tg_destroy(const struct xt_tgdtor_param *par,struct nf_conn_help *help;if (ct) { +if (info->helper[0 ] || info->timeout[0 ]) +nf_queue_nf_hook_drop (par->net); + help =nfct_help (ct);if (help)nf_conntrack_helper_put (help->helper);
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 261/570 netfilter: xt_time: use unsigned int for monthday bit shift
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jenny Guanni Qu <[email protected]>
[ Upstream commit 00050ec08cecfda447e1209b388086d76addda3a ]
The monthday field can be up to 31, and shifting a signed integer 1 by 31 positions (1 << 31) is undefined behavior in C, as the result overflows a 32-bit signed int. Use 1U to ensure well-defined behavior for all valid monthday values.
Change the weekday shift to 1U as well for consistency.
--- net/netfilter/xt_time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/xt_time.c +2 -2
@@ -227,13 +227,13 @@ time_mt(const struct sk_buff *skb, struct xt_action_param *par)localtime_2 (¤t_time, stamp); -if (!(info->weekdays_match & (1 << current_time.weekday))) +if (!(info->weekdays_match & (1U << current_time.weekday)))return false;/* Do not spend time computing monthday if all days match anyway */ if (info->monthdays_match !=XT_TIME_ALL_MONTHDAYS ) {localtime_3 (¤t_time, stamp); -if (!(info->monthdays_match & (1 << current_time.monthday))) +if (!(info->monthdays_match & (1U << current_time.monthday)))return false; }
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 262/570 netfilter: nf_conntrack_h323: check for zero length in DecodeQ931()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jenny Guanni Qu <[email protected]>
[ Upstream commit f173d0f4c0f689173f8cdac79991043a4a89bf66 ]
In DecodeQ931(), the UserUserIE code path reads a 16-bit length from the packet, then decrements it by 1 to skip the protocol discriminator byte before passing it to DecodeH323_UserInformation(). If the encoded length is 0, the decrement wraps to -1, which is then passed as a large value to the decoder, leading to an out-of-bounds read.
Add a check to ensure len is positive after the decrement.
--- net/netfilter/nf_conntrack_h323_asn1.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/nf_conntrack_h323_asn1.c +2 -0
@@ -924,6 +924,8 @@ int DecodeQ931(unsigned char *buf, size_t sz, Q931 *q931)break ; p++; len--; +if (len <=0 ) +break ;return DecodeH323_UserInformation (buf, p, len, &q931->UUIE); }
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 263/570 net: bcmgenet: increase WoL poll timeout
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Justin Chen <[email protected]>
[ Upstream commit 6cfc3bc02b977f2fba5f7268e6504d1931a774f7 ]
Some systems require more than 5ms to get into WoL mode. Increase the timeout value to 50ms.
--- drivers/net/ethernet/broadcom/genet/bcmgenet_wol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/broadcom/genet/bcmgenet_wol.c +1 -1
@@ -101,7 +101,7 @@ static int bcmgenet_poll_wol_status(struct bcmgenet_priv *priv)while (!(bcmgenet_rbuf_readl (priv,RBUF_STATUS ) &RBUF_STATUS_WOL )) { retries++; -if (retries >5 ) { +if (retries >50 ) {netdev_crit (dev,"polling wol mode timeout\n" );return -ETIMEDOUT ; }
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 264/570 net: mana: Improve the HWC error handling
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dexuan Cui <[email protected]>
[ Upstream commit 62ea8b77ed3b7086561765df0226ebc7bb442020 ]
Currently when the HWC creation fails, the error handling is flawed, e.g. if mana_hwc_create_channel() -> mana_hwc_establish_channel() fails, the resources acquired in mana_hwc_init_queues() is not released.
Enhance mana_hwc_destroy_channel() to do the proper cleanup work and call it accordingly.
Stable-dep-of: fa103fc8f569 ("net: mana: fix use-after-free in mana_hwc_destroy_channel() by reordering teardown")
--- .../net/ethernet/microsoft/mana/gdma_main.c | 4 -- .../net/ethernet/microsoft/mana/hw_channel.c | 71 ++++++++----------- 2 files changed, 31 insertions(+), 44 deletions(-)
drivers/net/ethernet/microsoft/mana/gdma_main.c +0 -4
@@ -1336,8 +1336,6 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent) clean_up_gdma:mana_hwc_destroy_channel (gc); -vfree (gc->cq_table); - gc->cq_table =NULL ; remove_irq:mana_gd_remove_irqs (pdev); unmap_bar:
@@ -1360,8 +1358,6 @@ static void mana_gd_remove(struct pci_dev *pdev)mana_remove (&gc->mana);mana_hwc_destroy_channel (gc); -vfree (gc->cq_table); - gc->cq_table =NULL ;mana_gd_remove_irqs (pdev);
drivers/net/ethernet/microsoft/mana/hw_channel.c +31 -40
156 lines not on this page · raw message
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 265/570 net: mana: fix use-after-free in mana_hwc_destroy_channel() by reordering teardown
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dipayaan Roy <[email protected]>
[ Upstream commit fa103fc8f56954a60699a29215cb713448a39e87 ]
A potential race condition exists in mana_hwc_destroy_channel() where hwc->caller_ctx is freed before the HWC's Completion Queue (CQ) and Event Queue (EQ) are destroyed. This allows an in-flight CQ interrupt handler to dereference freed memory, leading to a use-after-free or NULL pointer dereference in mana_hwc_handle_resp().
mana_smc_teardown_hwc() signals the hardware to stop but does not synchronize against IRQ handlers already executing on other CPUs. The IRQ synchronization only happens in mana_hwc_destroy_cq() via mana_gd_destroy_eq() -> mana_gd_deregister_irq(). Since this runs after kfree(hwc->caller_ctx), a concurrent mana_hwc_rx_event_handler() can dereference freed caller_ctx (and rxq->msg_buf) in mana_hwc_handle_resp().
Fix this by reordering teardown to reverse-of-creation order: destroy the TX/RX work queues and CQ/EQ before freeing hwc->caller_ctx. This ensures all in-flight interrupt handlers complete before the memory they access is freed.
--- drivers/net/ethernet/microsoft/mana/hw_channel.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/microsoft/mana/hw_channel.c +3 -3
@@ -749,9 +749,6 @@ void mana_hwc_destroy_channel(struct gdma_context *gc) gc->max_num_cqs =0 ; } -kfree (hwc->caller_ctx); - hwc->caller_ctx =NULL ; -if (hwc->txq)mana_hwc_destroy_wq (hwc, hwc->txq);
@@ -761,6 +758,9 @@ void mana_hwc_destroy_channel(struct gdma_context *gc)if (hwc->cq)mana_hwc_destroy_cq (hwc->gdma_dev->gdma_context, hwc->cq); +kfree (hwc->caller_ctx); + hwc->caller_ctx =NULL ; +mana_gd_free_res_map (&hwc->inflight_msg_res); hwc->num_inflight_msg =0 ;
Signature · 1 line
2.51.0
Re: [PATCH 5.15 265/570] net: mana: fix use-after-free in mana_hwc_destroy_channel() by reordering teardown
Hi,
Quoted 10 lines · Greg Kroah-Hartman
From: Dipayaan Roy<[email protected]>
[ Upstream commit
fa103fc8f56954a60699a29215cb713448a39e87]A potential race condition exists in
mana_hwc_destroy_channel()wherehwc->caller_ctxis freed before the HWC's Completion Queue (CQ) and Event Queue (EQ) are destroyed. This allows an in-flight CQ interrupt handler to dereference freed memory, leading to a use-after-free or NULL pointer dereference inmana_hwc_handle_resp().
Quoted 8 lines
mana_smc_teardown_hwc()signals the hardware to stop but does not synchronize against IRQ handlers already executing on other CPUs. The IRQ synchronization only happens inmana_hwc_destroy_cq()viamana_gd_destroy_eq()->mana_gd_deregister_irq(). Since this runs afterkfree(hwc->caller_ctx), a concurrentmana_hwc_rx_event_handler()can dereference freedcaller_ctx(andrxq->msg_buf) inmana_hwc_handle_resp().
I have run an AI assisted backport review and it spotted a probable issue, I checked it and I think is worth checking here from the authors:
I think this fix relies on presence of commit: 02fed6d92bad ("net: mana: add msix index sharing between EQs") which is not present in 5.15.y.
This patch mentions:
""
The IRQ synchronization only happens in mana_hwc_destroy_cq() via mana_gd_destroy_eq() -> mana_gd_deregister_irq().
""
and I think that is referring to the synchronization added in 2fed6d92bad ("net: mana: add msix index sharing between EQs"), and give that we don't have this in 5.15.y, the UAF is still possible ?
Thoughts ?
Thanks,
Harshit
Quoted 8 lines
Fix this by reordering teardown to reverse-of-creation order: destroy the TX/RX work queues and CQ/EQ before freeing
hwc->caller_ctx. This ensures all in-flight interrupt handlers complete before the memory they access is freed.Fixes ca9c54d2d6a5 ("net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)")Reviewed-by Haiyang Zhang<[email protected]>Signed-off-by Dipayaan Roy<[email protected]>