mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Bill Wendling <morbo@google.com>,
	Zhiqi Song <songzhiqi1@huawei.com>,
	Longfang Liu <liulongfang@huawei.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	Weili Qian <qianweili@huawei.com>,
	Zhou Wang <wangzhou1@hisilicon.com>,
	Chenghai Huang <huangchenghai2@huawei.com>
Cc: Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org,
	codemender-patching+linux@google.com
Subject: Re: [PATCH] crypto: hisilicon/qm - annotate cap_tables with __counted_by_ptr
Date: Wed, 23 Sep 2026 15:11:01 +0900	[thread overview]
Message-ID: <abbd8862-cb64-4c58-a78b-c971fdada7be@embeddedor.com> (raw)
In-Reply-To: <20260923060114.2605310-1-morbo@google.com>



On 9/23/26 15:01, Bill Wendling wrote:
> Annotate the 'qm_cap_table' and 'dev_cap_table' pointer fields in
> 'struct hisi_qm_cap_tables' with the '__counted_by_ptr' attribute.
> This improves bounds checking via CONFIG_UBSAN_BOUNDS and
> CONFIG_FORTIFY_SOURCE, allowing KASAN and compiler diagnostics to
> detect out-of-bounds accesses.
> 
> The 'qm_cap_table' pointer is associated with 'qm_cap_size' which
> specifies its element count. Similarly, 'dev_cap_table' is associated
> with 'dev_cap_size'.
> 
> To ensure safety under compiler instrumentation, the assignments in the
> initialization paths have been updated to set the 'size'/'count' fields
> prior to setting the pointer fields. This prevents any transient state
> where the pointer is valid but the count is 0 (or uninitialized),
> ensuring that subsequent accesses to these tables do not trigger
> false-positive bounds check panics.
> 
> Cc: codemender-patching+linux@google.com
> Assisted-by: LLM
> Signed-off-by: Bill Wendling <morbo@google.com>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
-Gustavo

> ---
>   drivers/crypto/hisilicon/hpre/hpre_main.c | 2 +-
>   drivers/crypto/hisilicon/qm.c             | 2 +-
>   drivers/crypto/hisilicon/sec2/sec_main.c  | 2 +-
>   drivers/crypto/hisilicon/zip/zip_main.c   | 2 +-
>   include/linux/hisi_acc_qm.h               | 4 ++--
>   5 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/crypto/hisilicon/hpre/hpre_main.c b/drivers/crypto/hisilicon/hpre/hpre_main.c
> index b6903fce6071..4a1b2de476f5 100644
> --- a/drivers/crypto/hisilicon/hpre/hpre_main.c
> +++ b/drivers/crypto/hisilicon/hpre/hpre_main.c
> @@ -1234,8 +1234,8 @@ static int hpre_pre_store_cap_reg(struct hisi_qm *qm)
>   		return -EINVAL;
>   	}
>   
> -	qm->cap_tables.dev_cap_table = hpre_cap;
>   	qm->cap_tables.dev_cap_size = size;
> +	qm->cap_tables.dev_cap_table = hpre_cap;
>   
>   	return 0;
>   }
> diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
> index c01966a4a33f..7d13476451e3 100644
> --- a/drivers/crypto/hisilicon/qm.c
> +++ b/drivers/crypto/hisilicon/qm.c
> @@ -5743,8 +5743,8 @@ static int qm_pre_store_caps(struct hisi_qm *qm)
>   							i, qm->cap_ver);
>   	}
>   
> -	qm->cap_tables.qm_cap_table = qm_cap;
>   	qm->cap_tables.qm_cap_size = size;
> +	qm->cap_tables.qm_cap_table = qm_cap;
>   
>   	return 0;
>   }
> diff --git a/drivers/crypto/hisilicon/sec2/sec_main.c b/drivers/crypto/hisilicon/sec2/sec_main.c
> index 752565200c16..ac423d016998 100644
> --- a/drivers/crypto/hisilicon/sec2/sec_main.c
> +++ b/drivers/crypto/hisilicon/sec2/sec_main.c
> @@ -1285,8 +1285,8 @@ static int sec_pre_store_cap_reg(struct hisi_qm *qm)
>   				     i, qm->cap_ver);
>   	}
>   
> -	qm->cap_tables.dev_cap_table = sec_cap;
>   	qm->cap_tables.dev_cap_size = size;
> +	qm->cap_tables.dev_cap_table = sec_cap;
>   
>   	return 0;
>   }
> diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
> index 706a73656977..10091ad4a6a8 100644
> --- a/drivers/crypto/hisilicon/zip/zip_main.c
> +++ b/drivers/crypto/hisilicon/zip/zip_main.c
> @@ -1400,8 +1400,8 @@ static int zip_pre_store_cap_reg(struct hisi_qm *qm)
>   				     i, qm->cap_ver);
>   	}
>   
> -	qm->cap_tables.dev_cap_table = zip_cap;
>   	qm->cap_tables.dev_cap_size = size;
> +	qm->cap_tables.dev_cap_table = zip_cap;
>   
>   	return 0;
>   }
> diff --git a/include/linux/hisi_acc_qm.h b/include/linux/hisi_acc_qm.h
> index f7570a409905..8dc49fa2123b 100644
> --- a/include/linux/hisi_acc_qm.h
> +++ b/include/linux/hisi_acc_qm.h
> @@ -332,9 +332,9 @@ struct hisi_qm_cap_record {
>   
>   struct hisi_qm_cap_tables {
>   	u32 qm_cap_size;
> -	struct hisi_qm_cap_record *qm_cap_table;
> +	struct hisi_qm_cap_record *qm_cap_table __counted_by_ptr(qm_cap_size);
>   	u32 dev_cap_size;
> -	struct hisi_qm_cap_record *dev_cap_table;
> +	struct hisi_qm_cap_record *dev_cap_table __counted_by_ptr(dev_cap_size);
>   };
>   
>   struct hisi_qm_list {


  reply	other threads:[~2026-09-23  6:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23  6:01 Bill Wendling
2026-09-23  6:11 ` Gustavo A. R. Silva [this message]
2026-09-23  7:09 ` liulongfang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=abbd8862-cb64-4c58-a78b-c971fdada7be@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=codemender-patching+linux@google.com \
    --cc=davem@davemloft.net \
    --cc=gustavoars@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=huangchenghai2@huawei.com \
    --cc=kees@kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liulongfang@huawei.com \
    --cc=morbo@google.com \
    --cc=qianweili@huawei.com \
    --cc=songzhiqi1@huawei.com \
    --cc=wangzhou1@hisilicon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®