From owner-svn-src-head@freebsd.org Mon Jul 30 11:27:52 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C4F1D1053340; Mon, 30 Jul 2018 11:27:52 +0000 (UTC) (envelope-from royger@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 674E194D83; Mon, 30 Jul 2018 11:27:52 +0000 (UTC) (envelope-from royger@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 39A0023AB3; Mon, 30 Jul 2018 11:27:52 +0000 (UTC) (envelope-from royger@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6UBRpUl085391; Mon, 30 Jul 2018 11:27:51 GMT (envelope-from royger@FreeBSD.org) Received: (from royger@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6UBRpaV085390; Mon, 30 Jul 2018 11:27:51 GMT (envelope-from royger@FreeBSD.org) Message-Id: <201807301127.w6UBRpaV085390@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: royger set sender to royger@FreeBSD.org using -f From: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Date: Mon, 30 Jul 2018 11:27:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336896 - head/sys/dev/xen/blkfront X-SVN-Group: head X-SVN-Commit-Author: royger X-SVN-Commit-Paths: head/sys/dev/xen/blkfront X-SVN-Commit-Revision: 336896 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jul 2018 11:27:52 -0000 Author: royger Date: Mon Jul 30 11:27:51 2018 New Revision: 336896 URL: https://svnweb.freebsd.org/changeset/base/336896 Log: xen-blkfront: fix memory leak in xbd_connect error path If gnttab_grant_foreign_access() fails for any of the indirection pages, the code breaks out of both the loops without freeing the local variable indirectpages, causing a memory leak. Submitted by: Pratyush Yadav Differential Review: https://reviews.freebsd.org/D16136 Modified: head/sys/dev/xen/blkfront/blkfront.c Modified: head/sys/dev/xen/blkfront/blkfront.c ============================================================================== --- head/sys/dev/xen/blkfront/blkfront.c Mon Jul 30 11:15:20 2018 (r336895) +++ head/sys/dev/xen/blkfront/blkfront.c Mon Jul 30 11:27:51 2018 (r336896) @@ -1333,7 +1333,10 @@ xbd_connect(struct xbd_softc *sc) if (sc->xbd_max_request_indirectpages > 0) { indirectpages = contigmalloc( PAGE_SIZE * sc->xbd_max_request_indirectpages, - M_XENBLOCKFRONT, M_ZERO, 0, ~0, PAGE_SIZE, 0); + M_XENBLOCKFRONT, M_ZERO | M_NOWAIT, 0, ~0, + PAGE_SIZE, 0); + if (indirectpages == NULL) + sc->xbd_max_request_indirectpages = 0; } else { indirectpages = NULL; } @@ -1345,8 +1348,12 @@ xbd_connect(struct xbd_softc *sc) &cm->cm_indirectionrefs[j])) break; } - if (j < sc->xbd_max_request_indirectpages) + if (j < sc->xbd_max_request_indirectpages) { + contigfree(indirectpages, + PAGE_SIZE * sc->xbd_max_request_indirectpages, + M_XENBLOCKFRONT); break; + } cm->cm_indirectionpages = indirectpages; xbd_free_command(cm); }