From patchwork Thu Feb 6 07:47:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11367743 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D8FD192A for ; Thu, 6 Feb 2020 07:48:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A5758214AF for ; Thu, 6 Feb 2020 07:48:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BL15CYui" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A5758214AF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D1B926B0007; Thu, 6 Feb 2020 02:48:03 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CCD9F6B0008; Thu, 6 Feb 2020 02:48:03 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE0F36B000A; Thu, 6 Feb 2020 02:48:03 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0007.hostedemail.com [216.40.44.7]) by kanga.kvack.org (Postfix) with ESMTP id A502E6B0007 for ; Thu, 6 Feb 2020 02:48:03 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 48888180AD804 for ; Thu, 6 Feb 2020 07:48:03 +0000 (UTC) X-FDA: 76458923646.15.cast79_29262d5ac242d X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,mst@redhat.com,:linux-kernel@vger.kernel.org:jasowang@redhat.com:virtualization@lists.linux-foundation.org:david@redhat.com:,RULES_HIT:30054,0,RBL:205.139.110.61:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: cast79_29262d5ac242d X-Filterd-Recvd-Size: 4142 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Thu, 6 Feb 2020 07:48:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580975282; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6YoSJG/5CG/HyJuE7ahwi0KvUe76a2nh9vuUxvjqtG8=; b=BL15CYuiswyFY02zKjhOzL8XBsiBc79bmCJAPc2JWtZ1DPJgNHCEJHWb4VXho78dDSD94Q 7sgfVEwf5mHMdpwbErJfWTZyEWtxCWdw4UYRBiSO3kZ4opG5CVe2nIoKXnXdHKePufd4Ai J6pHhfBvkKRb2Wcp0A/1FOq+VsF2Bzs= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-140-Airmd9RiOdmjV8aBA6ioGw-1; Thu, 06 Feb 2020 02:48:00 -0500 Received: by mail-qk1-f197.google.com with SMTP id b23so3003998qkg.17 for ; Wed, 05 Feb 2020 23:48:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=vfV+T2mR+ZINyLA8LbxLyRCcFt6072JPvLxeCgd1lQo=; b=jsj1wMwUZTJlpynNhSFUDFK1xNczfUgkw+tDAFL6YM2d0wVsYEnJoP0gdOCiAI+RwN F/ATaHVvE/GcA82yf98iG/9Wf+B6PRtdIcYmOTNIMUDeXGuU0BNQT5AlBLjSvi7HvQvj unDX2ncury0v5JNiC10bcRK1E5/1oeC9lS7WIi9MFCOgb8gOr1LyRHo+EWwlXEEES56E VIj1bfFQ1MvJmb7jUWATBsAZeuvCv4wDRp+7vYjv1UVYeqzd9DuamuZOM1FjJilPRPIw AzEB9aIAi6CtWAQMK3C85bbwtksyA/vJjrAtBlOU6Pa2qwHYplihorSvZ23ebva97EBz rXfg== X-Gm-Message-State: APjAAAVEPDZiXfk/PgO/oSBn8m+wc3PdTwEzKGUWdhtDw5cscogD4bI2 lGQVM6ZFMQ8naClKH1D9/xT+dyKqMQ9AU0ocyXOFYlgfYESEmU8zbbkjESrFRRZ2HC8xQr02yHO GTNo+lzB3XvE= X-Received: by 2002:ac8:7b9b:: with SMTP id p27mr1563778qtu.2.1580975279419; Wed, 05 Feb 2020 23:47:59 -0800 (PST) X-Google-Smtp-Source: APXvYqyFG1AMzWVRgSI1qX48T8kdlxIMXg0Zo6VHwW7vlPrw3PtMkvwlNKHMeCwck82QMACgkj8XhA== X-Received: by 2002:ac8:7b9b:: with SMTP id p27mr1563767qtu.2.1580975279213; Wed, 05 Feb 2020 23:47:59 -0800 (PST) Received: from redhat.com (bzq-79-176-41-183.red.bezeqint.net. [79.176.41.183]) by smtp.gmail.com with ESMTPSA id 24sm1052973qka.32.2020.02.05.23.47.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 23:47:58 -0800 (PST) Date: Thu, 6 Feb 2020 02:47:55 -0500 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Jason Wang , virtualization@lists.linux-foundation.org, David Hildenbrand , linux-mm@kvack.org Subject: [PATCH] virtio_balloon: prevent pfn array overflow Message-ID: <20200206074644.1177551-1-mst@redhat.com> MIME-Version: 1.0 X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-MC-Unique: Airmd9RiOdmjV8aBA6ioGw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Make sure, at build time, that pfn array is big enough to hold a single page. It happens to be true since the PAGE_SHIFT value at the moment is 20, which is 1M - exactly 256 4K balloon pages. Signed-off-by: Michael S. Tsirkin Reviewed-by: David Hildenbrand Acked-by: Jason Wang --- drivers/virtio/virtio_balloon.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 8e400ece9273..2457c54b6185 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -158,6 +158,8 @@ static void set_page_pfns(struct virtio_balloon *vb, { unsigned int i; + BUILD_BUG_ON(VIRTIO_BALLOON_PAGES_PER_PAGE > VIRTIO_BALLOON_ARRAY_PFNS_MAX); + /* * Set balloon pfns pointing at this page. * Note that the first pfn points at start of the page.