linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: mtdram: check offs and len in mtdram->point     madram->unpoint,mtdram->write and mtdram->read
@ 2017-03-03  7:31 chenwy
  2017-03-16  9:20 ` [PATCH] mtd: mtdram: check offs and len in mtdram->point madram->unpoint, mtdram->write " Boris Brezillon
  0 siblings, 1 reply; 2+ messages in thread
From: chenwy @ 2017-03-03  7:31 UTC (permalink / raw)
  To: linux-mtd; +Cc: fnstml-fjl, linux-kernel, chenwy

    We should prevent user to erasing mtd device with
    an unaligned offset or length.

Signed-off-by: Chen  Wenyong <chenwy-fnst@cn.fujitsu.com>
---
 drivers/mtd/devices/mtdram.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index cbd8547..b0468c1 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -67,6 +67,8 @@ static int ram_erase(struct mtd_info *mtd, struct erase_info *instr)
 static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
 		size_t *retlen, void **virt, resource_size_t *phys)
 {
+	if (check_offs_len(mtd, from, len))
+		return -EINVAL;
 	*virt = mtd->priv + from;
 	*retlen = len;
 	return 0;
@@ -74,6 +76,8 @@ static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
 
 static int ram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
 {
+	if (check_offs_len(mtd, from, len))
+		return -EINVAL;
 	return 0;
 }
 
@@ -93,6 +97,8 @@ static unsigned long ram_get_unmapped_area(struct mtd_info *mtd,
 static int ram_read(struct mtd_info *mtd, loff_t from, size_t len,
 		size_t *retlen, u_char *buf)
 {
+	if (check_offs_len(mtd, from, len))
+		return -EINVAL;
 	memcpy(buf, mtd->priv + from, len);
 	*retlen = len;
 	return 0;
@@ -101,6 +107,8 @@ static int ram_read(struct mtd_info *mtd, loff_t from, size_t len,
 static int ram_write(struct mtd_info *mtd, loff_t to, size_t len,
 		size_t *retlen, const u_char *buf)
 {
+	if (check_offs_len(mtd, to, len))
+		return -EINVAL;
 	memcpy((char *)mtd->priv + to, buf, len);
 	*retlen = len;
 	return 0;
-- 
2.9.3

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

* Re: [PATCH] mtd: mtdram: check offs and len in mtdram->point madram->unpoint, mtdram->write and mtdram->read
  2017-03-03  7:31 [PATCH] mtd: mtdram: check offs and len in mtdram->point madram->unpoint,mtdram->write and mtdram->read chenwy
@ 2017-03-16  9:20 ` Boris Brezillon
  0 siblings, 0 replies; 2+ messages in thread
From: Boris Brezillon @ 2017-03-16  9:20 UTC (permalink / raw)
  To: chenwy; +Cc: linux-mtd, fnstml-fjl, linux-kernel

Hi Chen,

Can you use something shorter for your commit title. Something like

"mtd: mtdram: check offs and len where appropriate"

On Fri, 3 Mar 2017 15:31:00 +0800
chenwy <chenwy-fnst@cn.fujitsu.com> wrote:

>     We should prevent user to erasing mtd device with

			     ^ from

>     an unaligned offset or length.

Why are you putting 5 spaces before each line of your commit message?

> 
> Signed-off-by: Chen  Wenyong <chenwy-fnst@cn.fujitsu.com>
> ---
>  drivers/mtd/devices/mtdram.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
> index cbd8547..b0468c1 100644
> --- a/drivers/mtd/devices/mtdram.c
> +++ b/drivers/mtd/devices/mtdram.c
> @@ -67,6 +67,8 @@ static int ram_erase(struct mtd_info *mtd, struct erase_info *instr)
>  static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
>  		size_t *retlen, void **virt, resource_size_t *phys)
>  {
> +	if (check_offs_len(mtd, from, len))
> +		return -EINVAL;

Add an empty line.

>  	*virt = mtd->priv + from;
>  	*retlen = len;
>  	return 0;
> @@ -74,6 +76,8 @@ static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
>  
>  static int ram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
>  {
> +	if (check_offs_len(mtd, from, len))
> +		return -EINVAL;

Ditto.

>  	return 0;
>  }
>  
> @@ -93,6 +97,8 @@ static unsigned long ram_get_unmapped_area(struct mtd_info *mtd,
>  static int ram_read(struct mtd_info *mtd, loff_t from, size_t len,
>  		size_t *retlen, u_char *buf)
>  {
> +	if (check_offs_len(mtd, from, len))
> +		return -EINVAL;

Ditto.

>  	memcpy(buf, mtd->priv + from, len);
>  	*retlen = len;
>  	return 0;
> @@ -101,6 +107,8 @@ static int ram_read(struct mtd_info *mtd, loff_t from, size_t len,
>  static int ram_write(struct mtd_info *mtd, loff_t to, size_t len,
>  		size_t *retlen, const u_char *buf)
>  {
> +	if (check_offs_len(mtd, to, len))
> +		return -EINVAL;

Ditto.

>  	memcpy((char *)mtd->priv + to, buf, len);
>  	*retlen = len;
>  	return 0;

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

end of thread, other threads:[~2017-03-16  9:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-03  7:31 [PATCH] mtd: mtdram: check offs and len in mtdram->point madram->unpoint,mtdram->write and mtdram->read chenwy
2017-03-16  9:20 ` [PATCH] mtd: mtdram: check offs and len in mtdram->point madram->unpoint, mtdram->write " Boris Brezillon

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).