5.10.163-rc1 review
Subsystems (11)
Greg Kroah-Hartman
maintainerPATCH 595/783 mmc: vub300: fix warning - do not call blocking ops when !TASK_RUNNING
In reply to Greg Kroah-HartmanFrom: Deren Wu <[email protected]>
commit 4a44cd249604e29e7b90ae796d7692f5773dd348 upstream.
vub300_enable_sdio_irq() works with mutex and need TASK_RUNNING here. Ensure that we mark current as TASK_RUNNING for sleepable context.
[ 77.554641] do not call blocking ops when !TASK_RUNNING; state=1 set at [<ffffffff92a72c1d>] sdio_irq_thread+0x17d/0x5b0 [ 77.554652] WARNING: CPU: 2 PID: 1983 at kernel/sched/core.c:9813 __might_sleep+0x116/0x160 [ 77.554905] CPU: 2 PID: 1983 Comm: ksdioirqd/mmc1 Tainted: G OE 6.1.0-rc5 #1 [ 77.554910] Hardware name: Intel(R) Client Systems NUC8i7BEH/NUC8BEB, BIOS BECFL357.86A.0081.2020.0504.1834 05/04/2020 [ 77.554912] RIP: 0010:__might_sleep+0x116/0x160 [ 77.554920] RSP: 0018:ffff888107b7fdb8 EFLAGS: 00010282 [ 77.554923] RAX: 0000000000000000 RBX: ffff888118c1b740 RCX: 0000000000000000 [ 77.554926] RDX: 0000000000000001 RSI: 0000000000000004 RDI: ffffed1020f6ffa9 [ 77.554928] RBP: ffff888107b7fde0 R08: 0000000000000001 R09: ffffed1043ea60ba [ 77.554930] R10: ffff88821f5305cb R11: ffffed1043ea60b9 R12: ffffffff93aa3a60 [ 77.554932] R13: 000000000000011b R14: 7fffffffffffffff R15: ffffffffc0558660 [ 77.554934] FS: 0000000000000000(0000) GS:ffff88821f500000(0000) knlGS:0000000000000000 [ 77.554937] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 77.554939] CR2: 00007f8a44010d68 CR3: 000000024421a003 CR4: 00000000003706e0 [ 77.554942] Call Trace: [ 77.554944] <TASK> [ 77.554952] mutex_lock+0x78/0xf0 [ 77.554973] vub300_enable_sdio_irq+0x103/0x3c0 [vub300] [ 77.554981] sdio_irq_thread+0x25c/0x5b0 [ 77.555006] kthread+0x2b8/0x370 [ 77.555017] ret_from_fork+0x1f/0x30 [ 77.555023] </TASK> [ 77.555025] ---[ end trace 0000000000000000 ]---
--- drivers/mmc/host/vub300.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mmc/host/vub300.c +2 -0
@@ -2049,6 +2049,7 @@ static void vub300_enable_sdio_irq(strucreturn ;kref_get (&vub300->kref);if (enable) { +set_current_state (TASK_RUNNING );mutex_lock (&vub300->irq_mutex);if (vub300->irqs_queued) { vub300->irqs_queued -=1 ;
@@ -2064,6 +2065,7 @@ static void vub300_enable_sdio_irq(strucvub300_queue_poll_work (vub300,0 ); }mutex_unlock (&vub300->irq_mutex); +set_current_state (TASK_INTERRUPTIBLE ); }else { vub300->irq_enabled =0 ; }
Greg Kroah-Hartman
maintainerPATCH 596/783 tpm: acpi: Call acpi_put_table() to fix memory leak
In reply to Greg Kroah-HartmanFrom: Hanjun Guo <[email protected]>
commit 8740a12ca2e2959531ad253bac99ada338b33d80 upstream.
The start and length of the event log area are obtained from TPM2 or TCPA table, so we call acpi_get_table() to get the ACPI information, but the acpi_get_table() should be coupled with acpi_put_table() to release the ACPI memory, add the acpi_put_table() properly to fix the memory leak.
While we are at it, remove the redundant empty line at the end of the tpm_read_log_acpi().
--- drivers/char/tpm/eventlog/acpi.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/char/tpm/eventlog/acpi.c +9 -3
@@ -90,16 +90,21 @@ int tpm_read_log_acpi(struct tpm_chip *creturn -ENODEV ;if (tbl->header.length < -sizeof (*tbl) +sizeof (struct acpi_tpm2_phy )) +sizeof (*tbl) +sizeof (struct acpi_tpm2_phy )) { +acpi_put_table ((struct acpi_table_header *)tbl);return -ENODEV ; + } tpm2_phy = (void *)tbl +sizeof (*tbl); len = tpm2_phy->log_area_minimum_length; start = tpm2_phy->log_area_start_address; -if (!start || !len) +if (!start || !len) { +acpi_put_table ((struct acpi_table_header *)tbl);return -ENODEV ; + } +acpi_put_table ((struct acpi_table_header *)tbl); format =EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ; }else {/* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
@@ -120,8 +125,10 @@ int tpm_read_log_acpi(struct tpm_chip *cbreak ; } +acpi_put_table ((struct acpi_table_header *)buff); format =EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 ; } +if (!len) {dev_warn (&chip->dev,"%s: TCPA log area empty\n" , __func__);return -EIO ;
@@ -156,5 +163,4 @@ err:kfree (log->bios_event_log); log->bios_event_log =NULL ;return ret; - }
Greg Kroah-Hartman
maintainerPATCH 597/783 tpm: tpm_crb: Add the missed acpi_put_table() to fix memory leak
In reply to Greg Kroah-HartmanFrom: Hanjun Guo <[email protected]>
commit 37e90c374dd11cf4919c51e847c6d6ced0abc555 upstream.
In crb_acpi_add(), we get the TPM2 table to retrieve information like start method, and then assign them to the priv data, so the TPM2 table is not used after the init, should be freed, call acpi_put_table() to fix the memory leak.
--- drivers/char/tpm/tpm_crb.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
drivers/char/tpm/tpm_crb.c +20 -9
@@ -676,12 +676,16 @@ static int crb_acpi_add(struct acpi_devi/* Should the FIFO driver handle this? */ sm = buf->start_method; -if (sm ==ACPI_TPM2_MEMORY_MAPPED ) -return -ENODEV ; +if (sm ==ACPI_TPM2_MEMORY_MAPPED ) { + rc = -ENODEV ; + goto out; + } priv =devm_kzalloc (dev,sizeof (struct crb_priv ),GFP_KERNEL ); -if (!priv) -return -ENOMEM ; +if (!priv) { + rc = -ENOMEM ; + goto out; + }if (sm ==ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC ) {if (buf->header.length < (sizeof (*buf) +sizeof (*crb_smc))) {
@@ -689,7 +693,8 @@ static int crb_acpi_add(struct acpi_deviFW_BUG "TPM2 ACPI table has wrong size %u for start method type %d\n" , buf->header.length, ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC); -return -EINVAL ; + rc = -EINVAL ; + goto out; } crb_smc = ACPI_ADD_PTR(struct tpm2_crb_smc, buf, sizeof(*buf)); priv->smc_func_id = crb_smc->smc_func_id;
@@ -700,17 +705,23 @@ static int crb_acpi_add(struct acpi_devi rc =crb_map_io (device, priv, buf);if (rc) -return rc; + goto out; chip =tpmm_chip_alloc (dev, &tpm_crb); -if (IS_ERR (chip)) -return PTR_ERR (chip); +if (IS_ERR (chip)) { + rc =PTR_ERR (chip); + goto out; + }dev_set_drvdata (&chip->dev, priv); chip->acpi_dev_handle = device->handle; chip->flags =TPM_CHIP_FLAG_TPM2 ; -return tpm_chip_register (chip); + rc =tpm_chip_register (chip); + +out: +acpi_put_table ((struct acpi_table_header *)buf); +return rc; }static int crb_acpi_remove (struct acpi_device *device)
Greg Kroah-Hartman
maintainerPATCH 598/783 tpm: tpm_tis: Add the missed acpi_put_table() to fix memory leak
In reply to Greg Kroah-HartmanFrom: Hanjun Guo <[email protected]>
commit db9622f762104459ff87ecdf885cc42c18053fd9 upstream.
In check_acpi_tpm2(), we get the TPM2 table just to make sure the table is there, not used after the init, so the acpi_put_table() should be added to release the ACPI memory.
--- drivers/char/tpm/tpm_tis.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/char/tpm/tpm_tis.c +5 -4
@@ -125,6 +125,7 @@ static int check_acpi_tpm2(struct deviceconst struct acpi_device_id *aid =acpi_match_device (tpm_acpi_tbl, dev);struct acpi_table_tpm2 *tbl;acpi_status st; +int ret =0 ;if (!aid || aid->driver_data !=DEVICE_IS_TPM2 )return 0 ;
@@ -132,8 +133,7 @@ static int check_acpi_tpm2(struct device/* If the ACPI TPM2 signature is matched then a global ACPI_SIG_TPM2 * table is mandatory */ - st = -acpi_get_table (ACPI_SIG_TPM2 ,1 , (struct acpi_table_header **)&tbl); + st =acpi_get_table (ACPI_SIG_TPM2 ,1 , (struct acpi_table_header **)&tbl);if (ACPI_FAILURE (st) || tbl->header.length <sizeof (*tbl)) {dev_err (dev,FW_BUG "failed to get TPM2 ACPI table\n" );return -EINVAL ;
@@ -141,9 +141,10 @@ static int check_acpi_tpm2(struct device/* The tpm2_crb driver handles this device */ if (tbl->start_method !=ACPI_TPM2_MEMORY_MAPPED ) -return -ENODEV ; + ret = -ENODEV ; - return 0; +acpi_put_table ((struct acpi_table_header *)tbl); + return ret; }#else static int check_acpi_tpm2 (struct device *dev)
Greg Kroah-Hartman
maintainerPATCH 599/783 SUNRPC: Dont leak netobj memory when gss_read_proxy_verf() fails
In reply to Greg Kroah-HartmanFrom: Chuck Lever <[email protected]>
commit da522b5fe1a5f8b7c20a0023e87b52a150e53bf5 upstream.
--- net/sunrpc/auth_gss/svcauth_gss.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/sunrpc/auth_gss/svcauth_gss.c +7 -2
@@ -1156,18 +1156,23 @@ static int gss_read_proxy_verf(struct svreturn res; inlen =svc_getnl (argv); -if (inlen > (argv->iov_len + rqstp->rq_arg.page_len)) +if (inlen > (argv->iov_len + rqstp->rq_arg.page_len)) { +kfree (in_handle->data);return SVC_DENIED ; + } pages =DIV_ROUND_UP (inlen,PAGE_SIZE ); in_token->pages =kcalloc (pages,sizeof (struct page *),GFP_KERNEL ); -if (!in_token->pages) +if (!in_token->pages) { +kfree (in_handle->data);return SVC_DENIED ; + } in_token->page_base =0 ; in_token->page_len = inlen;for (i =0 ; i < pages; i++) { in_token->pages[i] =alloc_page (GFP_KERNEL );if (!in_token->pages[i]) { +kfree (in_handle->data);gss_free_in_token_pages (in_token);return SVC_DENIED ; }
Greg Kroah-Hartman
maintainerPATCH 600/783 kcsan: Instrument memcpy/memset/memmove with newer Clang
In reply to Greg Kroah-HartmanFrom: Marco Elver <[email protected]>
commit 7c201739beef1a586d806463f1465429cdce34c5 upstream.
With Clang version 16+, -fsanitize=thread will turn memcpy/memset/memmove calls in instrumented functions into __tsan_memcpy/__tsan_memset/__tsan_memmove calls respectively.
Add these functions to the core KCSAN runtime, so that we (a) catch data races with mem* functions, and (b) won't run into linker errors with such newer compilers.
--- kernel/kcsan/core.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
kernel/kcsan/core.c +50 -0
@@ -9,10 +9,12 @@#include <linux/init.h> #include <linux/kernel.h> #include <linux/list.h> +#include <linux/minmax.h> #include <linux/moduleparam.h> #include <linux/percpu.h> #include <linux/preempt.h> #include <linux/sched.h> +#include <linux/string.h> #include <linux/uaccess.h> #include "atomic.h"
@@ -1045,3 +1047,51 @@ EXPORT_SYMBOL(__tsan_atomic_thread_fencevoid __tsan_atomic_signal_fence (int memorder);void __tsan_atomic_signal_fence (int memorder) { }EXPORT_SYMBOL (__tsan_atomic_signal_fence); + +#ifdef __HAVE_ARCH_MEMSET +void *__tsan_memset (void *s,int c,size_t count); +noinline void *__tsan_memset(void *s, int c, size_t count) +{ +/* +* Instead of not setting up watchpoints where accessed size is greater +* than MAX_ENCODABLE_SIZE, truncate checked size to MAX_ENCODABLE_SIZE. +*/ +size_t check_len =min_t (size_t, count,MAX_ENCODABLE_SIZE ); + +check_access (s, check_len,KCSAN_ACCESS_WRITE ); +return memset (s, c, count); +} +#else +void *__tsan_memset (void *s,int c,size_t count)__alias (memset); +#endif +EXPORT_SYMBOL (__tsan_memset); + +#ifdef __HAVE_ARCH_MEMMOVE +void *__tsan_memmove (void *dst,const void *src,size_t len); +noinline void *__tsan_memmove(void *dst, const void *src, size_t len) +{ +size_t check_len =min_t (size_t, len,MAX_ENCODABLE_SIZE ); + +check_access (dst, check_len,KCSAN_ACCESS_WRITE ); +check_access (src, check_len,0 ); +return memmove (dst, src, len); +} +#else +void *__tsan_memmove (void *dst,const void *src,size_t len)__alias (memmove); +#endif +EXPORT_SYMBOL (__tsan_memmove); + +#ifdef __HAVE_ARCH_MEMCPY +void *__tsan_memcpy (void *dst,const void *src,size_t len); +noinline void *__tsan_memcpy(void *dst, const void *src, size_t len) +{ +size_t check_len =min_t (size_t, len,MAX_ENCODABLE_SIZE ); + +check_access (dst, check_len,KCSAN_ACCESS_WRITE ); +check_access (src, check_len,0 ); +return memcpy (dst, src, len); +} +#else +void *__tsan_memcpy (void *dst,const void *src,size_t len)__alias (memcpy); +#endif +EXPORT_SYMBOL (__tsan_memcpy);
Greg Kroah-Hartman
maintainerPATCH 601/783 ASoC: Intel/SOF: use set_stream() instead of set_tdm_slots() for HDAudio
In reply to Greg Kroah-HartmanFrom: Pierre-Louis Bossart <[email protected]>
commit 636110411ca726f19ef8e87b0be51bb9a4cdef06 upstream.
Overloading the tx_mask with a linear value is asking for trouble and only works because the codec_dai hw_params() is called before the cpu_dai hw_params().
Move to the more generic set_stream() API to pass the hdac_stream information.
--- sound/soc/codecs/hdac_hda.c | 22 +++++++++++----------- sound/soc/intel/skylake/skl-pcm.c | 7 ++----- sound/soc/sof/intel/hda-dai.c | 7 ++----- 3 files changed, 15 insertions(+), 21 deletions(-)
sound/soc/codecs/hdac_hda.c +11 -11
@@ -46,9 +46,8 @@ static int hdac_hda_dai_hw_params(struct struct snd_soc_dai *dai);static int hdac_hda_dai_hw_free (struct snd_pcm_substream *substream,struct snd_soc_dai *dai); -static int hdac_hda_dai_set_tdm_slot (struct snd_soc_dai *dai, -unsigned int tx_mask,unsigned int rx_mask, -int slots,int slot_width); +static int hdac_hda_dai_set_stream (struct snd_soc_dai *dai,void *stream, +int direction);static struct hda_pcm *snd_soc_find_pcm_from_dai (struct hdac_hda_priv *hda_pvt,struct snd_soc_dai *dai);
@@ -58,7 +57,7 @@ static const struct snd_soc_dai_ops hdac .prepare = hdac_hda_dai_prepare, .hw_params = hdac_hda_dai_hw_params, .hw_free = hdac_hda_dai_hw_free, - .set_tdm_slot = hdac_hda_dai_set_tdm_slot, + .set_stream = hdac_hda_dai_set_stream, };static struct snd_soc_dai_driver hdac_hda_dais[] = {
@@ -180,21 +179,22 @@ static struct snd_soc_dai_driver hdac_hd }; -static int hdac_hda_dai_set_tdm_slot (struct snd_soc_dai *dai, -unsigned int tx_mask,unsigned int rx_mask, -int slots,int slot_width) +static int hdac_hda_dai_set_stream (struct snd_soc_dai *dai, +void *stream,int direction) {struct snd_soc_component *component = dai->component;struct hdac_hda_priv *hda_pvt;struct hdac_hda_pcm *pcm; +struct hdac_stream *hstream; + +if (!stream) +return -EINVAL ; hda_pvt =snd_soc_component_get_drvdata (component); pcm = &hda_pvt->pcm[dai->id]; + hstream = (struct hdac_stream *)stream; -if (tx_mask) - pcm->stream_tag[SNDRV_PCM_STREAM_PLAYBACK ] = tx_mask; -else - pcm->stream_tag[SNDRV_PCM_STREAM_CAPTURE ] = rx_mask; + pcm->stream_tag[direction] = hstream->stream_tag;return 0 ; }
sound/soc/intel/skylake/skl-pcm.c +2 -5
@@ -563,11 +563,8 @@ static int skl_link_hw_params(struct snd stream_tag =hdac_stream (link_dev)->stream_tag; -/* set the stream tag in the codec dai dma params */ -if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) -snd_soc_dai_set_tdm_slot (codec_dai, stream_tag,0 ,0 ,0 ); -else -snd_soc_dai_set_tdm_slot (codec_dai,0 , stream_tag,0 ,0 ); +/* set the hdac_stream in the codec dai */ +snd_soc_dai_set_stream (codec_dai,hdac_stream (link_dev), substream->stream); p_params.s_fmt =snd_pcm_format_width (params_format (params)); p_params.ch =params_channels (params);
sound/soc/sof/intel/hda-dai.c +2 -5
@@ -236,11 +236,8 @@ static int hda_link_hw_params(struct sndif (!link)return -EINVAL ; -/* set the stream tag in the codec dai dma params */ -if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) -snd_soc_dai_set_tdm_slot (codec_dai, stream_tag,0 ,0 ,0 ); -else -snd_soc_dai_set_tdm_slot (codec_dai,0 , stream_tag,0 ,0 ); +/* set the hdac_stream in the codec dai */ +snd_soc_dai_set_stream (codec_dai,hdac_stream (link_dev), substream->stream); p_params.s_fmt =snd_pcm_format_width (params_format (params)); p_params.ch =params_channels (params);
Greg Kroah-Hartman
maintainerPATCH 602/783 ASoC/SoundWire: dai: expand stream concept beyond SoundWire
In reply to Greg Kroah-HartmanFrom: Pierre-Louis Bossart <[email protected]>
commit e8444560b4d9302a511f0996f4cfdf85b628f4ca upstream.
The HDAudio ASoC support relies on the set_tdm_slots() helper to store the HDaudio stream tag in the tx_mask. This only works because of the pre-existing order in soc-pcm.c, where the hw_params() is handled for codec_dais *before* cpu_dais. When the order is reversed, the stream_tag is used as a mask in the codec fixup functions:
/* fixup params based on TDM slot masks */ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && codec_dai->tx_mask) soc_pcm_codec_params_fixup(&codec_params, codec_dai->tx_mask);
As a result of this confusion, the codec_params_fixup() ends-up generating bad channel masks, depending on what stream_tag was allocated.
We could add a flag to state that the tx_mask is really not a mask, but it would be quite ugly to persist in overloading concepts.
Instead, this patch suggests a more generic get/set 'stream' API based on the existing model for SoundWire. We can expand the concept to store 'stream' opaque information that is specific to different DAI types. In the case of HDAudio DAIs, we only need to store a stream tag as an unsigned char pointer. The TDM rx_ and tx_masks should really only be used to store masks.
Rename get_sdw_stream/set_sdw_stream callbacks and helpers as get_stream/set_stream. No functionality change beyond the rename.
--- drivers/soundwire/intel.c | 8 ++++---- drivers/soundwire/qcom.c | 8 ++++---- drivers/soundwire/stream.c | 4 ++-- include/sound/soc-dai.h | 32 ++++++++++++++++---------------- sound/soc/codecs/max98373-sdw.c | 2 +- sound/soc/codecs/rt1308-sdw.c | 2 +- sound/soc/codecs/rt5682-sdw.c | 2 +- sound/soc/codecs/rt700.c | 2 +- sound/soc/codecs/rt711.c | 2 +- sound/soc/codecs/rt715.c | 2 +- sound/soc/codecs/wsa881x.c | 2 +- sound/soc/intel/boards/sof_sdw.c | 6 +++--- sound/soc/qcom/sdm845.c | 4 ++-- 13 files changed, 38 insertions(+), 38 deletions(-)
drivers/soundwire/intel.c +4 -4
@@ -1140,8 +1140,8 @@ static const struct snd_soc_dai_ops inte .prepare = intel_prepare, .hw_free = intel_hw_free, .shutdown = intel_shutdown, - .set_sdw_stream = intel_pcm_set_sdw_stream, - .get_sdw_stream = intel_get_sdw_stream, + .set_stream = intel_pcm_set_sdw_stream, + .get_stream = intel_get_sdw_stream, };static const struct snd_soc_dai_ops intel_pdm_dai_ops = {
@@ -1150,8 +1150,8 @@ static const struct snd_soc_dai_ops inte .prepare = intel_prepare, .hw_free = intel_hw_free, .shutdown = intel_shutdown, - .set_sdw_stream = intel_pdm_set_sdw_stream, - .get_sdw_stream = intel_get_sdw_stream, + .set_stream = intel_pdm_set_sdw_stream, + .get_stream = intel_get_sdw_stream, };static const struct snd_soc_component_driver dai_component = {
drivers/soundwire/qcom.c +4 -4
@@ -649,8 +649,8 @@ static int qcom_swrm_startup(struct snd_ ctrl->sruntime[dai->id] = sruntime;for_each_rtd_codec_dais (rtd, i, codec_dai) { - ret =snd_soc_dai_set_sdw_stream (codec_dai, sruntime, - substream->stream); + ret =snd_soc_dai_set_stream (codec_dai, sruntime, + substream->stream);if (ret <0 && ret != -ENOTSUPP ) {dev_err (dai->dev,"Failed to set sdw stream on %s" , codec_dai->name);
@@ -676,8 +676,8 @@ static const struct snd_soc_dai_ops qcom .hw_free = qcom_swrm_hw_free, .startup = qcom_swrm_startup, .shutdown = qcom_swrm_shutdown, - .set_sdw_stream = qcom_swrm_set_sdw_stream, - .get_sdw_stream = qcom_swrm_get_sdw_stream, + .set_stream = qcom_swrm_set_sdw_stream, + .get_stream = qcom_swrm_get_sdw_stream, };static const struct snd_soc_component_driver qcom_swrm_dai_component = {
drivers/soundwire/stream.c +2 -2
@@ -1860,7 +1860,7 @@ static int set_stream(struct snd_pcm_sub/* Set stream pointer on all DAIs */ for_each_rtd_dais (rtd, i, dai) { - ret =snd_soc_dai_set_sdw_stream (dai, sdw_stream, substream->stream); + ret =snd_soc_dai_set_stream (dai, sdw_stream, substream->stream);if (ret <0 ) {dev_err (rtd->dev,"failed to set stream pointer on dai %s" , dai->name);break ;
@@ -1931,7 +1931,7 @@ void sdw_shutdown_stream(void *sdw_subst/* Find stream from first CPU DAI */ dai =asoc_rtd_to_cpu (rtd,0 ); - sdw_stream =snd_soc_dai_get_sdw_stream (dai, substream->stream); + sdw_stream =snd_soc_dai_get_stream (dai, substream->stream);if (IS_ERR (sdw_stream)) {dev_err (rtd->dev,"no stream found for DAI %s" , dai->name);
include/sound/soc-dai.h +16 -16
@@ -239,9 +239,9 @@ struct snd_soc_dai_ops { unsigned int *rx_num, unsigned int *rx_slot);int (*set_tristate)(struct snd_soc_dai *dai,int tristate); -int (*set_sdw_stream)(struct snd_soc_dai *dai, -void *stream,int direction); -void *(*get_sdw_stream)(struct snd_soc_dai *dai,int direction); +int (*set_stream)(struct snd_soc_dai *dai, +void *stream,int direction); +void *(*get_stream)(struct snd_soc_dai *dai,int direction);/* * DAI digital mute - optional.
@@ -446,42 +446,42 @@ static inline void *snd_soc_dai_get_drvd }/** -* snd_soc_dai_set_sdw_stream() - Configures a DAI for SDW stream operation +* snd_soc_dai_set_stream() - Configures a DAI for stream operation * @dai: DAI -* @stream: STREAM +* @stream: STREAM (opaque structure depending on DAI type) * @direction: Stream direction(Playback/Capture) -* SoundWire subsystem doesn't have a notion of direction and we reuse +* Some subsystems, such as SoundWire, don't have a notion of direction and we reuse * the ASoC stream direction to configure sink/source ports. * Playback maps to source ports and Capture for sink ports. * * This should be invoked with NULL to clear the stream set previously. * Returns 0 on success, a negative error code otherwise. */ -static inline int snd_soc_dai_set_sdw_stream (struct snd_soc_dai *dai, -void *stream,int direction) +static inline int snd_soc_dai_set_stream (struct snd_soc_dai *dai, +void *stream,int direction) { -if (dai->driver->ops->set_sdw_stream) -return dai->driver->ops->set_sdw_stream (dai, stream, direction); +if (dai->driver->ops->set_stream) +return dai->driver->ops->set_stream (dai, stream, direction);else return -ENOTSUPP ; }/** -* snd_soc_dai_get_sdw_stream() - Retrieves SDW stream from DAI +* snd_soc_dai_get_stream() - Retrieves stream from DAI * @dai: DAI * @direction: Stream direction(Playback/Capture) * * This routine only retrieves that was previously configured -* with snd_soc_dai_get_sdw_stream() +* with snd_soc_dai_get_stream() * * Returns pointer to stream or an ERR_PTR value, e.g. * ERR_PTR(-ENOTSUPP) if callback is not supported; */ -static inline void *snd_soc_dai_get_sdw_stream (struct snd_soc_dai *dai, -int direction) +static inline void *snd_soc_dai_get_stream (struct snd_soc_dai *dai, +int direction) { -if (dai->driver->ops->get_sdw_stream) -return dai->driver->ops->get_sdw_stream (dai, direction); +if (dai->driver->ops->get_stream) +return dai->driver->ops->get_stream (dai, direction);else return ERR_PTR (-ENOTSUPP ); }
sound/soc/codecs/max98373-sdw.c +1 -1
@@ -728,7 +728,7 @@ static int max98373_sdw_set_tdm_slot(strstatic const struct snd_soc_dai_ops max98373_dai_sdw_ops = { .hw_params = max98373_sdw_dai_hw_params, .hw_free = max98373_pcm_hw_free, - .set_sdw_stream = max98373_set_sdw_stream, + .set_stream = max98373_set_sdw_stream, .shutdown = max98373_shutdown, .set_tdm_slot = max98373_sdw_set_tdm_slot, };
sound/soc/codecs/rt1308-sdw.c +1 -1
@@ -613,7 +613,7 @@ static const struct snd_soc_component_drstatic const struct snd_soc_dai_ops rt1308_aif_dai_ops = { .hw_params = rt1308_sdw_hw_params, .hw_free = rt1308_sdw_pcm_hw_free, - .set_sdw_stream = rt1308_set_sdw_stream, + .set_stream = rt1308_set_sdw_stream, .shutdown = rt1308_sdw_shutdown, .set_tdm_slot = rt1308_sdw_set_tdm_slot, };
sound/soc/codecs/rt5682-sdw.c +1 -1
@@ -272,7 +272,7 @@ static int rt5682_sdw_hw_free(struct sndstatic struct snd_soc_dai_ops rt5682_sdw_ops = { .hw_params = rt5682_sdw_hw_params, .hw_free = rt5682_sdw_hw_free, - .set_sdw_stream = rt5682_set_sdw_stream, + .set_stream = rt5682_set_sdw_stream, .shutdown = rt5682_sdw_shutdown, };
sound/soc/codecs/rt700.c +1 -1
@@ -1005,7 +1005,7 @@ static int rt700_pcm_hw_free(struct snd_static struct snd_soc_dai_ops rt700_ops = { .hw_params = rt700_pcm_hw_params, .hw_free = rt700_pcm_hw_free, - .set_sdw_stream = rt700_set_sdw_stream, + .set_stream = rt700_set_sdw_stream, .shutdown = rt700_shutdown, };
sound/soc/codecs/rt711.c +1 -1
@@ -1059,7 +1059,7 @@ static int rt711_pcm_hw_free(struct snd_static struct snd_soc_dai_ops rt711_ops = { .hw_params = rt711_pcm_hw_params, .hw_free = rt711_pcm_hw_free, - .set_sdw_stream = rt711_set_sdw_stream, + .set_stream = rt711_set_sdw_stream, .shutdown = rt711_shutdown, };
sound/soc/codecs/rt715.c +1 -1
@@ -686,7 +686,7 @@ static int rt715_pcm_hw_free(struct snd_static struct snd_soc_dai_ops rt715_ops = { .hw_params = rt715_pcm_hw_params, .hw_free = rt715_pcm_hw_free, - .set_sdw_stream = rt715_set_sdw_stream, + .set_stream = rt715_set_sdw_stream, .shutdown = rt715_shutdown, };
sound/soc/codecs/wsa881x.c +1 -1
@@ -1026,7 +1026,7 @@ static struct snd_soc_dai_ops wsa881x_da .hw_params = wsa881x_hw_params, .hw_free = wsa881x_hw_free, .mute_stream = wsa881x_digital_mute, - .set_sdw_stream = wsa881x_set_sdw_stream, + .set_stream = wsa881x_set_sdw_stream, };static struct snd_soc_dai_driver wsa881x_dais[] = {
sound/soc/intel/boards/sof_sdw.c +3 -3
@@ -231,7 +231,7 @@ int sdw_prepare(struct snd_pcm_substream/* Find stream from first CPU DAI */ dai =asoc_rtd_to_cpu (rtd,0 ); - sdw_stream =snd_soc_dai_get_sdw_stream (dai, substream->stream); + sdw_stream =snd_soc_dai_get_stream (dai, substream->stream);if (IS_ERR (sdw_stream)) {dev_err (rtd->dev,"no stream found for DAI %s" , dai->name);
@@ -251,7 +251,7 @@ int sdw_trigger(struct snd_pcm_substream/* Find stream from first CPU DAI */ dai =asoc_rtd_to_cpu (rtd,0 ); - sdw_stream =snd_soc_dai_get_sdw_stream (dai, substream->stream); + sdw_stream =snd_soc_dai_get_stream (dai, substream->stream);if (IS_ERR (sdw_stream)) {dev_err (rtd->dev,"no stream found for DAI %s" , dai->name);
@@ -290,7 +290,7 @@ int sdw_hw_free(struct snd_pcm_substream/* Find stream from first CPU DAI */ dai =asoc_rtd_to_cpu (rtd,0 ); - sdw_stream =snd_soc_dai_get_sdw_stream (dai, substream->stream); + sdw_stream =snd_soc_dai_get_stream (dai, substream->stream);if (IS_ERR (sdw_stream)) {dev_err (rtd->dev,"no stream found for DAI %s" , dai->name);
sound/soc/qcom/sdm845.c +2 -2
@@ -56,8 +56,8 @@ static int sdm845_slim_snd_hw_params(strint ret =0 , i;for_each_rtd_codec_dais (rtd, i, codec_dai) { - sruntime =snd_soc_dai_get_sdw_stream (codec_dai, - substream->stream); + sruntime =snd_soc_dai_get_stream (codec_dai, + substream->stream);if (sruntime !=ERR_PTR (-ENOTSUPP )) pdata->sruntime[cpu_dai->id] = sruntime;
Greg Kroah-Hartman
maintainerPATCH 603/783 net/mlx5e: Fix nullptr in mlx5e_tc_add_fdb_flow()
In reply to Greg Kroah-HartmanFrom: Dima Chumak <[email protected]>
commit fe7738eb3ca3631a75844e790f6cb576c0fe7b00 upstream.
The result of __dev_get_by_index() is not checked for NULL, which then passed to mlx5e_attach_encap() and gets dereferenced.
Also, in case of a successful lookup, the net_device reference count is not incremented, which may result in net_device pointer becoming invalid at any time during mlx5e_attach_encap() execution.
Fix by using dev_get_by_index(), which does proper reference counting on the net_device pointer. Also, handle nullptr return value when mirred device is not found.
It's safe to call dev_put() on the mirred net_device pointer, right after mlx5e_attach_encap() call, because it's not being saved/copied down the call chain.
Addresses-Coverity: ("Dereference null return value")
--- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +9 -3
@@ -1344,9 +1344,9 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv struct netlink_ext_ack *extack) {struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; -struct net_device *out_dev, *encap_dev =NULL ;struct mlx5e_tc_flow_parse_attr *parse_attr;struct mlx5_flow_attr *attr = flow->attr; +struct net_device *encap_dev =NULL ;struct mlx5_esw_flow_attr *esw_attr;struct mlx5_fc *counter =NULL ;struct mlx5e_rep_priv *rpriv;
@@ -1391,16 +1391,22 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv esw_attr = attr->esw_attr;for (out_index =0 ; out_index <MLX5_MAX_FLOW_FWD_VPORTS ; out_index++) { +struct net_device *out_dev;int mirred_ifindex;if (!(esw_attr->dests[out_index].flags &MLX5_ESW_DEST_ENCAP ))continue ; mirred_ifindex = parse_attr->mirred_ifindex[out_index]; - out_dev =__dev_get_by_index (dev_net (priv->netdev), - mirred_ifindex); + out_dev =dev_get_by_index (dev_net (priv->netdev), mirred_ifindex); +if (!out_dev) { +NL_SET_ERR_MSG_MOD (extack,"Requested mirred device not found" ); + err = -ENODEV ; +return err; + } err =mlx5e_attach_encap (priv, flow, out_dev, out_index, extack, &encap_dev, &encap_valid); +dev_put (out_dev);if (err)return err;
Greg Kroah-Hartman
maintainerPATCH 604/783 wifi: rtlwifi: remove always-true condition pointed out by GCC 12
In reply to Greg Kroah-HartmanFrom: Jakub Kicinski <[email protected]>
commit ee3db469dd317e82f57b13aa3bc61be5cb60c2b4 upstream.
The .value is a two-dim array, not a pointer.
struct iqk_matrix_regs {
bool iqk_done;
long value[1][IQK_MATRIX_REG_NUM];
};--- drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.c +1 -4
@@ -2385,10 +2385,7 @@ void rtl92d_phy_reload_iqk_setting(strucrtl_dbg (rtlpriv,COMP_SCAN ,DBG_LOUD ,"Just Read IQK Matrix reg for channel:%d....\n" , channel); -if ((rtlphy->iqk_matrix[indexforchannel]. - value[0 ] !=NULL ) -/*&&(regea4 != 0) */ ) - _rtl92d_phy_patha_fill_iqk_matrix(hw, true, + _rtl92d_phy_patha_fill_iqk_matrix(hw, true, rtlphy->iqk_matrix[ indexforchannel].value, 0, (rtlphy->iqk_matrix[
Greg Kroah-Hartman
maintainerPATCH 605/783 wifi: rtlwifi: 8192de: correct checking of IQK reload
In reply to Greg Kroah-HartmanFrom: Ping-Ke Shih <[email protected]>
commit 93fbc1ebd978cf408ef5765e9c1630fce9a8621b upstream.
Since IQK could spend time, we make a cache of IQK result matrix that looks like iqk_matrix[channel_idx].val[x][y], and we can reload the matrix if we have made a cache. To determine a cache is made, we check iqk_matrix[channel_idx].val[0][0].
The initial commit 7274a8c22980 ("rtlwifi: rtl8192de: Merge phy routines") make a mistake that checks incorrect iqk_matrix[channel_idx].val[0] that is always true, and this mistake is found by commit ee3db469dd31 ("wifi: rtlwifi: remove always-true condition pointed out by GCC 12"), so I recall the vendor driver to find fix and apply the correctness.
--- drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.c +4 -5
@@ -2385,11 +2385,10 @@ void rtl92d_phy_reload_iqk_setting(strucrtl_dbg (rtlpriv,COMP_SCAN ,DBG_LOUD ,"Just Read IQK Matrix reg for channel:%d....\n" , channel); -_rtl92d_phy_patha_fill_iqk_matrix (hw, true, - rtlphy->iqk_matrix[ - indexforchannel].value,0 , - (rtlphy->iqk_matrix[ - indexforchannel].value[0 ][2 ] ==0 )); +if (rtlphy->iqk_matrix[indexforchannel].value[0 ][0 ] !=0 ) +_rtl92d_phy_patha_fill_iqk_matrix (hw, true, + rtlphy->iqk_matrix[indexforchannel].value,0 , + rtlphy->iqk_matrix[indexforchannel].value[0 ][2 ] ==0 );if (IS_92D_SINGLEPHY (rtlhal->version)) {if ((rtlphy->iqk_matrix[ indexforchannel].value[0][4] != 0)
Greg Kroah-Hartman
maintainerPATCH 606/783 torture: Exclude "NOHZ tick-stop error" from fatal errors
In reply to Greg Kroah-HartmanFrom: Paul E. McKenney <[email protected]>
commit 8d68e68a781db80606c8e8f3e4383be6974878fd upstream.
The "NOHZ tick-stop error: Non-RCU local softirq work is pending" warning happens frequently and appears to be irrelevant to the various torture tests. This commit therefore filters it out.
If there proves to be a need to pay attention to it a later commit will add an "advice" category to allow the user to immediately see that although something happened, it was not an indictment of the system being tortured.
--- tools/testing/selftests/rcutorture/bin/console-badness.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/rcutorture/bin/console-badness.sh +2 -1
@@ -13,4 +13,5 @@ egrep 'Badness|WARNING:|Warn|BUG|===========|Call Trace:|Oops:|detected stalls on CPUs/tasks:|self-detected stall on CPU|Stall ended before state dump start|\?\?\? Writer stall state|rcu_.*kthread starved for|!!!' | grep -v 'ODEBUG: ' | grep -v 'This means that this is a DEBUG kernel and it is' | -grep -v 'Warning: unable to open an initial console' +grep -v 'Warning: unable to open an initial console' | +grep -v 'NOHZ tick-stop error: Non-RCU local softirq work is pending, handler'
Greg Kroah-Hartman
maintainerPATCH 607/783 rcu: Prevent lockdep-RCU splats on lock acquisition/release
In reply to Greg Kroah-HartmanFrom: Paul E. McKenney <[email protected]>
commit 4d60b475f858ebdb06c1339f01a890f287b5e587 upstream.
The rcu_cpu_starting() and rcu_report_dead() functions transition the current CPU between online and offline state from an RCU perspective. Unfortunately, this means that the rcu_cpu_starting() function's lock acquisition and the rcu_report_dead() function's lock releases happen while the CPU is offline from an RCU perspective, which can result in lockdep-RCU splats about using RCU from an offline CPU. And this situation can also result in too-short grace periods, especially in guest OSes that are subject to vCPU preemption.
This commit therefore uses sequence-count-like synchronization to forgive use of RCU while RCU thinks a CPU is offline across the full extent of the rcu_cpu_starting() and rcu_report_dead() function's lock acquisitions and releases.
One approach would have been to use the actual sequence-count primitives provided by the Linux kernel. Unfortunately, the resulting code looks completely broken and wrong, and is likely to result in patches that break RCU in an attempt to address this appearance of broken wrongness. Plus there is no net savings in lines of code, given the additional explicit memory barriers required.
Therefore, this sequence count is instead implemented by a new ->ofl_seq field in the rcu_node structure. If this counter's value is an odd number, RCU forgives RCU read-side critical sections on other CPUs covered by the same rcu_node structure, even if those CPUs are offline from an RCU perspective. In addition, if a given leaf rcu_node structure's ->ofl_seq counter value is an odd number, rcu_gp_init() delays starting the grace period until that counter value changes.
--- kernel/rcu/tree.c | 21 ++++++++++++++++++++- kernel/rcu/tree.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-)
kernel/rcu/tree.c +20 -1
@@ -1157,7 +1157,7 @@ bool rcu_lockdep_current_cpu_online(voidpreempt_disable_notrace (); rdp =this_cpu_ptr (&rcu_data); rnp = rdp->mynode; -if (rdp->grpmask &rcu_rnp_online_cpus (rnp)) +if (rdp->grpmask &rcu_rnp_online_cpus (rnp) ||READ_ONCE (rnp->ofl_seq) &0x1 ) ret = true;preempt_enable_notrace ();return ret;
@@ -1724,6 +1724,7 @@ static void rcu_strict_gp_boundary(void*/ static bool rcu_gp_init (void ) { +unsigned long firstseq;unsigned long flags;unsigned long oldmask;unsigned long mask;
@@ -1767,6 +1768,12 @@ static bool rcu_gp_init(void)*/ rcu_state.gp_state =RCU_GP_ONOFF ;rcu_for_each_leaf_node (rnp) { +smp_mb ();// Pair with barriers used when updating ->ofl_seq to odd values. + firstseq =READ_ONCE (rnp->ofl_seq); +if (firstseq &0x1 ) +while (firstseq ==READ_ONCE (rnp->ofl_seq)) +schedule_timeout_idle (1 );// Can't wake unless RCU is watching. +smp_mb ();// Pair with barriers used when updating ->ofl_seq to even values. raw_spin_lock (&rcu_state.ofl_lock);raw_spin_lock_irq_rcu_node (rnp); if (rnp->qsmaskinit == rnp->qsmaskinitnext &&
@@ -4107,6 +4114,9 @@ void rcu_cpu_starting(unsigned int cpu) rnp = rdp->mynode; mask = rdp->grpmask; +WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 ); +WARN_ON_ONCE (!(rnp->ofl_seq &0x1 )); +smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). raw_spin_lock_irqsave_rcu_node (rnp, flags);WRITE_ONCE (rnp->qsmaskinitnext, rnp->qsmaskinitnext | mask); newcpu = !(rnp->expmaskinitnext & mask);
@@ -4124,6 +4134,9 @@ void rcu_cpu_starting(unsigned int cpu) }else {raw_spin_unlock_irqrestore_rcu_node (rnp, flags); } +smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). +WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 ); +WARN_ON_ONCE (rnp->ofl_seq &0x1 );smp_mb ();/* Ensure RCU read-side usage follows above initialization. */ }
@@ -4150,6 +4163,9 @@ void rcu_report_dead(unsigned int cpu)/* Remove outgoing CPU from mask in the leaf rcu_node structure. */ mask = rdp->grpmask; +WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 ); +WARN_ON_ONCE (!(rnp->ofl_seq &0x1 )); +smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). raw_spin_lock (&rcu_state.ofl_lock);raw_spin_lock_irqsave_rcu_node (rnp, flags);/* Enforce GP memory-order guarantee. */ rdp->rcu_ofl_gp_seq =READ_ONCE (rcu_state.gp_seq);
@@ -4162,6 +4178,9 @@ void rcu_report_dead(unsigned int cpu)WRITE_ONCE (rnp->qsmaskinitnext, rnp->qsmaskinitnext & ~mask);raw_spin_unlock_irqrestore_rcu_node (rnp, flags);raw_spin_unlock (&rcu_state.ofl_lock); +smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). +WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 ); +WARN_ON_ONCE (rnp->ofl_seq &0x1 ); rdp->cpu_started = false; }
kernel/rcu/tree.h +1 -0
@@ -56,6 +56,7 @@ struct rcu_node {/* Initialized from ->qsmaskinitnext at the */ /* beginning of each grace period. */ unsigned long qsmaskinitnext; +unsigned long ofl_seq;/* CPU-hotplug operation sequence count. */ /* Online CPUs for next grace period. */ unsigned long expmask;/* CPUs or groups that need to check in */ /* to allow the current expedited GP */
Greg Kroah-Hartman
maintainerPATCH 608/783 net/af_packet: add VLAN support for AF_PACKET SOCK_RAW GSO
In reply to Greg Kroah-HartmanFrom: Hangbin Liu <[email protected]>
commit dfed913e8b55a0c2c4906f1242fd38fd9a116e49 upstream.
Currently, the kernel drops GSO VLAN tagged packet if it's created with socket(AF_PACKET, SOCK_RAW, 0) plus virtio_net_hdr.
The reason is AF_PACKET doesn't adjust the skb network header if there is a VLAN tag. Then after virtio_net_hdr_set_proto() called, the skb->protocol will be set to ETH_P_IP/IPv6. And in later inet/ipv6_gso_segment() the skb is dropped as network header position is invalid.
Let's handle VLAN packets by adjusting network header position in packet_parse_headers(). The adjustment is safe and does not affect the later xmit as tap device also did that.
In packet_snd(), packet_parse_headers() need to be moved before calling virtio_net_hdr_set_proto(), so we can set correct skb->protocol and network header first.
There is no need to update tpacket_snd() as it calls packet_parse_headers() in tpacket_fill_skb(), which is already before calling virtio_net_hdr_* functions.
skb->no_fcs setting is also moved upper to make all skb settings together and keep consistency with function packet_sendmsg_spkt().
--- net/packet/af_packet.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
net/packet/af_packet.c +13 -5
@@ -1885,12 +1885,20 @@ oom:static void packet_parse_headers (struct sk_buff *skb,struct socket *sock) { +int depth; +if ((!skb->protocol || skb->protocol ==htons (ETH_P_ALL )) && sock->type ==SOCK_RAW ) {skb_reset_mac_header (skb); skb->protocol =dev_parse_header_protocol (skb); } +/* Move network header to the right position for VLAN tagged packets */ +if (likely (skb->dev->type ==ARPHRD_ETHER ) && +eth_type_vlan (skb->protocol) && +__vlan_get_protocol (skb, skb->protocol, &depth) !=0 ) +skb_set_network_header (skb, depth); +skb_probe_transport_header (skb); }
@@ -3005,6 +3013,11 @@ static int packet_snd(struct socket *soc skb->mark = sockc.mark; skb->tstamp = sockc.transmit_time; +if (unlikely (extra_len ==4 )) + skb->no_fcs =1 ; + +packet_parse_headers (skb, sock); +if (has_vnet_hdr) { err =virtio_net_hdr_to_skb (skb, &vnet_hdr,vio_le ());if (err)
@@ -3013,11 +3026,6 @@ static int packet_snd(struct socket *socvirtio_net_hdr_set_proto (skb, &vnet_hdr); } -packet_parse_headers (skb, sock); - -if (unlikely (extra_len ==4 )) - skb->no_fcs =1 ; - err = po->xmit (skb);if (unlikely (err !=0 )) {if (err >0 )
Greg Kroah-Hartman
maintainerPATCH 609/783 net/af_packet: make sure to pull mac header
In reply to Greg Kroah-HartmanFrom: Eric Dumazet <[email protected]>
commit e9d3f80935b6607dcdc5682b00b1d4b28e0a0c5d upstream.
GSO assumes skb->head contains link layer headers.
tun device in some case can provide base 14 bytes, regardless of VLAN being used or not.
After blamed commit, we can end up setting a network header offset of 18+, we better pull the missing bytes to avoid a posible crash in GSO.
syzbot report was:
kernel BUG at include/linux/skbuff.h:2699!
invalid opcode: 0000 [#1] PREEMPT SMP KASAN
CPU: 1 PID: 3601 Comm: syz-executor210 Not tainted 5.18.0-syzkaller-11338-g2c5ca23f7414 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:__skb_pull include/linux/skbuff.h:2699 [inline] RIP: 0010:skb_mac_gso_segment+0x48f/0x530 net/core/gro.c:136 Code: 00 48 c7 c7 00 96 d4 8a c6 05 cb d3 45 06 01 e8 26 bb d0 01 e9 2f fd ff ff 49 c7 c4 ea ff ff ff e9 f1 fe ff ff e8 91 84 19 fa <0f> 0b 48 89 df e8 97 44 66 fa e9 7f fd ff ff e8 ad 44 66 fa e9 48 RSP: 0018:ffffc90002e2f4b8 EFLAGS: 00010293 RAX: 0000000000000000 RBX: 0000000000000012 RCX: 0000000000000000 RDX: ffff88805bb58000 RSI: ffffffff8760ed0f RDI: 0000000000000004 RBP: 0000000000005dbc R08: 0000000000000004 R09: 0000000000000fe0 R10: 0000000000000fe4 R11: 0000000000000000 R12: 0000000000000fe0 R13: ffff88807194d780 R14: 1ffff920005c5e9b R15: 0000000000000012 FS: 000055555730f300(0000) GS:ffff8880b9d00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000200015c0 CR3: 0000000071ff8000 CR4: 0000000000350ee0 Call Trace: <TASK> __skb_gso_segment+0x327/0x6e0 net/core/dev.c:3411 skb_gso_segment include/linux/netdevice.h:4749 [inline] validate_xmit_skb+0x6bc/0xf10 net/core/dev.c:3669 validate_xmit_skb_list+0xbc/0x120 net/core/dev.c:3719 sch_direct_xmit+0x3d1/0xbe0 net/sched/sch_generic.c:327 __dev_xmit_skb net/core/dev.c:3815 [inline] __dev_queue_xmit+0x14a1/0x3a00 net/core/dev.c:4219 packet_snd net/packet/af_packet.c:3071 [inline] packet_sendmsg+0x21cb/0x5550 net/packet/af_packet.c:3102 sock_sendmsg_nosec net/socket.c:714 [inline] sock_sendmsg+0xcf/0x120 net/socket.c:734 ____sys_sendmsg+0x6eb/0x810 net/socket.c:2492 ___sys_sendmsg+0xf3/0x170 net/socket.c:2546 __sys_sendmsg net/socket.c:2575 [inline] __do_sys_sendmsg net/socket.c:2584 [inline] __se_sys_sendmsg net/socket.c:2582 [inline] __x64_sys_sendmsg+0x132/0x220 net/socket.c:2582 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x46/0xb0 RIP: 0033:0x7f4b95da06c9 Code: 28 c3 e8 4a 15 00 00 66 2e 0f 1f 84 00 00 00 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffd7defc4c8 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007ffd7defc4f0 RCX: 00007f4b95da06c9 RDX: 0000000000000000 RSI: 0000000020000140 RDI: 0000000000000003 RBP: 0000000000000003 R08: bb1414ac00000050 R09: bb1414ac00000050 R10: 0000000000000004 R11: 0000000000000246 R12: 0000000000000000 R13: 00007ffd7defc4e0 R14: 00007ffd7defc4d8 R15: 00007ffd7defc4d4 </TASK>
--- net/packet/af_packet.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/packet/af_packet.c +4 -2
@@ -1896,8 +1896,10 @@ static void packet_parse_headers(struct/* Move network header to the right position for VLAN tagged packets */ if (likely (skb->dev->type ==ARPHRD_ETHER ) &ð_type_vlan (skb->protocol) && -__vlan_get_protocol (skb, skb->protocol, &depth) !=0 ) -skb_set_network_header (skb, depth); +__vlan_get_protocol (skb, skb->protocol, &depth) !=0 ) { +if (pskb_may_pull (skb, depth)) +skb_set_network_header (skb, depth); + }skb_probe_transport_header (skb); }
Greg Kroah-Hartman
maintainerPATCH 610/783 media: stv0288: use explicitly signed char
In reply to Greg Kroah-HartmanFrom: Jason A. Donenfeld <[email protected]>
commit 7392134428c92a4cb541bd5c8f4f5c8d2e88364d upstream.
With char becoming unsigned by default, and with char alone being ambiguous and based on architecture, signed chars need to be marked explicitly as such. Use s8 and u8 types here, since that's what surrounding code does. This fixes:
drivers/media/dvb-frontends/stv0288.c:471 stv0288_set_frontend() warn: assigning (-9) to unsigned variable 'tm' drivers/media/dvb-frontends/stv0288.c:471 stv0288_set_frontend() warn: we never enter this loop
--- drivers/media/dvb-frontends/stv0288.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/dvb-frontends/stv0288.c +2 -3
@@ -440,9 +440,8 @@ static int stv0288_set_frontend(struct dstruct stv0288_state *state = fe->demodulator_priv;struct dtv_frontend_properties *c = &fe->dtv_property_cache; -char tm; -unsigned char tda[3 ]; -u8 reg, time_out =0 ; +u8 tda[3 ], reg, time_out =0 ; +s8 tm;dprintk ("%s : FE_SET_FRONTEND\n" , __func__);
Greg Kroah-Hartman
maintainerPATCH 611/783 soc: qcom: Select REMAP_MMIO for LLCC driver
In reply to Greg Kroah-HartmanFrom: Manivannan Sadhasivam <[email protected]>
commit 5d2fe2d7b616b8baa18348ead857b504fc2de336 upstream.
LLCC driver uses REGMAP_MMIO for accessing the hardware registers. So select the dependency in Kconfig. Without this, there will be errors while building the driver with COMPILE_TEST only:
ERROR: modpost: "__devm_regmap_init_mmio_clk" [drivers/soc/qcom/llcc-qcom.ko] undefined! make[1]: *** [scripts/Makefile.modpost:126: Module.symvers] Error 1
make: *** [Makefile:1944: modpost] Error 2
--- drivers/soc/qcom/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/soc/qcom/Kconfig +1 -0
@@ -63,6 +63,7 @@ config QCOM_GSBI config QCOM_LLCC tristate "Qualcomm Technologies, Inc. LLCC driver" depends on ARCH_QCOM || COMPILE_TEST + select REGMAP_MMIO help Qualcomm Technologies, Inc. platform specific Last Level Cache Controller(LLCC) driver for platforms such as,
Greg Kroah-Hartman
maintainerPATCH 612/783 kest.pl: Fix grub2 menu handling for rebooting
In reply to Greg Kroah-HartmanFrom: Steven Rostedt <[email protected]>
commit 26df05a8c1420ad3de314fdd407e7fc2058cc7aa upstream.
grub2 has submenus where to use grub-reboot, it requires:
grub-reboot X>Y
where X is the main index and Y is the submenu. Thus if you have:
menuentry 'Debian GNU/Linux' --class debian --class gnu-linux ...
[...]
}
submenu 'Advanced options for Debian GNU/Linux' $menuentry_id_option ...
menuentry 'Debian GNU/Linux, with Linux 6.0.0-4-amd64' --class debian --class gnu-linux ...
[...]
}
menuentry 'Debian GNU/Linux, with Linux 6.0.0-4-amd64 (recovery mode)' --class debian --class gnu-linux ...
[...]
}
menuentry 'Debian GNU/Linux, with Linux test' --class debian --class gnu-linux ...
[...]
}And wanted to boot to the "Linux test" kernel, you need to run:
# grub-reboot 1>2
As 1 is the second top menu (the submenu) and 2 is the third of the sub menu entries.
Have the grub.cfg parsing for grub2 handle such cases.
--- tools/testing/ktest/ktest.pl | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
tools/testing/ktest/ktest.pl +15 -5
@@ -1912,7 +1912,7 @@ sub run_scp_mod { sub _get_grub_index { - my ($command, $target, $skip) = @_; + my ($command, $target, $skip, $submenu) = @_; return if (defined($grub_number) && defined($last_grub_menu) && $last_grub_menu eq $grub_menu && defined($last_machine) &&
@@ -1929,11 +1929,16 @@ sub _get_grub_index { my $found = 0; + my $submenu_number = 0; + while (<IN>) { if (/$target/) { $grub_number++; $found = 1; last; + } elsif (defined($submenu) && /$submenu/) { + $submenu_number++; + $grub_number = -1; } elsif (/$skip/) { $grub_number++; }
@@ -1942,6 +1947,9 @@ sub _get_grub_index { dodie "Could not find '$grub_menu' through $command on $machine" if (!$found); + if ($submenu_number > 0) { + $grub_number = "$submenu_number>$grub_number"; + } doprint "$grub_number\n"; $last_grub_menu = $grub_menu; $last_machine = $machine;
@@ -1952,6 +1960,7 @@ sub get_grub_index { my $command; my $target; my $skip; + my $submenu; my $grub_menu_qt; if ($reboot_type !~ /^grub/) {
@@ -1966,8 +1975,9 @@ sub get_grub_index { $skip = '^\s*title\s'; } elsif ($reboot_type eq "grub2") { $command = "cat $grub_file"; - $target = '^menuentry.*' . $grub_menu_qt; - $skip = '^menuentry\s|^submenu\s'; + $target = '^\s*menuentry.*' . $grub_menu_qt; + $skip = '^\s*menuentry'; + $submenu = '^\s*submenu\s'; } elsif ($reboot_type eq "grub2bls") { $command = $grub_bls_get; $target = '^title=.*' . $grub_menu_qt;
@@ -1976,7 +1986,7 @@ sub get_grub_index { return; } - _get_grub_index($command, $target, $skip); + _get_grub_index($command, $target, $skip, $submenu); } sub wait_for_input
@@ -2040,7 +2050,7 @@ sub reboot_to { if ($reboot_type eq "grub") { run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'"; } elsif (($reboot_type eq "grub2") or ($reboot_type eq "grub2bls")) { - run_ssh "$grub_reboot $grub_number"; + run_ssh "$grub_reboot \"'$grub_number'\""; } elsif ($reboot_type eq "syslinux") { run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path"; } elsif (defined $reboot_script) {
Greg Kroah-Hartman
maintainerPATCH 613/783 ktest.pl minconfig: Unset configs instead of just removing them
In reply to Greg Kroah-HartmanFrom: Steven Rostedt <[email protected]>
commit ef784eebb56425eed6e9b16e7d47e5c00dcf9c38 upstream.
After a full run of a make_min_config test, I noticed there were a lot of CONFIGs still enabled that really should not be. Looking at them, I noticed they were all defined as "default y". The issue is that the test simple removes the config and re-runs make oldconfig, which enables it again because it is set to default 'y'. Instead, explicitly disable the config with writing "# CONFIG_FOO is not set" to the file to keep it from being set again.
With this change, one of my box's minconfigs went from 768 configs set, down to 521 configs set.
--- tools/testing/ktest/ktest.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/ktest/ktest.pl +2 -1
@@ -3773,9 +3773,10 @@ sub test_this_config { # .config to make sure it is missing the config that # we had before my %configs = %min_configs; - delete $configs{$config}; + $configs{$config} = "# $config is not set"; make_new_config ((values %configs), (values %keep_configs)); make_oldconfig; + delete $configs{$config}; undef %configs; assign_configs \%configs, $output_config;
Greg Kroah-Hartman
maintainerPATCH 614/783 jbd2: use the correct print format
In reply to Greg Kroah-HartmanFrom: Bixuan Cui <[email protected]>
commit d87a7b4c77a997d5388566dd511ca8e6b8e8a0a8 upstream.
The print format error was found when using ftrace event:
<...>-1406 [000] .... 23599442.895823: jbd2_end_commit: dev 252,8 transaction -1866216965 sync 0 head -1866217368
<...>-1406 [000] .... 23599442.896299: jbd2_start_commit: dev 252,8 transaction -1866216964 sync 0Use the correct print format for transaction, head and tid.
--- include/trace/events/jbd2.h | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-)
include/trace/events/jbd2.h +22 -22
@@ -40,7 +40,7 @@ DECLARE_EVENT_CLASS(jbd2_commit,TP_STRUCT__entry (__field (dev_t ,dev )__field ( char, sync_commit ) -__field ( int, transaction ) +__field ( tid_t, transaction ) ), TP_fast_assign(
@@ -49,7 +49,7 @@ DECLARE_EVENT_CLASS(jbd2_commit, __entry->transaction = commit_transaction->t_tid; ), -TP_printk ("dev %d,%d transaction %d sync %d" , +TP_printk ("dev %d,%d transaction %u sync %d" ,MAJOR (__entry->dev),MINOR (__entry->dev), __entry->transaction, __entry->sync_commit) );
@@ -97,8 +97,8 @@ TRACE_EVENT(jbd2_end_commit,TP_STRUCT__entry (__field (dev_t ,dev )__field ( char, sync_commit ) -__field ( int, transaction ) -__field ( int, head ) +__field ( tid_t, transaction ) +__field ( tid_t, head ) ), TP_fast_assign(
@@ -108,7 +108,7 @@ TRACE_EVENT(jbd2_end_commit, __entry->head = journal->j_tail_sequence; ), -TP_printk ("dev %d,%d transaction %d sync %d head %d" , +TP_printk ("dev %d,%d transaction %u sync %d head %u" ,MAJOR (__entry->dev),MINOR (__entry->dev), __entry->transaction, __entry->sync_commit, __entry->head) );
@@ -134,14 +134,14 @@ TRACE_EVENT(jbd2_submit_inode_data, ); DECLARE_EVENT_CLASS(jbd2_handle_start_class, - TP_PROTO(dev_t dev, unsigned long tid, unsigned int type, + TP_PROTO(dev_t dev, tid_t tid, unsigned int type, unsigned int line_no, int requested_blocks), TP_ARGS(dev, tid, type, line_no, requested_blocks), TP_STRUCT__entry( __field( dev_t, dev ) - __field( unsigned long, tid ) + __field( tid_t, tid ) __field( unsigned int, type ) __field( unsigned int, line_no ) __field( int, requested_blocks)
@@ -155,28 +155,28 @@ DECLARE_EVENT_CLASS(jbd2_handle_start_cl __entry->requested_blocks = requested_blocks; ), -TP_printk ("dev %d,%d tid %lu type %u line_no %u " +TP_printk ("dev %d,%d tid %u type %u line_no %u " "requested_blocks %d" ,MAJOR (__entry->dev),MINOR (__entry->dev), __entry->tid, __entry->type, __entry->line_no, __entry->requested_blocks) );DEFINE_EVENT (jbd2_handle_start_class, jbd2_handle_start, - TP_PROTO(dev_t dev, unsigned long tid, unsigned int type, + TP_PROTO(dev_t dev, tid_t tid, unsigned int type, unsigned int line_no, int requested_blocks),TP_ARGS (dev, tid, type, line_no, requested_blocks) );DEFINE_EVENT (jbd2_handle_start_class, jbd2_handle_restart, - TP_PROTO(dev_t dev, unsigned long tid, unsigned int type, + TP_PROTO(dev_t dev, tid_t tid, unsigned int type, unsigned int line_no, int requested_blocks),TP_ARGS (dev, tid, type, line_no, requested_blocks) ); TRACE_EVENT(jbd2_handle_extend, - TP_PROTO(dev_t dev, unsigned long tid, unsigned int type, + TP_PROTO(dev_t dev, tid_t tid, unsigned int type, unsigned int line_no, int buffer_credits, int requested_blocks),
@@ -184,7 +184,7 @@ TRACE_EVENT(jbd2_handle_extend,TP_STRUCT__entry (__field (dev_t ,dev ) - __field( unsigned long, tid ) +__field ( tid_t, tid ) __field( unsigned int, type ) __field( unsigned int, line_no ) __field( int, buffer_credits )
@@ -200,7 +200,7 @@ TRACE_EVENT(jbd2_handle_extend, __entry->requested_blocks = requested_blocks; ), - TP_printk("dev %d,%d tid %lu type %u line_no %u " + TP_printk("dev %d,%d tid %u type %u line_no %u " "buffer_credits %d requested_blocks %d", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->tid, __entry->type, __entry->line_no, __entry->buffer_credits,
@@ -208,7 +208,7 @@ TRACE_EVENT(jbd2_handle_extend, ); TRACE_EVENT(jbd2_handle_stats, - TP_PROTO(dev_t dev, unsigned long tid, unsigned int type, + TP_PROTO(dev_t dev, tid_t tid, unsigned int type, unsigned int line_no, int interval, int sync, int requested_blocks, int dirtied_blocks),
@@ -217,7 +217,7 @@ TRACE_EVENT(jbd2_handle_stats,TP_STRUCT__entry (__field (dev_t ,dev ) - __field( unsigned long, tid ) +__field ( tid_t, tid ) __field( unsigned int, type ) __field( unsigned int, line_no ) __field( int, interval )
@@ -237,7 +237,7 @@ TRACE_EVENT(jbd2_handle_stats, __entry->dirtied_blocks = dirtied_blocks; ), - TP_printk("dev %d,%d tid %lu type %u line_no %u interval %d " + TP_printk("dev %d,%d tid %u type %u line_no %u interval %d " "sync %d requested_blocks %d dirtied_blocks %d", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->tid, __entry->type, __entry->line_no, __entry->interval,
@@ -246,14 +246,14 @@ TRACE_EVENT(jbd2_handle_stats, ); TRACE_EVENT(jbd2_run_stats, - TP_PROTO(dev_t dev, unsigned long tid, + TP_PROTO(dev_t dev, tid_t tid, struct transaction_run_stats_s *stats), TP_ARGS(dev, tid, stats), TP_STRUCT__entry( __field( dev_t, dev ) - __field( unsigned long, tid ) + __field( tid_t, tid ) __field( unsigned long, wait ) __field( unsigned long, request_delay ) __field( unsigned long, running )
@@ -279,7 +279,7 @@ TRACE_EVENT(jbd2_run_stats, __entry->blocks_logged = stats->rs_blocks_logged; ), - TP_printk("dev %d,%d tid %lu wait %u request_delay %u running %u " + TP_printk("dev %d,%d tid %u wait %u request_delay %u running %u " "locked %u flushing %u logging %u handle_count %u " "blocks %u blocks_logged %u", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->tid,
@@ -294,14 +294,14 @@ TRACE_EVENT(jbd2_run_stats, ); TRACE_EVENT(jbd2_checkpoint_stats, - TP_PROTO(dev_t dev, unsigned long tid, + TP_PROTO(dev_t dev, tid_t tid, struct transaction_chp_stats_s *stats), TP_ARGS(dev, tid, stats), TP_STRUCT__entry( __field( dev_t, dev ) - __field( unsigned long, tid ) + __field( tid_t, tid ) __field( unsigned long, chp_time ) __field( __u32, forced_to_close ) __field( __u32, written )
@@ -317,7 +317,7 @@ TRACE_EVENT(jbd2_checkpoint_stats, __entry->dropped = stats->cs_dropped; ), - TP_printk("dev %d,%d tid %lu chp_time %u forced_to_close %u " + TP_printk("dev %d,%d tid %u chp_time %u forced_to_close %u " "written %u dropped %u", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->tid, jiffies_to_msecs(__entry->chp_time),
Greg Kroah-Hartman
maintainerPATCH 615/783 arm64: dts: qcom: sdm845-db845c: correct SPI2 pins drive strength
In reply to Greg Kroah-HartmanFrom: Krzysztof Kozlowski <[email protected]>
commit 9905370560d9c29adc15f4937c5a0c0dac05f0b4 upstream.
The pin configuration (done with generic pin controller helpers and as expressed by bindings) requires children nodes with either:
1. "pins" property and the actual configuration,
2. another set of nodes with above point.
The qup_spi2_default pin configuration uses alreaady the second method with a "pinmux" child, so configure drive-strength similarly in "pinconf". Otherwise the PIN drive strength would not be applied.
--- arch/arm64/boot/dts/qcom/sdm845-db845c.dts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/sdm845-db845c.dts +4 -1
@@ -1045,7 +1045,10 @@ /* PINCTRL - additions to nodes defined in sdm845.dtsi */ &qup_spi2_default { - drive-strength = <16>; + pinconf { + pins = "gpio27", "gpio28", "gpio29", "gpio30"; + drive-strength = <16>; + }; }; &qup_uart3_default{
Greg Kroah-Hartman
maintainerPATCH 616/783 mmc: sdhci-sprd: Disable CLK_AUTO when the clock is less than 400K
In reply to Greg Kroah-HartmanFrom: Wenchao Chen <[email protected]>
commit ff874dbc4f868af128b412a9bd92637103cf11d7 upstream.
When the clock is less than 400K, some SD cards fail to initialize because CLK_AUTO is enabled.
--- drivers/mmc/host/sdhci-sprd.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/mmc/host/sdhci-sprd.c +9 -7
@@ -224,13 +224,15 @@ static inline void _sdhci_sprd_set_clock div = ((div &0x300 ) >>2 ) | ((div &0xFF ) <<8 );sdhci_enable_clk (host, div); -/* enable auto gate sdhc_enable_auto_gate */ - val =sdhci_readl (host,SDHCI_SPRD_REG_32_BUSY_POSI ); - mask =SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN | -SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN ; -if (mask != (val & mask)) { - val |= mask; -sdhci_writel (host, val,SDHCI_SPRD_REG_32_BUSY_POSI ); +/* Enable CLK_AUTO when the clock is greater than 400K. */ +if (clk >400000 ) { + val =sdhci_readl (host,SDHCI_SPRD_REG_32_BUSY_POSI ); + mask =SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN | +SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN ; +if (mask != (val & mask)) { + val |= mask; +sdhci_writel (host, val,SDHCI_SPRD_REG_32_BUSY_POSI ); + } } }
Greg Kroah-Hartman
maintainerPATCH 617/783 btrfs: fix resolving backrefs for inline extent followed by prealloc
In reply to Greg Kroah-HartmanFrom: Boris Burkov <[email protected]>
commit 560840afc3e63bbe5d9c5ef6b2ecf8f3589adff6 upstream.
If a file consists of an inline extent followed by a regular or prealloc extent, then a legitimate attempt to resolve a logical address in the non-inline region will result in add_all_parents reading the invalid offset field of the inline extent. If the inline extent item is placed in the leaf eb s.t. it is the first item, attempting to access the offset field will not only be meaningless, it will go past the end of the eb and cause this panic:
[17.626048] BTRFS warning (device dm-2): bad eb member end: ptr 0x3fd4 start 30834688 member offset 16377 size 8 [17.631693] general protection fault, probably for non-canonical address 0x5088000000000: 0000 [#1] SMP PTI [17.635041] CPU: 2 PID: 1267 Comm: btrfs Not tainted 5.12.0-07246-g75175d5adc74-dirty #199 [17.637969] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014 [17.641995] RIP: 0010:btrfs_get_64+0xe7/0x110 [17.649890] RSP: 0018:ffffc90001f73a08 EFLAGS: 00010202 [17.651652] RAX: 0000000000000001 RBX: ffff88810c42d000 RCX: 0000000000000000 [17.653921] RDX: 0005088000000000 RSI: ffffc90001f73a0f RDI: 0000000000000001 [17.656174] RBP: 0000000000000ff9 R08: 0000000000000007 R09: c0000000fffeffff [17.658441] R10: ffffc90001f73790 R11: ffffc90001f73788 R12: ffff888106afe918 [17.661070] R13: 0000000000003fd4 R14: 0000000000003f6f R15: cdcdcdcdcdcdcdcd [17.663617] FS: 00007f64e7627d80(0000) GS:ffff888237c80000(0000) knlGS:0000000000000000 [17.666525] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [17.668664] CR2: 000055d4a39152e8 CR3: 000000010c596002 CR4: 0000000000770ee0 [17.671253] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [17.673634] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [17.676034] PKRU: 55555554 [17.677004] Call Trace: [17.677877] add_all_parents+0x276/0x480 [17.679325] find_parent_nodes+0xfae/0x1590 [17.680771] btrfs_find_all_leafs+0x5e/0xa0 [17.682217] iterate_extent_inodes+0xce/0x260 [17.683809] ? btrfs_inode_flags_to_xflags+0x50/0x50 [17.685597] ? iterate_inodes_from_logical+0xa1/0xd0 [17.687404] iterate_inodes_from_logical+0xa1/0xd0 [17.689121] ? btrfs_inode_flags_to_xflags+0x50/0x50 [17.691010] btrfs_ioctl_logical_to_ino+0x131/0x190 [17.692946] btrfs_ioctl+0x104a/0x2f60 [17.694384] ? selinux_file_ioctl+0x182/0x220 [17.695995] ? __x64_sys_ioctl+0x84/0xc0 [17.697394] __x64_sys_ioctl+0x84/0xc0 [17.698697] do_syscall_64+0x33/0x40 [17.700017] entry_SYSCALL_64_after_hwframe+0x44/0xae [17.701753] RIP: 0033:0x7f64e72761b7 [17.709355] RSP: 002b:00007ffefb067f58 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 [17.712088] RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007f64e72761b7 [17.714667] RDX: 00007ffefb067fb0 RSI: 00000000c0389424 RDI: 0000000000000003 [17.717386] RBP: 00007ffefb06d188 R08: 000055d4a390d2b0 R09: 00007f64e7340a60 [17.719938] R10: 0000000000000231 R11: 0000000000000246 R12: 0000000000000001 [17.722383] R13: 0000000000000000 R14: 00000000c0389424 R15: 000055d4a38fd2a0 [17.724839] Modules linked in:
Fix the bug by detecting the inline extent item in add_all_parents and skipping to the next extent item.
--- fs/btrfs/backref.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/btrfs/backref.c +4 -0
@@ -432,6 +432,7 @@ static int add_all_parents(struct btrfs_u64 wanted_disk_byte = ref->wanted_disk_byte;u64 count =0 ;u64 data_offset; +u8 type;if (level !=0 ) { eb = path->nodes[level];
@@ -486,6 +487,9 @@ static int add_all_parents(struct btrfs_continue ; } fi = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item); + type =btrfs_file_extent_type (eb, fi); +if (type ==BTRFS_FILE_EXTENT_INLINE ) + goto next; disk_byte =btrfs_file_extent_disk_bytenr (eb, fi); data_offset =btrfs_file_extent_offset (eb, fi);
Greg Kroah-Hartman
maintainerPATCH 618/783 ARM: ux500: do not directly dereference __iomem
In reply to Greg Kroah-HartmanFrom: Jason A. Donenfeld <[email protected]>
commit 65b0e307a1a9193571db12910f382f84195a3d29 upstream.
Sparse reports that calling add_device_randomness() on uid is a violation of address spaces. And indeed the next usage uses readl() properly, but that was left out when passing it toadd_device_ randomness(). So instead copy the whole thing to the stack first.
--- drivers/soc/ux500/ux500-soc-id.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/soc/ux500/ux500-soc-id.c +4 -6
@@ -167,20 +167,18 @@ ATTRIBUTE_GROUPS(ux500_soc);static const char *db8500_read_soc_id (struct device_node *backupram) {void __iomem *base; -void __iomem *uid;const char *retstr; +u32 uid[5 ]; base =of_iomap (backupram,0 );if (!base)return NULL ; - uid = base +0x1fc0 ; +memcpy_fromio (uid, base +0x1fc0 ,sizeof (uid));/* Throw these device-specific numbers into the entropy pool */ -add_device_randomness (uid,0x14 ); +add_device_randomness (uid,sizeof (uid)); retstr =kasprintf (GFP_KERNEL ,"%08x%08x%08x%08x%08x" , -readl ((u32 *)uid+0 ), -readl ((u32 *)uid+1 ),readl ((u32 *)uid+2 ), -readl ((u32 *)uid+3 ),readl ((u32 *)uid+4 )); + uid[0 ], uid[1 ], uid[2 ], uid[3 ], uid[4 ]);iounmap (base);return retstr; }
Greg Kroah-Hartman
maintainerPATCH 619/783 arm64: dts: qcom: sdm850-lenovo-yoga-c630: correct I2C12 pins drive strength
In reply to Greg Kroah-HartmanFrom: Krzysztof Kozlowski <[email protected]>
commit fd49776d8f458bba5499384131eddc0b8bcaf50c upstream.
The pin configuration (done with generic pin controller helpers and as expressed by bindings) requires children nodes with either:
1. "pins" property and the actual configuration,
2. another set of nodes with above point.
The qup_i2c12_default pin configuration used second method - with a "pinmux" child.
--- arch/arm64/boot/dts/qcom/sdm850-lenovo-yoga-c630.dts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/sdm850-lenovo-yoga-c630.dts +4 -2
@@ -322,8 +322,10 @@ }; &qup_i2c12_default { - drive-strength = <2>; - bias-disable; + pinmux { + drive-strength = <2>; + bias-disable; + }; }; &qup_uart6_default {
Greg Kroah-Hartman
maintainerPATCH 620/783 selftests: Use optional USERCFLAGS and USERLDFLAGS
In reply to Greg Kroah-HartmanFrom: Mickaël Salaün <[email protected]>
commit de3ee3f63400a23954e7c1ad1cb8c20f29ab6fe3 upstream.
This change enables to extend CFLAGS and LDFLAGS from command line, e.g. to extend compiler checks: make USERCFLAGS=-Werror USERLDFLAGS=-static
USERCFLAGS and USERLDFLAGS are documented in Documentation/kbuild/makefiles.rst and Documentation/kbuild/kbuild.rst
This should be backported (down to 5.10) to improve previous kernel versions testing as well.
--- tools/testing/selftests/lib.mk | 5 +++++ 1 file changed, 5 insertions(+)
tools/testing/selftests/lib.mk +5 -0
@@ -128,6 +128,11 @@ endef clean: $(CLEAN) +# Enables to extend CFLAGS and LDFLAGS from command line, e.g. +# make USERCFLAGS=-Werror USERLDFLAGS=-static +CFLAGS += $(USERCFLAGS) +LDFLAGS += $(USERLDFLAGS) + # When make O= with kselftest target from main level # the following aren't defined. #
Greg Kroah-Hartman
maintainerPATCH 621/783 PM/devfreq: governor: Add a private governor_data for governor
In reply to Greg Kroah-HartmanFrom: Kant Fan <[email protected]>
commit 5fdded8448924e3631d466eea499b11606c43640 upstream.
The member void *data in the structure devfreq can be overwrite by governor_userspace. For example:
1. The device driver assigned the devfreq governor to simple_ondemand by the function devfreq_add_device() and init the devfreq member void *data to a pointer of a static structure devfreq_simple_ondemand_data by the function devfreq_add_device().
2. The user changed the devfreq governor to userspace by the command "echo userspace > /sys/class/devfreq/.../governor".
3. The governor userspace alloced a dynamic memory for the struct userspace_data and assigend the member void *data of devfreq to this memory by the function userspace_init().
4. The user changed the devfreq governor back to simple_ondemand by the command "echo simple_ondemand > /sys/class/devfreq/.../governor".
5. The governor userspace exited and assigned the member void *data in the structure devfreq to NULL by the function userspace_exit().
6. The governor simple_ondemand fetched the static information of devfreq_simple_ondemand_data in the function devfreq_simple_ondemand_func() but the member void *data of devfreq was assigned to NULL by the function userspace_exit().
7. The information of upthreshold and downdifferential is lost and the governor simple_ondemand can't work correctly.
The member void *data in the structure devfreq is designed for a static pointer used in a governor and inited by the function devfreq_add_device(). This patch add an element named governor_data in the devfreq structure which can be used by a governor(E.g userspace) who want to assign a private data to do some private things.
--- drivers/devfreq/devfreq.c | 6 ++---- drivers/devfreq/governor_userspace.c | 12 ++++++------ include/linux/devfreq.h | 7 ++++--- 3 files changed, 12 insertions(+), 13 deletions(-)
drivers/devfreq/devfreq.c +2 -4
@@ -740,8 +740,7 @@ static void devfreq_dev_release(struct d* @dev: the device to add devfreq feature. * @profile: device-specific profile to run devfreq. * @governor_name: name of the policy to choose frequency. -* @data: private data for the governor. The devfreq framework does not -* touch this value. +* @data: devfreq driver pass to governors, governor should not change it. */ struct devfreq *devfreq_add_device(struct device *dev, struct devfreq_dev_profile *profile,
@@ -953,8 +952,7 @@ static void devm_devfreq_dev_release(str* @dev: the device to add devfreq feature. * @profile: device-specific profile to run devfreq. * @governor_name: name of the policy to choose frequency. -* @data: private data for the governor. The devfreq framework does not -* touch this value. +* @data: devfreq driver pass to governors, governor should not change it. * * This function manages automatically the memory of devfreq device using device * resource management and simplify the free operation for memory of devfreq
drivers/devfreq/governor_userspace.c +6 -6
@@ -21,7 +21,7 @@ struct userspace_data {static int devfreq_userspace_func (struct devfreq *df,unsigned long *freq) { -struct userspace_data *data = df->data; +struct userspace_data *data = df->governor_data;if (data->valid) *freq = data->user_frequency;
@@ -40,7 +40,7 @@ static ssize_t store_freq(struct deviceint err =0 ;mutex_lock (&devfreq->lock); - data = devfreq->data; + data = devfreq->governor_data;sscanf (buf,"%lu" , &wanted); data->user_frequency = wanted;
@@ -60,7 +60,7 @@ static ssize_t show_freq(struct device *int err =0 ;mutex_lock (&devfreq->lock); - data = devfreq->data; + data = devfreq->governor_data;if (data->valid) err =sprintf (buf,"%lu\n" , data->user_frequency);
@@ -91,7 +91,7 @@ static int userspace_init(struct devfreq goto out; } data->valid = false; - devfreq->data = data; + devfreq->governor_data = data; err =sysfs_create_group (&devfreq->dev.kobj, &dev_attr_group); out:
@@ -107,8 +107,8 @@ static void userspace_exit(struct devfreif (devfreq->dev.kobj.sd)sysfs_remove_group (&devfreq->dev.kobj, &dev_attr_group); -kfree (devfreq->data); - devfreq->data =NULL ; +kfree (devfreq->governor_data); + devfreq->governor_data =NULL ; } static int devfreq_userspace_handler(struct devfreq *devfreq,
include/linux/devfreq.h +4 -3
@@ -146,8 +146,8 @@ struct devfreq_stats {* @work: delayed work for load monitoring. * @previous_freq: previously configured frequency value. * @last_status: devfreq user device info, performance statistics -* @data: Private data of the governor. The devfreq framework does not -* touch this. +* @data: devfreq driver pass to governors, governor should not change it. +* @governor_data: private data for governors, devfreq core doesn't touch it. * @user_min_freq_req: PM QoS minimum frequency request from user (via sysfs) * @user_max_freq_req: PM QoS maximum frequency request from user (via sysfs) * @scaling_min_freq: Limit minimum frequency requested by OPP interface
@@ -183,7 +183,8 @@ struct devfreq {unsigned long previous_freq;struct devfreq_dev_status last_status; -void *data;/* private data for governors */ +void *data; +void *governor_data;struct dev_pm_qos_request user_min_freq_req;struct dev_pm_qos_request user_max_freq_req;
Greg Kroah-Hartman
maintainerPATCH 622/783 cpufreq: Init completion before kobject_init_and_add()
In reply to Greg Kroah-HartmanFrom: Yongqiang Liu <[email protected]>
commit 5c51054896bcce1d33d39fead2af73fec24f40b6 upstream.
In cpufreq_policy_alloc(), it will call uninitialed completion in cpufreq_sysfs_release() when kobject_init_and_add() fails. And that will cause a crash such as the following page fault in complete:
BUG: unable to handle page fault for address: fffffffffffffff8 [..] RIP: 0010:complete+0x98/0x1f0 [..] Call Trace: kobject_put+0x1be/0x4c0 cpufreq_online.cold+0xee/0x1fd cpufreq_add_dev+0x183/0x1e0 subsys_interface_register+0x3f5/0x4e0 cpufreq_register_driver+0x3b7/0x670 acpi_cpufreq_init+0x56c/0x1000 [acpi_cpufreq] do_one_initcall+0x13d/0x780 do_init_module+0x1c3/0x630 load_module+0x6e67/0x73b0 __do_sys_finit_module+0x181/0x240 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd
--- drivers/cpufreq/cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +1 -1
@@ -1211,6 +1211,7 @@ static struct cpufreq_policy *cpufreq_poif (!zalloc_cpumask_var (&policy->real_cpus,GFP_KERNEL )) goto err_free_rcpumask; +init_completion (&policy->kobj_unregister); ret =kobject_init_and_add (&policy->kobj, &ktype_cpufreq, cpufreq_global_kobject,"policy%u" , cpu);if (ret) {
@@ -1249,7 +1250,6 @@ static struct cpufreq_policy *cpufreq_poinit_rwsem (&policy->rwsem);spin_lock_init (&policy->transition_lock);init_waitqueue_head (&policy->transition_wait); -init_completion (&policy->kobj_unregister);INIT_WORK (&policy->update, handle_update); policy->cpu = cpu;
Greg Kroah-Hartman
maintainerPATCH 623/783 ALSA: patch_realtek: Fix Dell Inspiron Plus 16
In reply to Greg Kroah-HartmanFrom: Philipp Jungkamp <[email protected]>
[ Upstream commit 2912cdda734d9136615ed05636d9fcbca2a7a3c5 ]
The Dell Inspiron Plus 16, in both laptop and 2in1 form factor, has top speakers connected on NID 0x17, which the codec reports as unconnected. These speakers should be connected to the DAC on NID 0x03.
Stable-dep-of: a4517c4f3423 ("ALSA: hda/realtek: Apply dual codec fixup for Dell Latitude laptops")
--- sound/pci/hda/patch_realtek.c | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
sound/pci/hda/patch_realtek.c +37 -0
@@ -6654,6 +6654,34 @@ static void alc256_fixup_mic_no_presence_and_resume(struct hda_codec *codec, } } +static void alc295_fixup_dell_inspiron_top_speakers (struct hda_codec *codec, +const struct hda_fixup *fix,int action) +{ +static const struct hda_pintbl pincfgs[] = { + {0x14 ,0x90170151 }, + {0x17 ,0x90170150 }, + { } + }; +static const hda_nid_t conn[] = {0x02 ,0x03 }; +static const hda_nid_t preferred_pairs[] = { +0x14 ,0x02 , +0x17 ,0x03 , +0x21 ,0x02 , +0 + }; +struct alc_spec *spec = codec->spec; + +alc_fixup_no_shutup (codec, fix, action); + +switch (action) { +case HDA_FIXUP_ACT_PRE_PROBE : +snd_hda_apply_pincfgs (codec, pincfgs); +snd_hda_override_conn_list (codec,0x17 ,ARRAY_SIZE (conn), conn); + spec->gen.preferred_dacs = preferred_pairs; +break ; + } +} +enum {ALC269_FIXUP_GPIO2 ,ALC269_FIXUP_SONY_VAIO ,
@@ -6884,6 +6912,7 @@ enum {ALC285_FIXUP_LEGION_Y9000X_SPEAKERS ,ALC285_FIXUP_LEGION_Y9000X_AUTOMUTE ,ALC285_FIXUP_HP_SPEAKERS_MICMUTE_LED , + ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS, };/* A special fixup for Lenovo C940 and Yoga Duet 7;
@@ -8704,6 +8733,12 @@ static const struct hda_fixup alc269_fixups[] = { .chained = true, .chain_id = ALC285_FIXUP_HP_MUTE_LED, }, + [ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS] = { + .type = HDA_FIXUP_FUNC, + .v.func = alc295_fixup_dell_inspiron_top_speakers, + .chained = true, + .chain_id = ALC269_FIXUP_DELL4_MIC_NO_PRESENCE, + }, }; static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -8803,6 +8838,8 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x1028 ,0x0a9e ,"Dell Latitude 5430" ,ALC269_FIXUP_DELL4_MIC_NO_PRESENCE ),SND_PCI_QUIRK (0x1028 ,0x0b19 ,"Dell XPS 15 9520" ,ALC289_FIXUP_DUAL_SPK ),SND_PCI_QUIRK (0x1028 ,0x0b1a ,"Dell Precision 5570" ,ALC289_FIXUP_DUAL_SPK ), +SND_PCI_QUIRK (0x1028 ,0x0b37 ,"Dell Inspiron 16 Plus 7620 2-in-1" ,ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS ), +SND_PCI_QUIRK (0x1028 ,0x0b71 ,"Dell Inspiron 16 Plus 7620" ,ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS ),SND_PCI_QUIRK (0x1028 ,0x164a ,"Dell" ,ALC293_FIXUP_DELL1_MIC_NO_PRESENCE ),SND_PCI_QUIRK (0x1028 ,0x164b ,"Dell" ,ALC293_FIXUP_DELL1_MIC_NO_PRESENCE ), SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 624/783 ALSA: hda/realtek: Apply dual codec fixup for Dell Latitude laptops
In reply to Greg Kroah-HartmanFrom: Chris Chiu <[email protected]>
[ Upstream commit a4517c4f3423c7c448f2c359218f97c1173523a1 ]
The Dell Latiture 3340/3440/3540 laptops with Realtek ALC3204 have dual codecs and need the ALC1220_FIXUP_GB_DUAL_CODECS to fix the conflicts of Master controls. The existing headset mic fixup for Dell is also required to enable the jack sense and the headset mic.
Introduce a new fixup to fix the dual codec and headset mic issues for particular Dell laptops since other old Dell laptops with the same codec configuration are already well handled by the fixup in alc269_fallback_pin_fixup_tbl[].
--- sound/pci/hda/patch_realtek.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
sound/pci/hda/patch_realtek.c +13 -0
@@ -6913,6 +6913,7 @@ enum {ALC285_FIXUP_LEGION_Y9000X_AUTOMUTE ,ALC285_FIXUP_HP_SPEAKERS_MICMUTE_LED ,ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS , + ALC236_FIXUP_DELL_DUAL_CODECS, };/* A special fixup for Lenovo C940 and Yoga Duet 7;
@@ -8739,6 +8740,12 @@ static const struct hda_fixup alc269_fix .chained = true, .chain_id = ALC269_FIXUP_DELL4_MIC_NO_PRESENCE, }, + [ALC236_FIXUP_DELL_DUAL_CODECS] = { + .type = HDA_FIXUP_PINS, + .v.func = alc1220_fixup_gb_dual_codecs, + .chained = true, + .chain_id = ALC255_FIXUP_DELL1_MIC_NO_PRESENCE, + }, }; static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -8840,6 +8847,12 @@ static const struct snd_pci_quirk alc269SND_PCI_QUIRK (0x1028 ,0x0b1a ,"Dell Precision 5570" ,ALC289_FIXUP_DUAL_SPK ),SND_PCI_QUIRK (0x1028 ,0x0b37 ,"Dell Inspiron 16 Plus 7620 2-in-1" ,ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS ),SND_PCI_QUIRK (0x1028 ,0x0b71 ,"Dell Inspiron 16 Plus 7620" ,ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS ), +SND_PCI_QUIRK (0x1028 ,0x0c19 ,"Dell Precision 3340" ,ALC236_FIXUP_DELL_DUAL_CODECS ), +SND_PCI_QUIRK (0x1028 ,0x0c1a ,"Dell Precision 3340" ,ALC236_FIXUP_DELL_DUAL_CODECS ), +SND_PCI_QUIRK (0x1028 ,0x0c1b ,"Dell Precision 3440" ,ALC236_FIXUP_DELL_DUAL_CODECS ), +SND_PCI_QUIRK (0x1028 ,0x0c1c ,"Dell Precision 3540" ,ALC236_FIXUP_DELL_DUAL_CODECS ), +SND_PCI_QUIRK (0x1028 ,0x0c1d ,"Dell Precision 3440" ,ALC236_FIXUP_DELL_DUAL_CODECS ), +SND_PCI_QUIRK (0x1028 ,0x0c1e ,"Dell Precision 3540" ,ALC236_FIXUP_DELL_DUAL_CODECS ),SND_PCI_QUIRK (0x1028 ,0x164a ,"Dell" ,ALC293_FIXUP_DELL1_MIC_NO_PRESENCE ),SND_PCI_QUIRK (0x1028 ,0x164b ,"Dell" ,ALC293_FIXUP_DELL1_MIC_NO_PRESENCE ), SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
Greg Kroah-Hartman
maintainerPATCH 625/783 dm cache: Fix ABBA deadlock between shrink_slab and dm_cache_metadata_abort
In reply to Greg Kroah-HartmanFrom: Mike Snitzer <[email protected]>
commit 352b837a5541690d4f843819028cf2b8be83d424 upstream.
Same ABBA deadlock pattern fixed in commit 4b60f452ec51 ("dm thin: Fix ABBA deadlock between shrink_slab and dm_pool_abort_metadata") to DM-cache's metadata.
--- drivers/md/dm-cache-metadata.c | 54 +++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-)
drivers/md/dm-cache-metadata.c +47 -7
@@ -551,11 +551,13 @@ static int __create_persistent_data_objereturn r; } -static void __destroy_persistent_data_objects (struct dm_cache_metadata *cmd) +static void __destroy_persistent_data_objects (struct dm_cache_metadata *cmd, +bool destroy_bm) {dm_sm_destroy (cmd->metadata_sm);dm_tm_destroy (cmd->tm); -dm_block_manager_destroy (cmd->bm); +if (destroy_bm) +dm_block_manager_destroy (cmd->bm); }typedef unsigned long (*flags_mutator )(unsigned long );
@@ -826,7 +828,7 @@ static struct dm_cache_metadata *lookup_ cmd2 =lookup (bdev);if (cmd2) {mutex_unlock (&table_lock); -__destroy_persistent_data_objects (cmd); +__destroy_persistent_data_objects (cmd, true);kfree (cmd);return cmd2; }
@@ -874,7 +876,7 @@ void dm_cache_metadata_close(struct dm_cmutex_unlock (&table_lock);if (!cmd->fail_io) -__destroy_persistent_data_objects (cmd); +__destroy_persistent_data_objects (cmd, true);kfree (cmd); } }
@@ -1808,14 +1810,52 @@ int dm_cache_metadata_needs_check(structint dm_cache_metadata_abort (struct dm_cache_metadata *cmd) { -int r; +int r = -EINVAL ; +struct dm_block_manager *old_bm =NULL , *new_bm =NULL ; + +/* fail_io is double-checked with cmd->root_lock held below */ +if (unlikely (cmd->fail_io)) +return r; + +/* +* Replacement block manager (new_bm) is created and old_bm destroyed outside of +* cmd root_lock to avoid ABBA deadlock that would result (due to life-cycle of +* shrinker associated with the block manager's bufio client vs cmd root_lock). +* - must take shrinker_rwsem without holding cmd->root_lock +*/ + new_bm =dm_block_manager_create (cmd->bdev,DM_CACHE_METADATA_BLOCK_SIZE <<SECTOR_SHIFT , +CACHE_MAX_CONCURRENT_LOCKS );WRITE_LOCK (cmd); -__destroy_persistent_data_objects (cmd); - r =__create_persistent_data_objects (cmd, false); +if (cmd->fail_io) { +WRITE_UNLOCK (cmd); + goto out; + } + +__destroy_persistent_data_objects (cmd, false); + old_bm = cmd->bm; +if (IS_ERR (new_bm)) { +DMERR ("could not create block manager during abort" ); + cmd->bm =NULL ; + r =PTR_ERR (new_bm); + goto out_unlock; + } + + cmd->bm = new_bm; + r =__open_or_format_metadata (cmd, false); +if (r) { + cmd->bm =NULL ; + goto out_unlock; + } + new_bm =NULL ; +out_unlock:if (r) cmd->fail_io = true;WRITE_UNLOCK (cmd); +dm_block_manager_destroy (old_bm); +out: +if (new_bm && !IS_ERR (new_bm)) +dm_block_manager_destroy (new_bm);return r; }
Greg Kroah-Hartman
maintainerPATCH 626/783 dm thin: Fix ABBA deadlock between shrink_slab and dm_pool_abort_metadata
In reply to Greg Kroah-HartmanFrom: Zhihao Cheng <[email protected]>
commit 8111964f1b8524c4bb56b02cd9c7a37725ea21fd upstream.
Following concurrent processes:
P1(drop cache) P2(kworker)drop_caches_sysctl_handler
drop_slab
shrink_slab
down_read(&shrinker_rwsem) - LOCK A
do_shrink_slab
super_cache_scan
prune_icache_sb
dispose_list
evict
ext4_evict_inode
ext4_clear_inode
ext4_discard_preallocations
ext4_mb_load_buddy_gfp
ext4_mb_init_cache
ext4_read_block_bitmap_nowait
ext4_read_bh_nowait
submit_bh
dm_submit_bio
do_worker
process_deferred_bios
commit
metadata_operation_failed
dm_pool_abort_metadata
down_write(&pmd->root_lock) - LOCK B
__destroy_persistent_data_objects
dm_block_manager_destroy
dm_bufio_client_destroy
unregister_shrinker
down_write(&shrinker_rwsem)
thin_map |
dm_thin_find_block ↓
down_read(&pmd->root_lock) --> ABBA deadlock, which triggers hung task:
[ 76.974820] INFO: task kworker/u4:3:63 blocked for more than 15 seconds. [ 76.976019] Not tainted 6.1.0-rc4-00011-g8f17dd350364-dirty #910 [ 76.978521] task:kworker/u4:3 state:D stack:0 pid:63 ppid:2 [ 76.978534] Workqueue: dm-thin do_worker [ 76.978552] Call Trace: [ 76.978564] __schedule+0x6ba/0x10f0 [ 76.978582] schedule+0x9d/0x1e0 [ 76.978588] rwsem_down_write_slowpath+0x587/0xdf0 [ 76.978600] down_write+0xec/0x110 [ 76.978607] unregister_shrinker+0x2c/0xf0 [ 76.978616] dm_bufio_client_destroy+0x116/0x3d0 [ 76.978625] dm_block_manager_destroy+0x19/0x40 [ 76.978629] __destroy_persistent_data_objects+0x5e/0x70 [ 76.978636] dm_pool_abort_metadata+0x8e/0x100 [ 76.978643] metadata_operation_failed+0x86/0x110 [ 76.978649] commit+0x6a/0x230 [ 76.978655] do_worker+0xc6e/0xd90 [ 76.978702] process_one_work+0x269/0x630 [ 76.978714] worker_thread+0x266/0x630 [ 76.978730] kthread+0x151/0x1b0 [ 76.978772] INFO: task test.sh:2646 blocked for more than 15 seconds. [ 76.979756] Not tainted 6.1.0-rc4-00011-g8f17dd350364-dirty #910 [ 76.982111] task:test.sh state:D stack:0 pid:2646 ppid:2459 [ 76.982128] Call Trace: [ 76.982139] __schedule+0x6ba/0x10f0 [ 76.982155] schedule+0x9d/0x1e0 [ 76.982159] rwsem_down_read_slowpath+0x4f4/0x910 [ 76.982173] down_read+0x84/0x170 [ 76.982177] dm_thin_find_block+0x4c/0xd0 [ 76.982183] thin_map+0x201/0x3d0 [ 76.982188] __map_bio+0x5b/0x350 [ 76.982195] dm_submit_bio+0x2b6/0x930 [ 76.982202] __submit_bio+0x123/0x2d0 [ 76.982209] submit_bio_noacct_nocheck+0x101/0x3e0 [ 76.982222] submit_bio_noacct+0x389/0x770 [ 76.982227] submit_bio+0x50/0xc0 [ 76.982232] submit_bh_wbc+0x15e/0x230 [ 76.982238] submit_bh+0x14/0x20 [ 76.982241] ext4_read_bh_nowait+0xc5/0x130 [ 76.982247] ext4_read_block_bitmap_nowait+0x340/0xc60 [ 76.982254] ext4_mb_init_cache+0x1ce/0xdc0 [ 76.982259] ext4_mb_load_buddy_gfp+0x987/0xfa0 [ 76.982263] ext4_discard_preallocations+0x45d/0x830 [ 76.982274] ext4_clear_inode+0x48/0xf0 [ 76.982280] ext4_evict_inode+0xcf/0xc70 [ 76.982285] evict+0x119/0x2b0 [ 76.982290] dispose_list+0x43/0xa0 [ 76.982294] prune_icache_sb+0x64/0x90 [ 76.982298] super_cache_scan+0x155/0x210 [ 76.982303] do_shrink_slab+0x19e/0x4e0 [ 76.982310] shrink_slab+0x2bd/0x450 [ 76.982317] drop_slab+0xcc/0x1a0 [ 76.982323] drop_caches_sysctl_handler+0xb7/0xe0 [ 76.982327] proc_sys_call_handler+0x1bc/0x300 [ 76.982331] proc_sys_write+0x17/0x20 [ 76.982334] vfs_write+0x3d3/0x570 [ 76.982342] ksys_write+0x73/0x160 [ 76.982347] __x64_sys_write+0x1e/0x30 [ 76.982352] do_syscall_64+0x35/0x80 [ 76.982357] entry_SYSCALL_64_after_hwframe+0x63/0xcd
Function metadata_operation_failed() is called when operations failed on dm pool metadata, dm pool will destroy and recreate metadata. So, shrinker will be unregistered and registered, which could down write shrinker_rwsem under pmd_write_lock.
Fix it by allocating dm_block_manager before locking pmd->root_lock and destroying old dm_block_manager after unlocking pmd->root_lock, then old dm_block_manager is replaced with new dm_block_manager under pmd->root_lock. So, shrinker register/unregister could be done without holding pmd->root_lock.
Fetch a reproducer in [Link].
--- drivers/md/dm-thin-metadata.c | 51 +++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 8 deletions(-)
drivers/md/dm-thin-metadata.c +43 -8
@@ -753,13 +753,15 @@ static int __create_persistent_data_objereturn r; } -static void __destroy_persistent_data_objects (struct dm_pool_metadata *pmd) +static void __destroy_persistent_data_objects (struct dm_pool_metadata *pmd, +bool destroy_bm) {dm_sm_destroy (pmd->data_sm);dm_sm_destroy (pmd->metadata_sm);dm_tm_destroy (pmd->nb_tm);dm_tm_destroy (pmd->tm); -dm_block_manager_destroy (pmd->bm); +if (destroy_bm) +dm_block_manager_destroy (pmd->bm); }static int __begin_transaction (struct dm_pool_metadata *pmd)
@@ -966,7 +968,7 @@ int dm_pool_metadata_close(struct dm_poo }pmd_write_unlock (pmd);if (!pmd->fail_io) -__destroy_persistent_data_objects (pmd); +__destroy_persistent_data_objects (pmd, true);kfree (pmd);return 0 ;
@@ -1873,19 +1875,52 @@ static void __set_abort_with_changes_flaint dm_pool_abort_metadata (struct dm_pool_metadata *pmd) {int r = -EINVAL ; +struct dm_block_manager *old_bm =NULL , *new_bm =NULL ; + +/* fail_io is double-checked with pmd->root_lock held below */ +if (unlikely (pmd->fail_io)) +return r; + +/* +* Replacement block manager (new_bm) is created and old_bm destroyed outside of +* pmd root_lock to avoid ABBA deadlock that would result (due to life-cycle of +* shrinker associated with the block manager's bufio client vs pmd root_lock). +* - must take shrinker_rwsem without holding pmd->root_lock +*/ + new_bm =dm_block_manager_create (pmd->bdev,THIN_METADATA_BLOCK_SIZE <<SECTOR_SHIFT , +THIN_MAX_CONCURRENT_LOCKS );pmd_write_lock (pmd); -if (pmd->fail_io) +if (pmd->fail_io) { +pmd_write_unlock (pmd); goto out; + }__set_abort_with_changes_flags (pmd); -__destroy_persistent_data_objects (pmd); - r =__create_persistent_data_objects (pmd, false); +__destroy_persistent_data_objects (pmd, false); + old_bm = pmd->bm; +if (IS_ERR (new_bm)) { +DMERR ("could not create block manager during abort" ); + pmd->bm =NULL ; + r =PTR_ERR (new_bm); + goto out_unlock; + } + + pmd->bm = new_bm; + r =__open_or_format_metadata (pmd, false); +if (r) { + pmd->bm =NULL ; + goto out_unlock; + } + new_bm =NULL ; +out_unlock:if (r) pmd->fail_io = true; - -out:pmd_write_unlock (pmd); +dm_block_manager_destroy (old_bm); +out: +if (new_bm && !IS_ERR (new_bm)) +dm_block_manager_destroy (new_bm);return r; }
Greg Kroah-Hartman
maintainerPATCH 627/783 dm thin: Use last transactions pmd->root when commit failed
In reply to Greg Kroah-HartmanFrom: Zhihao Cheng <[email protected]>
commit 7991dbff6849f67e823b7cc0c15e5a90b0549b9f upstream.
Recently we found a softlock up problem in dm thin pool btree lookup code due to corrupted metadata:
Kernel panic - not syncing: softlockup: hung tasks CPU: 7 PID: 2669225 Comm: kworker/u16:3 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) Workqueue: dm-thin do_worker [dm_thin_pool] Call Trace: <IRQ> dump_stack+0x9c/0xd3 panic+0x35d/0x6b9 watchdog_timer_fn.cold+0x16/0x25 __run_hrtimer+0xa2/0x2d0 </IRQ> RIP: 0010:__relink_lru+0x102/0x220 [dm_bufio] __bufio_new+0x11f/0x4f0 [dm_bufio] new_read+0xa3/0x1e0 [dm_bufio] dm_bm_read_lock+0x33/0xd0 [dm_persistent_data] ro_step+0x63/0x100 [dm_persistent_data] btree_lookup_raw.constprop.0+0x44/0x220 [dm_persistent_data] dm_btree_lookup+0x16f/0x210 [dm_persistent_data] dm_thin_find_block+0x12c/0x210 [dm_thin_pool] __process_bio_read_only+0xc5/0x400 [dm_thin_pool] process_thin_deferred_bios+0x1a4/0x4a0 [dm_thin_pool] process_one_work+0x3c5/0x730
Following process may generate a broken btree mixed with fresh and stale btree nodes, which could get dm thin trapped in an infinite loop while looking up data block:
Transaction 1: pmd->root = A, A->B->C // One path in btree
pmd->root = X, X->Y->Z // Copy-up
Transaction 2: X,Z is updated on disk, Y write failed.
// Commit failed, dm thin becomes read-only.
process_bio_read_only
dm_thin_find_block
__find_block
dm_btree_lookup(pmd->root)The pmd->root points to a broken btree, Y may contain stale node pointing to any block, for example X, which gets dm thin trapped into a dead loop while looking up Z.
Fix this by setting pmd->root in __open_metadata(), so that dm thin will use the last transaction's pmd->root if commit failed.
Fetch a reproducer in [Link].
Linke: https://bugzilla.kernel.org/show_bug.cgi?id=216790
--- drivers/md/dm-thin-metadata.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/md/dm-thin-metadata.c +9 -0
@@ -701,6 +701,15 @@ static int __open_metadata(struct dm_poo goto bad_cleanup_data_sm; } +/* +* For pool metadata opening process, root setting is redundant +* because it will be set again in __begin_transaction(). But dm +* pool aborting process really needs to get last transaction's +* root to avoid accessing broken btree. +*/ + pmd->root =le64_to_cpu (disk_super->data_mapping_root); + pmd->details_root =le64_to_cpu (disk_super->device_details_root); +__setup_btree_details (pmd);dm_bm_unlock (sblock);
Greg Kroah-Hartman
maintainerPATCH 628/783 dm thin: resume even if in FAIL mode
In reply to Greg Kroah-HartmanFrom: Luo Meng <[email protected]>
commit 19eb1650afeb1aa86151f61900e9e5f1de5d8d02 upstream.
If a thinpool set fail_io while suspending, resume will fail with:
device-mapper: resume ioctl on vg-thinpool failed: Invalid argument
The thin-pool also can't be removed if an in-flight bio is in the deferred list.
This can be easily reproduced using:
echo "offline" > /sys/block/sda/device/state dd if=/dev/zero of=/dev/mapper/thin bs=4K count=1 dmsetup suspend /dev/mapper/pool mkfs.ext4 /dev/mapper/thin
dmsetup resume /dev/mapper/pool
The root cause is maybe_resize_data_dev() will check fail_io and return error before called dm_resume.
Fix this by adding FAIL mode check at the end of pool_preresume().
--- drivers/md/dm-thin.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/md/dm-thin.c +12 -4
@@ -3566,20 +3566,28 @@ static int pool_preresume(struct dm_targ*/ r =bind_control_target (pool, ti);if (r) -return r; + goto out; r =maybe_resize_data_dev (ti, &need_commit1);if (r) -return r; + goto out; r =maybe_resize_metadata_dev (ti, &need_commit2);if (r) -return r; + goto out;if (need_commit1 || need_commit2) (void )commit (pool); +out: +/* +* When a thin-pool is PM_FAIL, it cannot be rebuilt if +* bio is in deferred list. Therefore need to return 0 +* to allow pool_resume() to flush IO. +*/ +if (r &&get_pool_mode (pool) ==PM_FAIL ) + r =0 ; -return 0 ; +return r; }static void pool_suspend_active_thins (struct pool *pool)
Greg Kroah-Hartman
maintainerPATCH 629/783 dm thin: Fix UAF in run_timer_softirq()
In reply to Greg Kroah-HartmanFrom: Luo Meng <[email protected]>
commit 88430ebcbc0ec637b710b947738839848c20feff upstream.
When dm_resume() and dm_destroy() are concurrent, it will lead to UAF, as follows:
BUG: KASAN: use-after-free in __run_timers+0x173/0x710 Write of size 8 at addr ffff88816d9490f0 by task swapper/0/0 <snip> Call Trace: <IRQ> dump_stack_lvl+0x73/0x9f print_report.cold+0x132/0xaa2 _raw_spin_lock_irqsave+0xcd/0x160 __run_timers+0x173/0x710 kasan_report+0xad/0x110 __run_timers+0x173/0x710 __asan_store8+0x9c/0x140 __run_timers+0x173/0x710 call_timer_fn+0x310/0x310 pvclock_clocksource_read+0xfa/0x250 kvm_clock_read+0x2c/0x70 kvm_clock_get_cycles+0xd/0x20 ktime_get+0x5c/0x110 lapic_next_event+0x38/0x50 clockevents_program_event+0xf1/0x1e0 run_timer_softirq+0x49/0x90 __do_softirq+0x16e/0x62c __irq_exit_rcu+0x1fa/0x270 irq_exit_rcu+0x12/0x20 sysvec_apic_timer_interrupt+0x8e/0xc0
One of the concurrency UAF can be shown as below:
use free
do_resume |
__find_device_hash_cell |
dm_get |
atomic_inc(&md->holders) |
| dm_destroy
| __dm_destroy
| if (!dm_suspended_md(md))
| atomic_read(&md->holders)
| msleep(1)
dm_resume |
__dm_resume |
dm_table_resume_targets |
pool_resume |
do_waker #add delay work |
dm_put |
atomic_dec(&md->holders) |
| dm_table_destroy
| pool_dtr
| __pool_dec
| __pool_destroy
| destroy_workqueue
| kfree(pool) # free pool time out__do_softirq
run_timer_softirq # pool has already been freed
This can be easily reproduced using:
1. create thin-pool
2. dmsetup suspend pool
3. dmsetup resume pool
4. dmsetup remove_all # Concurrent with 3
The root cause of this UAF bug is that dm_resume() adds timer after dm_destroy() skips cancelling the timer because of suspend status. After timeout, it will call run_timer_softirq(), however pool has already been freed. The concurrency UAF bug will happen.
Therefore, cancelling timer again in __pool_destroy().
--- drivers/md/dm-thin.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/md/dm-thin.c +2 -0
@@ -2907,6 +2907,8 @@ static void __pool_destroy(struct pool *dm_bio_prison_destroy (pool->prison);dm_kcopyd_client_destroy (pool->copier); +cancel_delayed_work_sync (&pool->waker); +cancel_delayed_work_sync (&pool->no_space_timeout);if (pool->wq)destroy_workqueue (pool->wq);
Greg Kroah-Hartman
maintainerPATCH 630/783 dm integrity: Fix UAF in dm_integrity_dtr()
In reply to Greg Kroah-HartmanFrom: Luo Meng <[email protected]>
commit f50cb2cbabd6c4a60add93d72451728f86e4791c upstream.
Dm_integrity also has the same UAF problem when dm_resume() and dm_destroy() are concurrent.
Therefore, cancelling timer again in dm_integrity_dtr().
--- drivers/md/dm-integrity.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/md/dm-integrity.c +2 -0
@@ -4388,6 +4388,8 @@ static void dm_integrity_dtr(struct dm_tBUG_ON (!RB_EMPTY_ROOT (&ic->in_progress));BUG_ON (!list_empty (&ic->wait_list)); +if (ic->mode =='B' ) +cancel_delayed_work_sync (&ic->bitmap_flush_work);if (ic->metadata_wq)destroy_workqueue (ic->metadata_wq);if (ic->wait_wq)
Greg Kroah-Hartman
maintainerPATCH 631/783 dm clone: Fix UAF in clone_dtr()
In reply to Greg Kroah-HartmanFrom: Luo Meng <[email protected]>
commit e4b5957c6f749a501c464f92792f1c8e26b61a94 upstream.
Dm_clone also has the same UAF problem when dm_resume() and dm_destroy() are concurrent.
Therefore, cancelling timer again in clone_dtr().
--- drivers/md/dm-clone-target.c | 1 + 1 file changed, 1 insertion(+)
drivers/md/dm-clone-target.c +1 -0
@@ -1966,6 +1966,7 @@ static void clone_dtr(struct dm_target *mempool_exit (&clone->hydration_pool);dm_kcopyd_client_destroy (clone->kcopyd_client); +cancel_delayed_work_sync (&clone->waker);destroy_workqueue (clone->wq);hash_table_exit (clone);dm_clone_metadata_close (clone->cmd);
Greg Kroah-Hartman
maintainerPATCH 632/783 dm cache: Fix UAF in destroy()
In reply to Greg Kroah-HartmanFrom: Luo Meng <[email protected]>
commit 6a459d8edbdbe7b24db42a5a9f21e6aa9e00c2aa upstream.
Dm_cache also has the same UAF problem when dm_resume() and dm_destroy() are concurrent.
Therefore, cancelling timer again in destroy().
--- drivers/md/dm-cache-target.c | 1 + 1 file changed, 1 insertion(+)
drivers/md/dm-cache-target.c +1 -0
@@ -1965,6 +1965,7 @@ static void destroy(struct cache *cache)if (cache->prison)dm_bio_prison_destroy_v2 (cache->prison); +cancel_delayed_work_sync (&cache->waker);if (cache->wq)destroy_workqueue (cache->wq);
Greg Kroah-Hartman
maintainerPATCH 633/783 dm cache: set needs_check flag after aborting metadata
In reply to Greg Kroah-HartmanFrom: Mike Snitzer <[email protected]>
commit 6b9973861cb2e96dcd0bb0f1baddc5c034207c5c upstream.
Otherwise the commit that will be aborted will be associated with the metadata objects that will be torn down. Must write needs_check flag to metadata with a reset block manager.
Found through code-inspection (and compared against dm-thin.c).
--- drivers/md/dm-cache-target.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/dm-cache-target.c +5 -5
@@ -985,16 +985,16 @@ static void abort_transaction(struct cacif (get_cache_mode (cache) >=CM_READ_ONLY )return ; -if (dm_cache_metadata_set_needs_check (cache->cmd)) { -DMERR ("%s: failed to set 'needs_check' flag in metadata" , dev_name); -set_cache_mode (cache,CM_FAIL ); - } -DMERR_LIMIT ("%s: aborting current metadata transaction" , dev_name);if (dm_cache_metadata_abort (cache->cmd)) {DMERR ("%s: failed to abort metadata transaction" , dev_name);set_cache_mode (cache,CM_FAIL ); } + +if (dm_cache_metadata_set_needs_check (cache->cmd)) { +DMERR ("%s: failed to set 'needs_check' flag in metadata" , dev_name); +set_cache_mode (cache,CM_FAIL ); + } }static void metadata_operation_failed (struct cache *cache,const char *op,int r)
Greg Kroah-Hartman
maintainerPATCH 634/783 tracing/hist: Fix out-of-bound write on action_data.var_ref_idx
In reply to Greg Kroah-HartmanFrom: Zheng Yejian <[email protected]>
commit 82470f7d9044842618c847a7166de2b7458157a7 upstream.
When generate a synthetic event with many params and then create a trace action for it [1], kernel panic happened [2].
It is because that in trace_action_create() 'data->n_params' is up to SYNTH_FIELDS_MAX (current value is 64), and array 'data->var_ref_idx' keeps indices into array 'hist_data->var_refs' for each synthetic event param, but the length of 'data->var_ref_idx' is TRACING_MAP_VARS_MAX (current value is 16), so out-of-bound write happened when 'data->n_params' more than 16. In this case, 'data->match_data.event' is overwritten and eventually cause the panic.
To solve the issue, adjust the length of 'data->var_ref_idx' to be SYNTH_FIELDS_MAX and add sanity checks to avoid out-of-bound write.
[1]
# cd /sys/kernel/tracing/ # echo "my_synth_event int v1; int v2; int v3; int v4; int v5; int v6;\ int v7; int v8; int v9; int v10; int v11; int v12; int v13; int v14;\ int v15; int v16; int v17; int v18; int v19; int v20; int v21; int v22;\ int v23; int v24; int v25; int v26; int v27; int v28; int v29; int v30;\ int v31; int v32; int v33; int v34; int v35; int v36; int v37; int v38;\ int v39; int v40; int v41; int v42; int v43; int v44; int v45; int v46;\ int v47; int v48; int v49; int v50; int v51; int v52; int v53; int v54;\ int v55; int v56; int v57; int v58; int v59; int v60; int v61; int v62;\ int v63" >> synthetic_events # echo 'hist:keys=pid:ts0=common_timestamp.usecs if comm=="bash"' >> \ events/sched/sched_waking/trigger # echo "hist:keys=next_pid:onmatch(sched.sched_waking).my_synth_event(\ pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,\ pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,\ pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,\ pid,pid,pid,pid,pid,pid,pid,pid,pid)" >> events/sched/sched_switch/trigger
[2]
BUG: unable to handle page fault for address: ffff91c900000000 PGD 61001067 P4D 61001067 PUD 0 Oops: 0000 [#1] PREEMPT SMP NOPTI CPU: 2 PID: 322 Comm: bash Tainted: G W 6.1.0-rc8+ #229 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014 RIP: 0010:strcmp+0xc/0x30 Code: 75 f7 31 d2 44 0f b6 04 16 44 88 04 11 48 83 c2 01 45 84 c0 75 ee c3 cc cc cc cc 0f 1f 00 31 c0 eb 08 48 83 c0 01 84 d2 74 13 <0f> b6 14 07 3a 14 06 74 ef 19 c0 83 c8 01 c3 cc cc cc cc 31 c3 RSP: 0018:ffff9b3b00f53c48 EFLAGS: 00000246 RAX: 0000000000000000 RBX: ffffffffba958a68 RCX: 0000000000000000 RDX: 0000000000000010 RSI: ffff91c943d33a90 RDI: ffff91c900000000 RBP: ffff91c900000000 R08: 00000018d604b529 R09: 0000000000000000 R10: ffff91c9483eddb1 R11: ffff91ca483eddab R12: ffff91c946171580 R13: ffff91c9479f0538 R14: ffff91c9457c2848 R15: ffff91c9479f0538 FS: 00007f1d1cfbe740(0000) GS:ffff91c9bdc80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffff91c900000000 CR3: 0000000006316000 CR4: 00000000000006e0 Call Trace: <TASK> __find_event_file+0x55/0x90 action_create+0x76c/0x1060 event_hist_trigger_parse+0x146d/0x2060 ? event_trigger_write+0x31/0xd0 trigger_process_regex+0xbb/0x110 event_trigger_write+0x6b/0xd0 vfs_write+0xc8/0x3e0 ? alloc_fd+0xc0/0x160 ? preempt_count_add+0x4d/0xa0 ? preempt_count_add+0x70/0xa0 ksys_write+0x5f/0xe0 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd RIP: 0033:0x7f1d1d0cf077 Code: 64 89 02 48 c7 c0 ff ff ff ff eb bb 0f 1f 80 00 00 00 00 f3 0f 1e
fa 64 8b 04 25 18 00 00 00 85 c0 75 10 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 51 c3 48 83 ec 28 48 89 54 24 18 48 89 74
RSP: 002b:00007ffcebb0e568 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 0000000000000143 RCX: 00007f1d1d0cf077
RDX: 0000000000000143 RSI: 00005639265aa7e0 RDI: 0000000000000001
RBP: 00005639265aa7e0 R08: 000000000000000a R09: 0000000000000142
R10: 000056392639c017 R11: 0000000000000246 R12: 0000000000000143
R13: 00007f1d1d1ae6a0 R14: 00007f1d1d1aa4a0 R15: 00007f1d1d1a98a0
</TASK> Modules linked in: CR2: ffff91c900000000 ---[ end trace 0000000000000000 ]--- RIP: 0010:strcmp+0xc/0x30 Code: 75 f7 31 d2 44 0f b6 04 16 44 88 04 11 48 83 c2 01 45 84 c0 75 ee c3 cc cc cc cc 0f 1f 00 31 c0 eb 08 48 83 c0 01 84 d2 74 13 <0f> b6 14 07 3a 14 06 74 ef 19 c0 83 c8 01 c3 cc cc cc cc 31 c3 RSP: 0018:ffff9b3b00f53c48 EFLAGS: 00000246 RAX: 0000000000000000 RBX: ffffffffba958a68 RCX: 0000000000000000 RDX: 0000000000000010 RSI: ffff91c943d33a90 RDI: ffff91c900000000 RBP: ffff91c900000000 R08: 00000018d604b529 R09: 0000000000000000 R10: ffff91c9483eddb1 R11: ffff91ca483eddab R12: ffff91c946171580 R13: ffff91c9479f0538 R14: ffff91c9457c2848 R15: ffff91c9479f0538 FS: 00007f1d1cfbe740(0000) GS:ffff91c9bdc80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffff91c900000000 CR3: 0000000006316000 CR4: 00000000000006e0
--- kernel/trace/trace_events_hist.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
kernel/trace/trace_events_hist.c +8 -2
@@ -417,7 +417,7 @@ struct action_data {* event param, and is passed to the synthetic event * invocation. */ -unsigned int var_ref_idx[TRACING_MAP_VARS_MAX ]; +unsigned int var_ref_idx[SYNTH_FIELDS_MAX ];struct synth_event *synth_event;bool use_trace_keyword;char *synth_event_name;
@@ -1846,7 +1846,9 @@ static struct hist_field *create_var_refreturn ref_field; } } - +/* Sanity check to avoid out-of-bound write on 'hist_data->var_refs' */ +if (hist_data->n_var_refs >=TRACING_MAP_VARS_MAX ) +return NULL ; ref_field =create_hist_field (var_field->hist_data,NULL , flags,NULL );if (ref_field) {if (init_var_ref (ref_field, var_field, system, event_name)) {
@@ -3449,6 +3451,10 @@ static int trace_action_create(struct hilockdep_assert_held (&event_mutex); +/* Sanity check to avoid out-of-bound write on 'data->var_ref_idx' */ +if (data->n_params >SYNTH_FIELDS_MAX ) +return -EINVAL ; +if (data->use_trace_keyword) synth_event_name = data->synth_event_name;else
Greg Kroah-Hartman
maintainerPATCH 635/783 perf/core: Call LSM hook after copying perf_event_attr
In reply to Greg Kroah-HartmanFrom: Namhyung Kim <[email protected]>
commit 0a041ebca4956292cadfb14a63ace3a9c1dcb0a3 upstream.
It passes the attr struct to the security_perf_event_open() but it's not initialized yet.
--- kernel/events/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/events/core.c +3 -3
@@ -11781,12 +11781,12 @@ SYSCALL_DEFINE5(perf_event_open,if (flags & ~PERF_FLAG_ALL )return -EINVAL ; -/* Do we allow access to perf_event_open(2) ? */ - err =security_perf_event_open (&attr,PERF_SECURITY_OPEN ); + err =perf_copy_attr (attr_uptr, &attr);if (err)return err; - err =perf_copy_attr (attr_uptr, &attr); +/* Do we allow access to perf_event_open(2) ? */ + err =security_perf_event_open (&attr,PERF_SECURITY_OPEN );if (err)return err;
Greg Kroah-Hartman
maintainerPATCH 636/783 KVM: nVMX: Inject #GP, not #UD, if "generic" VMXON CR0/CR4 check fails
In reply to Greg Kroah-HartmanFrom: Sean Christopherson <[email protected]>
commit 9cc409325ddd776f6fd6293d5ce93ce1248af6e4 upstream.
Inject #GP for if VMXON is attempting with a CR0/CR4 that fails the generic "is CRx valid" check, but passes the CR4.VMXE check, and do the generic checks _after_ handling the post-VMXON VM-Fail.
The CR4.VMXE check, and all other #UD cases, are special pre-conditions that are enforced prior to pivoting on the current VMX mode, i.e. occur before interception if VMXON is attempted in VMX non-root mode.
All other CR0/CR4 checks generate #GP and effectively have lower priority than the post-VMXON check.
Per the SDM:
IF (register operand) or (CR0.PE = 0) or (CR4.VMXE = 0) or ...
THEN #UD;
ELSIF not in VMX operation
THEN
IF (CPL > 0) or (in A20M mode) or
(the values of CR0 and CR4 are not supported in VMX operation)
THEN #GP(0);
ELSIF in VMX non-root operation
THEN VMexit;
ELSIF CPL > 0
THEN #GP(0);
ELSE VMfail("VMXON executed in VMX root operation");
FI;which, if re-written without ELSIF, yields:
IF (register operand) or (CR0.PE = 0) or (CR4.VMXE = 0) or ...
THEN #UD
IF in VMX non-root operation
THEN VMexit;
IF CPL > 0
THEN #GP(0)
IF in VMX operation
THEN VMfail("VMXON executed in VMX root operation");
IF (in A20M mode) or
(the values of CR0 and CR4 are not supported in VMX operation)
THEN #GP(0);
Note, KVM unconditionally forwards VMXON VM-Exits that occur in L2 to L1, i.e. there is no need to check the vCPU is not in VMX non-root mode. Add a comment to explain why unconditionally forwarding such exits is functionally correct.
--- arch/x86/kvm/vmx/nested.c | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-)
arch/x86/kvm/vmx/nested.c +33 -11
@@ -4901,24 +4901,35 @@ static int handle_vmon(struct kvm_vcpu * | FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX;/* -* Note, KVM cannot rely on hardware to perform the CR0/CR4 #UD checks -* that have higher priority than VM-Exit (see Intel SDM's pseudocode -* for VMXON), as KVM must load valid CR0/CR4 values into hardware while -* running the guest, i.e. KVM needs to check the _guest_ values. +* Manually check CR4.VMXE checks, KVM must force CR4.VMXE=1 to enter +* the guest and so cannot rely on hardware to perform the check, +* which has higher priority than VM-Exit (see Intel SDM's pseudocode +* for VMXON). * -* Rely on hardware for the other two pre-VM-Exit checks, !VM86 and -* !COMPATIBILITY modes. KVM may run the guest in VM86 to emulate Real -* Mode, but KVM will never take the guest out of those modes. +* Rely on hardware for the other pre-VM-Exit checks, CR0.PE=1, !VM86 +* and !COMPATIBILITY modes. For an unrestricted guest, KVM doesn't +* force any of the relevant guest state. For a restricted guest, KVM +* does force CR0.PE=1, but only to also force VM86 in order to emulate +* Real Mode, and so there's no need to check CR0.PE manually. */ -if (!nested_host_cr0_valid (vcpu,kvm_read_cr0 (vcpu)) || - !nested_host_cr4_valid (vcpu,kvm_read_cr4 (vcpu))) { +if (!kvm_read_cr4_bits (vcpu,X86_CR4_VMXE )) {kvm_queue_exception (vcpu,UD_VECTOR );return 1 ; }/* -* CPL=0 and all other checks that are lower priority than VM-Exit must -* be checked manually. +* The CPL is checked for "not in VMX operation" and for "in VMX root", +* and has higher priority than the VM-Fail due to being post-VMXON, +* i.e. VMXON #GPs outside of VMX non-root if CPL!=0. In VMX non-root, +* VMXON causes VM-Exit and KVM unconditionally forwards VMXON VM-Exits +* from L2 to L1, i.e. there's no need to check for the vCPU being in +* VMX non-root. +* +* Forwarding the VM-Exit unconditionally, i.e. without performing the +* #UD checks (see above), is functionally ok because KVM doesn't allow +* L1 to run L2 without CR4.VMXE=0, and because KVM never modifies L2's +* CR0 or CR4, i.e. it's L2's responsibility to emulate #UDs that are +* missed by hardware due to shadowing CR0 and/or CR4. */ if (vmx_get_cpl (vcpu)) {kvm_inject_gp (vcpu,0 );
@@ -4928,6 +4939,17 @@ static int handle_vmon(struct kvm_vcpu *if (vmx->nested.vmxon)return nested_vmx_fail (vcpu,VMXERR_VMXON_IN_VMX_ROOT_OPERATION ); +/* +* Invalid CR0/CR4 generates #GP. These checks are performed if and +* only if the vCPU isn't already in VMX operation, i.e. effectively +* have lower priority than the VM-Fail above. +*/ +if (!nested_host_cr0_valid (vcpu,kvm_read_cr0 (vcpu)) || + !nested_host_cr4_valid (vcpu,kvm_read_cr4 (vcpu))) { +kvm_inject_gp (vcpu,0 ); +return 1 ; + } +if ((vmx->msr_ia32_feature_control &VMXON_NEEDED_FEATURES ) !=VMXON_NEEDED_FEATURES ) {kvm_inject_gp (vcpu,0 );
Greg Kroah-Hartman
maintainerPATCH 637/783 x86/microcode/intel: Do not retry microcode reloading on the APs
In reply to Greg Kroah-HartmanFrom: Ashok Raj <[email protected]>
commit be1b670f61443aa5d0d01782e9b8ea0ee825d018 upstream.
The retries in load_ucode_intel_ap() were in place to support systems with mixed steppings. Mixed steppings are no longer supported and there is only one microcode image at a time. Any retries will simply reattempt to apply the same image over and over without making progress.
[ bp: Zap the circumstantial reasoning from the commit message. ]
--- arch/x86/kernel/cpu/microcode/intel.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +1 -7
@@ -659,7 +659,6 @@ void load_ucode_intel_ap(void)else iup = &intel_ucode_patch; -reget:if (!*iup) { patch =__load_ucode_intel (&uci);if (!patch)
@@ -670,12 +669,7 @@ reget: uci.mc = *iup; -if (apply_microcode_early (&uci, true)) { -/* Mixed-silicon system? Try to refetch the proper patch: */ - *iup =NULL ; - - goto reget; - } +apply_microcode_early (&uci, true); }static struct microcode_intel *find_patch (struct ucode_cpu_info *uci)
Greg Kroah-Hartman
maintainerPATCH 638/783 ftrace/x86: Add back ftrace_expected for ftrace bug reports
In reply to Greg Kroah-HartmanFrom: Steven Rostedt (Google) <[email protected]>
commit fd3dc56253acbe9c641a66d312d8393cd55eb04c upstream.
After someone reported a bug report with a failed modification due to the expected value not matching what was found, it came to my attention that the ftrace_expected is no longer set when that happens. This makes for debugging the issue a bit more difficult.
Set ftrace_expected to the expected code before calling ftrace_bug, so that it shows what was expected and why it failed.
--- arch/x86/kernel/ftrace.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/kernel/ftrace.c +2 -0
@@ -219,7 +219,9 @@ void ftrace_replace_code(int enable) ret =ftrace_verify_code (rec->ip, old);if (ret) { + ftrace_expected = old;ftrace_bug (ret, rec); + ftrace_expected =NULL ;return ; } }
Greg Kroah-Hartman
maintainerPATCH 639/783 x86/kprobes: Fix kprobes instruction boudary check with CONFIG_RETHUNK
In reply to Greg Kroah-HartmanFrom: Masami Hiramatsu (Google) <[email protected]>
commit 1993bf97992df2d560287f3c4120eda57426843d upstream.
Since the CONFIG_RETHUNK and CONFIG_SLS will use INT3 for stopping speculative execution after RET instruction, kprobes always failes to check the probed instruction boundary by decoding the function body if the probed address is after such sequence. (Note that some conditional code blocks will be placed after function return, if compiler decides it is not on the hot path.)
This is because kprobes expects kgdb puts the INT3 as a software breakpoint and it will replace the original instruction. But these INT3 are not such purpose, it doesn't need to recover the original instruction.
To avoid this issue, kprobes checks whether the INT3 is owned by kgdb or not, and if so, stop decoding and make it fail. The other INT3 will come from CONFIG_RETHUNK/CONFIG_SLS and those can be treated as a one-byte instruction.
--- arch/x86/kernel/kprobes/core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
arch/x86/kernel/kprobes/core.c +7 -3
@@ -37,6 +37,7 @@#include <linux/extable.h> #include <linux/kdebug.h> #include <linux/kallsyms.h> +#include <linux/kgdb.h> #include <linux/ftrace.h> #include <linux/kasan.h> #include <linux/moduleloader.h>
@@ -306,12 +307,15 @@ static int can_probe(unsigned long paddrkernel_insn_init (&insn, (void *)__addr,MAX_INSN_SIZE );insn_get_length (&insn); +#ifdef CONFIG_KGDB /* -* Another debugging subsystem might insert this breakpoint. -* In that case, we can't recover it. +* If there is a dynamically installed kgdb sw breakpoint, +* this function should not be probed. */ -if (insn.opcode.bytes[0 ] ==INT3_INSN_OPCODE ) +if (insn.opcode.bytes[0 ] ==INT3_INSN_OPCODE && +kgdb_has_hit_break (addr))return 0 ; +#endif addr += insn.length; }
Greg Kroah-Hartman
maintainerPATCH 640/783 tracing/hist: Fix wrong return value in parse_action_params()
In reply to Greg Kroah-HartmanFrom: Zheng Yejian <[email protected]>
commit 2cc6a528882d0e0ccbc1bca5f95b8c963cedac54 upstream.
When number of synth fields is more than SYNTH_FIELDS_MAX, parse_action_params() should return -EINVAL.
--- kernel/trace/trace_events_hist.c | 1 + 1 file changed, 1 insertion(+)
kernel/trace/trace_events_hist.c +1 -0
@@ -3115,6 +3115,7 @@ static int parse_action_params(struct trwhile (params) {if (data->n_params >=SYNTH_FIELDS_MAX ) {hist_err (tr,HIST_ERR_TOO_MANY_PARAMS ,0 ); + ret = -EINVAL ; goto out; }
Greg Kroah-Hartman
maintainerPATCH 641/783 tracing: Fix infinite loop in tracing_read_pipe on overflowed print_trace_line
In reply to Greg Kroah-HartmanFrom: Yang Jihong <[email protected]>
commit c1ac03af6ed45d05786c219d102f37eb44880f28 upstream.
print_trace_line may overflow seq_file buffer. If the event is not consumed, the while loop keeps peeking this event, causing a infinite loop.
--- kernel/trace/trace.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
kernel/trace/trace.c +14 -1
@@ -6371,7 +6371,20 @@ waitagain: ret =print_trace_line (iter);if (ret ==TRACE_TYPE_PARTIAL_LINE ) { -/* don't print partial lines */ +/* +* If one print_trace_line() fills entire trace_seq in one shot, +* trace_seq_to_user() will returns -EBUSY because save_len == 0, +* In this case, we need to consume it, otherwise, loop will peek +* this event next time, resulting in an infinite loop. +*/ +if (save_len ==0 ) { + iter->seq.full =0 ; +trace_seq_puts (&iter->seq,"[LINE TOO BIG]\n" ); +trace_consume (iter); +break ; + } + +/* In other cases, don't print partial lines */ iter->seq.seq.len = save_len;break ; }
Greg Kroah-Hartman
maintainerPATCH 642/783 staging: media: tegra-video: fix chan->mipi value on error
In reply to Greg Kroah-HartmanFrom: Luca Ceresoli <[email protected]>
commit 10b5ce6743c839fa75336042c64e2479caec9430 upstream.
chan->mipi takes the return value of tegra_mipi_request() which can be a valid pointer or an error. However chan->mipi is checked in several places, including error-cleanup code in tegra_csi_channels_cleanup(), as 'if (chan->mipi)', which suggests the initial intent was that chan->mipi should be either NULL or a valid pointer, never an error. As a consequence, cleanup code in case of tegra_mipi_request() errors would dereference an invalid pointer.
Fix by ensuring chan->mipi always contains either NULL or a void pointer.
Also add that to the documentation.
--- drivers/staging/media/tegra-video/csi.c | 1 + drivers/staging/media/tegra-video/csi.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/staging/media/tegra-video/csi.c +1 -0
@@ -435,6 +435,7 @@ static int tegra_csi_channel_alloc(struc chan->mipi =tegra_mipi_request (csi->dev, node);if (IS_ERR (chan->mipi)) { ret =PTR_ERR (chan->mipi); + chan->mipi =NULL ;dev_err (csi->dev,"failed to get mipi device: %d\n" , ret); }
drivers/staging/media/tegra-video/csi.h +1 -1
@@ -50,7 +50,7 @@ struct tegra_csi;* @framerate: active framerate for TPG * @h_blank: horizontal blanking for TPG active format * @v_blank: vertical blanking for TPG active format -* @mipi: mipi device for corresponding csi channel pads +* @mipi: mipi device for corresponding csi channel pads, or NULL if not applicable (TPG, error) * @pixel_rate: active pixel rate from the sensor on this channel */ struct tegra_csi_channel {
Greg Kroah-Hartman
maintainerPATCH 643/783 ARM: 9256/1: NWFPE: avoid compiler-generated __aeabi_uldivmod
In reply to Greg Kroah-HartmanFrom: Nick Desaulniers <[email protected]>
commit 3220022038b9a3845eea762af85f1c5694b9f861 upstream.
clang-15's ability to elide loops completely became more aggressive when it can deduce how a variable is being updated in a loop. Counting down one variable by an increment of another can be replaced by a modulo operation.
For 64b variables on 32b ARM EABI targets, this can result in the compiler generating calls to __aeabi_uldivmod, which it does for a do while loop in float64_rem().
For the kernel, we'd generally prefer that developers not open code 64b division via binary / operators and instead use the more explicit helpers from div64.h. On arm-linux-gnuabi targets, failure to do so can result in linkage failures due to undefined references to __aeabi_uldivmod().
While developers can avoid open coding divisions on 64b variables, the compiler doesn't know that the Linux kernel has a partial implementation of a compiler runtime (--rtlib) to enforce this convention.
It's also undecidable for the compiler whether the code in question would be faster to execute the loop vs elide it and do the 64b division.
While I actively avoid using the internal -mllvm command line flags, I think we get better code than using barrier() here, which will force reloads+spills in the loop for all toolchains.
--- arch/arm/nwfpe/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm/nwfpe/Makefile +6 -0
@@ -11,3 +11,9 @@ nwfpe-y += fpa11.o fpa11_cpdo.o fpa11 entry.o nwfpe-$(CONFIG_FPE_NWFPE_XP) += extended_cpdo.o + +# Try really hard to avoid generating calls to __aeabi_uldivmod() from +# float64_rem() due to loop elision. +ifdef CONFIG_CC_IS_CLANG +CFLAGS_softfloat.o += -mllvm -replexitval=never +endif
Greg Kroah-Hartman
maintainerPATCH 644/783 media: dvb-core: Fix double free in dvb_register_device()
In reply to Greg Kroah-HartmanFrom: Keita Suzuki <[email protected]>
commit 6b0d0477fce747d4137aa65856318b55fba72198 upstream.
In function dvb_register_device() -> dvb_register_media_device() -> dvb_create_media_entity(), dvb->entity is allocated and initialized. If the initialization fails, it frees the dvb->entity, and return an error code. The caller takes the error code and handles the error by calling dvb_media_device_free(), which unregisters the entity and frees the field again if it is not NULL. As dvb->entity may not NULLed in dvb_create_media_entity() when the allocation of dvbdev->pad fails, a double free may occur. This may also cause an Use After free in media_device_unregister_entity().
Fix this by storing NULL to dvb->entity when it is freed.
--- drivers/media/dvb-core/dvbdev.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/dvb-core/dvbdev.c +1 -0
@@ -345,6 +345,7 @@ static int dvb_create_media_entity(struc GFP_KERNEL);if (!dvbdev->pads) {kfree (dvbdev->entity); + dvbdev->entity =NULL ;return -ENOMEM ; } }
Greg Kroah-Hartman
maintainerPATCH 645/783 media: dvb-core: Fix UAF due to refcount races at releasing
In reply to Greg Kroah-HartmanFrom: Takashi Iwai <[email protected]>
commit fd3d91ab1c6ab0628fe642dd570b56302c30a792 upstream.
The dvb-core tries to sync the releases of opened files at dvb_dmxdev_release() with two refcounts: dvbdev->users and dvr_dvbdev->users. A problem is present in those two syncs: when yet another dvb_demux_open() is called during those sync waits, dvb_demux_open() continues to process even if the device is being closed. This includes the increment of the former refcount, resulting in the leftover refcount after the sync of the latter refcount at dvb_dmxdev_release(). It ends up with use-after-free, since the function believes that all usages were gone and releases the resources.
This patch addresses the problem by adding the check of dmxdev->exit flag at dvb_demux_open(), just like dvb_dvr_open() already does. With the exit flag check, the second call of dvb_demux_open() fails, hence the further corruption can be avoided.
Also for avoiding the races of the dmxdev->exit flag reference, this patch serializes the dmxdev->exit set up and the sync waits with the dmxdev->mutex lock at dvb_dmxdev_release(). Without the mutex lock, dvb_demux_open() (or dvb_dvr_open()) may run concurrently with dvb_dmxdev_release(), which allows to skip the exit flag check and continue the open process that is being closed.
CVE-2022-41218 is assigned to those bugs above.
--- drivers/media/dvb-core/dmxdev.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/media/dvb-core/dmxdev.c +8 -0
@@ -800,6 +800,11 @@ static int dvb_demux_open(struct inode *if (mutex_lock_interruptible (&dmxdev->mutex))return -ERESTARTSYS ; +if (dmxdev->exit) { +mutex_unlock (&dmxdev->mutex); +return -ENODEV ; + } +for (i =0 ; i < dmxdev->filternum; i++)if (dmxdev->filter[i].state ==DMXDEV_STATE_FREE )break ;
@@ -1458,7 +1463,10 @@ EXPORT_SYMBOL(dvb_dmxdev_init);void dvb_dmxdev_release (struct dmxdev *dmxdev) { +mutex_lock (&dmxdev->mutex); dmxdev->exit =1 ; +mutex_unlock (&dmxdev->mutex); +if (dmxdev->dvbdev->users >1 ) {wait_event (dmxdev->dvbdev->wait_queue, dmxdev->dvbdev->users ==1 );
Greg Kroah-Hartman
maintainerPATCH 646/783 cifs: fix confusing debug message
In reply to Greg Kroah-HartmanFrom: Paulo Alcantara <[email protected]>
commit a85ceafd41927e41a4103d228a993df7edd8823b upstream.
Since rc was initialised to -ENOMEM in cifs_get_smb_ses(), when an existing smb session was found, free_xid() would be called and then print
CIFS: fs/cifs/connect.c: Existing tcp session with server found
CIFS: fs/cifs/connect.c: VFS: in cifs_get_smb_ses as Xid: 44 with uid: 0
CIFS: fs/cifs/connect.c: Existing smb sess found (status=1)
CIFS: fs/cifs/connect.c: VFS: leaving cifs_get_smb_ses (xid = 44) rc = -12
Fix this by initialising rc to 0 and then let free_xid() print this instead
CIFS: fs/cifs/connect.c: Existing tcp session with server found
CIFS: fs/cifs/connect.c: VFS: in cifs_get_smb_ses as Xid: 14 with uid: 0
CIFS: fs/cifs/connect.c: Existing smb sess found (status=1)
CIFS: fs/cifs/connect.c: VFS: leaving cifs_get_smb_ses (xid = 14) rc = 0
--- fs/cifs/connect.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/cifs/connect.c +3 -1
@@ -3038,7 +3038,7 @@ cifs_set_cifscreds(struct smb_vol *vol _struct cifs_ses *cifs_get_smb_ses (struct TCP_Server_Info *server,struct smb_vol *volume_info) { -int rc = -ENOMEM ; +int rc =0 ;unsigned int xid;struct cifs_ses *ses;struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr;
@@ -3080,6 +3080,8 @@ cifs_get_smb_ses(struct TCP_Server_Inforeturn ses; } + rc = -ENOMEM ; +cifs_dbg (FYI ,"Existing smb sess not found\n" ); ses =sesInfoAlloc ();if (ses ==NULL )
Greg Kroah-Hartman
maintainerPATCH 647/783 cifs: fix missing display of three mount options
In reply to Greg Kroah-HartmanFrom: Steve French <[email protected]>
commit 2bfd81043e944af0e52835ef6d9b41795af22341 upstream.
Three mount options: "tcpnodelay" and "noautotune" and "noblocksend" were not displayed when passed in on cifs/smb3 mounts (e.g. displayed in /proc/mounts e.g.). No change to defaults so these are not displayed if not specified on mount.
--- fs/cifs/cifsfs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/cifs/cifsfs.c +7 -1
@@ -619,9 +619,15 @@ cifs_show_options(struct seq_file *s, stseq_printf (s,",echo_interval=%lu" , tcon->ses->server->echo_interval /HZ ); -/* Only display max_credits if it was overridden on mount */ +/* Only display the following if overridden on mount */ if (tcon->ses->server->max_credits !=SMB2_MAX_CREDITS_AVAILABLE )seq_printf (s,",max_credits=%u" , tcon->ses->server->max_credits); +if (tcon->ses->server->tcp_nodelay) +seq_puts (s,",tcpnodelay" ); +if (tcon->ses->server->noautotune) +seq_puts (s,",noautotune" ); +if (tcon->ses->server->noblocksnd) +seq_puts (s,",noblocksend" );if (tcon->snapshot_time)seq_printf (s,",snapshot=%llu" , tcon->snapshot_time);
Greg Kroah-Hartman
maintainerPATCH 648/783 rtc: ds1347: fix value written to century register
In reply to Greg Kroah-HartmanFrom: Ian Abbott <[email protected]>
commit 4dfe05bdc1ade79b943d4979a2e2a8b5ef68fbb5 upstream.
In ds1347_set_time(), the wrong value is being written to the DS1347_CENTURY_REG register. It needs to be converted to BCD. Fix it.
--- drivers/rtc/rtc-ds1347.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-ds1347.c +1 -1
@@ -112,7 +112,7 @@ static int ds1347_set_time(struct devicereturn err; century = (dt->tm_year /100 ) +19 ; - err =regmap_write (map,DS1347_CENTURY_REG , century); + err =regmap_write (map,DS1347_CENTURY_REG ,bin2bcd (century));if (err)return err;
Greg Kroah-Hartman
maintainerPATCH 649/783 md/bitmap: Fix bitmap chunk size overflow issues
In reply to Greg Kroah-HartmanFrom: Florian-Ewald Mueller <[email protected]>
commit 4555211190798b6b6fa2c37667d175bf67945c78 upstream.
- limit bitmap chunk size internal u64 variable to values not overflowing the u32 bitmap superblock structure variable stored on persistent media
- assign bitmap chunk size internal u64 variable from unsigned values to avoid possible sign extension artifacts when assigning from a s32 value
The bug has been there since at least kernel 4.0.
Steps to reproduce it:
1: mdadm -C /dev/mdx -l 1 --bitmap=internal --bitmap-chunk=256M -e 1.2 -n2 /dev/rnbd1 /dev/rnbd2
2 resize member device rnbd1 and rnbd2 to 8 TB
3 mdadm --grow /dev/mdx --size=max
The bitmap_chunksize will overflow without patch.
--- drivers/md/md-bitmap.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/md/md-bitmap.c +12 -8
@@ -486,7 +486,7 @@ void md_bitmap_print_sb(struct bitmap *b sb =kmap_atomic (bitmap->storage.sb_page);pr_debug ("%s: bitmap file superblock:\n" ,bmname (bitmap));pr_debug (" magic: %08x\n" ,le32_to_cpu (sb->magic)); -pr_debug (" version: %d\n" ,le32_to_cpu (sb->version)); +pr_debug (" version: %u\n" ,le32_to_cpu (sb->version)); pr_debug(" uuid: %08x.%08x.%08x.%08x\n", le32_to_cpu(*(__le32 *)(sb->uuid+0)), le32_to_cpu(*(__le32 *)(sb->uuid+4)),
@@ -497,11 +497,11 @@ void md_bitmap_print_sb(struct bitmap *bpr_debug ("events cleared: %llu\n" , (unsigned long long )le64_to_cpu (sb->events_cleared));pr_debug (" state: %08x\n" ,le32_to_cpu (sb->state)); -pr_debug (" chunksize: %d B\n" ,le32_to_cpu (sb->chunksize)); -pr_debug (" daemon sleep: %ds\n" ,le32_to_cpu (sb->daemon_sleep)); +pr_debug (" chunksize: %u B\n" ,le32_to_cpu (sb->chunksize)); +pr_debug (" daemon sleep: %us\n" ,le32_to_cpu (sb->daemon_sleep));pr_debug (" sync size: %llu KB\n" , (unsigned long long )le64_to_cpu (sb->sync_size)/2 ); -pr_debug ("max write behind: %d\n" ,le32_to_cpu (sb->write_behind)); +pr_debug ("max write behind: %u\n" ,le32_to_cpu (sb->write_behind));kunmap_atomic (sb); }
@@ -2106,7 +2106,8 @@ int md_bitmap_resize(struct bitmap *bitm bytes =DIV_ROUND_UP (chunks,8 );if (!bitmap->mddev->bitmap_info.external) bytes +=sizeof (bitmap_super_t); - }while (bytes > (space <<9 )); + }while (bytes > (space <<9 ) && (chunkshift +BITMAP_BLOCK_SHIFT ) < + (BITS_PER_BYTE *sizeof (((bitmap_super_t *)0 )->chunksize) -1 )); }else chunkshift =ffz (~chunksize) -BITMAP_BLOCK_SHIFT ;
@@ -2151,7 +2152,7 @@ int md_bitmap_resize(struct bitmap *bitm bitmap->counts.missing_pages = pages; bitmap->counts.chunkshift = chunkshift; bitmap->counts.chunks = chunks; - bitmap->mddev->bitmap_info.chunksize =1 << (chunkshift + + bitmap->mddev->bitmap_info.chunksize =1UL << (chunkshift +BITMAP_BLOCK_SHIFT ); blocks = min(old_counts.chunks << old_counts.chunkshift,
@@ -2177,8 +2178,8 @@ int md_bitmap_resize(struct bitmap *bitm bitmap->counts.missing_pages = old_counts.pages; bitmap->counts.chunkshift = old_counts.chunkshift; bitmap->counts.chunks = old_counts.chunks; - bitmap->mddev->bitmap_info.chunksize =1 << (old_counts.chunkshift + -BITMAP_BLOCK_SHIFT ); + bitmap->mddev->bitmap_info.chunksize = +1UL << (old_counts.chunkshift +BITMAP_BLOCK_SHIFT ); blocks = old_counts.chunks << old_counts.chunkshift;pr_warn ("Could not pre-allocate in-memory bitmap for cluster raid\n" );break ;
@@ -2519,6 +2520,9 @@ chunksize_store(struct mddev *mddev, conif (csize <512 || !is_power_of_2 (csize))return -EINVAL ; +if (BITS_PER_LONG >32 && csize >= (1ULL << (BITS_PER_BYTE * +sizeof (((bitmap_super_t *)0 )->chunksize)))) +return -EOVERFLOW ; mddev->bitmap_info.chunksize = csize;return len; }
Greg Kroah-Hartman
maintainerPATCH 650/783 efi: Add iMac Pro 2017 to uefi skip cert quirk
In reply to Greg Kroah-HartmanFrom: Aditya Garg <[email protected]>
commit 0be56a116220f9e5731a6609e66a11accfe8d8e2 upstream.
The iMac Pro 2017 is also a T2 Mac. Thus add it to the list of uefi skip cert.
--- security/integrity/platform_certs/load_uefi.c | 1 + 1 file changed, 1 insertion(+)
security/integrity/platform_certs/load_uefi.c +1 -0
@@ -34,6 +34,7 @@ static const struct dmi_system_id uefi_s { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacPro7,1") }, { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "iMac20,1") }, { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "iMac20,2") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "iMacPro1,1") }, { } };
Greg Kroah-Hartman
maintainerPATCH 651/783 wifi: wilc1000: sdio: fix module autoloading
In reply to Greg Kroah-HartmanFrom: Michael Walle <[email protected]>
commit 57d545b5a3d6ce3a8fb6b093f02bfcbb908973f3 upstream.
There are no SDIO module aliases included in the driver, therefore, module autoloading isn't working. Add the proper MODULE_DEVICE_TABLE().
--- drivers/net/wireless/microchip/wilc1000/sdio.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/wireless/microchip/wilc1000/sdio.c +1 -0
@@ -20,6 +20,7 @@ static const struct sdio_device_id wilc_ { SDIO_DEVICE(SDIO_VENDOR_ID_MICROCHIP_WILC, SDIO_DEVICE_ID_MICROCHIP_WILC1000) }, { }, }; +MODULE_DEVICE_TABLE (sdio, wilc_sdio_ids);#define WILC_SDIO_BLOCK_SIZE 512
Greg Kroah-Hartman
maintainerPATCH 652/783 ASoC: jz4740-i2s: Handle independent FIFO flush bits
In reply to Greg Kroah-HartmanFrom: Aidan MacDonald <[email protected]>
commit 8b3a9ad86239f80ed569e23c3954a311f66481d6 upstream.
On the JZ4740, there is a single bit that flushes (empties) both the transmit and receive FIFO. Later SoCs have independent flush bits for each FIFO.
Independent FIFOs can be flushed before the snd_soc_dai_active() check because it won't disturb other active streams. This ensures that the FIFO we're about to use is always flushed before starting up. With shared FIFOs we can't do that because if another substream is active, flushing its FIFO would cause underrun errors.
This also fixes a bug: since we were only setting the JZ4740's flush bit, which corresponds to the TX FIFO flush bit on other SoCs, other SoCs were not having their RX FIFO flushed at all.
--- sound/soc/jz4740/jz4740-i2s.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-)
sound/soc/jz4740/jz4740-i2s.c +34 -5
@@ -59,7 +59,8 @@#define JZ_AIC_CTRL_MONO_TO_STEREO BIT(11)#define JZ_AIC_CTRL_SWITCH_ENDIANNESS BIT(10)#define JZ_AIC_CTRL_SIGNED_TO_UNSIGNED BIT(9) -#define JZ_AIC_CTRL_FLUSH BIT(8) +#define JZ_AIC_CTRL_TFLUSH BIT(8) +#define JZ_AIC_CTRL_RFLUSH BIT(7)#define JZ_AIC_CTRL_ENABLE_ROR_INT BIT(6)#define JZ_AIC_CTRL_ENABLE_TUR_INT BIT(5)#define JZ_AIC_CTRL_ENABLE_RFS_INT BIT(4)
@@ -94,6 +95,8 @@ enum jz47xx_i2s_version {struct i2s_soc_info {enum jz47xx_i2s_version version;struct snd_soc_dai_driver *dai; + +bool shared_fifo_flush; };struct jz4740_i2s {
@@ -122,19 +125,44 @@ static inline void jz4740_i2s_write(conswritel (value, i2s->base + reg); } +static inline void jz4740_i2s_set_bits (const struct jz4740_i2s *i2s, +unsigned int reg,uint32_t bits) +{ +uint32_t value =jz4740_i2s_read (i2s, reg); + value |= bits; +jz4740_i2s_write (i2s, reg, value); +} +static int jz4740_i2s_startup (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) {struct jz4740_i2s *i2s =snd_soc_dai_get_drvdata (dai); -uint32_t conf, ctrl; +uint32_t conf;int ret; +/* +* When we can flush FIFOs independently, only flush the FIFO +* that is starting up. We can do this when the DAI is active +* because it does not disturb other active substreams. +*/ +if (!i2s->soc_info->shared_fifo_flush) { +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) +jz4740_i2s_set_bits (i2s,JZ_REG_AIC_CTRL ,JZ_AIC_CTRL_TFLUSH ); +else +jz4740_i2s_set_bits (i2s,JZ_REG_AIC_CTRL ,JZ_AIC_CTRL_RFLUSH ); + } +if (snd_soc_dai_active (dai))return 0 ; - ctrl =jz4740_i2s_read (i2s,JZ_REG_AIC_CTRL ); - ctrl |=JZ_AIC_CTRL_FLUSH ; -jz4740_i2s_write (i2s,JZ_REG_AIC_CTRL , ctrl); +/* +* When there is a shared flush bit for both FIFOs, the TFLUSH +* bit flushes both FIFOs. Flushing while the DAI is active would +* cause FIFO underruns in other active substreams so we have to +* guard this behind the snd_soc_dai_active() check. +*/ +if (i2s->soc_info->shared_fifo_flush) +jz4740_i2s_set_bits (i2s,JZ_REG_AIC_CTRL ,JZ_AIC_CTRL_TFLUSH ); ret =clk_prepare_enable (i2s->clk_i2s);if (ret)
@@ -467,6 +495,7 @@ static struct snd_soc_dai_driver jz4740_static const struct i2s_soc_info jz4740_i2s_soc_info = { .version =JZ_I2S_JZ4740 , .dai = &jz4740_i2s_dai, + .shared_fifo_flush = true, };static const struct i2s_soc_info jz4760_i2s_soc_info = {
Greg Kroah-Hartman
maintainerPATCH 653/783 ipmi: fix long wait in unload when IPMI disconnect
In reply to Greg Kroah-HartmanFrom: Zhang Yuchen <[email protected]>
commit f6f1234d98cce69578bfac79df147a1f6660596c upstream.
When fixing the problem mentioned in PATCH1, we also found the following problem:
If the IPMI is disconnected and in the sending process, the uninstallation driver will be stuck for a long time.
The main problem is that uninstalling the driver waits for curr_msg to be sent or HOSED. After stopping tasklet, the only place to trigger the timeout mechanism is the circular poll in shutdown_smi.
The poll function delays 10us and calls smi_event_handler(smi_info,10). Smi_event_handler deducts 10us from kcs->ibf_timeout.
But the poll func is followed by schedule_timeout_uninterruptible(1). The time consumed here is not counted in kcs->ibf_timeout.
So when 10us is deducted from kcs->ibf_timeout, at least 1 jiffies has actually passed. The waiting time has increased by more than a hundredfold.
Now instead of calling poll(). call smi_event_handler() directly and calculate the elapsed time.
For verification, you can directly use ebpf to check the kcs-> ibf_timeout for each call to kcs_event() when IPMI is disconnected. Decrement at normal rate before unloading. The decrement rate becomes very slow after unloading.
$ bpftrace -e 'kprobe:kcs_event {printf("kcs->ibftimeout : %d\n",
*(arg0+584));}'Message-Id: <[email protected]>
--- drivers/char/ipmi/ipmi_si_intf.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/char/ipmi/ipmi_si_intf.c +19 -8
@@ -2160,6 +2160,20 @@ skip_fallback_noirq: }module_init (init_ipmi_si); +static void wait_msg_processed (struct smi_info *smi_info) +{ +unsigned long jiffies_now; +long time_diff; + +while (smi_info->curr_msg || (smi_info->si_state !=SI_NORMAL )) { + jiffies_now = jiffies; + time_diff = (((long )jiffies_now - (long )smi_info->last_timeout_jiffies) + *SI_USEC_PER_JIFFY ); +smi_event_handler (smi_info, time_diff); +schedule_timeout_uninterruptible (1 ); + } +} +static void shutdown_smi (void *send_info) {struct smi_info *smi_info = send_info;
@@ -2194,16 +2208,13 @@ static void shutdown_smi(void *send_info* in the BMC. Note that timers and CPU interrupts are off, * so no need for locks. */ -while (smi_info->curr_msg || (smi_info->si_state !=SI_NORMAL )) { -poll (smi_info); -schedule_timeout_uninterruptible (1 ); - } +wait_msg_processed (smi_info); +if (smi_info->handlers)disable_si_irq (smi_info); -while (smi_info->curr_msg || (smi_info->si_state !=SI_NORMAL )) { -poll (smi_info); -schedule_timeout_uninterruptible (1 ); - } + +wait_msg_processed (smi_info); +if (smi_info->handlers) smi_info->handlers->cleanup (smi_info->si_sm);
Greg Kroah-Hartman
maintainerPATCH 654/783 mtd: spi-nor: Check for zero erase size in spi_nor_find_best_erase_type()
In reply to Greg Kroah-HartmanFrom: Alexander Sverdlin <[email protected]>
commit 2ebc336be08160debfe27f87660cf550d710f3e9 upstream.
Erase can be zeroed in spi_nor_parse_4bait() or spi_nor_init_non_uniform_erase_map(). In practice it happened with mt25qu256a, which supports 4K, 32K, 64K erases with 3b address commands, but only 4K and 64K erase with 4b address commands.
--- drivers/mtd/spi-nor/core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mtd/spi-nor/core.c +2 -0
@@ -1220,6 +1220,8 @@ spi_nor_find_best_erase_type(const struccontinue ; erase = &map->erase_type[i]; +if (!erase->size) +continue ;/* Alignment is not mandatory for overlaid regions */ if (region->offset & SNOR_OVERLAID_REGION &&
Greg Kroah-Hartman
maintainerPATCH 655/783 ima: Fix a potential NULL pointer access in ima_restore_measurement_list
In reply to Greg Kroah-HartmanFrom: Huaxin Lu <[email protected]>
commit 11220db412edae8dba58853238f53258268bdb88 upstream.
In restore_template_fmt, when kstrdup fails, a non-NULL value will still be returned, which causes a NULL pointer access in template_desc_init_fields.
--- security/integrity/ima/ima_template.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
security/integrity/ima/ima_template.c +4 -1
@@ -290,8 +290,11 @@ static struct ima_template_desc *restore template_desc->name ="" ; template_desc->fmt =kstrdup (template_name,GFP_KERNEL ); -if (!template_desc->fmt) +if (!template_desc->fmt) { +kfree (template_desc); + template_desc =NULL ; goto out; + }spin_lock (&template_list);list_add_tail_rcu (&template_desc->list, &defined_templates);
Greg Kroah-Hartman
maintainerPATCH 656/783 ipmi: fix use after free in _ipmi_destroy_user()
In reply to Greg Kroah-HartmanFrom: Dan Carpenter <[email protected]>
commit a92ce570c81dc0feaeb12a429b4bc65686d17967 upstream.
The intf_free() function frees the "intf" pointer so we cannot dereference it again on the next line.
Message-Id: <Y3M8xa1drZv4CToE@kili>
--- drivers/char/ipmi/ipmi_msghandler.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/ipmi/ipmi_msghandler.c +3 -1
@@ -1284,6 +1284,7 @@ static void _ipmi_destroy_user(struct ipunsigned long flags;struct cmd_rcvr *rcvr;struct cmd_rcvr *rcvrs =NULL ; +struct module *owner;if (!acquire_ipmi_user (user, &i)) {/*
@@ -1345,8 +1346,9 @@ static void _ipmi_destroy_user(struct ipkfree (rcvr); } + owner = intf->owner;kref_put (&intf->refcount, intf_free); -module_put (intf->owner); +module_put (owner); }int ipmi_destroy_user (struct ipmi_user *user)
Greg Kroah-Hartman
maintainerPATCH 657/783 PCI: Fix pci_device_is_present() for VFs by checking PF
In reply to Greg Kroah-HartmanFrom: Michael S. Tsirkin <[email protected]>
commit 98b04dd0b4577894520493d96bc4623387767445 upstream.
pci_device_is_present() previously didn't work for VFs because it reads the Vendor and Device ID, which are 0xffff for VFs, which looks like they aren't present. Check the PF instead.
Wei Gong reported that if virtio I/O is in progress when the driver is unbound or "0" is written to /sys/.../sriov_numvfs, the virtio I/O operation hangs, which may result in output like this:
task:bash state:D stack: 0 pid: 1773 ppid: 1241 flags:0x00004002
Call Trace: schedule+0x4f/0xc0 blk_mq_freeze_queue_wait+0x69/0xa0 blk_mq_freeze_queue+0x1b/0x20 blk_cleanup_queue+0x3d/0xd0 virtblk_remove+0x3c/0xb0 [virtio_blk] virtio_dev_remove+0x4b/0x80 ... device_unregister+0x1b/0x60 unregister_virtio_device+0x18/0x30 virtio_pci_remove+0x41/0x80 pci_device_remove+0x3e/0xb0
This happened because pci_device_is_present(VF) returned "false" in virtio_pci_remove(), so it called virtio_break_device(). The broken vq meant that vring_interrupt() skipped the vq.callback() that would have completed the virtio I/O operation via virtblk_done().
--- drivers/pci/pci.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/pci/pci.c +2 -0
@@ -6152,6 +6152,8 @@ bool pci_device_is_present(struct pci_de {u32 v; +/* Check PF if pdev is a VF, since VF Vendor/Device IDs are 0xffff */ + pdev =pci_physfn (pdev);if (pci_dev_is_disconnected (pdev))return false;return pci_bus_read_dev_vendor_id (pdev->bus, pdev->devfn, &v,0 );
Greg Kroah-Hartman
maintainerPATCH 658/783 PCI/sysfs: Fix double free in error path
In reply to Greg Kroah-HartmanFrom: Sascha Hauer <[email protected]>
commit aa382ffa705bea9931ec92b6f3c70e1fdb372195 upstream.
When pci_create_attr() fails, pci_remove_resource_files() is called which will iterate over the res_attr[_wc] arrays and frees every non NULL entry. To avoid a double free here set the array entry only after it's clear we successfully initialized it.
--- drivers/pci/pci-sysfs.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/pci/pci-sysfs.c +9 -4
@@ -1141,11 +1141,9 @@ static int pci_create_attr(struct pci_desysfs_bin_attr_init (res_attr);if (write_combine) { - pdev->res_attr_wc[num] = res_attr;sprintf (res_attr_name,"resource%d_wc" , num); res_attr->mmap = pci_mmap_resource_wc; }else { - pdev->res_attr[num] = res_attr;sprintf (res_attr_name,"resource%d" , num);if (pci_resource_flags (pdev, num) &IORESOURCE_IO ) { res_attr->read = pci_read_resource_io;
@@ -1161,10 +1159,17 @@ static int pci_create_attr(struct pci_de res_attr->size =pci_resource_len (pdev, num); res_attr->private = (void *)(unsigned long )num; retval =sysfs_create_bin_file (&pdev->dev.kobj, res_attr); -if (retval) +if (retval) {kfree (res_attr); +return retval; + } + +if (write_combine) + pdev->res_attr_wc[num] = res_attr; +else + pdev->res_attr[num] = res_attr; -return retval; +return 0 ; }/**
Greg Kroah-Hartman
maintainerPATCH 659/783 crypto: n2 - add missing hash statesize
In reply to Greg Kroah-HartmanFrom: Corentin Labbe <[email protected]>
commit 76a4e874593543a2dff91d249c95bac728df2774 upstream.
Add missing statesize to hash templates.
This is mandatory otherwise no algorithms can be registered as the core requires statesize to be set.
--- drivers/crypto/n2_core.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/crypto/n2_core.c +6 -0
@@ -1228,6 +1228,7 @@ struct n2_hash_tmpl {const u8 *hash_init;u8 hw_op_hashsz;u8 digest_size; +u8 statesize;u8 block_size;u8 auth_type;u8 hmac_type;
@@ -1259,6 +1260,7 @@ static const struct n2_hash_tmpl hash_tm .hmac_type = AUTH_TYPE_HMAC_MD5, .hw_op_hashsz = MD5_DIGEST_SIZE, .digest_size = MD5_DIGEST_SIZE, + .statesize = sizeof(struct md5_state), .block_size = MD5_HMAC_BLOCK_SIZE }, { .name = "sha1", .hash_zero = sha1_zero_message_hash,
@@ -1267,6 +1269,7 @@ static const struct n2_hash_tmpl hash_tm .hmac_type = AUTH_TYPE_HMAC_SHA1, .hw_op_hashsz = SHA1_DIGEST_SIZE, .digest_size = SHA1_DIGEST_SIZE, + .statesize = sizeof(struct sha1_state), .block_size = SHA1_BLOCK_SIZE }, { .name = "sha256", .hash_zero = sha256_zero_message_hash,
@@ -1275,6 +1278,7 @@ static const struct n2_hash_tmpl hash_tm .hmac_type = AUTH_TYPE_HMAC_SHA256, .hw_op_hashsz = SHA256_DIGEST_SIZE, .digest_size = SHA256_DIGEST_SIZE, + .statesize = sizeof(struct sha256_state), .block_size = SHA256_BLOCK_SIZE }, { .name = "sha224", .hash_zero = sha224_zero_message_hash,
@@ -1283,6 +1287,7 @@ static const struct n2_hash_tmpl hash_tm .hmac_type = AUTH_TYPE_RESERVED, .hw_op_hashsz = SHA256_DIGEST_SIZE, .digest_size = SHA224_DIGEST_SIZE, + .statesize = sizeof(struct sha256_state), .block_size = SHA224_BLOCK_SIZE }, };#define NUM_HASH_TMPLS ARRAY_SIZE(hash_tmpls)
@@ -1423,6 +1428,7 @@ static int __n2_register_one_ahash(const halg = &ahash->halg; halg->digestsize = tmpl->digest_size; + halg->statesize = tmpl->statesize; base = &halg->base;snprintf (base->cra_name,CRYPTO_MAX_ALG_NAME ,"%s" , tmpl->name);
Greg Kroah-Hartman
maintainerPATCH 660/783 driver core: Fix bus_type.match() error handling in __driver_attach()
In reply to Greg Kroah-HartmanFrom: Isaac J. Manjarres <[email protected]>
commit 27c0d217340e47ec995557f61423ef415afba987 upstream.
When a driver registers with a bus, it will attempt to match with every device on the bus through the __driver_attach() function. Currently, if the bus_type.match() function encounters an error that is not -EPROBE_DEFER, __driver_attach() will return a negative error code, which causes the driver registration logic to stop trying to match with the remaining devices on the bus.
This behavior is not correct; a failure while matching a driver to a device does not mean that the driver won't be able to match and bind with other devices on the bus. Update the logic in __driver_attach() to reflect this.
--- drivers/base/dd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/base/dd.c +5 -1
@@ -1088,7 +1088,11 @@ static int __driver_attach(struct devicereturn 0 ; }else if (ret <0 ) {dev_dbg (dev,"Bus failed to match device: %d\n" , ret); -return ret; +/* +* Driver could not match with device, but may match with +* another device on the bus. +*/ +return 0 ; }/* ret > 0 means positive match */ if (driver_allows_async_probing (drv)) {
Greg Kroah-Hartman
maintainerPATCH 661/783 iommu/amd: Fix ivrs_acpihid cmdline parsing code
In reply to Greg Kroah-HartmanFrom: Kim Phillips <[email protected]>
commit 5f18e9f8868c6d4eae71678e7ebd4977b7d8c8cf upstream.
The second (UID) strcmp in acpi_dev_hid_uid_match considers "0" and "00" different, which can prevent device registration.
Have the AMD IOMMU driver's ivrs_acpihid parsing code remove any leading zeroes to make the UID strcmp succeed. Now users can safely specify "AMDxxxxx:00" or "AMDxxxxx:0" and expect the same behaviour.
--- drivers/iommu/amd/init.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/iommu/amd/init.c +7 -0
@@ -3126,6 +3126,13 @@ static int __init parse_ivrs_acpihid(chareturn 1 ; } +/* +* Ignore leading zeroes after ':', so e.g., AMDI0095:00 +* will match AMDI0095:0 in the second strcmp in acpi_dev_hid_uid_match +*/ +while (*uid =='0' && *(uid +1 )) + uid++; + i = early_acpihid_map_size++;memcpy (early_acpihid_map[i].hid, hid,strlen (hid));memcpy (early_acpihid_map[i].uid, uid,strlen (uid));
Greg Kroah-Hartman
maintainerPATCH 662/783 remoteproc: core: Do pm_relax when in RPROC_OFFLINE state
In reply to Greg Kroah-HartmanFrom: Maria Yu <[email protected]>
commit 11c7f9e3131ad14b27a957496088fa488b153a48 upstream.
Make sure that pm_relax() happens even when the remoteproc is stopped before the crash handler work is scheduled.
--- drivers/remoteproc/remoteproc_core.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +8 -1
@@ -1741,12 +1741,18 @@ static void rproc_crash_handler_work(strmutex_lock (&rproc->lock); -if (rproc->state ==RPROC_CRASHED || rproc->state ==RPROC_OFFLINE ) { +if (rproc->state ==RPROC_CRASHED ) {/* handle only the first crash detected */ mutex_unlock (&rproc->lock);return ; } +if (rproc->state ==RPROC_OFFLINE ) { +/* Don't recover if the remote processor was stopped */ +mutex_unlock (&rproc->lock); + goto out; + } + rproc->state =RPROC_CRASHED ;dev_err (dev,"handling crash #%u in %s\n" , ++rproc->crash_cnt, rproc->name);
@@ -1756,6 +1762,7 @@ static void rproc_crash_handler_work(strif (!rproc->recovery_disabled)rproc_trigger_recovery (rproc); +out:pm_relax (rproc->dev.parent); }
Greg Kroah-Hartman
maintainerPATCH 663/783 parisc: led: Fix potential null-ptr-deref in start_task()
In reply to Greg Kroah-HartmanFrom: Shang XiaoJing <[email protected]>
commit 41f563ab3c33698bdfc3403c7c2e6c94e73681e4 upstream.
start_task() calls create_singlethread_workqueue() and not checked the ret value, which may return NULL. And a null-ptr-deref may happen:
start_task()
create_singlethread_workqueue() # failed, led_wq is NULL queue_delayed_work()
queue_delayed_work_on()
__queue_delayed_work() # warning here, but continue
__queue_work() # access wq->flags, null-ptr-deref
Check the ret value and return -ENOMEM if it is NULL.
--- drivers/parisc/led.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/parisc/led.c +3 -0
@@ -137,6 +137,9 @@ static int start_task(void)/* Create the work queue and queue the LED task */ led_wq =create_singlethread_workqueue ("led_wq" ); +if (!led_wq) +return -ENOMEM ; +queue_delayed_work (led_wq, &led_task,0 );return 0 ;
Greg Kroah-Hartman
maintainerPATCH 664/783 device_cgroup: Roll back to original exceptions after copy failure
In reply to Greg Kroah-HartmanFrom: Wang Weiyang <[email protected]>
commit e68bfbd3b3c3a0ec3cf8c230996ad8cabe90322f upstream.
When add the 'a *:* rwm' entry to devcgroup A's whitelist, at first A's exceptions will be cleaned and A's behavior is changed to DEVCG_DEFAULT_ALLOW. Then parent's exceptions will be copyed to A's whitelist. If copy failure occurs, just return leaving A to grant permissions to all devices. And A may grant more permissions than parent.
Backup A's whitelist and recover original exceptions after copy failure.
--- security/device_cgroup.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
security/device_cgroup.c +29 -4
@@ -81,6 +81,17 @@ free_and_exit:return -ENOMEM ; } +static void dev_exceptions_move (struct list_head *dest,struct list_head *orig) +{ +struct dev_exception_item *ex, *tmp; + +lockdep_assert_held (&devcgroup_mutex); + +list_for_each_entry_safe (ex, tmp, orig, list) { +list_move_tail (&ex->list, dest); + } +} +/* * called under devcgroup_mutex */
@@ -603,11 +614,13 @@ static int devcgroup_update_access(strucint count, rc =0 ;struct dev_exception_item ex;struct dev_cgroup *parent =css_to_devcgroup (devcgroup->css.parent); +struct dev_cgroup tmp_devcgrp;if (!capable (CAP_SYS_ADMIN ))return -EPERM ;memset (&ex,0 ,sizeof (ex)); +memset (&tmp_devcgrp,0 ,sizeof (tmp_devcgrp)); b = buffer;switch (*b) {
@@ -619,15 +632,27 @@ static int devcgroup_update_access(strucif (!may_allow_all (parent))return -EPERM ; -dev_exception_clean (devcgroup); - devcgroup->behavior =DEVCG_DEFAULT_ALLOW ; -if (!parent) +if (!parent) { + devcgroup->behavior =DEVCG_DEFAULT_ALLOW ; +dev_exception_clean (devcgroup);break ; + } +INIT_LIST_HEAD (&tmp_devcgrp.exceptions); + rc =dev_exceptions_copy (&tmp_devcgrp.exceptions, + &devcgroup->exceptions); +if (rc) +return rc; +dev_exception_clean (devcgroup); rc =dev_exceptions_copy (&devcgroup->exceptions, &parent->exceptions); -if (rc) +if (rc) { +dev_exceptions_move (&devcgroup->exceptions, + &tmp_devcgrp.exceptions);return rc; + } + devcgroup->behavior =DEVCG_DEFAULT_ALLOW ; +dev_exception_clean (&tmp_devcgrp);break ;case DEVCG_DENY :if (css_has_online_children (&devcgroup->css))
Greg Kroah-Hartman
maintainerPATCH 665/783 drm/connector: send hotplug uevent on connector cleanup
In reply to Greg Kroah-HartmanFrom: Simon Ser <[email protected]>
commit 6fdc2d490ea1369d17afd7e6eb66fecc5b7209bc upstream.
A typical DP-MST unplug removes a KMS connector. However care must be taken to properly synchronize with user-space. The expected sequence of events is the following:
1. The kernel notices that the DP-MST port is gone.
2. The kernel marks the connector as disconnected, then sends a uevent to make user-space re-scan the connector list.
3. User-space notices the connector goes from connected to disconnected, disables it.
4. Kernel handles the IOCTL disabling the connector. On success, the very last reference to the struct drm_connector is dropped and drm_connector_cleanup() is called.
5. The connector is removed from the list, and a uevent is sent to tell user-space that the connector disappeared.
The very last step was missing. As a result, user-space thought the connector still existed and could try to disable it again. Since the kernel no longer knows about the connector, that would end up with EINVAL and confused user-space.
Fix this by sending a hotplug uevent from drm_connector_cleanup().
--- drivers/gpu/drm/drm_connector.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_connector.c +3 -0
@@ -484,6 +484,9 @@ void drm_connector_cleanup(struct drm_comutex_destroy (&connector->mutex);memset (connector,0 ,sizeof (*connector)); + +if (dev->registered) +drm_sysfs_hotplug_event (dev); }EXPORT_SYMBOL (drm_connector_cleanup);
Greg Kroah-Hartman
maintainerPATCH 666/783 drm/vmwgfx: Validate the box size for the snooped cursor
In reply to Greg Kroah-HartmanFrom: Zack Rusin <[email protected]>
commit 4cf949c7fafe21e085a4ee386bb2dade9067316e upstream.
Invalid userspace dma surface copies could potentially overflow the memcpy from the surface to the snooped image leading to crashes. To fix it the dimensions of the copybox have to be validated against the expected size of the snooped cursor.
--- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +2 -1
@@ -182,7 +182,8 @@ void vmw_kms_cursor_snoop(struct vmw_surif (cmd->dma.guest.ptr.offset %PAGE_SIZE || box->x !=0 || box->y !=0 || box->z !=0 || box->srcx !=0 || box->srcy !=0 || box->srcz !=0 || - box->d !=1 || box_count !=1 ) { + box->d !=1 || box_count !=1 || + box->w >64 || box->h >64 ) {/* TODO handle none page aligned offsets */ /* TODO handle more dst & src != 0 */ /* TODO handle more then one copy */
Greg Kroah-Hartman
maintainerPATCH 667/783 drm/i915/dsi: fix VBT send packet port selection for dual link DSI
In reply to Greg Kroah-HartmanFrom: Mikko Kovanen <[email protected]>
commit f9cdf4130671d767071607d0a7568c9bd36a68d0 upstream.
intel_dsi->ports contains bitmask of enabled ports and correspondingly logic for selecting port for VBT packet sending must use port specific bitmask when deciding appropriate port.
--- drivers/gpu/drm/i915/display/intel_dsi_vbt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/display/intel_dsi_vbt.c +2 -2
@@ -133,9 +133,9 @@ static enum port intel_dsi_seq_port_to_preturn ffs (intel_dsi->ports) -1 ;if (seq_port) { -if (intel_dsi->ports &PORT_B ) +if (intel_dsi->ports &BIT (PORT_B ))return PORT_B ; -else if (intel_dsi->ports &PORT_C ) +else if (intel_dsi->ports &BIT (PORT_C ))return PORT_C ; }
Greg Kroah-Hartman
maintainerPATCH 668/783 drm/ingenic: Fix missing platform_driver_unregister() call in ingenic_drm_init()
In reply to Greg Kroah-HartmanFrom: Yuan Can <[email protected]>
commit 47078311b8efebdefd5b3b2f87e2b02b14f49c66 upstream.
A problem about modprobe ingenic-drm failed is triggered with the following log given:
[ 303.561088] Error: Driver 'ingenic-ipu' is already registered, aborting... modprobe: ERROR: could not insert 'ingenic_drm': Device or resource busy
The reason is that ingenic_drm_init() returns platform_driver_register() directly without checking its return value, if platform_driver_register() failed, it returns without unregistering ingenic_ipu_driver_ptr, resulting the ingenic-drm can never be installed later.
A simple call graph is shown as below:
ingenic_drm_init()
platform_driver_register() # ingenic_ipu_driver_ptr are registered platform_driver_register()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened
# return without unregister ingenic_ipu_driver_ptr
Fixing this problem by checking the return value of platform_driver_register() and do platform_unregister_drivers() if error happened.
--- drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/ingenic/ingenic-drm-drv.c +5 -1
@@ -1120,7 +1120,11 @@ static int ingenic_drm_init(void)return err; } -return platform_driver_register (&ingenic_drm_driver); + err =platform_driver_register (&ingenic_drm_driver); +if (IS_ENABLED (CONFIG_DRM_INGENIC_IPU ) && err) +platform_driver_unregister (ingenic_ipu_driver_ptr); + +return err; }module_init (ingenic_drm_init);
Greg Kroah-Hartman
maintainerPATCH 669/783 ext4: silence the warning when evicting inode with dioread_nolock
In reply to Greg Kroah-HartmanFrom: Zhang Yi <[email protected]>
commit bc12ac98ea2e1b70adc6478c8b473a0003b659d3 upstream.
When evicting an inode with default dioread_nolock, it could be raced by the unwritten extents converting kworker after writeback some new allocated dirty blocks. It convert unwritten extents to written, the extents could be merged to upper level and free extent blocks, so it could mark the inode dirty again even this inode has been marked I_FREEING. But the inode->i_io_list check and warning in ext4_evict_inode() missing this corner case. Fortunately, ext4_evict_inode() will wait all extents converting finished before this check, so it will not lead to inode use-after-free problem, every thing is OK besides this warning. The WARN_ON_ONCE was originally designed for finding inode use-after-free issues in advance, but if we add current dioread_nolock case in, it will become not quite useful, so fix this warning by just remove this check.
======
WARNING: CPU: 7 PID: 1092 at fs/ext4/inode.c:227 ext4_evict_inode+0x875/0xc60 ... RIP: 0010:ext4_evict_inode+0x875/0xc60 ... Call Trace: <TASK> evict+0x11c/0x2b0 iput+0x236/0x3a0 do_unlinkat+0x1b4/0x490 __x64_sys_unlinkat+0x4c/0xb0 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x46/0xb0 RIP: 0033:0x7fa933c1115b ======
rm kworker
ext4_end_io_end()
vfs_unlink()
ext4_unlink()
ext4_convert_unwritten_io_end_vec()
ext4_convert_unwritten_extents()
ext4_map_blocks()
ext4_ext_map_blocks()
ext4_ext_try_to_merge_up()
__mark_inode_dirty()
check !I_FREEING
locked_inode_to_wb_and_lock_list()
iput()
iput_final()
evict()
ext4_evict_inode()
truncate_inode_pages_final() //wait release io_end
inode_io_list_move_locked()
ext4_release_io_end()
trigger WARN_ON_ONCE()--- fs/ext4/inode.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/ext4/inode.c +5 -5
@@ -223,13 +223,13 @@ void ext4_evict_inode(struct inode *inod/* * For inodes with journalled data, transaction commit could have -* dirtied the inode. Flush worker is ignoring it because of I_FREEING -* flag but we still need to remove the inode from the writeback lists. +* dirtied the inode. And for inodes with dioread_nolock, unwritten +* extents converting worker could merge extents and also have dirtied +* the inode. Flush worker is ignoring it because of I_FREEING flag but +* we still need to remove the inode from the writeback lists. */ -if (!list_empty_careful (&inode->i_io_list)) { -WARN_ON_ONCE (!ext4_should_journal_data (inode)); +if (!list_empty_careful (&inode->i_io_list))inode_io_list_del (inode); - }/* * Protect us against freezing - iput() caller didn't have to have any
Greg Kroah-Hartman
maintainerPATCH 670/783 ext4: add inode table check in __ext4_get_inode_loc to aovid possible infinite loop
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit eee22187b53611e173161e38f61de1c7ecbeb876 upstream.
In do_writepages, if the value returned by ext4_writepages is "-ENOMEM" and "wbc->sync_mode == WB_SYNC_ALL", retry until the condition is not met.
In __ext4_get_inode_loc, if the bh returned by sb_getblk is NULL, the function returns -ENOMEM.
In __getblk_slow, if the return value of grow_buffers is less than 0, the function returns NULL.
When the three processes are connected in series like the following stack, an infinite loop may occur:
do_writepages <--- keep retrying
ext4_writepages
mpage_map_and_submit_extent
mpage_map_one_extent
ext4_map_blocks
ext4_ext_map_blocks
ext4_ext_handle_unwritten_extents
ext4_ext_convert_to_initialized
ext4_split_extent
ext4_split_extent_at
__ext4_ext_dirty
__ext4_mark_inode_dirty
ext4_reserve_inode_write
ext4_get_inode_loc
__ext4_get_inode_loc <--- return -ENOMEM
sb_getblk
__getblk_gfp
__getblk_slow <--- return NULL
grow_buffers
grow_dev_page <--- return -ENXIO
ret = (block < end_block) ? 1 : -ENXIO;In this issue, bg_inode_table_hi is overwritten as an incorrect value. As a result, block < end_block cannot be met in grow_dev_page. Therefore, __ext4_get_inode_loc always returns '-ENOMEM' and do_writepages keeps retrying. As a result, the writeback process is in the D state due to an infinite loop.
Add a check on inode table block in the __ext4_get_inode_loc function by referring to ext4_read_inode_bitmap to avoid this infinite loop.
--- fs/ext4/inode.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/ext4/inode.c +9 -1
@@ -4386,9 +4386,17 @@ static int __ext4_get_inode_loc(struct s inodes_per_block =EXT4_SB (sb)->s_inodes_per_block; inode_offset = ((ino -1 ) %EXT4_INODES_PER_GROUP (sb)); - block =ext4_inode_table (sb, gdp) + (inode_offset / inodes_per_block); iloc->offset = (inode_offset % inodes_per_block) *EXT4_INODE_SIZE (sb); + block =ext4_inode_table (sb, gdp); +if ((block <=le32_to_cpu (EXT4_SB (sb)->s_es->s_first_data_block)) || + (block >=ext4_blocks_count (EXT4_SB (sb)->s_es))) { +ext4_error (sb,"Invalid inode table block %llu in " +"block_group %u" , block, iloc->block_group); +return -EFSCORRUPTED ; + } + block += (inode_offset / inodes_per_block); + bh =sb_getblk (sb, block);if (unlikely (!bh))return -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 671/783 ext4: fix use-after-free in ext4_orphan_cleanup
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit a71248b1accb2b42e4980afef4fa4a27fa0e36f5 upstream.
I caught a issue as follows:
==================================================================
BUG: KASAN: use-after-free in __list_add_valid+0x28/0x1a0 Read of size 8 at addr ffff88814b13f378 by task mount/710 CPU: 1 PID: 710 Comm: mount Not tainted 6.1.0-rc3-next #370 Call Trace: <TASK> dump_stack_lvl+0x73/0x9f print_report+0x25d/0x759 kasan_report+0xc0/0x120 __asan_load8+0x99/0x140 __list_add_valid+0x28/0x1a0 ext4_orphan_cleanup+0x564/0x9d0 [ext4] __ext4_fill_super+0x48e2/0x5300 [ext4] ext4_fill_super+0x19f/0x3a0 [ext4] get_tree_bdev+0x27b/0x450 ext4_get_tree+0x19/0x30 [ext4] vfs_get_tree+0x49/0x150 path_mount+0xaae/0x1350 do_mount+0xe2/0x110 __x64_sys_mount+0xf0/0x190 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd </TASK> [...] ==================================================================
Above issue may happen as follows:
-------------------------------------ext4_fill_super
ext4_orphan_cleanup
--- loop1: assume last_orphan is 12 ---
list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan)
ext4_truncate --> return 0
ext4_inode_attach_jinode --> return -ENOMEM
iput(inode) --> free inode<12>
--- loop2: last_orphan is still 12 ---
list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
// use inode<12> and trigger UAFTo solve this issue, we need to propagate the return value of ext4_inode_attach_jinode() appropriately.
--- fs/ext4/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/inode.c +2 -1
@@ -4285,7 +4285,8 @@ int ext4_truncate(struct inode *inode)/* If we zero-out tail of the page, we have to create jinode for jbd2 */ if (inode->i_size & (inode->i_sb->s_blocksize -1 )) { -if (ext4_inode_attach_jinode (inode) <0 ) + err =ext4_inode_attach_jinode (inode); +if (err) goto out_trace; }
Greg Kroah-Hartman
maintainerPATCH 672/783 ext4: fix undefined behavior in bit shift for ext4_check_flag_values
In reply to Greg Kroah-HartmanFrom: Gaosheng Cui <[email protected]>
commit 3bf678a0f9c017c9ba7c581541dbc8453452a7ae upstream.
Shifting signed 32-bit value by 31 bits is undefined, so changing significant bit to unsigned. The UBSAN warning calltrace like below:
UBSAN: shift-out-of-bounds in fs/ext4/ext4.h:591:2 left shift of 1 by 31 places cannot be represented in type 'int' Call Trace: <TASK> dump_stack_lvl+0x7d/0xa5 dump_stack+0x15/0x1b ubsan_epilogue+0xe/0x4e __ubsan_handle_shift_out_of_bounds+0x1e7/0x20c ext4_init_fs+0x5a/0x277 do_one_initcall+0x76/0x430 kernel_init_freeable+0x3b3/0x422 kernel_init+0x24/0x1e0 ret_from_fork+0x1f/0x30 </TASK>
--- fs/ext4/ext4.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/ext4.h +1 -1
@@ -553,7 +553,7 @@ enum {* * It's not paranoia if the Murphy's Law really *is* out to get you. :-) */ -#define TEST_FLAG_VALUE (FLAG ) (EXT4_##FLAG##_FL == (1 << EXT4_INODE_##FLAG)) +#define TEST_FLAG_VALUE (FLAG ) (EXT4_##FLAG##_FL == (1U << EXT4_INODE_##FLAG))#define CHECK_FLAG_VALUE (FLAG ) BUILD_BUG_ON(!TEST_FLAG_VALUE(FLAG))static inline void ext4_check_flag_values (void )
Greg Kroah-Hartman
maintainerPATCH 673/783 ext4: add EXT4_IGET_BAD flag to prevent unexpected bad inode
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit 63b1e9bccb71fe7d7e3ddc9877dbdc85e5d2d023 upstream.
There are many places that will get unhappy (and crash) when ext4_iget() returns a bad inode. However, if iget the boot loader inode, allows a bad inode to be returned, because the inode may not be initialized. This mechanism can be used to bypass some checks and cause panic. To solve this problem, we add a special iget flag EXT4_IGET_BAD. Only with this flag we'd be returning bad inode from ext4_iget(), otherwise we always return the error code if the inode is bad inode.(suggested by Jan Kara)
--- fs/ext4/ext4.h | 3 ++- fs/ext4/inode.c | 8 +++++++- fs/ext4/ioctl.c | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-)
fs/ext4/ext4.h +2 -1
@@ -2842,7 +2842,8 @@ int do_journal_get_write_access(handle_ttypedef enum {EXT4_IGET_NORMAL =0 ,EXT4_IGET_SPECIAL =0x0001 ,/* OK to iget a system inode */ -EXT4_IGET_HANDLE =0x0002 /* Inode # is from a handle */ +EXT4_IGET_HANDLE =0x0002 ,/* Inode # is from a handle */ +EXT4_IGET_BAD =0x0004 /* Allow to iget a bad inode */ }ext4_iget_flags ; extern struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
fs/ext4/inode.c +7 -1
@@ -4969,8 +4969,14 @@ struct inode *__ext4_iget(struct super_bif (IS_CASEFOLDED (inode) && !ext4_has_feature_casefold (inode->i_sb))ext4_error_inode (inode, function, line,0 ,"casefold flag without casefold feature" ); -brelse (iloc.bh); +if (is_bad_inode (inode) && !(flags &EXT4_IGET_BAD )) { +ext4_error_inode (inode, function, line,0 , +"bad inode without EXT4_IGET_BAD flag" ); + ret = -EUCLEAN ; + goto bad_inode; + } +brelse (iloc.bh);unlock_new_inode (inode);return inode;
fs/ext4/ioctl.c +2 -1
@@ -121,7 +121,8 @@ static long swap_inode_boot_loader(strucblkcnt_t blocks;unsigned short bytes; - inode_bl =ext4_iget (sb,EXT4_BOOT_LOADER_INO ,EXT4_IGET_SPECIAL ); + inode_bl =ext4_iget (sb,EXT4_BOOT_LOADER_INO , +EXT4_IGET_SPECIAL |EXT4_IGET_BAD );if (IS_ERR (inode_bl))return PTR_ERR (inode_bl); ei_bl =EXT4_I (inode_bl);
Greg Kroah-Hartman
maintainerPATCH 674/783 ext4: add helper to check quota inums
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit 07342ec259df2a35d6a34aebce010567a80a0e15 upstream.
Before quota is enabled, a check on the preset quota inums in ext4_super_block is added to prevent wrong quota inodes from being loaded. In addition, when the quota fails to be enabled, the quota type and quota inum are printed to facilitate fault locating.
--- fs/ext4/super.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)
fs/ext4/super.c +25 -3
@@ -6385,6 +6385,20 @@ static int ext4_quota_on(struct super_blreturn err; } +static inline bool ext4_check_quota_inum (int type,unsigned long qf_inum) +{ +switch (type) { +case USRQUOTA : +return qf_inum ==EXT4_USR_QUOTA_INO ; +case GRPQUOTA : +return qf_inum ==EXT4_GRP_QUOTA_INO ; +case PRJQUOTA : +return qf_inum >=EXT4_GOOD_OLD_FIRST_INO ; +default : +BUG (); + } +} +static int ext4_quota_enable (struct super_block *sb,int type,int format_id,unsigned int flags) {
@@ -6401,9 +6415,16 @@ static int ext4_quota_enable(struct supeif (!qf_inums[type])return -EPERM ; +if (!ext4_check_quota_inum (type, qf_inums[type])) { +ext4_error (sb,"Bad quota inum: %lu, type: %d" , + qf_inums[type], type); +return -EUCLEAN ; + } + qf_inode =ext4_iget (sb, qf_inums[type],EXT4_IGET_SPECIAL );if (IS_ERR (qf_inode)) { -ext4_error (sb,"Bad quota inode # %lu" , qf_inums[type]); +ext4_error (sb,"Bad quota inode: %lu, type: %d" , + qf_inums[type], type);return PTR_ERR (qf_inode); }
@@ -6442,8 +6463,9 @@ static int ext4_enable_quotas(struct supif (err) {ext4_warning (sb,"Failed to enable quota tracking " -"(type=%d, err=%d). Please run " -"e2fsck to fix." , type, err); +"(type=%d, err=%d, ino=%lu). " +"Please run e2fsck to fix." , type, + err, qf_inums[type]);for (type--; type >=0 ; type--) {struct inode *inode;
Greg Kroah-Hartman
maintainerPATCH 675/783 ext4: fix bug_on in __es_tree_search caused by bad quota inode
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit d323877484765aaacbb2769b06e355c2041ed115 upstream.
We got a issue as fllows:
==================================================================
kernel BUG at fs/ext4/extents_status.c:202!
invalid opcode: 0000 [#1] PREEMPT SMP
CPU: 1 PID: 810 Comm: mount Not tainted 6.1.0-rc1-next-g9631525255e3 #352 RIP: 0010:__es_tree_search.isra.0+0xb8/0xe0 RSP: 0018:ffffc90001227900 EFLAGS: 00010202 RAX: 0000000000000000 RBX: 0000000077512a0f RCX: 0000000000000000 RDX: 0000000000000002 RSI: 0000000000002a10 RDI: ffff8881004cd0c8 RBP: ffff888177512ac8 R08: 47ffffffffffffff R09: 0000000000000001 R10: 0000000000000001 R11: 00000000000679af R12: 0000000000002a10 R13: ffff888177512d88 R14: 0000000077512a10 R15: 0000000000000000 FS: 00007f4bd76dbc40(0000)GS:ffff88842fd00000(0000)knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00005653bf993cf8 CR3: 000000017bfdf000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> ext4_es_cache_extent+0xe2/0x210 ext4_cache_extents+0xd2/0x110 ext4_find_extent+0x5d5/0x8c0 ext4_ext_map_blocks+0x9c/0x1d30 ext4_map_blocks+0x431/0xa50 ext4_getblk+0x82/0x340 ext4_bread+0x14/0x110 ext4_quota_read+0xf0/0x180 v2_read_header+0x24/0x90 v2_check_quota_file+0x2f/0xa0 dquot_load_quota_sb+0x26c/0x760 dquot_load_quota_inode+0xa5/0x190 ext4_enable_quotas+0x14c/0x300 __ext4_fill_super+0x31cc/0x32c0 ext4_fill_super+0x115/0x2d0 get_tree_bdev+0x1d2/0x360 ext4_get_tree+0x19/0x30 vfs_get_tree+0x26/0xe0 path_mount+0x81d/0xfc0 do_mount+0x8d/0xc0 __x64_sys_mount+0xc0/0x160 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd </TASK> ==================================================================
Above issue may happen as follows:
-------------------------------------ext4_fill_super
ext4_orphan_cleanup
ext4_enable_quotas
ext4_quota_enable
ext4_iget --> get error inode <5>
ext4_ext_check_inode --> Wrong imode makes it escape inspection
make_bad_inode(inode) --> EXT4_BOOT_LOADER_INO set imode
dquot_load_quota_inode
vfs_setup_quota_inode --> check pass
dquot_load_quota_sb
v2_check_quota_file
v2_read_header
ext4_quota_read
ext4_bread
ext4_getblk
ext4_map_blocks
ext4_ext_map_blocks
ext4_find_extent
ext4_cache_extents
ext4_es_cache_extent
__es_tree_search.isra.0
ext4_es_end --> Wrong extents trigger BUG_ONIn the above issue, s_usr_quota_inum is set to 5, but inode<5> contains incorrect imode and disordered extents. Because 5 is EXT4_BOOT_LOADER_INO, the ext4_ext_check_inode check in the ext4_iget function can be bypassed, finally, the extents that are not checked trigger the BUG_ON in the __es_tree_search function. To solve this issue, check whether the inode is bad_inode in vfs_setup_quota_inode().
--- fs/quota/dquot.c | 2 ++ 1 file changed, 2 insertions(+)
fs/quota/dquot.c +2 -0
@@ -2319,6 +2319,8 @@ static int vfs_setup_quota_inode(structstruct super_block *sb = inode->i_sb;struct quota_info *dqopt =sb_dqopt (sb); +if (is_bad_inode (inode)) +return -EUCLEAN ;if (!S_ISREG (inode->i_mode))return -EACCES ;if (IS_RDONLY (inode))
Greg Kroah-Hartman
maintainerPATCH 676/783 ext4: fix reserved cluster accounting in __es_remove_extent()
In reply to Greg Kroah-HartmanFrom: Ye Bin <[email protected]>
commit 1da18e38cb97e9521e93d63034521a9649524f64 upstream.
When bigalloc is enabled, reserved cluster accounting for delayed allocation is handled in extent_status.c. With a corrupted file system, it's possible for this accounting to be incorrect, dsicovered by Syzbot:
EXT4-fs error (device loop0): ext4_validate_block_bitmap:398: comm rep:
bg 0: block 5: invalid block bitmap
EXT4-fs (loop0): Delayed block allocation failed for inode 18 at logical
offset 0 with max blocks 32 with error 28
EXT4-fs (loop0): This should not happen!! Data will be lost
EXT4-fs (loop0): Total free blocks count 0
EXT4-fs (loop0): Free/Dirty block details
EXT4-fs (loop0): free_blocks=0
EXT4-fs (loop0): dirty_blocks=32
EXT4-fs (loop0): Block reservation details
EXT4-fs (loop0): i_reserved_data_blocks=2
EXT4-fs (loop0): Inode 18 (00000000845cd634):
i_reserved_data_blocks (1) not cleared!
Above issue happens as follows:
Assume:sbi->s_cluster_ratio = 16
Step1:
Insert delay block [0, 31] -> ei->i_reserved_data_blocks=2 Step2:ext4_writepages
mpage_map_and_submit_extent -> return failed mpage_release_unused_pages -> to release [0, 30]
ext4_es_remove_extent -> remove lblk=0 end=30
__es_remove_extent -> len1=0 len2=31-30=1
__es_remove_extent:
...
if (len2 > 0) {
...
if (len1 > 0) {
...
} else {
es->es_lblk = end + 1;
es->es_len = len2;
...
}
if (count_reserved)
count_rsvd(inode, lblk, ...);
goto out; -> will return but didn't calculate 'reserved' ...
Step3:ext4_destroy_inode -> trigger "i_reserved_data_blocks (1) not cleared!"
To solve above issue if 'len2>0' call 'get_rsvd()' before goto out.
--- fs/ext4/extents_status.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/extents_status.c +2 -1
@@ -1372,7 +1372,7 @@ retry:if (count_reserved)count_rsvd (inode, lblk, orig_es.es_len - len1 - len2, &orig_es, &rc); - goto out; + goto out_get_reserved; }if (len1 >0 ) {
@@ -1414,6 +1414,7 @@ retry: } } +out_get_reserved:if (count_reserved) *reserved =get_rsvd (inode, end, es, &rc); out:
Greg Kroah-Hartman
maintainerPATCH 677/783 ext4: check and assert if marking an no_delete evicting inode dirty
In reply to Greg Kroah-HartmanFrom: Zhang Yi <[email protected]>
commit 318cdc822c63b6e2befcfdc2088378ae6fa18def upstream.
In ext4_evict_inode(), if we evicting an inode in the 'no_delete' path, it cannot be raced by another mark_inode_dirty(). If it happens, someone else may accidentally dirty it without holding inode refcount and probably cause use-after-free issues in the writeback procedure. It's indiscoverable and hard to debug, so add an WARN_ON_ONCE() to check and detect this issue in advance.
--- fs/ext4/inode.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/ext4/inode.c +6 -0
@@ -336,6 +336,12 @@ stop_handle:ext4_xattr_inode_array_free (ea_inode_array);return ; no_delete: +/* +* Check out some where else accidentally dirty the evicting inode, +* which may probably cause inode use-after-free issues later. +*/ +WARN_ON_ONCE (!list_empty_careful (&inode->i_io_list)); +if (!list_empty (&EXT4_I (inode)->i_fc_list))ext4_fc_mark_ineligible (inode->i_sb,EXT4_FC_REASON_NOMEM );ext4_clear_inode (inode);/* We must guarantee clearing of inode... */
Greg Kroah-Hartman
maintainerPATCH 678/783 ext4: fix bug_on in __es_tree_search caused by bad boot loader inode
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit 991ed014de0840c5dc405b679168924afb2952ac upstream.
We got a issue as fllows:
==================================================================
kernel BUG at fs/ext4/extents_status.c:203!
invalid opcode: 0000 [#1] PREEMPT SMP
CPU: 1 PID: 945 Comm: cat Not tainted 6.0.0-next-20221007-dirty #349 RIP: 0010:ext4_es_end.isra.0+0x34/0x42 RSP: 0018:ffffc9000143b768 EFLAGS: 00010203 RAX: 0000000000000000 RBX: ffff8881769cd0b8 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffffffff8fc27cf7 RDI: 00000000ffffffff RBP: ffff8881769cd0bc R08: 0000000000000000 R09: ffffc9000143b5f8 R10: 0000000000000001 R11: 0000000000000001 R12: ffff8881769cd0a0 R13: ffff8881768e5668 R14: 00000000768e52f0 R15: 0000000000000000 FS: 00007f359f7f05c0(0000)GS:ffff88842fd00000(0000)knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f359f5a2000 CR3: 000000017130c000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> __es_tree_search.isra.0+0x6d/0xf5 ext4_es_cache_extent+0xfa/0x230 ext4_cache_extents+0xd2/0x110 ext4_find_extent+0x5d5/0x8c0 ext4_ext_map_blocks+0x9c/0x1d30 ext4_map_blocks+0x431/0xa50 ext4_mpage_readpages+0x48e/0xe40 ext4_readahead+0x47/0x50 read_pages+0x82/0x530 page_cache_ra_unbounded+0x199/0x2a0 do_page_cache_ra+0x47/0x70 page_cache_ra_order+0x242/0x400 ondemand_readahead+0x1e8/0x4b0 page_cache_sync_ra+0xf4/0x110 filemap_get_pages+0x131/0xb20 filemap_read+0xda/0x4b0 generic_file_read_iter+0x13a/0x250 ext4_file_read_iter+0x59/0x1d0 vfs_read+0x28f/0x460 ksys_read+0x73/0x160 __x64_sys_read+0x1e/0x30 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd </TASK> ==================================================================
In the above issue, ioctl invokes the swap_inode_boot_loader function to swap inode<5> and inode<12>. However, inode<5> contain incorrect imode and disordered extents, and i_nlink is set to 1. The extents check for inode in the ext4_iget function can be bypassed bacause 5 is EXT4_BOOT_LOADER_INO. While links_count is set to 1, the extents are not initialized in swap_inode_boot_loader. After the ioctl command is executed successfully, the extents are swapped to inode<12>, in this case, run the cat command to view inode<12>. And Bug_ON is triggered due to the incorrect extents.
When the boot loader inode is not initialized, its imode can be one of the following:
1) the imode is a bad type, which is marked as bad_inode in ext4_iget and set to S_IFREG.
2) the imode is good type but not S_IFREG.
3) the imode is S_IFREG.
The BUG_ON may be triggered by bypassing the check in cases 1 and 2. Therefore, when the boot loader inode is bad_inode or its imode is not S_IFREG, initialize the inode to avoid triggering the BUG.
--- fs/ext4/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/ioctl.c +1 -1
@@ -171,7 +171,7 @@ static long swap_inode_boot_loader(struc/* Protect extent tree against block allocations via delalloc */ ext4_double_down_write_data_sem (inode, inode_bl); -if (inode_bl->i_nlink ==0 ) { +if (is_bad_inode (inode_bl) || !S_ISREG (inode_bl->i_mode)) {/* this inode has never been used as a BOOT_LOADER */ set_nlink (inode_bl,1 );i_uid_write (inode_bl,0 );
Greg Kroah-Hartman
maintainerPATCH 679/783 ext4: init quota for old.inode in ext4_rename
In reply to Greg Kroah-HartmanFrom: Ye Bin <[email protected]>
commit fae381a3d79bb94aa2eb752170d47458d778b797 upstream.
Syzbot found the following issue:ext4_parse_param: s_want_extra_isize=128ext4_inode_info_init: s_want_extra_isize=32ext4_rename: old.inode=ffff88823869a2c8 old.dir=ffff888238699828 new.inode=ffff88823869d7e8 new.dir=ffff888238699828 __ext4_mark_inode_dirty: inode=ffff888238699828 ea_isize=32 want_ea_size=128 __ext4_mark_inode_dirty: inode=ffff88823869a2c8 ea_isize=32 want_ea_size=128ext4_xattr_block_set: inode=ffff88823869a2c8
------------[ cut here ]------------ WARNING: CPU: 13 PID: 2234 at fs/ext4/xattr.c:2070 ext4_xattr_block_set.cold+0x22/0x980 Modules linked in: RIP: 0010:ext4_xattr_block_set.cold+0x22/0x980 RSP: 0018:ffff888227d3f3b0 EFLAGS: 00010202 RAX: 0000000000000001 RBX: ffff88823007a000 RCX: 0000000000000000 RDX: 0000000000000a03 RSI: 0000000000000040 RDI: ffff888230078178 RBP: 0000000000000000 R08: 000000000000002c R09: ffffed1075c7df8e R10: ffff8883ae3efc6b R11: ffffed1075c7df8d R12: 0000000000000000 R13: ffff88823869a2c8 R14: ffff8881012e0460 R15: dffffc0000000000 FS: 00007f350ac1f740(0000) GS:ffff8883ae200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f350a6ed6a0 CR3: 0000000237456000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> ? ext4_xattr_set_entry+0x3b7/0x2320 ? ext4_xattr_block_set+0x0/0x2020 ? ext4_xattr_set_entry+0x0/0x2320 ? ext4_xattr_check_entries+0x77/0x310 ? ext4_xattr_ibody_set+0x23b/0x340 ext4_xattr_move_to_block+0x594/0x720 ext4_expand_extra_isize_ea+0x59a/0x10f0 __ext4_expand_extra_isize+0x278/0x3f0 __ext4_mark_inode_dirty.cold+0x347/0x410 ext4_rename+0xed3/0x174f vfs_rename+0x13a7/0x2510 do_renameat2+0x55d/0x920 __x64_sys_rename+0x7d/0xb0 do_syscall_64+0x3b/0xa0 entry_SYSCALL_64_after_hwframe+0x72/0xdc
As 'ext4_rename' will modify 'old.inode' ctime and mark inode dirty, which may trigger expand 'extra_isize' and allocate block. If inode didn't init quota will lead to warning. To solve above issue, init 'old.inode' firstly in 'ext4_rename'.
--- fs/ext4/namei.c | 3 +++ 1 file changed, 3 insertions(+)
fs/ext4/namei.c +3 -0
@@ -3844,6 +3844,9 @@ static int ext4_rename(struct inode *old retval =dquot_initialize (old.dir);if (retval)return retval; + retval =dquot_initialize (old.inode); +if (retval) +return retval; retval =dquot_initialize (new.dir);if (retval)return retval;
Greg Kroah-Hartman
maintainerPATCH 680/783 ext4: fix delayed allocation bug in ext4_clu_mapped for bigalloc + inline
In reply to Greg Kroah-HartmanFrom: Eric Whitney <[email protected]>
commit 131294c35ed6f777bd4e79d42af13b5c41bf2775 upstream.
When converting files with inline data to extents, delayed allocations made on a file system created with both the bigalloc and inline options can result in invalid extent status cache content, incorrect reserved cluster counts, kernel memory leaks, and potential kernel panics.
With bigalloc, the code that determines whether a block must be delayed allocated searches the extent tree to see if that block maps to a previously allocated cluster. If not, the block is delayed allocated, and otherwise, it isn't. However, if the inline option is also used, and if the file containing the block is marked as able to store data inline, there isn't a valid extent tree associated with the file. The current code in ext4_clu_mapped() calls ext4_find_extent() to search the non-existent tree for a previously allocated cluster anyway, which typically finds nothing, as desired. However, a side effect of the search can be to cache invalid content from the non-existent tree (garbage) in the extent status tree, including bogus entries in the pending reservation tree.
To fix this, avoid searching the extent tree when allocating blocks for bigalloc + inline files that are being converted from inline to extent mapped.
--- fs/ext4/extents.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ext4/extents.c +8 -0
@@ -5802,6 +5802,14 @@ int ext4_clu_mapped(struct inode *inode,struct ext4_extent *extent;ext4_lblk_t first_lblk, first_lclu, last_lclu; +/* +* if data can be stored inline, the logical cluster isn't +* mapped - no physical clusters have been allocated, and the +* file has no extents +*/ +if (ext4_test_inode_state (inode,EXT4_STATE_MAY_INLINE_DATA )) +return 0 ; +/* search for the extent closest to the first block in the cluster */ path =ext4_find_extent (inode,EXT4_C2B (sbi, lclu),NULL ,0 );if (IS_ERR (path)) {
Greg Kroah-Hartman
maintainerPATCH 681/783 ext4: fix corruption when online resizing a 1K bigalloc fs
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit 0aeaa2559d6d53358fca3e3fce73807367adca74 upstream.
When a backup superblock is updated in update_backups(), the primary superblock's offset in the group (that is, sbi->s_sbh->b_blocknr) is used as the backup superblock's offset in its group. However, when the block size is 1K and bigalloc is enabled, the two offsets are not equal. This causes the backup group descriptors to be overwritten by the superblock in update_backups(). Moreover, if meta_bg is enabled, the file system will be corrupted because this feature uses backup group descriptors.
To solve this issue, we use a more accurate ext4_group_first_block_no() as the offset of the backup superblock in its group.
--- fs/ext4/resize.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ext4/resize.c +3 -3
@@ -1545,8 +1545,8 @@ exit_journal:int meta_bg =ext4_has_feature_meta_bg (sb);sector_t old_gdb =0 ; -update_backups (sb, sbi->s_sbh->b_blocknr, (char *)es, -sizeof (struct ext4_super_block ),0 ); +update_backups (sb,ext4_group_first_block_no (sb,0 ), + (char *)es,sizeof (struct ext4_super_block ),0 );for (; gdb_num <= gdb_num_end; gdb_num++) {struct buffer_head *gdb_bh;
@@ -1753,7 +1753,7 @@ errout:if (test_opt (sb,DEBUG ))printk (KERN_DEBUG "EXT4-fs: extended group to %llu " "blocks\n" ,ext4_blocks_count (es)); -update_backups (sb,EXT4_SB (sb)->s_sbh->b_blocknr, +update_backups (sb,ext4_group_first_block_no (sb,0 ), (char *)es,sizeof (struct ext4_super_block ),0 ); }return err;
Greg Kroah-Hartman
maintainerPATCH 682/783 ext4: fix error code return to user-space in ext4_get_branch()
In reply to Greg Kroah-HartmanFrom: Luís Henriques <[email protected]>
commit 26d75a16af285a70863ba6a81f85d81e7e65da50 upstream.
If a block is out of range in ext4_get_branch(), -ENOMEM will be returned to user-space. Obviously, this error code isn't really useful. This patch fixes it by making sure the right error code (-EFSCORRUPTED) is propagated to user-space. EUCLEAN is more informative than ENOMEM.
--- fs/ext4/indirect.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/ext4/indirect.c +8 -1
@@ -148,6 +148,7 @@ static Indirect *ext4_get_branch(structstruct super_block *sb = inode->i_sb;Indirect *p = chain;struct buffer_head *bh; +unsigned int key;int ret = -EIO ; *err =0 ;
@@ -156,7 +157,13 @@ static Indirect *ext4_get_branch(structif (!p->key) goto no_block;while (--depth) { - bh =sb_getblk (sb,le32_to_cpu (p->key)); + key =le32_to_cpu (p->key); +if (key >ext4_blocks_count (EXT4_SB (sb)->s_es)) { +/* the block was out of range */ + ret = -EFSCORRUPTED ; + goto failure; + } + bh =sb_getblk (sb, key);if (unlikely (!bh)) { ret = -ENOMEM ; goto failure;
Greg Kroah-Hartman
maintainerPATCH 683/783 ext4: avoid BUG_ON when creating xattrs
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
commit b40ebaf63851b3a401b0dc9263843538f64f5ce6 upstream.
Commit fb0a387dcdcd ("ext4: limit block allocations for indirect-block files to < 2^32") added code to try to allocate xattr block with 32-bit block number for indirect block based files on the grounds that these files cannot use larger block numbers. It also added BUG_ON when allocated block could not fit into 32 bits. This is however bogus reasoning because xattr block is stored in inode->i_file_acl and inode->i_file_acl_hi and as such even indirect block based files can happily use full 48 bits for xattr block number. The proper handling seems to be there basically since 64-bit block number support was added. So remove the bogus limitation and BUG_ON.
--- fs/ext4/xattr.c | 8 -------- 1 file changed, 8 deletions(-)
fs/ext4/xattr.c +0 -8
@@ -2049,19 +2049,11 @@ inserted: goal =ext4_group_first_block_no (sb,EXT4_I (inode)->i_block_group); - -/* non-extent files can't have physical blocks past 2^32 */ -if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) - goal = goal &EXT4_MAX_BLOCK_FILE_PHYS ; - block =ext4_new_meta_blocks (handle, inode, goal,0 ,NULL , &error);if (error) goto cleanup; -if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) -BUG_ON (block >EXT4_MAX_BLOCK_FILE_PHYS ); -ea_idebug (inode,"creating block %llu" , (unsigned long long )block);
Greg Kroah-Hartman
maintainerPATCH 684/783 ext4: fix inode leak in ext4_xattr_inode_create() on an error path
In reply to Greg Kroah-HartmanFrom: Ye Bin <[email protected]>
commit e4db04f7d3dbbe16680e0ded27ea2a65b10f766a upstream.
There is issue as follows when do setxattr with inject fault:
[localhost]# fsck.ext4 -fn /dev/sda
e2fsck 1.46.6-rc1 (12-Sep-2022)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Unattached zero-length inode 15. Clear? no
Unattached inode 15
Connect to /lost+found? no
Pass 5: Checking group summary information
/dev/sda: ********** WARNING: Filesystem still has errors **********
/dev/sda: 15/655360 files (0.0% non-contiguous), 66755/2621440 blocks
This occurs in 'ext4_xattr_inode_create()'. If 'ext4_mark_inode_dirty()' fails, dropping i_nlink of the inode is needed. Or will lead to inode leak.
--- fs/ext4/xattr.c | 3 +++ 1 file changed, 3 insertions(+)
fs/ext4/xattr.c +3 -0
@@ -1425,6 +1425,9 @@ static struct inode *ext4_xattr_inode_crif (!err) err =ext4_inode_attach_jinode (ea_inode);if (err) { +if (ext4_xattr_inode_dec_ref (handle, ea_inode)) +ext4_warning_inode (ea_inode, +"cleanup dec ref error %d" , err);iput (ea_inode);return ERR_PTR (err); }
Greg Kroah-Hartman
maintainerPATCH 685/783 ext4: initialize quota before expanding inode in setproject ioctl
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
commit 1485f726c6dec1a1f85438f2962feaa3d585526f upstream.
Make sure we initialize quotas before possibly expanding inode space (and thus maybe needing to allocate external xattr block) in ext4_ioctl_setproject(). This prevents not accounting the necessary block allocation.
--- fs/ext4/ioctl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ext4/ioctl.c +4 -4
@@ -495,6 +495,10 @@ static int ext4_ioctl_setproject(structif (ext4_is_quota_file (inode))return err; + err =dquot_initialize (inode); +if (err) +return err; + err =ext4_get_inode_loc (inode, &iloc);if (err)return err;
@@ -510,10 +514,6 @@ static int ext4_ioctl_setproject(structbrelse (iloc.bh); } - err =dquot_initialize (inode); -if (err) -return err; - handle =ext4_journal_start (inode,EXT4_HT_QUOTA ,EXT4_QUOTA_INIT_BLOCKS (sb) +EXT4_QUOTA_DEL_BLOCKS (sb) +3 );
Greg Kroah-Hartman
maintainerPATCH 686/783 ext4: avoid unaccounted block allocation when expanding inode
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
commit 8994d11395f8165b3deca1971946f549f0822630 upstream.
When expanding inode space in ext4_expand_extra_isize_ea() we may need to allocate external xattr block. If quota is not initialized for the inode, the block allocation will not be accounted into quota usage. Make sure the quota is initialized before we try to expand inode space.
--- fs/ext4/inode.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ext4/inode.c +8 -0
@@ -5879,6 +5879,14 @@ static int __ext4_expand_extra_isize(strreturn 0 ; } +/* +* We may need to allocate external xattr block so we need quotas +* initialized. Here we can be called with various locks held so we +* cannot affort to initialize quotas ourselves. So just bail. +*/ +if (dquot_initialize_needed (inode)) +return -EAGAIN ; +/* try to expand with EAs present */ error =ext4_expand_extra_isize_ea (inode, new_extra_isize, raw_inode, handle);
Greg Kroah-Hartman
maintainerPATCH 687/783 ext4: allocate extended attribute value in vmalloc area
In reply to Greg Kroah-HartmanFrom: Ye Bin <[email protected]>
commit cc12a6f25e07ed05d5825a1664b67a970842b2ca upstream.
Now, extended attribute value maximum length is 64K. The memory requested here does not need continuous physical addresses, so it is appropriate to use kvmalloc to request memory. At the same time, it can also cope with the situation that the extended attribute will become longer in the future.
--- fs/ext4/xattr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ext4/xattr.c +2 -2
@@ -2551,7 +2551,7 @@ static int ext4_xattr_move_to_block(hand is =kzalloc (sizeof (struct ext4_xattr_ibody_find ),GFP_NOFS ); bs =kzalloc (sizeof (struct ext4_xattr_block_find ),GFP_NOFS ); - buffer =kmalloc (value_size,GFP_NOFS ); + buffer =kvmalloc (value_size,GFP_NOFS ); b_entry_name =kmalloc (entry->e_name_len +1 ,GFP_NOFS );if (!is || !bs || !buffer || !b_entry_name) { error = -ENOMEM ;
@@ -2603,7 +2603,7 @@ static int ext4_xattr_move_to_block(hand error =0 ; out:kfree (b_entry_name); -kfree (buffer); +kvfree (buffer);if (is)brelse (is->iloc.bh);if (bs)
Greg Kroah-Hartman
maintainerPATCH 688/783 drm/amdgpu: handle polaris10/11 overlap asics (v2)
In reply to Greg Kroah-HartmanFrom: Alex Deucher <[email protected]>
commit 1d4624cd72b912b2680c08d0be48338a1629a858 upstream.
Some special polaris 10 chips overlap with the polaris11 DID range. Handle this properly in the driver.
v2: use local flags for other function calls.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +11 -2
@@ -1121,6 +1121,15 @@ static int amdgpu_pci_probe(struct pci_d "See modparam exp_hw_support\n");return -ENODEV ; } +/* differentiate between P10 and P11 asics with the same DID */ +if (pdev->device ==0x67FF && + (pdev->revision ==0xE3 || + pdev->revision ==0xE7 || + pdev->revision ==0xF3 || + pdev->revision ==0xF7 )) { + flags &= ~AMD_ASIC_MASK ; + flags |=CHIP_POLARIS10 ; + }/* Due to hardware bugs, S/G Display on raven requires a 1:1 IOMMU mapping, * however, SME requires an indirect IOMMU mapping because the encryption
@@ -1190,12 +1199,12 @@ static int amdgpu_pci_probe(struct pci_d ddev->pdev = pdev;pci_set_drvdata (pdev, ddev); - ret =amdgpu_driver_load_kms (adev, ent->driver_data); + ret =amdgpu_driver_load_kms (adev, flags);if (ret) goto err_pci; retry_init: - ret =drm_dev_register (ddev, ent->driver_data); + ret =drm_dev_register (ddev, flags);if (ret == -EAGAIN && ++retry <=3 ) {DRM_INFO ("retry init %d\n" , retry);/* Don't request EX mode too frequently which is attacking */
Greg Kroah-Hartman
maintainerPATCH 689/783 drm/amdgpu: make display pinning more flexible (v2)
In reply to Greg Kroah-HartmanFrom: Alex Deucher <[email protected]>
commit 81d0bcf9900932633d270d5bc4a54ff599c6ebdb upstream.
Only apply the static threshold for Stoney and Carrizo. This hardware has certain requirements that don't allow mixing of GTT and VRAM. Newer asics do not have these requirements so we should be able to be more flexible with where buffers end up.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -1
@@ -1531,7 +1531,8 @@ u64 amdgpu_bo_gpu_offset_no_check(structuint32_t amdgpu_bo_get_preferred_pin_domain (struct amdgpu_device *adev,uint32_t domain) { -if (domain == (AMDGPU_GEM_DOMAIN_VRAM |AMDGPU_GEM_DOMAIN_GTT )) { +if ((domain == (AMDGPU_GEM_DOMAIN_VRAM |AMDGPU_GEM_DOMAIN_GTT )) && + ((adev->asic_type ==CHIP_CARRIZO ) || (adev->asic_type ==CHIP_STONEY ))) { domain =AMDGPU_GEM_DOMAIN_VRAM ;if (adev->gmc.real_vram_size <=AMDGPU_SG_THRESHOLD ) domain =AMDGPU_GEM_DOMAIN_GTT ;
Greg Kroah-Hartman
maintainerPATCH 690/783 ARM: renumber bits related to _TIF_WORK_MASK
In reply to Greg Kroah-HartmanFrom: Jens Axboe <[email protected]>
commit 191f8453fc99a537ea78b727acea739782378b0d upstream.
We want to ensure that the mask related to calling do_work_pending() is within the first 16 bits. Move bits unrelated to that outside of that range, to avoid spuriously calling do_work_pending() when we don't need to.
--- arch/arm/include/asm/thread_info.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
arch/arm/include/asm/thread_info.h +7 -6
@@ -133,15 +133,16 @@ extern int vfp_restore_user_hwstate(stru#define TIF_NEED_RESCHED 1/* rescheduling necessary */ #define TIF_NOTIFY_RESUME 2/* callback before returning to user */ #define TIF_UPROBE 3/* breakpointed or singlestepping */ -#define TIF_SYSCALL_TRACE 4/* syscall trace active */ -#define TIF_SYSCALL_AUDIT 5/* syscall auditing active */ -#define TIF_SYSCALL_TRACEPOINT 6/* syscall tracepoint instrumentation */ -#define TIF_SECCOMP 7/* seccomp syscall filtering active */ -#define TIF_NOTIFY_SIGNAL 8/* signal notifications exist */ +#define TIF_NOTIFY_SIGNAL 4/* signal notifications exist */ #define TIF_USING_IWMMXT 17#define TIF_MEMDIE 18/* is terminating due to OOM killer */ -#define TIF_RESTORE_SIGMASK 20 +#define TIF_RESTORE_SIGMASK 19 +#define TIF_SYSCALL_TRACE 20/* syscall trace active */ +#define TIF_SYSCALL_AUDIT 21/* syscall auditing active */ +#define TIF_SYSCALL_TRACEPOINT 22/* syscall tracepoint instrumentation */ +#define TIF_SECCOMP 23/* seccomp syscall filtering active */ +#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
Greg Kroah-Hartman
maintainerPATCH 691/783 perf/x86/intel/uncore: Generalize I/O stacks to PMON mapping procedure
In reply to Greg Kroah-HartmanFrom: Alexander Antonov <[email protected]>
[ Upstream commit f471fac77b41a2573c7b677ef790bf18a0e64195 ]
Currently I/O stacks to IIO PMON mapping is available on Skylake servers only and need to make code more general to easily enable further platforms. So, introduce get_topology() callback in struct intel_uncore_type which allows to move common code to separate function and make mapping procedure more general.
--- arch/x86/events/intel/uncore.h | 1 + arch/x86/events/intel/uncore_snbep.c | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-)
arch/x86/events/intel/uncore.h +1 -0
@@ -84,6 +84,7 @@ struct intel_uncore_type {/* * Optional callbacks for managing mapping of Uncore units to PMONs */ +int (*get_topology)(struct intel_uncore_type *type);int (*set_mapping)(struct intel_uncore_type *type);void (*cleanup_mapping)(struct intel_uncore_type *type); };
arch/x86/events/intel/uncore_snbep.c +21 -7
@@ -3643,12 +3643,19 @@ static inline u8 skx_iio_stack(struct intel_uncore_pmu *pmu, int die) }static umode_t -skx_iio_mapping_visible (struct kobject *kobj,struct attribute *attr,int die) +pmu_iio_mapping_visible (struct kobject *kobj,struct attribute *attr, +int die,int zero_bus_pmu) {struct intel_uncore_pmu *pmu =dev_to_uncore_pmu (kobj_to_dev (kobj)); -/* Root bus 0x00 is valid only for die 0 AND pmu_idx = 0. */ -return (!skx_iio_stack (pmu, die) && pmu->pmu_idx) ?0 : attr->mode; +return (!skx_iio_stack (pmu, die) && pmu->pmu_idx != zero_bus_pmu) ?0 : attr->mode; +} + +static umode_t +skx_iio_mapping_visible (struct kobject *kobj,struct attribute *attr,int die) +{ +/* Root bus 0x00 is valid only for pmu_idx = 0. */ +return pmu_iio_mapping_visible (kobj, attr, die,0 ); } static ssize_t skx_iio_mapping_show(struct device *dev,
@@ -3740,7 +3747,8 @@ static const struct attribute_group *skx_iio_attr_update[] = { NULL, }; -static int skx_iio_set_mapping (struct intel_uncore_type *type) +static int +pmu_iio_set_mapping (struct intel_uncore_type *type,struct attribute_group *ag) {char buf[64 ];int ret;
@@ -3748,8 +3756,8 @@ static int skx_iio_set_mapping(struct intel_uncore_type *type)struct attribute **attrs =NULL ;struct dev_ext_attribute *eas =NULL ; - ret =skx_iio_get_topology (type); -if (ret) + ret = type->get_topology (type); +if (ret <0 ) goto clear_attr_update; ret = -ENOMEM ;
@@ -3775,7 +3783,7 @@ static int skx_iio_set_mapping(struct intel_uncore_type *type) eas[die].var = (void *)die; attrs[die] = &eas[die].attr.attr; } - skx_iio_mapping_group.attrs = attrs; + ag->attrs = attrs;return 0 ; err:
@@ -3791,6 +3799,11 @@ static int skx_iio_set_mapping(struct intel_uncore_type *type)return ret; } +static int skx_iio_set_mapping (struct intel_uncore_type *type) +{ +return pmu_iio_set_mapping (type, &skx_iio_mapping_group); +} +static void skx_iio_cleanup_mapping (struct intel_uncore_type *type) {struct attribute **attr = skx_iio_mapping_group.attrs;
@@ -3821,6 +3834,7 @@ static struct intel_uncore_type skx_uncore_iio = { .ops = &skx_uncore_iio_ops, .format_group = &skx_uncore_iio_format_group, .attr_update = skx_iio_attr_update, + .get_topology = skx_iio_get_topology, .set_mapping = skx_iio_set_mapping, .cleanup_mapping = skx_iio_cleanup_mapping, };
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 692/783 perf/x86/intel/uncore: Clear attr_update properly
In reply to Greg Kroah-HartmanFrom: Alexander Antonov <[email protected]>
[ Upstream commit 6532783310e2b2f50dc13f46c49aa6546cb6e7a3 ]
Current clear_attr_update procedure in pmu_set_mapping() sets attr_update field in NULL that is not correct because intel_uncore_type pmu types can contain several groups in attr_update field. For example, SPR platform already has uncore_alias_group to update and then UPI topology group will be added in next patches.
Fix current behavior and clear attr_update group related to mapping only.
--- arch/x86/events/intel/uncore_snbep.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
arch/x86/events/intel/uncore_snbep.c +16 -1
@@ -3747,6 +3747,21 @@ static const struct attribute_group *skx_iio_attr_update[] = { NULL, }; +static void pmu_clear_mapping_attr (const struct attribute_group **groups, +struct attribute_group *ag) +{ +int i; + +for (i =0 ; groups[i]; i++) { +if (groups[i] == ag) { +for (i++; groups[i]; i++) + groups[i -1 ] = groups[i]; + groups[i -1 ] =NULL ; +break ; + } + } +} +static int pmu_iio_set_mapping (struct intel_uncore_type *type,struct attribute_group *ag) {
@@ -3795,7 +3810,7 @@ pmu_iio_set_mapping(struct intel_uncore_type *type, struct attribute_group *ag) clear_topology:kfree (type->topology); clear_attr_update: - type->attr_update =NULL ; +pmu_clear_mapping_attr (type->attr_update, ag);return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 693/783 btrfs: replace strncpy() with strscpy()
In reply to Greg Kroah-Hartman[ Upstream commit 63d5429f68a3d4c4aa27e65a05196c17f86c41d6 ]
Using strncpy() on NUL-terminated strings are deprecated. To avoid possible forming of non-terminated string strscpy() should be used.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- fs/btrfs/ioctl.c | 9 +++------ fs/btrfs/rcu-string.h | 6 +++++- 2 files changed, 8 insertions(+), 7 deletions(-)
fs/btrfs/ioctl.c +3 -6
@@ -3401,13 +3401,10 @@ static long btrfs_ioctl_dev_info(struct btrfs_fs_info *fs_info, di_args->bytes_used =btrfs_device_get_bytes_used (dev); di_args->total_bytes =btrfs_device_get_total_bytes (dev);memcpy (di_args->uuid, dev->uuid,sizeof (di_args->uuid)); -if (dev->name) { -strncpy (di_args->path,rcu_str_deref (dev->name), -sizeof (di_args->path) -1 ); - di_args->path[sizeof (di_args->path) -1 ] =0 ; - }else { +if (dev->name) +strscpy (di_args->path,rcu_str_deref (dev->name),sizeof (di_args->path)); +else di_args->path[0 ] ='\0' ; - } out:rcu_read_unlock ();
fs/btrfs/rcu-string.h +5 -1
@@ -18,7 +18,11 @@ static inline struct rcu_string *rcu_string_strdup(const char *src, gfp_t mask) (len * sizeof(char)), mask);if (!ret)return ret; -strncpy (ret->str, src, len); +/* Warn if the source got unexpectedly truncated. */ +if (WARN_ON (strscpy (ret->str, src, len) <0 )) { +kfree (ret); +return NULL ; + }return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 694/783 x86/mce: Get rid of msr_ops
In reply to Greg Kroah-HartmanFrom: Borislav Petkov <[email protected]>
[ Upstream commit 8121b8f947be0033f567619be204639a50cad298 ]
Avoid having indirect calls and use a normal function which returns the proper MSR address based on ->smca setting.
No functional changes.
Stable-dep-of: bc1b705b0eee ("x86/MCE/AMD: Clear DFR errors found in THR handler")
--- arch/x86/kernel/cpu/mce/amd.c | 10 ++-- arch/x86/kernel/cpu/mce/core.c | 95 ++++++++++-------------------- arch/x86/kernel/cpu/mce/internal.h | 12 ++-- 3 files changed, 42 insertions(+), 75 deletions(-)
arch/x86/kernel/cpu/mce/amd.c +5 -5
@@ -513,7 +513,7 @@ static u32 get_block_address(u32 current_addr, u32 low, u32 high,/* Fall back to method we used for older processors: */ switch (block) {case 0 : - addr = msr_ops.misc (bank); + addr =mca_msr_reg (bank,MCA_MISC );break ;case 1 : offset = ((low &MASK_BLKPTR_LO ) >>21 );
@@ -965,8 +965,8 @@ static void log_error_deferred(unsigned int bank) {bool defrd; - defrd =_log_error_bank (bank, msr_ops.status (bank), - msr_ops.addr (bank),0 ); + defrd =_log_error_bank (bank,mca_msr_reg (bank,MCA_STATUS ), +mca_msr_reg (bank,MCA_ADDR ),0 );if (!mce_flags.smca)return ;
@@ -996,7 +996,7 @@ static void amd_deferred_error_interrupt(void)static void log_error_thresholding (unsigned int bank,u64 misc) { -_log_error_bank (bank, msr_ops.status (bank), msr_ops.addr (bank), misc); +_log_error_bank (bank,mca_msr_reg (bank,MCA_STATUS ),mca_msr_reg (bank,MCA_ADDR ), misc); }static void log_and_reset_block (struct threshold_block *block)
@@ -1384,7 +1384,7 @@ static int threshold_create_bank(struct threshold_bank **bp, unsigned int cpu, } } - err =allocate_threshold_blocks (cpu, b, bank,0 , msr_ops.misc (bank)); + err =allocate_threshold_blocks (cpu, b, bank,0 ,mca_msr_reg (bank,MCA_MISC ));if (err) goto out_kobj;
arch/x86/kernel/cpu/mce/core.c +31 -64
182 lines not on this page · raw message
arch/x86/kernel/cpu/mce/internal.h +6 -6
@@ -168,14 +168,14 @@ struct mce_vendor_flags {extern struct mce_vendor_flags mce_flags; -struct mca_msr_regs { -u32 (*ctl) (int bank); -u32 (*status) (int bank); -u32 (*addr) (int bank); -u32 (*misc) (int bank); +enum mca_msr { +MCA_CTL , +MCA_STATUS , +MCA_ADDR , +MCA_MISC , }; -extern struct mca_msr_regs msr_ops; +u32 mca_msr_reg (int bank,enum mca_msr reg);/* Decide whether to add MCE record to MCE event pool or filter it out. */ extern bool filter_mce (struct mce *m);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 695/783 x86/MCE/AMD: Clear DFR errors found in THR handler
In reply to Greg Kroah-HartmanFrom: Yazen Ghannam <[email protected]>
[ Upstream commit bc1b705b0eee4c645ad8b3bbff3c8a66e9688362 ]
AMD's MCA Thresholding feature counts errors of all severity levels, not just correctable errors. If a deferred error causes the threshold limit to be reached (it was the error that caused the overflow), then both a deferred error interrupt and a thresholding interrupt will be triggered.
The order of the interrupts is not guaranteed. If the threshold interrupt handler is executed first, then it will clear MCA_STATUS for the error. It will not check or clear MCA_DESTAT which also holds a copy of the deferred error. When the deferred error interrupt handler runs it will not find an error in MCA_STATUS, but it will find the error in MCA_DESTAT. This will cause two errors to be logged.
Check for deferred errors when handling a threshold interrupt. If a bank contains a deferred error, then clear the bank's MCA_DESTAT register.
Define a new helper function to do the deferred error check and clearing of MCA_DESTAT.
[ bp: Simplify, convert comment to passive voice. ]
--- arch/x86/kernel/cpu/mce/amd.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-)
arch/x86/kernel/cpu/mce/amd.c +20 -13
@@ -952,6 +952,24 @@ _log_error_bank(unsigned int bank, u32 msr_stat, u32 msr_addr, u64 misc)return status &MCI_STATUS_DEFERRED ; } +static bool _log_error_deferred (unsigned int bank,u32 misc) +{ +if (!_log_error_bank (bank,mca_msr_reg (bank,MCA_STATUS ), +mca_msr_reg (bank,MCA_ADDR ), misc)) +return false; + +/* +* Non-SMCA systems don't have MCA_DESTAT/MCA_DEADDR registers. +* Return true here to avoid accessing these registers. +*/ +if (!mce_flags.smca) +return true; + +/* Clear MCA_DESTAT if the deferred error was logged from MCA_STATUS. */ +wrmsrl (MSR_AMD64_SMCA_MCx_DESTAT (bank),0 ); +return true; +} +/* * We have three scenarios for checking for Deferred errors: *
@@ -963,19 +981,8 @@ _log_error_bank(unsigned int bank, u32 msr_stat, u32 msr_addr, u64 misc)*/ static void log_error_deferred (unsigned int bank) { -bool defrd; - - defrd =_log_error_bank (bank,mca_msr_reg (bank,MCA_STATUS ), -mca_msr_reg (bank,MCA_ADDR ),0 ); - -if (!mce_flags.smca) -return ; - -/* Clear MCA_DESTAT if we logged the deferred error from MCA_STATUS. */ -if (defrd) { -wrmsrl (MSR_AMD64_SMCA_MCx_DESTAT (bank),0 ); +if (_log_error_deferred (bank,0 ))return ; - }/* * Only deferred errors are logged in MCA_DE{STAT,ADDR} so just check
@@ -996,7 +1003,7 @@ static void amd_deferred_error_interrupt(void)static void log_error_thresholding (unsigned int bank,u64 misc) { -_log_error_bank (bank,mca_msr_reg (bank,MCA_STATUS ),mca_msr_reg (bank,MCA_ADDR ), misc); +_log_error_deferred (bank, misc); }static void log_and_reset_block (struct threshold_block *block)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 696/783 media: s5p-mfc: Fix to handle reference queue during finishing
In reply to Greg Kroah-HartmanFrom: Smitha T Murthy <[email protected]>
[ Upstream commit d8a46bc4e1e0446459daa77c4ce14218d32dacf9 ]
On receiving last buffer driver puts MFC to MFCINST_FINISHING state which in turn skips transferring of frame from SRC to REF queue. This causes driver to stop MFC encoding and last frame is lost.
This patch guarantees safe handling of frames during MFCINST_FINISHING and correct clearing of workbit to avoid early stopping of encoding.
--- drivers/media/platform/s5p-mfc/s5p_mfc_enc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/media/platform/s5p-mfc/s5p_mfc_enc.c +10 -2
@@ -1218,6 +1218,7 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)unsigned long mb_y_addr, mb_c_addr;int slice_type;unsigned int strm_size; +bool src_ready; slice_type =s5p_mfc_hw_call (dev->mfc_ops, get_enc_slice_type, dev); strm_size =s5p_mfc_hw_call (dev->mfc_ops, get_enc_strm_size, dev);
@@ -1257,7 +1258,8 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx) } } } -if ((ctx->src_queue_cnt >0 ) && (ctx->state ==MFCINST_RUNNING )) { +if (ctx->src_queue_cnt >0 && (ctx->state ==MFCINST_RUNNING || + ctx->state ==MFCINST_FINISHING )) { mb_entry = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);if (mb_entry->flags &MFC_BUF_FLAG_USED ) {
@@ -1288,7 +1290,13 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)vb2_set_plane_payload (&mb_entry->b->vb2_buf,0 , strm_size);vb2_buffer_done (&mb_entry->b->vb2_buf,VB2_BUF_STATE_DONE ); } -if ((ctx->src_queue_cnt ==0 ) || (ctx->dst_queue_cnt ==0 )) + + src_ready = true; +if (ctx->state ==MFCINST_RUNNING && ctx->src_queue_cnt ==0 ) + src_ready = false; +if (ctx->state ==MFCINST_FINISHING && ctx->ref_queue_cnt ==0 ) + src_ready = false; +if (!src_ready || ctx->dst_queue_cnt ==0 )clear_work_bit (ctx);return 0 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 697/783 media: s5p-mfc: Clear workbit to handle error condition
In reply to Greg Kroah-HartmanFrom: Smitha T Murthy <[email protected]>
[ Upstream commit d3f3c2fe54e30b0636496d842ffbb5ad3a547f9b ]
During error on CLOSE_INSTANCE command, ctx_work_bits was not getting cleared. During consequent mfc execution NULL pointer dereferencing of this context led to kernel panic. This patch fixes this issue by making sure to clear ctx_work_bits always.
--- drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c +3 -1
@@ -468,8 +468,10 @@ void s5p_mfc_close_mfc_inst(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx)s5p_mfc_hw_call (dev->mfc_ops, try_run, dev);/* Wait until instance is returned or timeout occurred */ if (s5p_mfc_wait_for_done_ctx (ctx, -S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET ,0 )) +S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET ,0 )){ +clear_work_bit_irqsave (ctx);mfc_err ("Err returning instance\n" ); + }/* Free resources */ s5p_mfc_hw_call (dev->mfc_ops, release_codec_buffers, ctx);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 698/783 media: s5p-mfc: Fix in register read and write for H264
In reply to Greg Kroah-HartmanFrom: Smitha T Murthy <[email protected]>
[ Upstream commit 06710cd5d2436135046898d7e4b9408c8bb99446 ]
Few of the H264 encoder registers written were not getting reflected since the read values were not stored and getting overwritten.
--- drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c +7 -7
@@ -1060,7 +1060,7 @@ static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx) }/* aspect ratio VUI */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<5 ); reg |= ((p_h264->vui_sar &0x1 ) <<5 );writel (reg, mfc_regs->e_h264_options);
@@ -1083,7 +1083,7 @@ static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx)/* intra picture period for H.264 open GOP */ /* control */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<4 ); reg |= ((p_h264->open_gop &0x1 ) <<4 );writel (reg, mfc_regs->e_h264_options);
@@ -1097,23 +1097,23 @@ static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx) }/* 'WEIGHTED_BI_PREDICTION' for B is disable */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x3 <<9 );writel (reg, mfc_regs->e_h264_options);/* 'CONSTRAINED_INTRA_PRED_ENABLE' is disable */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<14 );writel (reg, mfc_regs->e_h264_options);/* ASO */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<6 ); reg |= ((p_h264->aso &0x1 ) <<6 );writel (reg, mfc_regs->e_h264_options);/* hier qp enable */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<8 ); reg |= ((p_h264->open_gop &0x1 ) <<8 );writel (reg, mfc_regs->e_h264_options);
@@ -1134,7 +1134,7 @@ static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx)writel (reg, mfc_regs->e_h264_num_t_layer);/* frame packing SEI generation */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<25 ); reg |= ((p_h264->sei_frame_packing &0x1 ) <<25 );writel (reg, mfc_regs->e_h264_options);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 699/783 perf probe: Use dwarf_attr_integrate as generic DWARF attr accessor
In reply to Greg Kroah-HartmanFrom: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit f828929ab7f0dc3353e4a617f94f297fa8f3dec3 ]
Use dwarf_attr_integrate() instead of dwarf_attr() for generic attribute acccessor functions, so that it can find the specified attribute from abstact origin DIE etc.
Stable-dep-of: a9dfc46c67b5 ("perf probe: Fix to get the DW_AT_decl_file and DW_AT_call_file as unsinged data")
--- tools/perf/util/dwarf-aux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/dwarf-aux.c +2 -2
@@ -308,7 +308,7 @@ static int die_get_attr_udata(Dwarf_Die *tp_die, unsigned int attr_name, {Dwarf_Attribute attr; -if (dwarf_attr (tp_die, attr_name, &attr) ==NULL || +if (dwarf_attr_integrate (tp_die, attr_name, &attr) ==NULL ||dwarf_formudata (&attr, result) !=0 )return -ENOENT ;
@@ -321,7 +321,7 @@ static int die_get_attr_sdata(Dwarf_Die *tp_die, unsigned int attr_name, {Dwarf_Attribute attr; -if (dwarf_attr (tp_die, attr_name, &attr) ==NULL || +if (dwarf_attr_integrate (tp_die, attr_name, &attr) ==NULL ||dwarf_formsdata (&attr, result) !=0 )return -ENOENT ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 700/783 perf probe: Fix to get the DW_AT_decl_file and DW_AT_call_file as unsinged data
In reply to Greg Kroah-HartmanFrom: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit a9dfc46c67b52ad43b8e335e28f4cf8002c67793 ]
DWARF version 5 standard Sec 2.14 says that
Any debugging information entry representing the declaration of an object, module, subprogram or type may have DW_AT_decl_file, DW_AT_decl_line and DW_AT_decl_column attributes, each of whose value is an unsigned integer constant.
So it should be an unsigned integer data. Also, even though the standard doesn't clearly say the DW_AT_call_file is signed or unsigned, the elfutils (eu-readelf) interprets it as unsigned integer data and it is natural to handle it as unsigned integer data as same as DW_AT_decl_file. This changes the DW_AT_call_file as unsigned integer data too.
--- tools/perf/util/dwarf-aux.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)
tools/perf/util/dwarf-aux.c +4 -17
@@ -315,19 +315,6 @@ static int die_get_attr_udata(Dwarf_Die *tp_die, unsigned int attr_name,return 0 ; } -/* Get attribute and translate it as a sdata */ -static int die_get_attr_sdata (Dwarf_Die *tp_die,unsigned int attr_name, -Dwarf_Sword *result) -{ -Dwarf_Attribute attr; - -if (dwarf_attr_integrate (tp_die, attr_name, &attr) ==NULL || -dwarf_formsdata (&attr, result) !=0 ) -return -ENOENT ; - -return 0 ; -} -/** * die_is_signed_type - Check whether a type DIE is signed or not * @tp_die: a DIE of a type
@@ -467,9 +454,9 @@ int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs)/* Get the call file index number in CU DIE */ static int die_get_call_fileno (Dwarf_Die *in_die) { -Dwarf_Sword idx; +Dwarf_Word idx; -if (die_get_attr_sdata (in_die, DW_AT_call_file, &idx) ==0 ) +if (die_get_attr_udata (in_die, DW_AT_call_file, &idx) ==0 )return (int )idx;else return -ENOENT ;
@@ -478,9 +465,9 @@ static int die_get_call_fileno(Dwarf_Die *in_die)/* Get the declared file index number in CU DIE */ static int die_get_decl_fileno (Dwarf_Die *pdie) { -Dwarf_Sword idx; +Dwarf_Word idx; -if (die_get_attr_sdata (pdie, DW_AT_decl_file, &idx) ==0 ) +if (die_get_attr_udata (pdie, DW_AT_decl_file, &idx) ==0 )return (int )idx;else return -ENOENT ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 701/783 x86/kprobes: Convert to insn_decode()
In reply to Greg Kroah-HartmanFrom: Borislav Petkov <[email protected]>
[ Upstream commit 77e768ec1391dc0d6cd89822aa60b9a1c1bd8128 ]
Simplify code, improve decoding error checking.
Stable-dep-of: 63dc6325ff41 ("x86/kprobes: Fix optprobe optimization check with CONFIG_RETHUNK")
--- arch/x86/kernel/kprobes/core.c | 17 +++++++++++------ arch/x86/kernel/kprobes/opt.c | 9 +++++++-- 2 files changed, 18 insertions(+), 8 deletions(-)
arch/x86/kernel/kprobes/core.c +11 -6
@@ -293,6 +293,8 @@ static int can_probe(unsigned long paddr)/* Decode instructions */ addr = paddr - offset;while (addr < paddr) { +int ret; +/* * Check if the instruction has been modified by another * kprobe, in which case we replace the breakpoint by the
@@ -304,8 +306,10 @@ static int can_probe(unsigned long paddr) __addr =recover_probed_instruction (buf, addr);if (!__addr)return 0 ; -kernel_insn_init (&insn, (void *)__addr,MAX_INSN_SIZE ); -insn_get_length (&insn); + + ret =insn_decode (&insn, (void *)__addr,MAX_INSN_SIZE ,INSN_MODE_KERN ); +if (ret <0 ) +return 0 ;#ifdef CONFIG_KGDB /*
@@ -351,8 +355,8 @@ static int is_IF_modifier(kprobe_opcode_t *insn)int __copy_instruction (u8 *dest,u8 *src,u8 *real,struct insn *insn) {kprobe_opcode_t buf[MAX_INSN_SIZE ]; -unsigned long recovered_insn = -recover_probed_instruction (buf, (unsigned long )src); +unsigned long recovered_insn =recover_probed_instruction (buf, (unsigned long )src); +int ret;if (!recovered_insn || !insn)return 0 ;
@@ -362,8 +366,9 @@ int __copy_instruction(u8 *dest, u8 *src, u8 *real, struct insn *insn) MAX_INSN_SIZE))return 0 ; -kernel_insn_init (insn, dest,MAX_INSN_SIZE ); -insn_get_length (insn); + ret =insn_decode (insn, dest,MAX_INSN_SIZE ,INSN_MODE_KERN ); +if (ret <0 ) +return 0 ;/* We can not probe force emulate prefixed instruction */ if (insn_has_emulate_prefix (insn))
arch/x86/kernel/kprobes/opt.c +7 -2
@@ -312,6 +312,8 @@ static int can_optimize(unsigned long paddr) addr = paddr - offset;while (addr < paddr - offset + size) {/* Decode until function end */ unsigned long recovered_insn; +int ret; +if (search_exception_tables (addr))/* * Since some fixup code will jumps into this function,
@@ -321,8 +323,11 @@ static int can_optimize(unsigned long paddr) recovered_insn =recover_probed_instruction (buf, addr);if (!recovered_insn)return 0 ; -kernel_insn_init (&insn, (void *)recovered_insn,MAX_INSN_SIZE ); -insn_get_length (&insn); + + ret =insn_decode (&insn, (void *)recovered_insn,MAX_INSN_SIZE ,INSN_MODE_KERN ); +if (ret <0 ) +return 0 ; +/* * In the case of detecting unknown breakpoint, this could be * a padding INT3 between functions. Let's check that all the
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 702/783 x86/kprobes: Fix optprobe optimization check with CONFIG_RETHUNK
In reply to Greg Kroah-HartmanFrom: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit 63dc6325ff41ee9e570bde705ac34a39c5dbeb44 ]
Since the CONFIG_RETHUNK and CONFIG_SLS will use INT3 for stopping speculative execution after function return, kprobe jump optimization always fails on the functions with such INT3 inside the function body. (It already checks the INT3 padding between functions, but not inside
the function)
To avoid this issue, as same as kprobes, check whether the INT3 comes from kgdb or not, and if so, stop decoding and make it fail. The other INT3 will come from CONFIG_RETHUNK/CONFIG_SLS and those can be treated as a one-byte instruction.
--- arch/x86/kernel/kprobes/opt.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-)
arch/x86/kernel/kprobes/opt.c +8 -20
@@ -15,6 +15,7 @@#include <linux/extable.h> #include <linux/kdebug.h> #include <linux/kallsyms.h> +#include <linux/kgdb.h> #include <linux/ftrace.h> #include <linux/objtool.h> #include <linux/pgtable.h>
@@ -272,19 +273,6 @@ static int insn_is_indirect_jump(struct insn *insn)return ret; } -static bool is_padding_int3 (unsigned long addr,unsigned long eaddr) -{ -unsigned char ops; - -for (; addr < eaddr; addr++) { -if (get_kernel_nofault (ops, (void *)addr) <0 || - ops !=INT3_INSN_OPCODE ) -return false; - } - -return true; -} -/* Decode whole function to ensure any instructions don't jump into target */ static int can_optimize (unsigned long paddr) {
@@ -327,15 +315,15 @@ static int can_optimize(unsigned long paddr) ret =insn_decode (&insn, (void *)recovered_insn,MAX_INSN_SIZE ,INSN_MODE_KERN );if (ret <0 )return 0 ; - +#ifdef CONFIG_KGDB /* -* In the case of detecting unknown breakpoint, this could be -* a padding INT3 between functions. Let's check that all the -* rest of the bytes are also INT3. +* If there is a dynamically installed kgdb sw breakpoint, +* this function should not be probed. */ -if (insn.opcode.bytes[0 ] ==INT3_INSN_OPCODE ) -return is_padding_int3 (addr, paddr - offset + size) ?1 :0 ; - +if (insn.opcode.bytes[0 ] ==INT3_INSN_OPCODE && +kgdb_has_hit_break (addr)) +return 0 ; +#endif /* Recover address */ insn.kaddr = (void *)addr; insn.next_byte = (void *)(addr + insn.length);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 703/783 staging: media: tegra-video: fix device_node use after free
In reply to Greg Kroah-HartmanFrom: Luca Ceresoli <[email protected]>
[ Upstream commit c4d344163c3a7f90712525f931a6c016bbb35e18 ]
At probe time this code path is followed:
* tegra_csi_init
* tegra_csi_channels_alloc
* for_each_child_of_node(node, channel) -- iterates over channels
* automatically gets 'channel'
* tegra_csi_channel_alloc()
* saves into chan->of_node a pointer to the channel OF node
* automatically gets and puts 'channel'
* now the node saved in chan->of_node has refcount 0, can disappear
* tegra_csi_channels_init
* iterates over channels
* tegra_csi_channel_init -- uses chan->of_node
After that, chan->of_node keeps storing the node until the device is removed.
of_node_get() the node and of_node_put() it during teardown to avoid any risk.
--- drivers/staging/media/tegra-video/csi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/media/tegra-video/csi.c +2 -1
@@ -420,7 +420,7 @@ static int tegra_csi_channel_alloc(struct tegra_csi *csi, chan->csi = csi; chan->csi_port_num = port_num; chan->numlanes = lanes; - chan->of_node = node; + chan->of_node =of_node_get (node); chan->numpads = num_pads;if (num_pads &0x2 ) { chan->pads[0 ].flags =MEDIA_PAD_FL_SINK ;
@@ -621,6 +621,7 @@ static void tegra_csi_channels_cleanup(struct tegra_csi *csi)media_entity_cleanup (&subdev->entity); } +of_node_put (chan->of_node);list_del (&chan->list);kfree (chan); }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 704/783 ravb: Fix "failed to switch device to config mode" message during unbind
In reply to Greg Kroah-HartmanFrom: Biju Das <[email protected]>
[ Upstream commit c72a7e42592b2e18d862cf120876070947000d7a ]
This patch fixes the error "ravb 11c20000.ethernet eth0: failed to switch device to config mode" during unbind.
We are doing register access after pm_runtime_put_sync().
We usually do cleanup in reverse order of init. Currently in remove(), the "pm_runtime_put_sync" is not in reverse order.
Probe
reset_control_deassert(rstc); pm_runtime_enable(&pdev->dev); pm_runtime_get_sync(&pdev->dev);
remove
pm_runtime_put_sync(&pdev->dev); unregister_netdev(ndev); .. ravb_mdio_release(priv); pm_runtime_disable(&pdev->dev);
Consider the call to unregister_netdev() unregister_netdev->unregister_netdevice_queue->rollback_registered_many that calls the below functions which access the registers after pm_runtime_put_sync()
1) ravb_get_stats
2) ravb_close
--- drivers/net/ethernet/renesas/ravb_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/renesas/ravb_main.c +1 -1
@@ -2253,11 +2253,11 @@ static int ravb_remove(struct platform_device *pdev) priv->desc_bat_dma);/* Set reset mode */ ravb_write (ndev,CCC_OPC_RESET ,CCC ); -pm_runtime_put_sync (&pdev->dev);unregister_netdev (ndev);netif_napi_del (&priv->napi[RAVB_NC ]);netif_napi_del (&priv->napi[RAVB_BE ]);ravb_mdio_release (priv); +pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);free_netdev (ndev);platform_set_drvdata (pdev,NULL );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 705/783 riscv/stacktrace: Fix stack output without ra on the stack top
In reply to Greg Kroah-HartmanFrom: Chen Huang <[email protected]>
[ Upstream commit f766f77a74f5784d8d4d3c36b1900731f97d08d0 ]
When a function doesn't have a callee, then it will not push ra into the stack, such as lkdtm_BUG() function,
addi sp,sp,-16
sd s0,8(sp)
addi s0,sp,16
ebreak
The struct stackframe use {fp,ra} to get information from stack, if walk_stackframe() with pr_regs, we will obtain wrong value and bad stacktrace,
[<ffffffe00066c56c>] lkdtm_BUG+0x6/0x8 ---[ end trace 18da3fbdf08e25d5 ]---
Correct the next fp and pc, after that, full stacktrace shown as expects,
[<ffffffe00066c56c>] lkdtm_BUG+0x6/0x8 [<ffffffe0008b24a4>] lkdtm_do_action+0x14/0x1c [<ffffffe00066c372>] direct_entry+0xc0/0x10a [<ffffffe000439f86>] full_proxy_write+0x42/0x6a [<ffffffe000309626>] vfs_write+0x7e/0x214 [<ffffffe00030992a>] ksys_write+0x98/0xc0 [<ffffffe000309960>] sys_write+0xe/0x16 [<ffffffe0002014bc>] ret_from_syscall+0x0/0x2 ---[ end trace 61917f3d9a9fadcd ]---
Stable-dep-of: 5c3022e4a616 ("riscv: stacktrace: Fixup ftrace_graph_ret_addr retp argument")
--- arch/riscv/kernel/stacktrace.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
arch/riscv/kernel/stacktrace.c +9 -3
@@ -57,9 +57,15 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,/* Unwind stack frame */ frame = (struct stackframe *)fp -1 ; sp = fp; - fp = frame->fp; - pc =ftrace_graph_ret_addr (current,NULL , frame->ra, - (unsigned long *)(fp -8 )); +if (regs && (regs->epc == pc) && (frame->fp &0x7 )) { + fp = frame->ra; + pc = regs->ra; + }else { + fp = frame->fp; + pc =ftrace_graph_ret_addr (current,NULL , frame->ra, + (unsigned long *)(fp -8 )); + } + } }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 706/783 riscv: stacktrace: Fixup ftrace_graph_ret_addr retp argument
In reply to Greg Kroah-HartmanFrom: Guo Ren <[email protected]>
[ Upstream commit 5c3022e4a616d800cf5f4c3a981d7992179e44a1 ]
The 'retp' is a pointer to the return address on the stack, so we must pass the current return address pointer as the 'retp' argument to ftrace_push_return_trace(). Not parent function's return address on the stack.
--- arch/riscv/kernel/stacktrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/stacktrace.c +1 -1
@@ -63,7 +63,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, }else { fp = frame->fp; pc =ftrace_graph_ret_addr (current,NULL , frame->ra, - (unsigned long *)(fp -8 )); + &frame->ra); } }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 707/783 ext4: goto right label failed_mount3a
In reply to Greg Kroah-HartmanFrom: Jason Yan <[email protected]>
[ Upstream commit 43bd6f1b49b61f43de4d4e33661b8dbe8c911f14 ]
Before these two branches neither loaded the journal nor created the xattr cache. So the right label to goto is 'failed_mount3a'. Although this did not cause any issues because the error handler validated if the pointer is null. However this still made me confused when reading the code. So it's still worth to modify to goto the right label.
Stable-dep-of: 89481b5fa8c0 ("ext4: correct inconsistent error msg in nojournal mode")
--- fs/ext4/super.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/ext4/super.c +5 -5
@@ -4809,30 +4809,30 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) ext4_has_feature_journal_needs_recovery(sb)) { ext4_msg(sb, KERN_ERR, "required journal recovery " "suppressed and not mounted read-only"); - goto failed_mount_wq; + goto failed_mount3a; } else {/* Nojournal mode, all journal mount options are illegal */ if (test_opt2 (sb,EXPLICIT_JOURNAL_CHECKSUM )) {ext4_msg (sb,KERN_ERR ,"can't mount with " "journal_checksum, fs mounted w/o journal" ); - goto failed_mount_wq; + goto failed_mount3a; }if (test_opt (sb,JOURNAL_ASYNC_COMMIT )) {ext4_msg (sb,KERN_ERR ,"can't mount with " "journal_async_commit, fs mounted w/o journal" ); - goto failed_mount_wq; + goto failed_mount3a; }if (sbi->s_commit_interval !=JBD2_DEFAULT_MAX_COMMIT_AGE *HZ ) {ext4_msg (sb,KERN_ERR ,"can't mount with " "commit=%lu, fs mounted w/o journal" , sbi->s_commit_interval /HZ ); - goto failed_mount_wq; + goto failed_mount3a; }if (EXT4_MOUNT_DATA_FLAGS & (sbi->s_mount_opt ^ sbi->s_def_mount_opt)) {ext4_msg (sb,KERN_ERR ,"can't mount with " "data=, fs mounted w/o journal" ); - goto failed_mount_wq; + goto failed_mount3a; } sbi->s_def_mount_opt &= ~EXT4_MOUNT_JOURNAL_CHECKSUM ;clear_opt (sb,JOURNAL_CHECKSUM );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 708/783 ext4: correct inconsistent error msg in nojournal mode
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
[ Upstream commit 89481b5fa8c0640e62ba84c6020cee895f7ac643 ]
When we used the journal_async_commit mounting option in nojournal mode, the kernel told me that "can't mount with journal_checksum", was very confusing. I find that when we mount with journal_async_commit, both the JOURNAL_ASYNC_COMMIT and EXPLICIT_JOURNAL_CHECKSUM flags are set. However, in the error branch, CHECKSUM is checked before ASYNC_COMMIT. As a result, the above inconsistency occurs, and the ASYNC_COMMIT branch becomes dead code that cannot be executed. Therefore, we exchange the positions of the two judgments to make the error msg more accurate.
--- fs/ext4/super.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/ext4/super.c +5 -4
@@ -4812,14 +4812,15 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) goto failed_mount3a; }else {/* Nojournal mode, all journal mount options are illegal */ -if (test_opt2 (sb,EXPLICIT_JOURNAL_CHECKSUM )) { +if (test_opt (sb,JOURNAL_ASYNC_COMMIT )) {ext4_msg (sb,KERN_ERR ,"can't mount with " -"journal_checksum, fs mounted w/o journal" ); +"journal_async_commit, fs mounted w/o journal" ); goto failed_mount3a; } -if (test_opt (sb,JOURNAL_ASYNC_COMMIT )) { + +if (test_opt2 (sb,EXPLICIT_JOURNAL_CHECKSUM )) {ext4_msg (sb,KERN_ERR ,"can't mount with " -"journal_async_commit, fs mounted w/o journal" ); +"journal_checksum, fs mounted w/o journal" ); goto failed_mount3a; }if (sbi->s_commit_interval !=JBD2_DEFAULT_MAX_COMMIT_AGE *HZ ) {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 709/783 mm/highmem: Lift memcpy_[to|from]_page to core
In reply to Greg Kroah-HartmanFrom: Ira Weiny <[email protected]>
[ Upstream commit bb90d4bc7b6a536b2e4db45f4763e467c2008251 ]
Working through a conversion to a call kmap_local_page() instead of kmap() revealed many places where the pattern kmap/memcpy/kunmap occurred.
Eric Biggers, Matthew Wilcox, Christoph Hellwig, Dan Williams, and Al Viro all suggested putting this code into helper functions. Al Viro further pointed out that these functions already existed in the iov_iter code.[1]
Various locations for the lifted functions were considered.
Headers like mm.h or string.h seem ok but don't really portray the functionality well. pagemap.h made some sense but is for page cache functionality.[2]
Another alternative would be to create a new header for the promoted memcpy functions, but it masks the fact that these are designed to copy to/from pages using the kernel direct mappings and complicates matters with a new header.
Placing these functions in 'highmem.h' is suboptimal especially with the changes being proposed in the functionality of kmap. From a caller perspective including/using 'highmem.h' implies that the functions defined in that header are only required when highmem is in use which is increasingly not the case with modern processors. However, highmem.h is where all the current functions like this reside (zero_user(), clear_highpage(), clear_user_highpage(), copy_user_highpage(), and copy_highpage()). So it makes the most sense even though it is distasteful for some.[3]
Lift memcpy_to_page() and memcpy_from_page() to pagemap.h.
[1] https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/#t
https://lore.kernel.org/lkml/[email protected]/
Stable-dep-of: 956510c0c743 ("fs: ext4: initialize fsdata in pagecache_write()")
--- include/linux/highmem.h | 18 ++++++++++++++++++ lib/iov_iter.c | 14 -------------- 2 files changed, 18 insertions(+), 14 deletions(-)
include/linux/highmem.h +18 -0
@@ -345,4 +345,22 @@ static inline void copy_highpage(struct page *to, struct page *from)#endif +static inline void memcpy_from_page (char *to,struct page *page, +size_t offset,size_t len) +{ +char *from =kmap_atomic (page); + +memcpy (to, from + offset, len); +kunmap_atomic (from); +} + +static inline void memcpy_to_page (struct page *page,size_t offset, +const char *from,size_t len) +{ +char *to =kmap_atomic (page); + +memcpy (to + offset, from, len); +kunmap_atomic (to); +} +#endif /* _LINUX_HIGHMEM_H */
lib/iov_iter.c +0 -14
@@ -467,20 +467,6 @@ void iov_iter_init(struct iov_iter *i, unsigned int direction, }EXPORT_SYMBOL (iov_iter_init); -static void memcpy_from_page (char *to,struct page *page,size_t offset,size_t len) -{ -char *from =kmap_atomic (page); -memcpy (to, from + offset, len); -kunmap_atomic (from); -} - -static void memcpy_to_page (struct page *page,size_t offset,const char *from,size_t len) -{ -char *to =kmap_atomic (page); -memcpy (to + offset, from, len); -kunmap_atomic (to); -} -static void memzero_page (struct page *page,size_t offset,size_t len) {char *addr =kmap_atomic (page);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 710/783 ext4: use memcpy_to_page() in pagecache_write()
In reply to Greg Kroah-HartmanFrom: Chaitanya Kulkarni <[email protected]>
[ Upstream commit bd256fda92efe97b692dc72e246d35fa724d42d8 ]
Stable-dep-of: 956510c0c743 ("fs: ext4: initialize fsdata in pagecache_write()")
--- fs/ext4/verity.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
fs/ext4/verity.c +1 -4
@@ -80,7 +80,6 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count, PAGE_SIZE - offset_in_page(pos));struct page *page;void *fsdata; -void *addr;int res; res = pagecache_write_begin(NULL, inode->i_mapping, pos, n, 0,
@@ -88,9 +87,7 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count,if (res)return res; - addr =kmap_atomic (page); -memcpy (addr +offset_in_page (pos), buf, n); -kunmap_atomic (addr); +memcpy_to_page (page,offset_in_page (pos), buf, n); res =pagecache_write_end (NULL , inode->i_mapping, pos, n, n, page, fsdata);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 711/783 fs: ext4: initialize fsdata in pagecache_write()
In reply to Greg Kroah-HartmanFrom: Alexander Potapenko <[email protected]>
[ Upstream commit 956510c0c7439e90b8103aaeaf4da92878c622f0 ]
When aops->write_begin() does not initialize fsdata, KMSAN reports an error passing the latter to aops->write_end().
Fix this by unconditionally initializing fsdata.
--- fs/ext4/verity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/verity.c +1 -1
@@ -79,7 +79,7 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count,size_t n =min_t (size_t, count,PAGE_SIZE -offset_in_page (pos));struct page *page; -void *fsdata; +void *fsdata =NULL ;int res; res = pagecache_write_begin(NULL, inode->i_mapping, pos, n, 0,
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 712/783 ext4: move functions in super.c
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 4067662388f97d0f360e568820d9d5bac6a3c9fa ]
Just move error info related functions in super.c close to ext4_handle_error(). We'll want to combine save_error_info() with ext4_handle_error() and this makes change more obvious and saves a forward declaration as well. No functional change.
--- fs/ext4/super.c | 196 ++++++++++++++++++++++++------------------------ 1 file changed, 98 insertions(+), 98 deletions(-)
fs/ext4/super.c +98 -98
@@ -417,104 +417,6 @@ static time64_t __ext4_get_tstamp(__le32 *lo, __u8 *hi)#define ext4_get_tstamp (es, tstamp) \ __ext4_get_tstamp(&(es)->tstamp, &(es)->tstamp ## _hi) -static void __save_error_info (struct super_block *sb,int error, -__u32 ino,__u64 block, -const char *func,unsigned int line) -{ -struct ext4_super_block *es =EXT4_SB (sb)->s_es; -int err; - -EXT4_SB (sb)->s_mount_state |=EXT4_ERROR_FS ; -if (bdev_read_only (sb->s_bdev)) -return ; - es->s_state |=cpu_to_le16 (EXT4_ERROR_FS ); -ext4_update_tstamp (es, s_last_error_time); -strncpy (es->s_last_error_func, func,sizeof (es->s_last_error_func)); - es->s_last_error_line =cpu_to_le32 (line); - es->s_last_error_ino =cpu_to_le32 (ino); - es->s_last_error_block =cpu_to_le64 (block); -switch (error) { -case EIO : - err =EXT4_ERR_EIO ; -break ; -case ENOMEM : - err =EXT4_ERR_ENOMEM ; -break ; -case EFSBADCRC : - err =EXT4_ERR_EFSBADCRC ; -break ; -case 0 : -case EFSCORRUPTED : - err =EXT4_ERR_EFSCORRUPTED ; -break ; -case ENOSPC : - err =EXT4_ERR_ENOSPC ; -break ; -case ENOKEY : - err =EXT4_ERR_ENOKEY ; -break ; -case EROFS : - err =EXT4_ERR_EROFS ; -break ; -case EFBIG : - err =EXT4_ERR_EFBIG ; -break ; -case EEXIST : - err =EXT4_ERR_EEXIST ; -break ; -case ERANGE : - err =EXT4_ERR_ERANGE ; -break ; -case EOVERFLOW : - err =EXT4_ERR_EOVERFLOW ; -break ; -case EBUSY : - err =EXT4_ERR_EBUSY ; -break ; -case ENOTDIR : - err =EXT4_ERR_ENOTDIR ; -break ; -case ENOTEMPTY : - err =EXT4_ERR_ENOTEMPTY ; -break ; -case ESHUTDOWN : - err =EXT4_ERR_ESHUTDOWN ; -break ; -case EFAULT : - err =EXT4_ERR_EFAULT ; -break ; -default : - err =EXT4_ERR_UNKNOWN ; - } - es->s_last_error_errcode = err; -if (!es->s_first_error_time) { - es->s_first_error_time = es->s_last_error_time; - es->s_first_error_time_hi = es->s_last_error_time_hi; -strncpy (es->s_first_error_func, func, -sizeof (es->s_first_error_func)); - es->s_first_error_line =cpu_to_le32 (line); - es->s_first_error_ino = es->s_last_error_ino; - es->s_first_error_block = es->s_last_error_block; - es->s_first_error_errcode = es->s_last_error_errcode; - } -/* -* Start the daily error reporting function if it hasn't been -* started already -*/ -if (!es->s_error_count) -mod_timer (&EXT4_SB (sb)->s_err_report, jiffies +24 *60 *60 *HZ ); -le32_add_cpu (&es->s_error_count,1 ); -} - -static void save_error_info (struct super_block *sb,int error, -__u32 ino,__u64 block, -const char *func,unsigned int line) -{ -__save_error_info (sb, error, ino, block, func, line); -if (!bdev_read_only (sb->s_bdev)) -ext4_commit_super (sb,1 ); -} -/* * The del_gendisk() function uninitializes the disk-specific data * structures, including the bdi structure, without telling anyone
@@ -643,6 +545,104 @@ static bool system_going_down(void) || system_state == SYSTEM_RESTART; } +static void __save_error_info (struct super_block *sb,int error, +__u32 ino,__u64 block, +const char *func,unsigned int line) +{ +struct ext4_super_block *es =EXT4_SB (sb)->s_es; +int err; + +EXT4_SB (sb)->s_mount_state |=EXT4_ERROR_FS ; +if (bdev_read_only (sb->s_bdev)) +return ; + es->s_state |=cpu_to_le16 (EXT4_ERROR_FS ); +ext4_update_tstamp (es, s_last_error_time); +strncpy (es->s_last_error_func, func,sizeof (es->s_last_error_func)); + es->s_last_error_line =cpu_to_le32 (line); + es->s_last_error_ino =cpu_to_le32 (ino); + es->s_last_error_block =cpu_to_le64 (block); +switch (error) { +case EIO : + err =EXT4_ERR_EIO ; +break ; +case ENOMEM : + err =EXT4_ERR_ENOMEM ; +break ; +case EFSBADCRC : + err =EXT4_ERR_EFSBADCRC ; +break ; +case 0 : +case EFSCORRUPTED : + err =EXT4_ERR_EFSCORRUPTED ; +break ; +case ENOSPC : + err =EXT4_ERR_ENOSPC ; +break ; +case ENOKEY : + err =EXT4_ERR_ENOKEY ; +break ; +case EROFS : + err =EXT4_ERR_EROFS ; +break ; +case EFBIG : + err =EXT4_ERR_EFBIG ; +break ; +case EEXIST : + err =EXT4_ERR_EEXIST ; +break ; +case ERANGE : + err =EXT4_ERR_ERANGE ; +break ; +case EOVERFLOW : + err =EXT4_ERR_EOVERFLOW ; +break ; +case EBUSY : + err =EXT4_ERR_EBUSY ; +break ; +case ENOTDIR : + err =EXT4_ERR_ENOTDIR ; +break ; +case ENOTEMPTY : + err =EXT4_ERR_ENOTEMPTY ; +break ; +case ESHUTDOWN : + err =EXT4_ERR_ESHUTDOWN ; +break ; +case EFAULT : + err =EXT4_ERR_EFAULT ; +break ; +default : + err =EXT4_ERR_UNKNOWN ; + } + es->s_last_error_errcode = err; +if (!es->s_first_error_time) { + es->s_first_error_time = es->s_last_error_time; + es->s_first_error_time_hi = es->s_last_error_time_hi; +strncpy (es->s_first_error_func, func, +sizeof (es->s_first_error_func)); + es->s_first_error_line =cpu_to_le32 (line); + es->s_first_error_ino = es->s_last_error_ino; + es->s_first_error_block = es->s_last_error_block; + es->s_first_error_errcode = es->s_last_error_errcode; + } +/* +* Start the daily error reporting function if it hasn't been +* started already +*/ +if (!es->s_error_count) +mod_timer (&EXT4_SB (sb)->s_err_report, jiffies +24 *60 *60 *HZ ); +le32_add_cpu (&es->s_error_count,1 ); +} + +static void save_error_info (struct super_block *sb,int error, +__u32 ino,__u64 block, +const char *func,unsigned int line) +{ +__save_error_info (sb, error, ino, block, func, line); +if (!bdev_read_only (sb->s_bdev)) +ext4_commit_super (sb,1 ); +} +/* Deal with the reporting of failure conditions on a filesystem such as * inconsistencies detected or read IO failures. *
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 713/783 ext4: simplify ext4 error translation
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 02a7780e4d2fcf438ac6773bc469e7ada2af56be ]
We convert errno's to ext4 on-disk format error codes in save_error_info(). Add a function and a bit of macro magic to make this simpler.
--- fs/ext4/super.c | 95 +++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 55 deletions(-)
fs/ext4/super.c +40 -55
@@ -545,76 +545,61 @@ static bool system_going_down(void) || system_state == SYSTEM_RESTART; } +struct ext4_err_translation { +int code; +int errno; +}; + +#define EXT4_ERR_TRANSLATE (err) { .code = EXT4_ERR_##err, .errno = err } + +static struct ext4_err_translation err_translation[] = { +EXT4_ERR_TRANSLATE (EIO ), +EXT4_ERR_TRANSLATE (ENOMEM ), +EXT4_ERR_TRANSLATE (EFSBADCRC ), +EXT4_ERR_TRANSLATE (EFSCORRUPTED ), +EXT4_ERR_TRANSLATE (ENOSPC ), +EXT4_ERR_TRANSLATE (ENOKEY ), +EXT4_ERR_TRANSLATE (EROFS ), +EXT4_ERR_TRANSLATE (EFBIG ), +EXT4_ERR_TRANSLATE (EEXIST ), +EXT4_ERR_TRANSLATE (ERANGE ), +EXT4_ERR_TRANSLATE (EOVERFLOW ), +EXT4_ERR_TRANSLATE (EBUSY ), +EXT4_ERR_TRANSLATE (ENOTDIR ), +EXT4_ERR_TRANSLATE (ENOTEMPTY ), +EXT4_ERR_TRANSLATE (ESHUTDOWN ), +EXT4_ERR_TRANSLATE (EFAULT ), +}; + +static int ext4_errno_to_code (int errno) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (err_translation); i++) +if (err_translation[i].errno == errno) +return err_translation[i].code; +return EXT4_ERR_UNKNOWN ; +} +static void __save_error_info (struct super_block *sb,int error,__u32 ino,__u64 block,const char *func,unsigned int line) {struct ext4_super_block *es =EXT4_SB (sb)->s_es; -int err;EXT4_SB (sb)->s_mount_state |=EXT4_ERROR_FS ;if (bdev_read_only (sb->s_bdev))return ; +/* We default to EFSCORRUPTED error... */ +if (error ==0 ) + error =EFSCORRUPTED ; es->s_state |=cpu_to_le16 (EXT4_ERROR_FS );ext4_update_tstamp (es, s_last_error_time);strncpy (es->s_last_error_func, func,sizeof (es->s_last_error_func)); es->s_last_error_line =cpu_to_le32 (line); es->s_last_error_ino =cpu_to_le32 (ino); es->s_last_error_block =cpu_to_le64 (block); -switch (error) { -case EIO : - err =EXT4_ERR_EIO ; -break ; -case ENOMEM : - err =EXT4_ERR_ENOMEM ; -break ; -case EFSBADCRC : - err =EXT4_ERR_EFSBADCRC ; -break ; -case 0 : -case EFSCORRUPTED : - err =EXT4_ERR_EFSCORRUPTED ; -break ; -case ENOSPC : - err =EXT4_ERR_ENOSPC ; -break ; -case ENOKEY : - err =EXT4_ERR_ENOKEY ; -break ; -case EROFS : - err =EXT4_ERR_EROFS ; -break ; -case EFBIG : - err =EXT4_ERR_EFBIG ; -break ; -case EEXIST : - err =EXT4_ERR_EEXIST ; -break ; -case ERANGE : - err =EXT4_ERR_ERANGE ; -break ; -case EOVERFLOW : - err =EXT4_ERR_EOVERFLOW ; -break ; -case EBUSY : - err =EXT4_ERR_EBUSY ; -break ; -case ENOTDIR : - err =EXT4_ERR_ENOTDIR ; -break ; -case ENOTEMPTY : - err =EXT4_ERR_ENOTEMPTY ; -break ; -case ESHUTDOWN : - err =EXT4_ERR_ESHUTDOWN ; -break ; -case EFAULT : - err =EXT4_ERR_EFAULT ; -break ; -default : - err =EXT4_ERR_UNKNOWN ; - } - es->s_last_error_errcode = err; + es->s_last_error_errcode =ext4_errno_to_code (error);if (!es->s_first_error_time) { es->s_first_error_time = es->s_last_error_time; es->s_first_error_time_hi = es->s_last_error_time_hi;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 714/783 ext4: fix various seppling typos
In reply to Greg Kroah-HartmanFrom: Bhaskar Chowdhury <[email protected]>
[ Upstream commit 3088e5a5153cda27ec26461e5edf2821e15e802c ]
--- fs/ext4/fast_commit.c | 2 +- fs/ext4/indirect.c | 2 +- fs/ext4/inline.c | 2 +- fs/ext4/inode.c | 2 +- fs/ext4/mballoc.h | 2 +- fs/ext4/migrate.c | 6 +++--- fs/ext4/namei.c | 2 +- fs/ext4/xattr.c | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-)
fs/ext4/fast_commit.c +1 -1
@@ -66,7 +66,7 @@* Fast Commit Ineligibility * ------------------------- * Not all operations are supported by fast commits today (e.g extended -* attributes). Fast commit ineligiblity is marked by calling one of the +* attributes). Fast commit ineligibility is marked by calling one of the * two following functions: * * - ext4_fc_mark_ineligible(): This makes next fast commit operation to fall
fs/ext4/indirect.c +1 -1
@@ -712,7 +712,7 @@ static int ext4_ind_trunc_restart_fn(handle_t *handle, struct inode *inode,/* * Truncate transactions can be complex and absolutely huge. So we need to -* be able to restart the transaction at a conventient checkpoint to make +* be able to restart the transaction at a convenient checkpoint to make * sure we don't overflow the journal. * * Try to extend this transaction for the purposes of truncation. If
fs/ext4/inline.c +1 -1
@@ -799,7 +799,7 @@ ext4_journalled_write_inline_data(struct inode *inode,* clear the inode state safely. * 2. The inode has inline data, then we need to read the data, make it * update and dirty so that ext4_da_writepages can handle it. We don't -* need to start the journal since the file's metatdata isn't changed now. +* need to start the journal since the file's metadata isn't changed now. */ static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping, struct inode *inode,
fs/ext4/inode.c +1 -1
@@ -3885,7 +3885,7 @@ static int __ext4_block_zero_page_range(handle_t *handle,* starting from file offset 'from'. The range to be zero'd must * be contained with in one block. If the specified range exceeds * the end of the block it will be shortened to end of the block -* that cooresponds to 'from' +* that corresponds to 'from' */ static int ext4_block_zero_page_range (handle_t *handle,struct address_space *mapping,loff_t from,loff_t length)
fs/ext4/mballoc.h +1 -1
@@ -59,7 +59,7 @@* by the stream allocator, which purpose is to pack requests * as close each to other as possible to produce smooth I/O traffic * We use locality group prealloc space for stream request. -* We can tune the same via /proc/fs/ext4/<parition>/stream_req +* We can tune the same via /proc/fs/ext4/<partition>/stream_req */ #define MB_DEFAULT_STREAM_THRESHOLD 16/* 64K */
fs/ext4/migrate.c +3 -3
@@ -32,7 +32,7 @@ static int finish_range(handle_t *handle, struct inode *inode, newext.ee_block =cpu_to_le32 (lb->first_block); newext.ee_len =cpu_to_le16 (lb->last_block - lb->first_block +1 );ext4_ext_store_pblock (&newext, lb->first_pblock); -/* Locking only for convinience since we are operating on temp inode */ +/* Locking only for convenience since we are operating on temp inode */ down_write (&EXT4_I (inode)->i_data_sem); path =ext4_find_extent (inode, lb->first_block,NULL ,0 );if (IS_ERR (path)) {
@@ -43,8 +43,8 @@ static int finish_range(handle_t *handle, struct inode *inode,/* * Calculate the credit needed to inserting this extent -* Since we are doing this in loop we may accumalate extra -* credit. But below we try to not accumalate too much +* Since we are doing this in loop we may accumulate extra +* credit. But below we try to not accumulate too much * of them by restarting the journal. */ needed = ext4_ext_calc_credits_for_single_extent(inode,
fs/ext4/namei.c +1 -1
@@ -995,7 +995,7 @@ static int ext4_htree_next_block(struct inode *dir, __u32 hash,* If the hash is 1, then continue only if the next page has a * continuation hash of any value. This is used for readdir * handling. Otherwise, check to see if the hash matches the -* desired contiuation hash. If it doesn't, return since +* desired continuation hash. If it doesn't, return since * there's no point to read in the successive index pages. */ bhash =dx_get_hash (p->at);
fs/ext4/xattr.c +1 -1
@@ -1617,7 +1617,7 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,* If storing the value in an external inode is an option, * reserve space for xattr entries/names in the external * attribute block so that a long value does not occupy the -* whole space and prevent futher entries being added. +* whole space and prevent further entries being added. */ if (ext4_has_feature_ea_inode(inode->i_sb) && new_size && is_block &&
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 715/783 ext4: fix leaking uninitialized memory in fast-commit journal
In reply to Greg Kroah-HartmanFrom: Eric Biggers <[email protected]>
[ Upstream commit 594bc43b410316d70bb42aeff168837888d96810 ]
When space at the end of fast-commit journal blocks is unused, make sure to zero it out so that uninitialized memory is not leaked to disk.
--- fs/ext4/fast_commit.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/ext4/fast_commit.c +5 -0
@@ -628,6 +628,9 @@ static u8 *ext4_fc_reserve_space(struct super_block *sb, int len, u32 *crc) *crc =ext4_chksum (sbi, *crc, tl,sizeof (*tl));if (pad_len >0 )ext4_fc_memzero (sb, tl +1 , pad_len, crc); +/* Don't leak uninitialized memory in the unused last byte. */ + *((u8 *)(tl +1 ) + pad_len) =0 ; +ext4_fc_submit_bh (sb); ret =jbd2_fc_get_buf (EXT4_SB (sb)->s_journal, &bh);
@@ -684,6 +687,8 @@ static int ext4_fc_write_tail(struct super_block *sb, u32 crc) dst +=sizeof (tail.fc_tid); tail.fc_crc =cpu_to_le32 (crc);ext4_fc_memcpy (sb, dst, &tail.fc_crc,sizeof (tail.fc_crc),NULL ); + dst +=sizeof (tail.fc_crc); +memset (dst,0 , bsize - off);/* Don't leak uninitialized memory. */ ext4_fc_submit_bh (sb);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 716/783 ext4: use kmemdup() to replace kmalloc + memcpy
In reply to Greg Kroah-HartmanFrom: Shuqi Zhang <[email protected]>
[ Upstream commit 4efd9f0d120c55b08852ee5605dbb02a77089a5d ]
Replace kmalloc + memcpy with kmemdup()
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/ext4/xattr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ext4/xattr.c +1 -2
@@ -1890,11 +1890,10 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,unlock_buffer (bs->bh);ea_bdebug (bs->bh,"cloning" ); - s->base =kmalloc (bs->bh->b_size,GFP_NOFS ); + s->base =kmemdup (BHDR (bs->bh), bs->bh->b_size,GFP_NOFS ); error = -ENOMEM ;if (s->base ==NULL ) goto cleanup; -memcpy (s->base,BHDR (bs->bh), bs->bh->b_size); s->first =ENTRY (header (s->base)+1 );header (s->base)->h_refcount =cpu_to_le32 (1 ); s->here =ENTRY (s->base + offset);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 717/783 mbcache: dont reclaim used entries
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 58318914186c157477b978b1739dfe2f1b9dc0fe ]
Do not reclaim entries that are currently used by somebody from a shrinker. Firstly, these entries are likely useful. Secondly, we will need to keep such entries to protect pending increment of xattr block refcount.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/mbcache.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/mbcache.c +9 -1
@@ -288,7 +288,7 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache,while (nr_to_scan-- && !list_empty (&cache->c_list)) { entry =list_first_entry (&cache->c_list, struct mb_cache_entry, e_list); -if (entry->e_referenced) { +if (entry->e_referenced ||atomic_read (&entry->e_refcnt) >2 ) { entry->e_referenced =0 ;list_move_tail (&entry->e_list, &cache->c_list);continue ;
@@ -302,6 +302,14 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache,spin_unlock (&cache->c_list_lock); head =mb_cache_entry_head (cache, entry->e_key);hlist_bl_lock (head); +/* Now a reliable check if the entry didn't get used... */ +if (atomic_read (&entry->e_refcnt) >2 ) { +hlist_bl_unlock (head); +spin_lock (&cache->c_list_lock); +list_add_tail (&entry->e_list, &cache->c_list); + cache->c_entry_count++; +continue ; + }if (!hlist_bl_unhashed (&entry->e_hash_list)) {hlist_bl_del_init (&entry->e_hash_list);atomic_dec (&entry->e_refcnt);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 718/783 mbcache: add functions to delete entry if unused
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 3dc96bba65f53daa217f0a8f43edad145286a8f5 ]
Add function mb_cache_entry_delete_or_get() to delete mbcache entry if it is unused and also add a function to wait for entry to become unused
- mb_cache_entry_wait_unused(). We do not share code between the two deleting function as one of them will go away soon.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/mbcache.c | 66 +++++++++++++++++++++++++++++++++++++++-- include/linux/mbcache.h | 10 ++++++- 2 files changed, 73 insertions(+), 3 deletions(-)
fs/mbcache.c +64 -2
@@ -11,7 +11,7 @@/* * Mbcache is a simple key-value store. Keys need not be unique, however * key-value pairs are expected to be unique (we use this fact in -* mb_cache_entry_delete()). +* mb_cache_entry_delete_or_get()). * * Ext2 and ext4 use this cache for deduplication of extended attribute blocks. * Ext4 also uses it for deduplication of xattr values stored in inodes.
@@ -125,6 +125,19 @@ void __mb_cache_entry_free(struct mb_cache_entry *entry) }EXPORT_SYMBOL (__mb_cache_entry_free); +/* +* mb_cache_entry_wait_unused - wait to be the last user of the entry +* +* @entry - entry to work on +* +* Wait to be the last user of the entry. +*/ +void mb_cache_entry_wait_unused (struct mb_cache_entry *entry) +{ +wait_var_event (&entry->e_refcnt,atomic_read (&entry->e_refcnt) <=3 ); +} +EXPORT_SYMBOL (mb_cache_entry_wait_unused); +static struct mb_cache_entry *__entry_find (struct mb_cache *cache,struct mb_cache_entry *entry,u32 key)
@@ -217,7 +230,7 @@ struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key, }EXPORT_SYMBOL (mb_cache_entry_get); -/* mb_cache_entry_delete - remove a cache entry +/* mb_cache_entry_delete - try to remove a cache entry * @cache - cache we work with * @key - key * @value - value
@@ -254,6 +267,55 @@ void mb_cache_entry_delete(struct mb_cache *cache, u32 key, u64 value) }EXPORT_SYMBOL (mb_cache_entry_delete); +/* mb_cache_entry_delete_or_get - remove a cache entry if it has no users +* @cache - cache we work with +* @key - key +* @value - value +* +* Remove entry from cache @cache with key @key and value @value. The removal +* happens only if the entry is unused. The function returns NULL in case the +* entry was successfully removed or there's no entry in cache. Otherwise the +* function grabs reference of the entry that we failed to delete because it +* still has users and return it. +*/ +struct mb_cache_entry *mb_cache_entry_delete_or_get (struct mb_cache *cache, +u32 key,u64 value) +{ +struct hlist_bl_node *node; +struct hlist_bl_head *head; +struct mb_cache_entry *entry; + + head =mb_cache_entry_head (cache, key); +hlist_bl_lock (head); +hlist_bl_for_each_entry (entry, node, head, e_hash_list) { +if (entry->e_key == key && entry->e_value == value) { +if (atomic_read (&entry->e_refcnt) >2 ) { +atomic_inc (&entry->e_refcnt); +hlist_bl_unlock (head); +return entry; + } +/* We keep hash list reference to keep entry alive */ +hlist_bl_del_init (&entry->e_hash_list); +hlist_bl_unlock (head); +spin_lock (&cache->c_list_lock); +if (!list_empty (&entry->e_list)) { +list_del_init (&entry->e_list); +if (!WARN_ONCE (cache->c_entry_count ==0 , +"mbcache: attempt to decrement c_entry_count past zero" )) + cache->c_entry_count--; +atomic_dec (&entry->e_refcnt); + } +spin_unlock (&cache->c_list_lock); +mb_cache_entry_put (cache, entry); +return NULL ; + } + } +hlist_bl_unlock (head); + +return NULL ; +} +EXPORT_SYMBOL (mb_cache_entry_delete_or_get); +/* mb_cache_entry_touch - cache entry got used * @cache - cache the entry belongs to * @entry - entry that got used
include/linux/mbcache.h +9 -1
@@ -30,15 +30,23 @@ void mb_cache_destroy(struct mb_cache *cache);int mb_cache_entry_create (struct mb_cache *cache,gfp_t mask,u32 key,u64 value,bool reusable);void __mb_cache_entry_free (struct mb_cache_entry *entry); +void mb_cache_entry_wait_unused (struct mb_cache_entry *entry);static inline int mb_cache_entry_put (struct mb_cache *cache,struct mb_cache_entry *entry) { -if (!atomic_dec_and_test (&entry->e_refcnt)) +unsigned int cnt =atomic_dec_return (&entry->e_refcnt); + +if (cnt >0 ) { +if (cnt <=3 ) +wake_up_var (&entry->e_refcnt);return 0 ; + }__mb_cache_entry_free (entry);return 1 ; } +struct mb_cache_entry *mb_cache_entry_delete_or_get (struct mb_cache *cache, +u32 key,u64 value);void mb_cache_entry_delete (struct mb_cache *cache,u32 key,u64 value);struct mb_cache_entry *mb_cache_entry_get (struct mb_cache *cache,u32 key,u64 value);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 719/783 ext4: remove EA inode entry from mbcache on inode eviction
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 6bc0d63dad7f9f54d381925ee855b402f652fa39 ]
Currently we remove EA inode from mbcache as soon as its xattr refcount drops to zero. However there can be pending attempts to reuse the inode and thus refcount handling code has to handle the situation when refcount increases from zero anyway. So save some work and just keep EA inode in mbcache until it is getting evicted. At that moment we are sure following iget() of EA inode will fail anyway (or wait for eviction to finish and load things from the disk again) and so removing mbcache entry at that moment is fine and simplifies the code a bit.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/ext4/inode.c | 2 ++ fs/ext4/xattr.c | 24 ++++++++---------------- fs/ext4/xattr.h | 1 + 3 files changed, 11 insertions(+), 16 deletions(-)
fs/ext4/inode.c +2 -0
@@ -179,6 +179,8 @@ void ext4_evict_inode(struct inode *inode)trace_ext4_evict_inode (inode); +if (EXT4_I (inode)->i_flags &EXT4_EA_INODE_FL ) +ext4_evict_ea_inode (inode);if (inode->i_nlink) {/* * When journalling data dirty buffers are tracked only in the
fs/ext4/xattr.c +8 -16
@@ -436,6 +436,14 @@ static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino,return err; } +/* Remove entry from mbcache when EA inode is getting evicted */ +void ext4_evict_ea_inode (struct inode *inode) +{ +if (EA_INODE_CACHE (inode)) +mb_cache_entry_delete (EA_INODE_CACHE (inode), +ext4_xattr_inode_get_hash (inode), inode->i_ino); +} + static int ext4_xattr_inode_verify_hashes(struct inode *ea_inode, struct ext4_xattr_entry *entry, void *buffer,
@@ -972,10 +980,8 @@ int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode,static int ext4_xattr_inode_update_ref (handle_t *handle,struct inode *ea_inode,int ref_change) { -struct mb_cache *ea_inode_cache =EA_INODE_CACHE (ea_inode);struct ext4_iloc iloc;s64 ref_count; -u32 hash;int ret;inode_lock (ea_inode);
@@ -998,14 +1004,6 @@ static int ext4_xattr_inode_update_ref(handle_t *handle, struct inode *ea_inode,set_nlink (ea_inode,1 );ext4_orphan_del (handle, ea_inode); - -if (ea_inode_cache) { - hash =ext4_xattr_inode_get_hash (ea_inode); -mb_cache_entry_create (ea_inode_cache, -GFP_NOFS , hash, - ea_inode->i_ino, - true/* reusable */ ); - } } }else { WARN_ONCE(ref_count < 0, "EA inode %lu ref_count=%lld",
@@ -1018,12 +1016,6 @@ static int ext4_xattr_inode_update_ref(handle_t *handle, struct inode *ea_inode,clear_nlink (ea_inode);ext4_orphan_add (handle, ea_inode); - -if (ea_inode_cache) { - hash =ext4_xattr_inode_get_hash (ea_inode); -mb_cache_entry_delete (ea_inode_cache, hash, - ea_inode->i_ino); - } } }
fs/ext4/xattr.h +1 -0
@@ -191,6 +191,7 @@ extern void ext4_xattr_inode_array_free(struct ext4_xattr_inode_array *array);extern int ext4_expand_extra_isize_ea (struct inode *inode,int new_extra_isize,struct ext4_inode *raw_inode,handle_t *handle); +extern void ext4_evict_ea_inode (struct inode *inode);extern const struct xattr_handler *ext4_xattr_handlers[];
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 720/783 ext4: unindent codeblock in ext4_xattr_block_set()
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit fd48e9acdf26d0cbd80051de07d4a735d05d29b2 ]
Remove unnecessary else (and thus indentation level) from a code block in ext4_xattr_block_set(). It will also make following code changes easier. No functional changes.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/ext4/xattr.c | 77 ++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 39 deletions(-)
fs/ext4/xattr.c +38 -39
@@ -1846,6 +1846,8 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,#define header (x) ((struct ext4_xattr_header *)(x))if (s->base) { +int offset = (char *)s->here - bs->bh->b_data; +BUFFER_TRACE (bs->bh,"get_write_access" ); error =ext4_journal_get_write_access (handle, bs->bh);if (error)
@@ -1877,49 +1879,46 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,if (error) goto cleanup; goto inserted; - }else { -int offset = (char *)s->here - bs->bh->b_data; + } +unlock_buffer (bs->bh); +ea_bdebug (bs->bh,"cloning" ); + s->base =kmemdup (BHDR (bs->bh), bs->bh->b_size,GFP_NOFS ); + error = -ENOMEM ; +if (s->base ==NULL ) + goto cleanup; + s->first =ENTRY (header (s->base)+1 ); +header (s->base)->h_refcount =cpu_to_le32 (1 ); + s->here =ENTRY (s->base + offset); + s->end = s->base + bs->bh->b_size; -unlock_buffer (bs->bh); -ea_bdebug (bs->bh,"cloning" ); - s->base =kmemdup (BHDR (bs->bh), bs->bh->b_size,GFP_NOFS ); - error = -ENOMEM ; -if (s->base ==NULL ) +/* +* If existing entry points to an xattr inode, we need +* to prevent ext4_xattr_set_entry() from decrementing +* ref count on it because the reference belongs to the +* original block. In this case, make the entry look +* like it has an empty value. +*/ +if (!s->not_found && s->here->e_value_inum) { + ea_ino =le32_to_cpu (s->here->e_value_inum); + error =ext4_xattr_inode_iget (inode, ea_ino, +le32_to_cpu (s->here->e_hash), + &tmp_inode); +if (error) goto cleanup; - s->first =ENTRY (header (s->base)+1 ); -header (s->base)->h_refcount =cpu_to_le32 (1 ); - s->here =ENTRY (s->base + offset); - s->end = s->base + bs->bh->b_size; -/* -* If existing entry points to an xattr inode, we need -* to prevent ext4_xattr_set_entry() from decrementing -* ref count on it because the reference belongs to the -* original block. In this case, make the entry look -* like it has an empty value. -*/ -if (!s->not_found && s->here->e_value_inum) { - ea_ino =le32_to_cpu (s->here->e_value_inum); - error =ext4_xattr_inode_iget (inode, ea_ino, -le32_to_cpu (s->here->e_hash), - &tmp_inode); -if (error) - goto cleanup; - -if (!ext4_test_inode_state (tmp_inode, -EXT4_STATE_LUSTRE_EA_INODE )) { -/* -* Defer quota free call for previous -* inode until success is guaranteed. -*/ - old_ea_inode_quota =le32_to_cpu ( - s->here->e_value_size); - } -iput (tmp_inode); - - s->here->e_value_inum =0 ; - s->here->e_value_size =0 ; +if (!ext4_test_inode_state (tmp_inode, +EXT4_STATE_LUSTRE_EA_INODE )) { +/* +* Defer quota free call for previous +* inode until success is guaranteed. +*/ + old_ea_inode_quota =le32_to_cpu ( + s->here->e_value_size); } +iput (tmp_inode); + + s->here->e_value_inum =0 ; + s->here->e_value_size =0 ; } }else {/* Allocate a buffer where we construct the new block. */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 721/783 ext4: fix race when reusing xattr blocks
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 65f8b80053a1b2fd602daa6814e62d6fa90e5e9b ]
When ext4_xattr_block_set() decides to remove xattr block the following race can happen:
CPU1 CPU2ext4_xattr_block_set() ext4_xattr_release_block()
new_bh = ext4_xattr_block_cache_find()
lock_buffer(bh);
ref = le32_to_cpu(BHDR(bh)->h_refcount);
if (ref == 1) {
...
mb_cache_entry_delete();
unlock_buffer(bh);
ext4_free_blocks();
...
ext4_forget(..., bh, ...);
jbd2_journal_revoke(..., bh); ext4_journal_get_write_access(..., new_bh, ...)
do_get_write_access()
jbd2_journal_cancel_revoke(..., new_bh);Later the code in ext4_xattr_block_set() finds out the block got freed and cancels reusal of the block but the revoke stays canceled and so in case of block reuse and journal replay the filesystem can get corrupted. If the race works out slightly differently, we can also hit assertions in the jbd2 code.
Fix the problem by making sure that once matching mbcache entry is found, code dropping the last xattr block reference (or trying to modify xattr block in place) waits until the mbcache entry reference is dropped. This way code trying to reuse xattr block is protected from someone trying to drop the last reference to xattr block.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/ext4/xattr.c | 67 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 22 deletions(-)
fs/ext4/xattr.c +45 -22
@@ -439,9 +439,16 @@ static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino,/* Remove entry from mbcache when EA inode is getting evicted */ void ext4_evict_ea_inode (struct inode *inode) { -if (EA_INODE_CACHE (inode)) -mb_cache_entry_delete (EA_INODE_CACHE (inode), -ext4_xattr_inode_get_hash (inode), inode->i_ino); +struct mb_cache_entry *oe; + +if (!EA_INODE_CACHE (inode)) +return ; +/* Wait for entry to get unused so that we can remove it */ +while ((oe =mb_cache_entry_delete_or_get (EA_INODE_CACHE (inode), +ext4_xattr_inode_get_hash (inode), inode->i_ino))) { +mb_cache_entry_wait_unused (oe); +mb_cache_entry_put (EA_INODE_CACHE (inode), oe); + } } static int
@@ -1223,6 +1230,7 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,if (error) goto out; +retry_ref:lock_buffer (bh); hash =le32_to_cpu (BHDR (bh)->h_hash); ref =le32_to_cpu (BHDR (bh)->h_refcount);
@@ -1232,9 +1240,18 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,* This must happen under buffer lock for * ext4_xattr_block_set() to reliably detect freed block */ -if (ea_block_cache) -mb_cache_entry_delete (ea_block_cache, hash, - bh->b_blocknr); +if (ea_block_cache) { +struct mb_cache_entry *oe; + + oe =mb_cache_entry_delete_or_get (ea_block_cache, hash, + bh->b_blocknr); +if (oe) { +unlock_buffer (bh); +mb_cache_entry_wait_unused (oe); +mb_cache_entry_put (ea_block_cache, oe); + goto retry_ref; + } + }get_bh (bh);unlock_buffer (bh);
@@ -1862,9 +1879,20 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,* ext4_xattr_block_set() to reliably detect modified * block */ -if (ea_block_cache) -mb_cache_entry_delete (ea_block_cache, hash, - bs->bh->b_blocknr); +if (ea_block_cache) { +struct mb_cache_entry *oe; + + oe =mb_cache_entry_delete_or_get (ea_block_cache, + hash, bs->bh->b_blocknr); +if (oe) { +/* +* Xattr block is getting reused. Leave +* it alone. +*/ +mb_cache_entry_put (ea_block_cache, oe); + goto clone_block; + } + }ea_bdebug (bs->bh,"modifying in-place" ); error =ext4_xattr_set_entry (i, s, handle, inode, true/* is_block */ );
@@ -1880,6 +1908,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, goto cleanup; goto inserted; } +clone_block:unlock_buffer (bs->bh);ea_bdebug (bs->bh,"cloning" ); s->base =kmemdup (BHDR (bs->bh), bs->bh->b_size,GFP_NOFS );
@@ -1985,18 +2014,13 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,lock_buffer (new_bh);/* * We have to be careful about races with -* freeing, rehashing or adding references to -* xattr block. Once we hold buffer lock xattr -* block's state is stable so we can check -* whether the block got freed / rehashed or -* not. Since we unhash mbcache entry under -* buffer lock when freeing / rehashing xattr -* block, checking whether entry is still -* hashed is reliable. Same rules hold for -* e_reusable handling. +* adding references to xattr block. Once we +* hold buffer lock xattr block's state is +* stable so we can check the additional +* reference fits. */ -if (hlist_bl_unhashed (&ce->e_hash_list) || - !ce->e_reusable) { + ref =le32_to_cpu (BHDR (new_bh)->h_refcount) +1 ; +if (ref >EXT4_XATTR_REFCOUNT_MAX ) {/* * Undo everything and check mbcache * again.
@@ -2011,9 +2035,8 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, new_bh =NULL ; goto inserted; } - ref =le32_to_cpu (BHDR (new_bh)->h_refcount) +1 ;BHDR (new_bh)->h_refcount =cpu_to_le32 (ref); -if (ref >=EXT4_XATTR_REFCOUNT_MAX ) +if (ref ==EXT4_XATTR_REFCOUNT_MAX ) ce->e_reusable =0 ;ea_bdebug (new_bh,"reusing; refcount now=%d" , ref);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 722/783 mbcache: automatically delete entries from cache on freeing
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 307af6c879377c1c63e71cbdd978201f9c7ee8df ]
Use the fact that entries with elevated refcount are not removed from the hash and just move removal of the entry from the hash to the entry freeing time. When doing this we also change the generic code to hold one reference to the cache entry, not two of them, which makes code somewhat more obvious.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/mbcache.c | 108 +++++++++++++++------------------------- include/linux/mbcache.h | 24 ++++++--- 2 files changed, 55 insertions(+), 77 deletions(-)
fs/mbcache.c +39 -69
@@ -90,7 +90,7 @@ int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key,return -ENOMEM ;INIT_LIST_HEAD (&entry->e_list); -/* One ref for hash, one ref returned */ +/* Initial hash reference */ atomic_set (&entry->e_refcnt,1 ); entry->e_key = key; entry->e_value = value;
@@ -106,21 +106,28 @@ int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key, } }hlist_bl_add_head (&entry->e_hash_list, head); -hlist_bl_unlock (head); - +/* +* Add entry to LRU list before it can be found by +* mb_cache_entry_delete() to avoid races +*/ spin_lock (&cache->c_list_lock);list_add_tail (&entry->e_list, &cache->c_list); -/* Grab ref for LRU list */ -atomic_inc (&entry->e_refcnt); cache->c_entry_count++;spin_unlock (&cache->c_list_lock); +hlist_bl_unlock (head);return 0 ; }EXPORT_SYMBOL (mb_cache_entry_create); -void __mb_cache_entry_free (struct mb_cache_entry *entry) +void __mb_cache_entry_free (struct mb_cache *cache,struct mb_cache_entry *entry) { +struct hlist_bl_head *head; + + head =mb_cache_entry_head (cache, entry->e_key); +hlist_bl_lock (head); +hlist_bl_del (&entry->e_hash_list); +hlist_bl_unlock (head);kmem_cache_free (mb_entry_cache, entry); }EXPORT_SYMBOL (__mb_cache_entry_free);
@@ -134,7 +141,7 @@ EXPORT_SYMBOL(__mb_cache_entry_free);*/ void mb_cache_entry_wait_unused (struct mb_cache_entry *entry) { -wait_var_event (&entry->e_refcnt,atomic_read (&entry->e_refcnt) <=3 ); +wait_var_event (&entry->e_refcnt,atomic_read (&entry->e_refcnt) <=2 ); }EXPORT_SYMBOL (mb_cache_entry_wait_unused);
@@ -155,10 +162,9 @@ static struct mb_cache_entry *__entry_find(struct mb_cache *cache,while (node) { entry = hlist_bl_entry(node, struct mb_cache_entry, e_hash_list); -if (entry->e_key == key && entry->e_reusable) { -atomic_inc (&entry->e_refcnt); +if (entry->e_key == key && entry->e_reusable && +atomic_inc_not_zero (&entry->e_refcnt)) goto out; - } node = node->next; } entry =NULL ;
@@ -218,10 +224,9 @@ struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key, head =mb_cache_entry_head (cache, key);hlist_bl_lock (head);hlist_bl_for_each_entry (entry, node, head, e_hash_list) { -if (entry->e_key == key && entry->e_value == value) { -atomic_inc (&entry->e_refcnt); +if (entry->e_key == key && entry->e_value == value && +atomic_inc_not_zero (&entry->e_refcnt)) goto out; - } } entry =NULL ; out:
@@ -281,37 +286,25 @@ EXPORT_SYMBOL(mb_cache_entry_delete);struct mb_cache_entry *mb_cache_entry_delete_or_get (struct mb_cache *cache,u32 key,u64 value) { -struct hlist_bl_node *node; -struct hlist_bl_head *head;struct mb_cache_entry *entry; - head =mb_cache_entry_head (cache, key); -hlist_bl_lock (head); -hlist_bl_for_each_entry (entry, node, head, e_hash_list) { -if (entry->e_key == key && entry->e_value == value) { -if (atomic_read (&entry->e_refcnt) >2 ) { -atomic_inc (&entry->e_refcnt); -hlist_bl_unlock (head); -return entry; - } -/* We keep hash list reference to keep entry alive */ -hlist_bl_del_init (&entry->e_hash_list); -hlist_bl_unlock (head); -spin_lock (&cache->c_list_lock); -if (!list_empty (&entry->e_list)) { -list_del_init (&entry->e_list); -if (!WARN_ONCE (cache->c_entry_count ==0 , -"mbcache: attempt to decrement c_entry_count past zero" )) - cache->c_entry_count--; -atomic_dec (&entry->e_refcnt); - } -spin_unlock (&cache->c_list_lock); -mb_cache_entry_put (cache, entry); -return NULL ; - } - } -hlist_bl_unlock (head); + entry =mb_cache_entry_get (cache, key, value); +if (!entry) +return NULL ; +/* +* Drop the ref we got from mb_cache_entry_get() and the initial hash +* ref if we are the last user +*/ +if (atomic_cmpxchg (&entry->e_refcnt,2 ,0 ) !=2 ) +return entry; + +spin_lock (&cache->c_list_lock); +if (!list_empty (&entry->e_list)) +list_del_init (&entry->e_list); + cache->c_entry_count--; +spin_unlock (&cache->c_list_lock); +__mb_cache_entry_free (cache, entry);return NULL ; }EXPORT_SYMBOL (mb_cache_entry_delete_or_get);
@@ -343,42 +336,24 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache, unsigned long nr_to_scan) {struct mb_cache_entry *entry; -struct hlist_bl_head *head;unsigned long shrunk =0 ;spin_lock (&cache->c_list_lock);while (nr_to_scan-- && !list_empty (&cache->c_list)) { entry =list_first_entry (&cache->c_list, struct mb_cache_entry, e_list); -if (entry->e_referenced ||atomic_read (&entry->e_refcnt) >2 ) { +/* Drop initial hash reference if there is no user */ +if (entry->e_referenced || +atomic_cmpxchg (&entry->e_refcnt,1 ,0 ) !=1 ) { entry->e_referenced =0 ;list_move_tail (&entry->e_list, &cache->c_list);continue ; }list_del_init (&entry->e_list); cache->c_entry_count--; -/* -* We keep LRU list reference so that entry doesn't go away -* from under us. -*/ spin_unlock (&cache->c_list_lock); - head =mb_cache_entry_head (cache, entry->e_key); -hlist_bl_lock (head); -/* Now a reliable check if the entry didn't get used... */ -if (atomic_read (&entry->e_refcnt) >2 ) { -hlist_bl_unlock (head); -spin_lock (&cache->c_list_lock); -list_add_tail (&entry->e_list, &cache->c_list); - cache->c_entry_count++; -continue ; - } -if (!hlist_bl_unhashed (&entry->e_hash_list)) { -hlist_bl_del_init (&entry->e_hash_list); -atomic_dec (&entry->e_refcnt); - } -hlist_bl_unlock (head); -if (mb_cache_entry_put (cache, entry)) - shrunk++; +__mb_cache_entry_free (cache, entry); + shrunk++;cond_resched ();spin_lock (&cache->c_list_lock); }
@@ -470,11 +445,6 @@ void mb_cache_destroy(struct mb_cache *cache)* point. */ list_for_each_entry_safe (entry, next, &cache->c_list, e_list) { -if (!hlist_bl_unhashed (&entry->e_hash_list)) { -hlist_bl_del_init (&entry->e_hash_list); -atomic_dec (&entry->e_refcnt); - }else -WARN_ON (1 );list_del (&entry->e_list);WARN_ON (atomic_read (&entry->e_refcnt) !=1 );mb_cache_entry_put (cache, entry);
include/linux/mbcache.h +16 -8
@@ -13,8 +13,16 @@ struct mb_cache;struct mb_cache_entry {/* List of entries in cache - protected by cache->c_list_lock */ struct list_head e_list; -/* Hash table list - protected by hash chain bitlock */ +/* +* Hash table list - protected by hash chain bitlock. The entry is +* guaranteed to be hashed while e_refcnt > 0. +*/ struct hlist_bl_node e_hash_list; +/* +* Entry refcount. Once it reaches zero, entry is unhashed and freed. +* While refcount > 0, the entry is guaranteed to stay in the hash and +* e.g. mb_cache_entry_try_delete() will fail. +*/ atomic_t e_refcnt;/* Key in hash - stable during lifetime of the entry */ u32 e_key;
@@ -29,20 +37,20 @@ void mb_cache_destroy(struct mb_cache *cache);int mb_cache_entry_create (struct mb_cache *cache,gfp_t mask,u32 key,u64 value,bool reusable); -void __mb_cache_entry_free (struct mb_cache_entry *entry); +void __mb_cache_entry_free (struct mb_cache *cache, +struct mb_cache_entry *entry);void mb_cache_entry_wait_unused (struct mb_cache_entry *entry); -static inline int mb_cache_entry_put (struct mb_cache *cache, -struct mb_cache_entry *entry) +static inline void mb_cache_entry_put (struct mb_cache *cache, +struct mb_cache_entry *entry) {unsigned int cnt =atomic_dec_return (&entry->e_refcnt);if (cnt >0 ) { -if (cnt <=3 ) +if (cnt <=2 )wake_up_var (&entry->e_refcnt); -return 0 ; +return ; } -__mb_cache_entry_free (entry); -return 1 ; +__mb_cache_entry_free (cache, entry); } struct mb_cache_entry *mb_cache_entry_delete_or_get(struct mb_cache *cache,
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 723/783 ext4: fix deadlock due to mbcache entry corruption
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit a44e84a9b7764c72896f7241a0ec9ac7e7ef38dd ]
When manipulating xattr blocks, we can deadlock infinitely looping inside ext4_xattr_block_set() where we constantly keep finding xattr block for reuse in mbcache but we are unable to reuse it because its reference count is too big. This happens because cache entry for the xattr block is marked as reusable (e_reusable set) although its reference count is too big. When this inconsistency happens, this inconsistent state is kept indefinitely and so ext4_xattr_block_set() keeps retrying indefinitely.
The inconsistent state is caused by non-atomic update of e_reusable bit. e_reusable is part of a bitfield and e_reusable update can race with update of e_referenced bit in the same bitfield resulting in loss of one of the updates. Fix the problem by using atomic bitops instead.
This bug has been around for many years, but it became *much* easier to hit after commit 65f8b80053a1 ("ext4: fix race when reusing xattr blocks").
--- fs/ext4/xattr.c | 4 ++-- fs/mbcache.c | 14 ++++++++------ include/linux/mbcache.h | 9 +++++++-- 3 files changed, 17 insertions(+), 10 deletions(-)
fs/ext4/xattr.c +2 -2
@@ -1275,7 +1275,7 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode, ce =mb_cache_entry_get (ea_block_cache, hash, bh->b_blocknr);if (ce) { - ce->e_reusable =1 ; +set_bit (MBE_REUSABLE_B , &ce->e_flags);mb_cache_entry_put (ea_block_cache, ce); } }
@@ -2037,7 +2037,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, }BHDR (new_bh)->h_refcount =cpu_to_le32 (ref);if (ref ==EXT4_XATTR_REFCOUNT_MAX ) - ce->e_reusable =0 ; +clear_bit (MBE_REUSABLE_B , &ce->e_flags);ea_bdebug (new_bh,"reusing; refcount now=%d" , ref);ext4_xattr_block_csum_set (inode, new_bh);
fs/mbcache.c +8 -6
@@ -94,8 +94,9 @@ int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key,atomic_set (&entry->e_refcnt,1 ); entry->e_key = key; entry->e_value = value; - entry->e_reusable = reusable; - entry->e_referenced =0 ; + entry->e_flags =0 ; +if (reusable) +set_bit (MBE_REUSABLE_B , &entry->e_flags); head =mb_cache_entry_head (cache, key);hlist_bl_lock (head);hlist_bl_for_each_entry (dup, dup_node, head, e_hash_list) {
@@ -162,7 +163,8 @@ static struct mb_cache_entry *__entry_find(struct mb_cache *cache,while (node) { entry = hlist_bl_entry(node, struct mb_cache_entry, e_hash_list); -if (entry->e_key == key && entry->e_reusable && +if (entry->e_key == key && +test_bit (MBE_REUSABLE_B , &entry->e_flags) &&atomic_inc_not_zero (&entry->e_refcnt)) goto out; node = node->next;
@@ -318,7 +320,7 @@ EXPORT_SYMBOL(mb_cache_entry_delete_or_get);void mb_cache_entry_touch (struct mb_cache *cache,struct mb_cache_entry *entry) { - entry->e_referenced =1 ; +set_bit (MBE_REFERENCED_B , &entry->e_flags); }EXPORT_SYMBOL (mb_cache_entry_touch);
@@ -343,9 +345,9 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache, entry =list_first_entry (&cache->c_list, struct mb_cache_entry, e_list);/* Drop initial hash reference if there is no user */ -if (entry->e_referenced || +if (test_bit (MBE_REFERENCED_B , &entry->e_flags) ||atomic_cmpxchg (&entry->e_refcnt,1 ,0 ) !=1 ) { - entry->e_referenced =0 ; +clear_bit (MBE_REFERENCED_B , &entry->e_flags);list_move_tail (&entry->e_list, &cache->c_list);continue ; }
include/linux/mbcache.h +7 -2
@@ -10,6 +10,12 @@struct mb_cache ; +/* Cache entry flags */ +enum { +MBE_REFERENCED_B =0 , +MBE_REUSABLE_B +}; +struct mb_cache_entry {/* List of entries in cache - protected by cache->c_list_lock */ struct list_head e_list;
@@ -26,8 +32,7 @@ struct mb_cache_entry {atomic_t e_refcnt;/* Key in hash - stable during lifetime of the entry */ u32 e_key; - u32 e_referenced:1; - u32 e_reusable:1; +unsigned long e_flags;/* User provided value - stable during lifetime of the entry */ u64 e_value; };
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 724/783 SUNRPC: ensure the matching upcall is in-flight upon downcall
In reply to Greg Kroah-HartmanFrom: minoura makoto <[email protected]>
[ Upstream commit b18cba09e374637a0a3759d856a6bca94c133952 ]
Commit 9130b8dbc6ac ("SUNRPC: allow for upcalls for the same uid but different gss service") introduced auth argument to __gss_find_upcall(), but in gss_pipe_downcall() it was left as NULL since it (and auth->service) was not (yet) determined.
When multiple upcalls with the same uid and different service are ongoing, it could happen that __gss_find_upcall(), which returns the first match found in the pipe->in_downcall list, could not find the correct gss_msg corresponding to the downcall we are looking for. Moreover, it might return a msg which is not sent to rpc.gssd yet.
We could see mount.nfs process hung in D state with multiple mount.nfs are executed in parallel. The call trace below is of CentOS 7.9 kernel-3.10.0-1160.24.1.el7.x86_64 but we observed the same hang w/ elrepo kernel-ml-6.0.7-1.el7.
PID: 71258 TASK: ffff91ebd4be0000 CPU: 36 COMMAND: "mount.nfs"
#0 [ffff9203ca3234f8] __schedule at ffffffffa3b8899f
#1 [ffff9203ca323580] schedule at ffffffffa3b88eb9
#2 [ffff9203ca323590] gss_cred_init at ffffffffc0355818 [auth_rpcgss] #3 [ffff9203ca323658] rpcauth_lookup_credcache at ffffffffc0421ebc
[sunrpc]
#4 [ffff9203ca3236d8] gss_lookup_cred at ffffffffc0353633 [auth_rpcgss] #5 [ffff9203ca3236e8] rpcauth_lookupcred at ffffffffc0421581 [sunrpc] #6 [ffff9203ca323740] rpcauth_refreshcred at ffffffffc04223d3 [sunrpc] #7 [ffff9203ca3237a0] call_refresh at ffffffffc04103dc [sunrpc] #8 [ffff9203ca3237b8] __rpc_execute at ffffffffc041e1c9 [sunrpc] #9 [ffff9203ca323820] rpc_execute at ffffffffc0420a48 [sunrpc]
The scenario is like this. Let's say there are two upcalls for services A and B, A -> B in pipe->in_downcall, B -> A in pipe->pipe.
When rpc.gssd reads pipe to get the upcall msg corresponding to service B from pipe->pipe and then writes the response, in gss_pipe_downcall the msg corresponding to service A will be picked because only uid is used to find the msg and it is before the one for B in pipe->in_downcall. And the process waiting for the msg corresponding to service A will be woken up.
Actual scheduing of that process might be after rpc.gssd processes the next msg. In rpc_pipe_generic_upcall it clears msg->errno (for A). The process is scheduled to see gss_msg->ctx == NULL and gss_msg->msg.errno == 0, therefore it cannot break the loop in gss_create_upcall and is never woken up after that.
This patch adds a simple check to ensure that a msg which is not sent to rpc.gssd yet is not chosen as the matching upcall upon receiving a downcall.
--- include/linux/sunrpc/rpc_pipe_fs.h | 5 +++++ net/sunrpc/auth_gss/auth_gss.c | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-)
include/linux/sunrpc/rpc_pipe_fs.h +5 -0
@@ -92,6 +92,11 @@ extern ssize_t rpc_pipe_generic_upcall(struct file *, struct rpc_pipe_msg *, char __user *, size_t);extern int rpc_queue_upcall (struct rpc_pipe *,struct rpc_pipe_msg *); +/* returns true if the msg is in-flight, i.e., already eaten by the peer */ +static inline bool rpc_msg_is_inflight (const struct rpc_pipe_msg *msg) { +return (msg->copied !=0 &&list_empty (&msg->list)); +} +struct rpc_clnt ;extern struct dentry *rpc_create_client_dir (struct dentry *,const char *,struct rpc_clnt *);extern int rpc_remove_client_dir (struct rpc_clnt *);
net/sunrpc/auth_gss/auth_gss.c +17 -2
@@ -301,7 +301,7 @@ __gss_find_upcall(struct rpc_pipe *pipe, kuid_t uid, const struct gss_auth *authlist_for_each_entry (pos, &pipe->in_downcall, list) {if (!uid_eq (pos->uid, uid))continue ; -if (auth && pos->auth->service != auth->service) +if (pos->auth->service != auth->service)continue ;refcount_inc (&pos->count);return pos;
@@ -685,6 +685,21 @@ gss_create_upcall(struct gss_auth *gss_auth, struct gss_cred *gss_cred)return err; } +static struct gss_upcall_msg * +gss_find_downcall (struct rpc_pipe *pipe,kuid_t uid) +{ +struct gss_upcall_msg *pos; +list_for_each_entry (pos, &pipe->in_downcall, list) { +if (!uid_eq (pos->uid, uid)) +continue ; +if (!rpc_msg_is_inflight (&pos->msg)) +continue ; +refcount_inc (&pos->count); +return pos; + } +return NULL ; +} +#define MSG_BUF_MAXSIZE 1024 static ssize_t
@@ -731,7 +746,7 @@ gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen) err = -ENOENT ;/* Find a matching upcall */ spin_lock (&pipe->lock); - gss_msg =__gss_find_upcall (pipe, uid,NULL ); + gss_msg =gss_find_downcall (pipe, uid);if (gss_msg ==NULL ) {spin_unlock (&pipe->lock); goto err_put_ctx;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 725/783 bpf: pull before calling skb_postpull_rcsum()
In reply to Greg Kroah-HartmanFrom: Jakub Kicinski <[email protected]>
[ Upstream commit 54c3f1a81421f85e60ae2eaae7be3727a09916ee ]
Anand hit a BUG() when pulling off headers on egress to a SW tunnel. We get to skb_checksum_help() with an invalid checksum offset (commit d7ea0d9df2a6 ("net: remove two BUG() from skb_checksum_help()") converted those BUGs to WARN_ONs()).
He points out oddness in how skb_postpull_rcsum() gets used. Indeed looks like we should pull before "postpull", otherwise the CHECKSUM_PARTIAL fixup from skb_postpull_rcsum() will not be able to do its job:
if (skb->ip_summed == CHECKSUM_PARTIAL && skb_checksum_start_offset(skb) < 0) skb->ip_summed = CHECKSUM_NONE;
--- net/core/filter.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/core/filter.c +5 -2
@@ -3201,15 +3201,18 @@ static int bpf_skb_generic_push(struct sk_buff *skb, u32 off, u32 len)static int bpf_skb_generic_pop (struct sk_buff *skb,u32 off,u32 len) { +void *old_data; +/* skb_ensure_writable() is not needed here, as we're * already working on an uncloned skb. */ if (unlikely (!pskb_may_pull (skb, off + len)))return -ENOMEM ; -skb_postpull_rcsum (skb, skb->data + off, len); -memmove (skb->data + len, skb->data, off); + old_data = skb->data;__skb_pull (skb, len); +skb_postpull_rcsum (skb, old_data + off, len); +memmove (skb->data, old_data, off);return 0 ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 726/783 drm/panfrost: Fix GEM handle creation ref-counting
In reply to Greg Kroah-HartmanFrom: Steven Price <[email protected]>
[ Upstream commit 4217c6ac817451d5116687f3cc6286220dc43d49 ]
panfrost_gem_create_with_handle() previously returned a BO but with the only reference being from the handle, which user space could in theory guess and release, causing a use-after-free. Additionally if the call to panfrost_gem_mapping_get() in panfrost_ioctl_create_bo() failed then a(nother) reference on the BO was dropped.
The _create_with_handle() is a problematic pattern, so ditch it and instead create the handle in panfrost_ioctl_create_bo(). If the call to panfrost_gem_mapping_get() fails then this means that user space has indeed gone behind our back and freed the handle. In which case just return an error code.
--- drivers/gpu/drm/panfrost/panfrost_drv.c | 27 ++++++++++++++++--------- drivers/gpu/drm/panfrost/panfrost_gem.c | 16 +-------------- drivers/gpu/drm/panfrost/panfrost_gem.h | 5 +---- 3 files changed, 20 insertions(+), 28 deletions(-)
drivers/gpu/drm/panfrost/panfrost_drv.c +18 -9
@@ -81,6 +81,7 @@ static int panfrost_ioctl_create_bo(struct drm_device *dev, void *data,struct panfrost_gem_object *bo;struct drm_panfrost_create_bo *args = data;struct panfrost_gem_mapping *mapping; +int ret;if (!args->size || args->pad || (args->flags & ~(PANFROST_BO_NOEXEC |PANFROST_BO_HEAP )))
@@ -91,21 +92,29 @@ static int panfrost_ioctl_create_bo(struct drm_device *dev, void *data, !(args->flags & PANFROST_BO_NOEXEC))return -EINVAL ; - bo =panfrost_gem_create_with_handle (file, dev, args->size, args->flags, - &args->handle); + bo =panfrost_gem_create (dev, args->size, args->flags);if (IS_ERR (bo))return PTR_ERR (bo); + ret =drm_gem_handle_create (file, &bo->base.base, &args->handle); +if (ret) + goto out; + mapping =panfrost_gem_mapping_get (bo, priv); -if (!mapping) { -drm_gem_object_put (&bo->base.base); -return -EINVAL ; +if (mapping) { + args->offset = mapping->mmnode.start <<PAGE_SHIFT ; +panfrost_gem_mapping_put (mapping); + }else { +/* This can only happen if the handle from +* drm_gem_handle_create() has already been guessed and freed +* by user space +*/ + ret = -EINVAL ; } - args->offset = mapping->mmnode.start <<PAGE_SHIFT ; -panfrost_gem_mapping_put (mapping); - -return 0 ; +out: +drm_gem_object_put (&bo->base.base); +return ret; }/**
drivers/gpu/drm/panfrost/panfrost_gem.c +1 -15
@@ -232,12 +232,8 @@ struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t }struct panfrost_gem_object * -panfrost_gem_create_with_handle (struct drm_file *file_priv, -struct drm_device *dev,size_t size, -u32 flags, -uint32_t *handle) +panfrost_gem_create (struct drm_device *dev,size_t size,u32 flags) { -int ret;struct drm_gem_shmem_object *shmem;struct panfrost_gem_object *bo;
@@ -253,16 +249,6 @@ panfrost_gem_create_with_handle(struct drm_file *file_priv, bo->noexec = !!(flags &PANFROST_BO_NOEXEC ); bo->is_heap = !!(flags &PANFROST_BO_HEAP ); -/* -* Allocate an id of idr table where the obj is registered -* and handle has the id what user can see. -*/ - ret =drm_gem_handle_create (file_priv, &shmem->base, handle); -/* drop reference from allocate - handle holds it now. */ -drm_gem_object_put (&shmem->base); -if (ret) -return ERR_PTR (ret); -return bo; }
drivers/gpu/drm/panfrost/panfrost_gem.h +1 -4
@@ -69,10 +69,7 @@ panfrost_gem_prime_import_sg_table(struct drm_device *dev, struct sg_table *sgt);struct panfrost_gem_object * -panfrost_gem_create_with_handle (struct drm_file *file_priv, -struct drm_device *dev,size_t size, -u32 flags, -uint32_t *handle); +panfrost_gem_create (struct drm_device *dev,size_t size,u32 flags);int panfrost_gem_open (struct drm_gem_object *obj,struct drm_file *file_priv); void panfrost_gem_close(struct drm_gem_object *obj,
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 727/783 vmxnet3: correctly report csum_level for encapsulated packet
In reply to Greg Kroah-HartmanFrom: Ronak Doshi <[email protected]>
[ Upstream commit 3d8f2c4269d08f8793e946279dbdf5e972cc4911 ]
Commit dacce2be3312 ("vmxnet3: add geneve and vxlan tunnel offload support") added support for encapsulation offload. However, the pathc did not report correctly the csum_level for encapsulated packet.
This patch fixes this issue by reporting correct csum level for the encapsulated packet.
--- drivers/net/vmxnet3/vmxnet3_drv.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/vmxnet3/vmxnet3_drv.c +8 -0
@@ -1236,6 +1236,10 @@ vmxnet3_rx_csum(struct vmxnet3_adapter *adapter, (le32_to_cpu(gdesc->dword[3]) & VMXNET3_RCD_CSUM_OK) == VMXNET3_RCD_CSUM_OK) { skb->ip_summed =CHECKSUM_UNNECESSARY ; +if ((le32_to_cpu (gdesc->dword[0 ]) & + (1UL <<VMXNET3_RCD_HDR_INNER_SHIFT ))) { + skb->csum_level =1 ; + }WARN_ON_ONCE (!(gdesc->rcd.tcp || gdesc->rcd.udp) && !(le32_to_cpu (gdesc->dword[0 ]) & (1UL <<VMXNET3_RCD_HDR_INNER_SHIFT )));
@@ -1245,6 +1249,10 @@ vmxnet3_rx_csum(struct vmxnet3_adapter *adapter, }else if (gdesc->rcd.v6 && (le32_to_cpu (gdesc->dword[3 ]) & (1 <<VMXNET3_RCD_TUC_SHIFT ))) { skb->ip_summed =CHECKSUM_UNNECESSARY ; +if ((le32_to_cpu (gdesc->dword[0 ]) & + (1UL <<VMXNET3_RCD_HDR_INNER_SHIFT ))) { + skb->csum_level =1 ; + }WARN_ON_ONCE (!(gdesc->rcd.tcp || gdesc->rcd.udp) && !(le32_to_cpu (gdesc->dword[0 ]) & (1UL <<VMXNET3_RCD_HDR_INNER_SHIFT )));
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 728/783 veth: Fix race with AF_XDP exposing old or uninitialized descriptors
In reply to Greg Kroah-HartmanFrom: Shawn Bohrer <[email protected]>
[ Upstream commit fa349e396e4886d742fd6501c599ec627ef1353b ]
When AF_XDP is used on on a veth interface the RX ring is updated in two steps. veth_xdp_rcv() removes packet descriptors from the FILL ring fills them and places them in the RX ring updating the cached_prod pointer. Later xdp_do_flush() syncs the RX ring prod pointer with the cached_prod pointer allowing user-space to see the recently filled in descriptors. The rings are intended to be SPSC, however the existing order in veth_poll allows the xdp_do_flush() to run concurrently with another CPU creating a race condition that allows user-space to see old or uninitialized descriptors in the RX ring. This bug has been observed in production systems.
To summarize, we are expecting this ordering:
CPU 0 __xsk_rcv_zc()
CPU 0 __xsk_map_flush()
CPU 2 __xsk_rcv_zc()
CPU 2 __xsk_map_flush()
But we are seeing this order:
CPU 0 __xsk_rcv_zc()
CPU 2 __xsk_rcv_zc()
CPU 0 __xsk_map_flush()
CPU 2 __xsk_map_flush()
This occurs because we rely on NAPI to ensure that only one napi_poll handler is running at a time for the given veth receive queue. napi_schedule_prep() will prevent multiple instances from getting scheduled. However calling napi_complete_done() signals that this napi_poll is complete and allows subsequent calls to napi_schedule_prep() and __napi_schedule() to succeed in scheduling a concurrent napi_poll before the xdp_do_flush() has been called. For the veth driver a concurrent call to napi_schedule_prep() and __napi_schedule() can occur on a different CPU because the veth xmit path can additionally schedule a napi_poll creating the race.
The fix as suggested by Magnus Karlsson, is to simply move the xdp_do_flush() call before napi_complete_done(). This syncs the producer ring pointers before another instance of napi_poll can be scheduled on another CPU. It will also slightly improve performance by moving the flush closer to when the descriptors were placed in the RX ring.
--- drivers/net/veth.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/veth.c +3 -2
@@ -849,6 +849,9 @@ static int veth_poll(struct napi_struct *napi, int budget)xdp_set_return_frame_no_direct (); done =veth_xdp_rcv (rq, budget, &bq, &stats); +if (stats.xdp_redirect >0 ) +xdp_do_flush (); +if (done < budget &&napi_complete_done (napi, done)) {/* Write rx_notify_masked before reading ptr_ring */ smp_store_mb (rq->rx_notify_masked, false);
@@ -862,8 +865,6 @@ static int veth_poll(struct napi_struct *napi, int budget)if (stats.xdp_tx >0 )veth_xdp_flush (rq, &bq); -if (stats.xdp_redirect >0 ) -xdp_do_flush ();xdp_clear_return_frame_no_direct ();return done;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 729/783 nfsd: shut down the NFSv4 state objects before the filecache
In reply to Greg Kroah-HartmanFrom: Jeff Layton <[email protected]>
[ Upstream commit 789e1e10f214c00ca18fc6610824c5b9876ba5f2 ]
Currently, we shut down the filecache before trying to clean up the stateids that depend on it. This leads to the kernel trying to free an nfsd_file twice, and a refcount overput on the nf_mark.
Change the shutdown procedure to tear down all of the stateids prior to shutting down the filecache.
--- fs/nfsd/nfssvc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfssvc.c +1 -1
@@ -426,8 +426,8 @@ static void nfsd_shutdown_net(struct net *net) {struct nfsd_net *nn =net_generic (net, nfsd_net_id); -nfsd_file_cache_shutdown_net (net);nfs4_state_shutdown_net (net); +nfsd_file_cache_shutdown_net (net);if (nn->lockd_up) {lockd_down (net); nn->lockd_up = false;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 730/783 net: hns3: add interrupts re-initialization while doing VF FLR
In reply to Greg Kroah-HartmanFrom: Jie Wang <[email protected]>
[ Upstream commit 09e6b30eeb254f1818a008cace3547159e908dfd ]
Currently keep alive message between PF and VF may be lost and the VF is unalive in PF. So the VF will not do reset during PF FLR reset process. This would make the allocated interrupt resources of VF invalid and VF would't receive or respond to PF any more.
So this patch adds VF interrupts re-initialization during VF FLR for VF recovery in above cases.
--- drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c +2 -1
@@ -3089,7 +3089,8 @@ static int hclgevf_pci_reset(struct hclgevf_dev *hdev)struct pci_dev *pdev = hdev->pdev;int ret =0 ; -if (hdev->reset_type ==HNAE3_VF_FULL_RESET && +if ((hdev->reset_type ==HNAE3_VF_FULL_RESET || + hdev->reset_type ==HNAE3_FLR_RESET ) &&test_bit (HCLGEVF_STATE_IRQ_INITED , &hdev->state)) {hclgevf_misc_irq_uninit (hdev);hclgevf_uninit_msi (hdev);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 731/783 net: sched: fix memory leak in tcindex_set_parms
In reply to Greg Kroah-HartmanFrom: Hawkins Jiawei <[email protected]>
[ Upstream commit 399ab7fe0fa0d846881685fd4e57e9a8ef7559f7 ]
Syzkaller reports a memory leak as follows:
====================================
BUG: memory leak
unreferenced object 0xffff88810c287f00 (size 256):
comm "syz-executor105", pid 3600, jiffies 4294943292 (age 12.990s)
hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<ffffffff814cf9f0>] kmalloc_trace+0x20/0x90 mm/slab_common.c:1046
[<ffffffff839c9e07>] kmalloc include/linux/slab.h:576 [inline]
[<ffffffff839c9e07>] kmalloc_array include/linux/slab.h:627 [inline]
[<ffffffff839c9e07>] kcalloc include/linux/slab.h:659 [inline]
[<ffffffff839c9e07>] tcf_exts_init include/net/pkt_cls.h:250 [inline]
[<ffffffff839c9e07>] tcindex_set_parms+0xa7/0xbe0 net/sched/cls_tcindex.c:342
[<ffffffff839caa1f>] tcindex_change+0xdf/0x120 net/sched/cls_tcindex.c:553
[<ffffffff8394db62>] tc_new_tfilter+0x4f2/0x1100 net/sched/cls_api.c:2147
[<ffffffff8389e91c>] rtnetlink_rcv_msg+0x4dc/0x5d0 net/core/rtnetlink.c:6082
[<ffffffff839eba67>] netlink_rcv_skb+0x87/0x1d0 net/netlink/af_netlink.c:2540
[<ffffffff839eab87>] netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline]
[<ffffffff839eab87>] netlink_unicast+0x397/0x4c0 net/netlink/af_netlink.c:1345
[<ffffffff839eb046>] netlink_sendmsg+0x396/0x710 net/netlink/af_netlink.c:1921
[<ffffffff8383e796>] sock_sendmsg_nosec net/socket.c:714 [inline]
[<ffffffff8383e796>] sock_sendmsg+0x56/0x80 net/socket.c:734
[<ffffffff8383eb08>] ____sys_sendmsg+0x178/0x410 net/socket.c:2482
[<ffffffff83843678>] ___sys_sendmsg+0xa8/0x110 net/socket.c:2536
[<ffffffff838439c5>] __sys_sendmmsg+0x105/0x330 net/socket.c:2622
[<ffffffff83843c14>] __do_sys_sendmmsg net/socket.c:2651 [inline]
[<ffffffff83843c14>] __se_sys_sendmmsg net/socket.c:2648 [inline]
[<ffffffff83843c14>] __x64_sys_sendmmsg+0x24/0x30 net/socket.c:2648
[<ffffffff84605fd5>] do_syscall_x64 arch/x86/entry/common.c:50 [inline]
[<ffffffff84605fd5>] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
[<ffffffff84800087>] entry_SYSCALL_64_after_hwframe+0x63/0xcd
====================================Kernel uses tcindex_change() to change an existing filter properties.
Yet the problem is that, during the process of changing, if old_r is retrieved from p->perfect, then kernel uses tcindex_alloc_perfect_hash() to newly allocate filter results, uses tcindex_filter_result_init() to clear the old filter result, without destroying its tcf_exts structure, which triggers the above memory leak.
To be more specific, there are only two source for the old_r, according to the tcindex_lookup(). old_r is retrieved from p->perfect, or old_r is retrieved from p->h.
* If old_r is retrieved from p->perfect, kernel usestcindex_alloc_perfect_hash() to newly allocate the
filter results. Then r is assigned with cp->perfect + handle, which is newly allocated. So condition old_r && old_r != r is true in this situation, and kernel uses tcindex_filter_result_init() to clear the old filter result, without destroying
its tcf_exts structure
* If old_r is retrieved from p->h, then p->perfect is NULL
according to the tcindex_lookup(). Considering that cp->h is directly copied from p->h and p->perfect is NULL, r is assigned with tcindex_lookup(cp, handle), whose value should be the same as old_r, so condition old_r && old_r != r is false in this situation, kernel ignores using tcindex_filter_result_init() to clear the old filter result.
So only when old_r is retrieved from p->perfect does kernel use tcindex_filter_result_init() to clear the old filter result, which triggers the above memory leak.
Considering that there already exists a tc_filter_wq workqueue to destroy the old tcindex_data by tcindex_partial_destroy_work() at the end of tcindex_set_parms(), this patch solves this memory leak bug by removing this old filter result clearing part and delegating it to the tc_filter_wq workqueue.
Note that this patch doesn't introduce any other issues. If old_r is retrieved from p->perfect, this patch just delegates old filter result clearing part to the tc_filter_wq workqueue; If old_r is retrieved from p->h, kernel doesn't reach the old filter result clearing part, so removing this part has no effect.
[Thanks to the suggestion from Jakub Kicinski, Cong Wang, Paolo Abeni and Dmitry Vyukov]
--- net/sched/cls_tcindex.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
net/sched/cls_tcindex.c +2 -10
@@ -332,7 +332,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, struct tcindex_filter_result *r, struct nlattr **tb, struct nlattr *est, bool ovr, struct netlink_ext_ack *extack) { - struct tcindex_filter_result new_filter_result, *old_r = r; + struct tcindex_filter_result new_filter_result;struct tcindex_data *cp =NULL , *oldp;struct tcindex_filter *f =NULL ;/* make gcc behave */ struct tcf_result cr = {};
@@ -401,7 +401,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, err =tcindex_filter_result_init (&new_filter_result, cp, net);if (err <0 ) goto errout_alloc; -if (old_r) +if (r) cr = r->res; err = -EBUSY ;
@@ -478,14 +478,6 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,tcf_bind_filter (tp, &cr, base); } -if (old_r && old_r != r) { - err =tcindex_filter_result_init (old_r, cp, net); -if (err <0 ) { -kfree (f); - goto errout_alloc; - } - } - oldp = p; r->res = cr;tcf_exts_change (&r->exts, &e);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 732/783 qlcnic: prevent ->dcb use-after-free on qlcnic_dcb_enable() failure
In reply to Greg Kroah-HartmanFrom: Daniil Tatianin <[email protected]>
[ Upstream commit 13a7c8964afcd8ca43c0b6001ebb0127baa95362 ]
adapter->dcb would get silently freed inside qlcnic_dcb_enable() in case qlcnic_dcb_attach() would return an error, which always happens under OOM conditions. This would lead to use-after-free because both of the existing callers invoke qlcnic_dcb_get_info() on the obtained pointer, which is potentially freed at that point.
Propagate errors from qlcnic_dcb_enable(), and instead free the dcb pointer at callsite using qlcnic_dcb_free(). This also removes the now unused qlcnic_clear_dcb_ops() helper, which was a simple wrapper around kfree() also causing memory leaks for partially initialized dcb.
Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool.
--- drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c | 8 +++++++- drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.h | 10 ++-------- drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c | 8 +++++++- 3 files changed, 16 insertions(+), 10 deletions(-)
drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c +7 -1
@@ -2505,7 +2505,13 @@ int qlcnic_83xx_init(struct qlcnic_adapter *adapter, int pci_using_dac) goto disable_mbx_intr;qlcnic_83xx_clear_function_resources (adapter); -qlcnic_dcb_enable (adapter->dcb); + + err =qlcnic_dcb_enable (adapter->dcb); +if (err) { +qlcnic_dcb_free (adapter->dcb); + goto disable_mbx_intr; + } +qlcnic_83xx_initialize_nic (adapter,1 );qlcnic_dcb_get_info (adapter->dcb);
drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.h +2 -8
@@ -41,11 +41,6 @@ struct qlcnic_dcb {unsigned long state; }; -static inline void qlcnic_clear_dcb_ops (struct qlcnic_dcb *dcb) -{ -kfree (dcb); -} -static inline int qlcnic_dcb_get_hw_capability (struct qlcnic_dcb *dcb) {if (dcb && dcb->ops->get_hw_capability)
@@ -112,9 +107,8 @@ static inline void qlcnic_dcb_init_dcbnl_ops(struct qlcnic_dcb *dcb) dcb->ops->init_dcbnl_ops(dcb); } -static inline void qlcnic_dcb_enable (struct qlcnic_dcb *dcb) +static inline int qlcnic_dcb_enable (struct qlcnic_dcb *dcb) { -if (dcb &&qlcnic_dcb_attach (dcb)) -qlcnic_clear_dcb_ops (dcb); +return dcb ?qlcnic_dcb_attach (dcb) :0 ; }#endif
drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c +7 -1
@@ -2622,7 +2622,13 @@ qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) "Device does not support MSI interrupts\n");if (qlcnic_82xx_check (adapter)) { -qlcnic_dcb_enable (adapter->dcb); + err =qlcnic_dcb_enable (adapter->dcb); +if (err) { +qlcnic_dcb_free (adapter->dcb); +dev_err (&pdev->dev,"Failed to enable DCB\n" ); + goto err_out_free_hw; + } +qlcnic_dcb_get_info (adapter->dcb); err =qlcnic_setup_intr (adapter);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 733/783 nfc: Fix potential resource leaks
In reply to Greg Kroah-HartmanFrom: Miaoqian Lin <[email protected]>
[ Upstream commit df49908f3c52d211aea5e2a14a93bbe67a2cb3af ]
nfc_get_device() take reference for the device, add missing nfc_put_device() to release it when not need anymore. Also fix the style warnning by use error EOPNOTSUPP instead of ENOTSUPP.
--- net/nfc/netlink.c | 52 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 14 deletions(-)
net/nfc/netlink.c +38 -14
@@ -1497,6 +1497,7 @@ static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info)u32 dev_idx, se_idx;u8 *apdu;size_t apdu_len; +int rc; if (!info->attrs[NFC_ATTR_DEVICE_INDEX] || !info->attrs[NFC_ATTR_SE_INDEX] ||
@@ -1510,25 +1511,37 @@ static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info)if (!dev)return -ENODEV ; -if (!dev->ops || !dev->ops->se_io) -return -ENOTSUPP ; +if (!dev->ops || !dev->ops->se_io) { + rc = -EOPNOTSUPP ; + goto put_dev; + } apdu_len =nla_len (info->attrs[NFC_ATTR_SE_APDU ]); -if (apdu_len ==0 ) -return -EINVAL ; +if (apdu_len ==0 ) { + rc = -EINVAL ; + goto put_dev; + } apdu =nla_data (info->attrs[NFC_ATTR_SE_APDU ]); -if (!apdu) -return -EINVAL ; +if (!apdu) { + rc = -EINVAL ; + goto put_dev; + } ctx =kzalloc (sizeof (struct se_io_ctx ),GFP_KERNEL ); -if (!ctx) -return -ENOMEM ; +if (!ctx) { + rc = -ENOMEM ; + goto put_dev; + } ctx->dev_idx = dev_idx; ctx->se_idx = se_idx; -return nfc_se_io (dev, se_idx, apdu, apdu_len, se_io_cb, ctx); + rc =nfc_se_io (dev, se_idx, apdu, apdu_len, se_io_cb, ctx); + +put_dev: +nfc_put_device (dev); +return rc; } static int nfc_genl_vendor_cmd(struct sk_buff *skb,
@@ -1551,14 +1564,21 @@ static int nfc_genl_vendor_cmd(struct sk_buff *skb, subcmd =nla_get_u32 (info->attrs[NFC_ATTR_VENDOR_SUBCMD ]); dev =nfc_get_device (dev_idx); -if (!dev || !dev->vendor_cmds || !dev->n_vendor_cmds) +if (!dev)return -ENODEV ; +if (!dev->vendor_cmds || !dev->n_vendor_cmds) { + err = -ENODEV ; + goto put_dev; + } +if (info->attrs[NFC_ATTR_VENDOR_DATA ]) { data =nla_data (info->attrs[NFC_ATTR_VENDOR_DATA ]); data_len =nla_len (info->attrs[NFC_ATTR_VENDOR_DATA ]); -if (data_len ==0 ) -return -EINVAL ; +if (data_len ==0 ) { + err = -EINVAL ; + goto put_dev; + } }else { data =NULL ; data_len =0 ;
@@ -1573,10 +1593,14 @@ static int nfc_genl_vendor_cmd(struct sk_buff *skb, dev->cur_cmd_info = info; err = cmd->doit (dev, data, data_len); dev->cur_cmd_info =NULL ; -return err; + goto put_dev; } -return -EOPNOTSUPP ; + err = -EOPNOTSUPP ; + +put_dev: +nfc_put_device (dev); +return err; }/* message building helper */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 734/783 vhost/vsock: Fix error handling in vhost_vsock_init()
In reply to Greg Kroah-HartmanFrom: Yuan Can <[email protected]>
[ Upstream commit 7a4efe182ca61fb3e5307e69b261c57cbf434cd4 ]
A problem about modprobe vhost_vsock failed is triggered with the following log given:
modprobe: ERROR: could not insert 'vhost_vsock': Device or resource busy
The reason is that vhost_vsock_init() returns misc_register() directly without checking its return value, if misc_register() failed, it returns without calling vsock_core_unregister() on vhost_transport, resulting the vhost_vsock can never be installed later.
A simple call graph is shown as below:
vhost_vsock_init()
vsock_core_register() # register vhost_transport misc_register()
device_create_with_groups()
device_create_groups_vargs()
dev = kzalloc(...) # OOM happened
# return without unregister vhost_transport
Fix by calling vsock_core_unregister() when misc_register() returns error.
Message-Id: <[email protected]>
--- drivers/vhost/vsock.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/vhost/vsock.c +8 -1
@@ -854,7 +854,14 @@ static int __init vhost_vsock_init(void) VSOCK_TRANSPORT_F_H2G);if (ret <0 )return ret; -return misc_register (&vhost_vsock_misc); + + ret =misc_register (&vhost_vsock_misc); +if (ret) { +vsock_core_unregister (&vhost_transport.transport); +return ret; + } + +return 0 ; }; static void __exit vhost_vsock_exit(void)
Signature · 1 line
2.35.1