Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2845785ybd; Mon, 24 Jun 2019 13:53:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqzqDCEIH/zL7gFUez+dX8ij1pjoBRIM1GyhFQcHoLw294aE8RRZ+J2XOknmNO6rUzrIKWsS X-Received: by 2002:a63:9143:: with SMTP id l64mr23988251pge.65.1561409632985; Mon, 24 Jun 2019 13:53:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561409632; cv=none; d=google.com; s=arc-20160816; b=ZqLyjwWXQ2aJi0sxPGgZXWgfPIf0xaT8MididyJATNCls9ifcXf6TqGLsabdL19ZzW 1DTtufLbviz52AFLM1I9l81zk6o1uUQJ+jjHkY3dyGOvxp8T270Zc9lezyjWESEtRvqr VWi15BpZ71vBcvOWHL2JREngPs2R+5TL4r66sIbwIJBAqWJbJ5NGlwtaPE5FqKVIX0qf Gma4YJHsb3SgeZIsvj0Q8xvlL0BC0HvvAaKAFtip3YQST7cxLO82kRZU8wJZeLde/0HJ LSOkT+GTkrsaU93DjHJruPecbWFZpTiiDywVkbGLoPUDQKfx5J4U7wT6CB227X16VkTT sJhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date; bh=hHgPG7fw9E4ZkpxfkhsNdyqwERF+fINw7SvftNloffo=; b=XxB71MjH4sLtmBPyEnpGYZ+Ns9Y1aofF1y2ca+cjXe/7l3y7msuq3gAxL4EvrNSgH1 Q74JxQTkVbBKuWxDQ4AiAtBM5JYDO5j9fqz6ErfPdfs5/445HequBpoORfijcd7FEB5t z+3BZOm8QlscOV5n+gXP8l3whTqrYmMldfvS+Q2GVBQ3uLjqBKjioDITh9UAzHoJcANK 5wZ4Lq5ctMFwsZl4WPOpFZTwr3UFecJ1GhvukE1EU/wtKcXzQfGiWdzFsRS6j1b6R2jn RQSyUH5zkju1KinDmsLkEv9ABH/u3CRdaXauk/2BzR5f8SwXLxzEysWzK4nzPMfSToPn ilBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1si11323195pld.439.2019.06.24.13.53.35; Mon, 24 Jun 2019 13:53:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731313AbfFXRfg (ORCPT + 99 others); Mon, 24 Jun 2019 13:35:36 -0400 Received: from mga07.intel.com ([134.134.136.100]:15148 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731032AbfFXRfg (ORCPT ); Mon, 24 Jun 2019 13:35:36 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jun 2019 10:35:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,412,1557212400"; d="scan'208";a="187988905" Received: from ideak-desk.fi.intel.com ([10.237.72.204]) by fmsmga002.fm.intel.com with ESMTP; 24 Jun 2019 10:35:33 -0700 Date: Mon, 24 Jun 2019 20:35:33 +0300 From: Imre Deak To: Herbert Xu Cc: Christophe Leroy , "David S. Miller" , horia.geanta@nxp.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH v4 1/4] lib/scatterlist: Fix mapping iterator when sg->offset is greater than PAGE_SIZE Message-ID: <20190624173533.GA809@ideak-desk.fi.intel.com> Reply-To: imre.deak@intel.com References: <20190620060221.q4pbsqzsza3pxs42@gondor.apana.org.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190620060221.q4pbsqzsza3pxs42@gondor.apana.org.au> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Hi, On Thu, Jun 20, 2019 at 02:02:21PM +0800, Herbert Xu wrote: > On Mon, Jun 17, 2019 at 09:15:02PM +0000, Christophe Leroy wrote: > > All mapping iterator logic is based on the assumption that sg->offset > > is always lower than PAGE_SIZE. > > > > But there are situations where sg->offset is such that the SG item > > is on the second page. could you explain how sg->offset becomes >= PAGE_SIZE? --Imre > > In that case sg_copy_to_buffer() fails > > properly copying the data into the buffer. One of the reason is > > that the data will be outside the kmapped area used to access that > > data. > > > > This patch fixes the issue by adjusting the mapping iterator > > offset and pgoffset fields such that offset is always lower than > > PAGE_SIZE. > > > > Signed-off-by: Christophe Leroy > > Fixes: 4225fc8555a9 ("lib/scatterlist: use page iterator in the mapping iterator") > > Cc: stable@vger.kernel.org > > --- > > lib/scatterlist.c | 9 +++++++-- > > 1 file changed, 7 insertions(+), 2 deletions(-) > > Good catch. > > > @@ -686,7 +686,12 @@ static bool sg_miter_get_next_page(struct sg_mapping_iter *miter) > > sg = miter->piter.sg; > > pgoffset = miter->piter.sg_pgoffset; > > > > - miter->__offset = pgoffset ? 0 : sg->offset; > > + offset = pgoffset ? 0 : sg->offset; > > + while (offset >= PAGE_SIZE) { > > + miter->piter.sg_pgoffset = ++pgoffset; > > + offset -= PAGE_SIZE; > > + } > > How about > > miter->piter.sg_pgoffset += offset >> PAGE_SHIFT; > offset &= PAGE_SIZE - 1; > > Thanks, > -- > Email: Herbert Xu > Home Page: http://gondor.apana.org.au/~herbert/ > PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt