Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp432380ybm; Fri, 29 May 2020 03:52:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxV3hBhr8A63sOIX1gt2LQ4W/+0zZN/2BobuvcEb/9fEaVMp9TazBUsA5DttP7epaXdobjF X-Received: by 2002:a17:906:1d55:: with SMTP id o21mr6841371ejh.491.1590749546316; Fri, 29 May 2020 03:52:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590749546; cv=none; d=google.com; s=arc-20160816; b=P4s61F1xbEJn/xtdrTBFmlAWMFb95dkTCrt++x4MAGACjZSyNyYDffn4EXpEu1ucXw B7g+aH2mYqE8/MPpESauuj0M+LJdqZWcBhPmmiVi9jsEu5WL+UnPbAnTxINbOM98EynB 6kigTp0kp4ps+5LvWIuy0hkYKE+/7wH3h5wG5GLatkbgnreVz3BF0dq4H/RRNOCwhQnv AECW+VveP8TF1NvQkR1/L+BCttoiADffh68LDlvge/3MzButKuvg/ntg2lFMpikqIXaC 4JvfQYlT8z11MdD9apOV56rqc4fVpaZT9+bBIG7HMwbxliI27E9rpWvoNVPmJ2ALMh5g cprw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature; bh=B8L7vHtKkHs16625TWlJ0o9ar7jOJ9s+CGFbVBkgeRU=; b=b9uMrFlGlgU5zyeDd2gFas6kf6pHg0gvH12uWcRNKDaehjoJU0xzJ+EFjIwIuw6Mra dvcmwYVHiwyPb9cn5USZ8Ww7KkMTto83tEme3U7jiz1eUfRl52I7E5UL33CWkaPAFMa8 MYnp3RmkR4InT+9qh324xez2qu+k4+aBV0VjODE5nOB4kkicJM7Ylfhq9pUCUjWe5aD3 SJJ35mR5xy1lJn4iRhPhgz3m9QH7YC1RGelbNUlf6zZx2fFfYn1H/Q2VBtaYFrU7bqFH 3XSYQktwC2Wqc6So3zq80EnNoBhOVxc5rEv9IP9qnkMpzRqeDUl94Zyd4PNDn+A2esMt XORg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=vmLwAIE9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z14si5361542ejb.309.2020.05.29.03.52.03; Fri, 29 May 2020 03:52:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=vmLwAIE9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726411AbgE2KsZ (ORCPT + 99 others); Fri, 29 May 2020 06:48:25 -0400 Received: from mail27.static.mailgun.info ([104.130.122.27]:36040 "EHLO mail27.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725863AbgE2KsY (ORCPT ); Fri, 29 May 2020 06:48:24 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1590749304; h=Content-Transfer-Encoding: Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: From: References: Cc: To: Subject: Sender; bh=B8L7vHtKkHs16625TWlJ0o9ar7jOJ9s+CGFbVBkgeRU=; b=vmLwAIE9q1Q3wP4Q5DrHzGlPNHFHJUWiVdnMcTGFYtMwwq5P28sP2vDm/gpuUNvRU5daCGpM uWJGfnREQ2qRiYISbp8rKMp4yBjNBT/e9h+AH6tA7dEF7iEU21dCwbxeUNVd9hkKR6meQDfP VsKtlbxF4oyYgqN+Jv2J7TEb1rY= X-Mailgun-Sending-Ip: 104.130.122.27 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n03.prod.us-west-2.postgun.com with SMTP id 5ed0e87242288e951fad69fa (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Fri, 29 May 2020 10:48:18 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 08E1AC433CA; Fri, 29 May 2020 10:48:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from [10.50.50.126] (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: rbokka) by smtp.codeaurora.org (Postfix) with ESMTPSA id BDD1AC433C6; Fri, 29 May 2020 10:48:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org BDD1AC433C6 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=rbokka@codeaurora.org Subject: Re: [PATCH] nvmem: Enforce nvmem stride in the sysfs interface To: Douglas Anderson , Srinivas Kandagatla Cc: evgreen@chromium.org, dhavalp@codeaurora.org, mturney@codeaurora.org, sparate@codeaurora.org, rnayak@codeaurora.org, saiprakash.ranjan@codeaurora.org, linux-kernel@vger.kernel.org References: <20200528165250.1.Iad7dec5afecba175c816773a0088be805476453f@changeid> From: "Ravi Kumar Bokka (Temp)" Message-ID: Date: Fri, 29 May 2020 16:18:11 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: <20200528165250.1.Iad7dec5afecba175c816773a0088be805476453f@changeid> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 5/29/2020 5:23 AM, Douglas Anderson wrote: > The 'struct nvmem_config' has a stride attribute that specifies the > needed alignment for accesses into the nvmem. This is used in > nvmem_cell_info_to_nvmem_cell() but not in the sysfs read/write > functions. If the alignment is important in one place it's important > everywhere, so let's add enforcement. > > For now we'll consider it totally invalid to access with the wrong > alignment. We could relax this in the read case where we could just > read some extra bytes and throw them away. Relaxing it in the write > case seems harder (and less safe?) since we'd have to read some data > first and then write it back. To keep it symmetric we'll just > disallow it in both cases. > > Reported-by: Ravi Kumar Bokka > Signed-off-by: Douglas Anderson > --- > > drivers/nvmem/core.c | 6 ++++++ > 1 file changed, 6 insertions(+) > I have reviewed and tested this patch. Result: kernel crash resolved with unaligned offset. Reviewed-by: Ravi Kumar Bokka Tested-by: Ravi Kumar Bokka > diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c > index 05c6ae4b0b97..1c0e7953f90d 100644 > --- a/drivers/nvmem/core.c > +++ b/drivers/nvmem/core.c > @@ -111,6 +111,9 @@ static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj, > if (pos >= nvmem->size) > return 0; > > + if (!IS_ALIGNED(pos, nvmem->stride)) > + return -EINVAL; > + > if (count < nvmem->word_size) > return -EINVAL; > > @@ -148,6 +151,9 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj, > if (pos >= nvmem->size) > return -EFBIG; > > + if (!IS_ALIGNED(pos, nvmem->stride)) > + return -EINVAL; > + > if (count < nvmem->word_size) > return -EINVAL; > > Regards, Ravi Kumar.B -- Qualcomm INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by the Linux Foundation.