Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1539382ybi; Wed, 19 Jun 2019 23:03:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSvzfqsKu+TrphCgpkDjU1XoTLnB4QU/6F8Ovj5U12iQawhEiv/TJx/T/HgulknKWjuhlJ X-Received: by 2002:a65:408d:: with SMTP id t13mr11341836pgp.373.1561010624308; Wed, 19 Jun 2019 23:03:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561010624; cv=none; d=google.com; s=arc-20160816; b=jGCfwjab4F02Be8SQkig5Yl4H32/bXxZBCEP+kPhg+7u2yDUSG/4iIVJhe5QYDVoCS z3fpT4+Kq3cpa1Gsjg8wXRTyYtjEzntfCszAqCTDp5rZLVoDK2lOctsMrr3Ghq+XJf8j CNNv/GrE+0FnA9F74UqLVs+1Y0VoeHC7CO8ToQAWES2KfagjvcgXx46z71gVdRaUTskB yIJ65OgEwIylT7GYlKkENhGZ24cd+ogno/GYhsh+6oWlHveBlHzzuFwaY21t0YSOXwQg TfBg0vQz8XdZf5TjHd9D7Q4A2PQPXOm6hK10GDIuYsNXP1tpL8S6PFd4mpFzvgLj+2+s Ta7g== 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:message-id:subject:cc :to:from:date; bh=thK/bv6YzWxYHGv9vicnY82bL/UGkdO/b+hfnoM5sr4=; b=VyQDC8COZDks0Sa8puoc80kcB8NA3dfUAPRTQLpKgCADX5dCzxGOjI0zwGxjU1wuuu w62MY5AZAeZp6LAOQZ0+psjCmcJXJDsDJ7NJttgMJ4OLxfzMoj4qaFjVfIrMJMiU/Zdn YjcDjxVkn09Yh9c6lCBsju5Sahvtqc801vRCQHzt2SwGf20H6rUkLSjYO1b1Nh8WDOKX ZDSXvEngEzk/yyfwy4kIi2qn9NbJgZzD5dMSysnuOtjAyCIlHkA3sDYsLu9Neckicjye 1foRv/yl2MMugsE/W3BOZmQZPmuG0maaWJu+LsVLn0J1tONOFYSBhm1SS8nhilAguOjS dsug== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c22si16675435pls.388.2019.06.19.23.03.23; Wed, 19 Jun 2019 23:03:44 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725953AbfFTGCm (ORCPT + 99 others); Thu, 20 Jun 2019 02:02:42 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:38376 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725871AbfFTGCm (ORCPT ); Thu, 20 Jun 2019 02:02:42 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1hdq9X-0008UB-3U; Thu, 20 Jun 2019 14:02:31 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1hdq9N-0006tl-Hn; Thu, 20 Jun 2019 14:02:21 +0800 Date: Thu, 20 Jun 2019 14:02:21 +0800 From: Herbert Xu To: Christophe Leroy Cc: "David S. Miller" , horia.geanta@nxp.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Imre Deak Subject: Re: [PATCH v4 1/4] lib/scatterlist: Fix mapping iterator when sg->offset is greater than PAGE_SIZE Message-ID: <20190620060221.q4pbsqzsza3pxs42@gondor.apana.org.au> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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. 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