Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2744757imm; Wed, 3 Oct 2018 08:32:15 -0700 (PDT) X-Google-Smtp-Source: ACcGV63FBRLpLMEkWhq/jJe8EPTe077muc5G9xR24YeEs7jdMHMCq9LSy1RIFIE2kdjtPtxURPbU X-Received: by 2002:a62:9015:: with SMTP id a21-v6mr2192583pfe.49.1538580735913; Wed, 03 Oct 2018 08:32:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538580735; cv=none; d=google.com; s=arc-20160816; b=uM1+jKT1NrMaLSmKR8wUJYs+I2YlAGps6qLTB0D6agd3OpuvKrC2Y5tYSoZjgjmRpF 2OYkAluzX1HP6V7hiZhf6eFzw8DYIashr5L2tXS602+y0cxqd5uOVQqIJPzNzunpQDUx VjB59NKBenBoLI/PDdDumWgR7wF1826nb5afcqGk8MPxIaM9N2ncn9VJzgK6alkNmue4 cwYYWDFJQc2GgoZ4CqcbqVqaLJTgO8KqQKhcX4vMDCArYUDEyKbmqdwvSOQCck+CKBXd U8vqNb9CywhchZrT0Fgojr+tjdvMbyt1nT+fQFiHF38vLLk8wfjJmdZqWRbCJgos+0+w b8Mg== 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:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=js62U15/LuGH3LSaXd+WaC8tDRKZzmtaBadXD40y9Ow=; b=uNVTfIYm3S+BVZeciVgvBDcrnecUvf93XwTtR9T4mN0SA8nHJZuVdSuseThC7Yi8/t xIp/kVnZ0qS8U6K3ujwYN81mPNPEnCPRlQc07wVq3NiAnbvY7RESJz73pTvySQOnZCLM ClQIRJIVGpP8WQOTWC7d1FCbA3eT1oL8aaJuFlwJ3mCJdGlz31Hah6+/0ljfr7zCXAay /THe2LNF3TvulTatLXKgWVcPOzC3fT7Bg7bxVkSCG93mK3ig6Ql4qxOk+6DOgJ+elS0C l0uUCFDFNsGABFWujwl20sPl43vKulkZirPij3tWVviqZaD8EYAJRNt03eybuAj2qtjK VjYg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 j1-v6si1680214pfh.63.2018.10.03.08.31.54; Wed, 03 Oct 2018 08:32:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727197AbeJCWUh (ORCPT + 99 others); Wed, 3 Oct 2018 18:20:37 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:45742 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726811AbeJCWUf (ORCPT ); Wed, 3 Oct 2018 18:20:35 -0400 Received: by mail-pf1-f195.google.com with SMTP id a23-v6so1844663pfi.12 for ; Wed, 03 Oct 2018 08:31:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=js62U15/LuGH3LSaXd+WaC8tDRKZzmtaBadXD40y9Ow=; b=PNjgX5xRjhn+KEgqi+ArlriKCX7ZHBjHfxHzvCcU6SdkaTt3HO4Vg6NcwcjEFA3g8W CJARmLqSaVZQzb5WRIZ3U1KBOVaSxeCHK+wheASHoEzqij09r2OYUu+Dlv63xRszGWks 60gkGXCAimzAwtsHoFHnix011U0QjgF5Gesscx0sdFrLIXpc4WIMx56S9Sa84QjsJp47 cqtRBQdmVrStD+MB1twinDgzUJxh21Ev6bOZXh30B985DgvJU5lOX/AE8TQ3Nx2Dq9ii O1UgXTZds7l+A1IQ62+dLc6vBsoqKYkdvRL7xnud3F1kieqjWQiiUu07jkLvup3PQW5A XXKg== X-Gm-Message-State: ABuFfohUIofBg6EEakDNcE2PE3ZClVSheOqWcZe9flheo5pcwf4ntulB odXMKcS/jVA5HaL7NzQDr9zc2M4yx7lFLA== X-Received: by 2002:a62:5044:: with SMTP id e65-v6mr2131349pfb.157.1538580701819; Wed, 03 Oct 2018 08:31:41 -0700 (PDT) Received: from ?IPv6:2620:15c:2cd:203:5cdc:422c:7b28:ebb5? ([2620:15c:2cd:203:5cdc:422c:7b28:ebb5]) by smtp.gmail.com with ESMTPSA id j5-v6sm1990111pgm.79.2018.10.03.08.31.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Oct 2018 08:31:41 -0700 (PDT) Message-ID: <1538580700.205649.10.camel@acm.org> Subject: Re: [PATCH 4/6] lib/scatterlist: Do not leak pages when high-order allocation fails From: Bart Van Assche To: Tvrtko Ursulin , linux-kernel@vger.kernel.org Cc: tvrtko.ursulin@linux.intel.com, Tvrtko Ursulin , Bart Van Assche , Hannes Reinecke , Johannes Thumshirn , Jens Axboe Date: Wed, 03 Oct 2018 08:31:40 -0700 In-Reply-To: <20180926141625.17727-5-tvrtko.ursulin@linux.intel.com> References: <20180926141625.17727-1-tvrtko.ursulin@linux.intel.com> <20180926141625.17727-5-tvrtko.ursulin@linux.intel.com> Content-Type: text/plain; charset="UTF-7" X-Mailer: Evolution 3.26.2-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2018-09-26 at 15:16 +-0100, Tvrtko Ursulin wrote: +AD4 From: Tvrtko Ursulin +ADw-tvrtko.ursulin+AEA-intel.com+AD4 +AD4 +AD4 If a higher-order allocation fails, the existing abort and cleanup path +AD4 would consider all segments allocated so far as 0-order page allocations +AD4 and would therefore leak memory. +AD4 +AD4 Fix this by cleaning up using sgl+AF8-free+AF8-n+AF8-order which allows the correct +AD4 page order to be passed in. +AD4 +AD4 Signed-off-by: Tvrtko Ursulin +ADw-tvrtko.ursulin+AEA-intel.com+AD4 +AD4 Cc: Bart Van Assche +ADw-bart.vanassche+AEA-wdc.com+AD4 +AD4 Cc: Hannes Reinecke +ADw-hare+AEA-suse.com+AD4 +AD4 Cc: Johannes Thumshirn +ADw-jthumshirn+AEA-suse.de+AD4 +AD4 Cc: Jens Axboe +ADw-axboe+AEA-kernel.dk+AD4 +AD4 --- +AD4 lib/scatterlist.c +AHw 6 +-+-+-+--- +AD4 1 file changed, 4 insertions(+-), 2 deletions(-) +AD4 +AD4 diff --git a/lib/scatterlist.c b/lib/scatterlist.c +AD4 index 3cc01cd82242..0caed79d7291 100644 +AD4 --- a/lib/scatterlist.c +AD4 +-+-+- b/lib/scatterlist.c +AD4 +AEAAQA -481,7 +-481,7 +AEAAQA struct scatterlist +ACo-sgl+AF8-alloc+AF8-order(unsigned long length, unsigned int order, +AD4 +AHs +AD4 struct scatterlist +ACo-sgl, +ACo-sg+ADs +AD4 struct page +ACo-page+ADs +AD4 - unsigned int nent, nalloc+ADs +AD4 +- unsigned int nent, nalloc, i+ADs +AD4 u32 elem+AF8-len+ADs +AD4 +AD4 nent +AD0 round+AF8-up(length, PAGE+AF8-SIZE +ADwAPA order) +AD4APg (PAGE+AF8-SHIFT +- order)+ADs +AD4 +AEAAQA -501,17 +-501,19 +AEAAQA struct scatterlist +ACo-sgl+AF8-alloc+AF8-order(unsigned long length, unsigned int order, +AD4 +AD4 sg+AF8-init+AF8-table(sgl, nalloc)+ADs +AD4 sg +AD0 sgl+ADs +AD4 +- i +AD0 0+ADs +AD4 while (length) +AHs +AD4 elem+AF8-len +AD0 min+AF8-t(u64, length, PAGE+AF8-SIZE +ADwAPA order)+ADs +AD4 page +AD0 alloc+AF8-pages(gfp, order)+ADs +AD4 if (+ACE-page) +AHs +AD4 - sgl+AF8-free(sgl)+ADs +AD4 +- sgl+AF8-free+AF8-n+AF8-order(sgl, i, order)+ADs +AD4 return NULL+ADs +AD4 +AH0 +AD4 +AD4 sg+AF8-set+AF8-page(sg, page, elem+AF8-len, 0)+ADs +AD4 length -+AD0 elem+AF8-len+ADs +AD4 sg +AD0 sg+AF8-next(sg)+ADs +AD4 +- i+-+-+ADs +AD4 +AH0 +AD4 WARN+AF8-ONCE(length, +ACI-length +AD0 +ACU-ld+AFw-n+ACI, length)+ADs +AD4 if (nent+AF8-p) sg+AF8-init+AF8-table() clears all page pointers and sgl+AF8-free+AF8-n+AF8-order() can handle elements of which the page pointer is zero. So I think if sgl+AF8-free+AF8-n+AF8-order(sgl, i, order) would be changed into sgl+AF8-free+AF8-n+AF8-order(sgl, UINT+AF8-MAX, order) that the variable 'i' can be left out. Bart.