linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/3] crypto: hisilicon/qm - some misc-fixes by fuzz test
@ 2022-10-22  1:17 Kai Ye
  2022-10-22  1:17 ` [PATCH v3 1/3] crypto: hisilicon/qm - increase the memory of local variables Kai Ye
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Kai Ye @ 2022-10-22  1:17 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-kernel, yekai13

Resolve stack overflow risks for algqos api. Invalid parameter checking is
added. And simplify some code.

changes v1->v2:
        - modify a comment.
changes v2->v3:
	- document the stack overflow cause.

Kai Ye (3):
  crypto: hisilicon/qm - increase the memory of local variables
  crypto: hisilicon/qm - add pci bdf number check
  crypto: hisilicon/qm - delete redundancy check

 drivers/crypto/hisilicon/qm.c | 43 +++++++++++------------------------
 1 file changed, 13 insertions(+), 30 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/3] crypto: hisilicon/qm - increase the memory of local variables
  2022-10-22  1:17 [PATCH v3 0/3] crypto: hisilicon/qm - some misc-fixes by fuzz test Kai Ye
@ 2022-10-22  1:17 ` Kai Ye
  2022-10-22  1:17 ` [PATCH v3 2/3] crypto: hisilicon/qm - add pci bdf number check Kai Ye
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Kai Ye @ 2022-10-22  1:17 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-kernel, yekai13

Increase the buffer to prevent stack overflow by fuzz test. The maximum
length of the qos configuration buffer is 256 bytes. Currently, the value
of the 'val buffer' is only 32 bytes. The sscanf does not check the dest
memory length. So the 'val buffer' may stack overflow.

Signed-off-by: Kai Ye <yekai13@huawei.com>
---
 drivers/crypto/hisilicon/qm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
index e3edb176d976..5d79e9f0e7e1 100644
--- a/drivers/crypto/hisilicon/qm.c
+++ b/drivers/crypto/hisilicon/qm.c
@@ -250,7 +250,6 @@
 #define QM_QOS_MIN_CIR_B		100
 #define QM_QOS_MAX_CIR_U		6
 #define QM_QOS_MAX_CIR_S		11
-#define QM_QOS_VAL_MAX_LEN		32
 #define QM_DFX_BASE		0x0100000
 #define QM_DFX_STATE1		0x0104000
 #define QM_DFX_STATE2		0x01040C8
@@ -4612,7 +4611,7 @@ static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf,
 			       unsigned int *fun_index)
 {
 	char tbuf_bdf[QM_DBG_READ_LEN] = {0};
-	char val_buf[QM_QOS_VAL_MAX_LEN] = {0};
+	char val_buf[QM_DBG_READ_LEN] = {0};
 	u32 tmp1, device, function;
 	int ret, bus;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/3] crypto: hisilicon/qm - add pci bdf number check
  2022-10-22  1:17 [PATCH v3 0/3] crypto: hisilicon/qm - some misc-fixes by fuzz test Kai Ye
  2022-10-22  1:17 ` [PATCH v3 1/3] crypto: hisilicon/qm - increase the memory of local variables Kai Ye
@ 2022-10-22  1:17 ` Kai Ye
  2022-10-22  1:17 ` [PATCH v3 3/3] crypto: hisilicon/qm - delete redundancy check Kai Ye
  2022-10-28  5:03 ` [PATCH v3 0/3] crypto: hisilicon/qm - some misc-fixes by fuzz test Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Kai Ye @ 2022-10-22  1:17 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-kernel, yekai13

The pci bdf number check is added for qos written by using the pci api.
Directly get the devfn by pci_dev, so delete some redundant code.
And use the kstrtoul instead of sscanf to simplify code.

Signed-off-by: Kai Ye <yekai13@huawei.com>
---
 drivers/crypto/hisilicon/qm.c | 37 ++++++++++++-----------------------
 1 file changed, 12 insertions(+), 25 deletions(-)

diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
index 5d79e9f0e7e1..80eeb966cf89 100644
--- a/drivers/crypto/hisilicon/qm.c
+++ b/drivers/crypto/hisilicon/qm.c
@@ -4589,49 +4589,36 @@ static ssize_t qm_algqos_read(struct file *filp, char __user *buf,
 	return ret;
 }
 
-static ssize_t qm_qos_value_init(const char *buf, unsigned long *val)
-{
-	int buflen = strlen(buf);
-	int ret, i;
-
-	for (i = 0; i < buflen; i++) {
-		if (!isdigit(buf[i]))
-			return -EINVAL;
-	}
-
-	ret = sscanf(buf, "%lu", val);
-	if (ret != QM_QOS_VAL_NUM)
-		return -EINVAL;
-
-	return 0;
-}
-
 static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf,
 			       unsigned long *val,
 			       unsigned int *fun_index)
 {
+	struct bus_type *bus_type = qm->pdev->dev.bus;
 	char tbuf_bdf[QM_DBG_READ_LEN] = {0};
 	char val_buf[QM_DBG_READ_LEN] = {0};
-	u32 tmp1, device, function;
-	int ret, bus;
+	struct pci_dev *pdev;
+	struct device *dev;
+	int ret;
 
 	ret = sscanf(buf, "%s %s", tbuf_bdf, val_buf);
 	if (ret != QM_QOS_PARAM_NUM)
 		return -EINVAL;
 
-	ret = qm_qos_value_init(val_buf, val);
+	ret = kstrtoul(val_buf, 10, val);
 	if (ret || *val == 0 || *val > QM_QOS_MAX_VAL) {
 		pci_err(qm->pdev, "input qos value is error, please set 1~1000!\n");
 		return -EINVAL;
 	}
 
-	ret = sscanf(tbuf_bdf, "%u:%x:%u.%u", &tmp1, &bus, &device, &function);
-	if (ret != QM_QOS_BDF_PARAM_NUM) {
-		pci_err(qm->pdev, "input pci bdf value is error!\n");
-		return -EINVAL;
+	dev = bus_find_device_by_name(bus_type, NULL, tbuf_bdf);
+	if (!dev) {
+		pci_err(qm->pdev, "input pci bdf number is error!\n");
+		return -ENODEV;
 	}
 
-	*fun_index = PCI_DEVFN(device, function);
+	pdev = container_of(dev, struct pci_dev, dev);
+
+	*fun_index = pdev->devfn;
 
 	return 0;
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 3/3] crypto: hisilicon/qm - delete redundancy check
  2022-10-22  1:17 [PATCH v3 0/3] crypto: hisilicon/qm - some misc-fixes by fuzz test Kai Ye
  2022-10-22  1:17 ` [PATCH v3 1/3] crypto: hisilicon/qm - increase the memory of local variables Kai Ye
  2022-10-22  1:17 ` [PATCH v3 2/3] crypto: hisilicon/qm - add pci bdf number check Kai Ye
@ 2022-10-22  1:17 ` Kai Ye
  2022-10-28  5:03 ` [PATCH v3 0/3] crypto: hisilicon/qm - some misc-fixes by fuzz test Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Kai Ye @ 2022-10-22  1:17 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-kernel, yekai13

Because the permission on the VF debugfs file is "0444". So
the VF function checking is redundant in qos writing api.

Signed-off-by: Kai Ye <yekai13@huawei.com>
---
 drivers/crypto/hisilicon/qm.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
index 80eeb966cf89..363a02810a16 100644
--- a/drivers/crypto/hisilicon/qm.c
+++ b/drivers/crypto/hisilicon/qm.c
@@ -4632,9 +4632,6 @@ static ssize_t qm_algqos_write(struct file *filp, const char __user *buf,
 	unsigned long val;
 	int len, ret;
 
-	if (qm->fun_type == QM_HW_VF)
-		return -EINVAL;
-
 	if (*pos != 0)
 		return 0;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 0/3] crypto: hisilicon/qm - some misc-fixes by fuzz test
  2022-10-22  1:17 [PATCH v3 0/3] crypto: hisilicon/qm - some misc-fixes by fuzz test Kai Ye
                   ` (2 preceding siblings ...)
  2022-10-22  1:17 ` [PATCH v3 3/3] crypto: hisilicon/qm - delete redundancy check Kai Ye
@ 2022-10-28  5:03 ` Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2022-10-28  5:03 UTC (permalink / raw)
  To: Kai Ye; +Cc: linux-crypto, linux-kernel

On Sat, Oct 22, 2022 at 01:17:43AM +0000, Kai Ye wrote:
> Resolve stack overflow risks for algqos api. Invalid parameter checking is
> added. And simplify some code.
> 
> changes v1->v2:
>         - modify a comment.
> changes v2->v3:
> 	- document the stack overflow cause.
> 
> Kai Ye (3):
>   crypto: hisilicon/qm - increase the memory of local variables
>   crypto: hisilicon/qm - add pci bdf number check
>   crypto: hisilicon/qm - delete redundancy check
> 
>  drivers/crypto/hisilicon/qm.c | 43 +++++++++++------------------------
>  1 file changed, 13 insertions(+), 30 deletions(-)
> 
> -- 
> 2.17.1

All applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-28  5:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-22  1:17 [PATCH v3 0/3] crypto: hisilicon/qm - some misc-fixes by fuzz test Kai Ye
2022-10-22  1:17 ` [PATCH v3 1/3] crypto: hisilicon/qm - increase the memory of local variables Kai Ye
2022-10-22  1:17 ` [PATCH v3 2/3] crypto: hisilicon/qm - add pci bdf number check Kai Ye
2022-10-22  1:17 ` [PATCH v3 3/3] crypto: hisilicon/qm - delete redundancy check Kai Ye
2022-10-28  5:03 ` [PATCH v3 0/3] crypto: hisilicon/qm - some misc-fixes by fuzz test Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).