From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752188AbbJBJpj (ORCPT ); Fri, 2 Oct 2015 05:45:39 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:57974 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751100AbbJBJpi (ORCPT ); Fri, 2 Oct 2015 05:45:38 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="101316985" Message-ID: <560E50B6.5060103@cn.fujitsu.com> Date: Fri, 2 Oct 2015 17:39:02 +0800 From: Dongsheng Yang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: Sudip Mukherjee , David Woodhouse , Brian Norris CC: , Subject: Re: [PATCH] mtd: mtdram: check offs and len in mtdram->erase References: <1443631303-22057-1-git-send-email-sudipm.mukherjee@gmail.com> In-Reply-To: <1443631303-22057-1-git-send-email-sudipm.mukherjee@gmail.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.167.226.66] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/01/2015 12:41 AM, Sudip Mukherjee wrote: > We should prevent user to erasing mtd device with an unaligned offset > or length. > > Signed-off-by: Sudip Mukherjee > --- > > I am not sure if I should add the Signed-off-by of > Dongsheng Yang . He is the original author > and he should get the credit for that. But I had sent a a patch out to fix this problem before your v1. http://lists.infradead.org/pipermail/linux-mtd/2015-September/062234.html Yang > > drivers/mtd/devices/mtdram.c | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c > index 8e28508..21b6a05 100644 > --- a/drivers/mtd/devices/mtdram.c > +++ b/drivers/mtd/devices/mtdram.c > @@ -32,8 +32,35 @@ MODULE_PARM_DESC(erase_size, "Device erase block size in KiB"); > // We could store these in the mtd structure, but we only support 1 device.. > static struct mtd_info *mtd_info; > > +static int check_offs_len(struct mtd_info *mtd, loff_t ofs, uint64_t len) > +{ > + int ret = 0; > + uint64_t temp_len, rem; > + > + /* Start address must align on block boundary */ > + temp_len = ofs; > + rem = do_div(temp_len, mtd->erasesize); > + if (rem) { > + pr_debug("%s: unaligned address\n", __func__); > + ret = -EINVAL; > + } > + > + /* Length must align on block boundary */ > + temp_len = len; > + rem = do_div(temp_len, mtd->erasesize); > + > + if (rem) { > + pr_debug("%s: length not block aligned\n", __func__); > + ret = -EINVAL; > + } > + > + return ret; > +} > + > static int ram_erase(struct mtd_info *mtd, struct erase_info *instr) > { > + if (check_offs_len(mtd, instr->addr, instr->len)) > + return -EINVAL; > memset((char *)mtd->priv + instr->addr, 0xff, instr->len); > instr->state = MTD_ERASE_DONE; > mtd_erase_callback(instr); >