Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp466582imm; Mon, 21 May 2018 08:53:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZprtTNJN0M/TNhgNrKnxWDvQW7zV37bcbZSG2jLR7ZxpLnLUvBPx/2GXX8rwweSXdJ69xPH X-Received: by 2002:a62:d717:: with SMTP id b23-v6mr20319738pfh.5.1526918005937; Mon, 21 May 2018 08:53:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526918005; cv=none; d=google.com; s=arc-20160816; b=gpbE3TSHV9TQ+krdTAD0wRENQYAgiZP4sV7Fr3JqQHNYCMmo40TL9PA+5LPkrbfNPZ 10ZzGqT/HOpjExO/7FSym4sWtjJFdj9eA7LdA7zWVPd134END9xTh6SeIzNee96l8HMt ykHSmgigXZFnHm84bCzPf4AhVcTLgfyLLzNYi19XQqIjquMxKaI0Q+zbBBTZ83aImPGg KbY6BoT3qhX3WvHhptihJ7XNCzwI23dNevQZFnUBbMS9gzQiMRfjFLbs/iA55jhy520W zJjkWZQso28wJ6TIr5uQCcfSMcffjDuigfS/i0rkhwWkZSNsB4VF8h0i8+ik5yuo6+zt uqtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject:cc:dkim-signature:arc-authentication-results; bh=ExHJ5O+wrIJ2A8HyVB0GGMd9VtnjgSGO/RM5nTIWomI=; b=uV7XrTC9x0dWnq+SHvqJnLk6bae6iB5u16+KffUB1nxK3UNL3iBv+T+dcpH3V73tsz Z3/t1yoRtx2uxj8MRmWzdr809V+2ZoXv269+6KHoxiTOmLGu3JsXsYueX4Wz76sdVE8q fWtFBHUpdUAW+uNUMs6Fo8krS/pbscl/zDaUJW2W1XrK3g2lDcsas4Ks53bOnF12kXDx I/RIdfeglQPFD2oAyocLzpqUHjHv8NkHS/PmuVW1kb55YFLEgtSYzYXs1mKx2m/ZDa99 I9D5gp7hkEgeYJ3BJg5+GdzBIkSEfMSIexlhx/6tGs85r6M3sWTwuq0G6NYIPTPjhYmp MWWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector1-amd-com header.b=oc0qRAvD; 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 u3-v6si14697177plj.338.2018.05.21.08.53.10; Mon, 21 May 2018 08:53:25 -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; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector1-amd-com header.b=oc0qRAvD; 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 S1753332AbeEUPwy (ORCPT + 99 others); Mon, 21 May 2018 11:52:54 -0400 Received: from mail-dm3nam03on0085.outbound.protection.outlook.com ([104.47.41.85]:43840 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753307AbeEUPwp (ORCPT ); Mon, 21 May 2018 11:52:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ExHJ5O+wrIJ2A8HyVB0GGMd9VtnjgSGO/RM5nTIWomI=; b=oc0qRAvDdFxWOHE18sU5n0TANtqlwZgHTo8f0TMADrApZ/G6uEx0BVShCmBgLzYUx/YuUqXmxKqTuqwzBWP2FcAmyi4Lyk0jewqsAsJo8DgDVpipu3YCs1EKmI5BkemqMcgV+J7Q+3VYrfbS8+p1Ji8PkFYYZ1XmRoqP/7VNVeI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [10.236.136.62] (165.204.77.1) by BL0PR12MB2449.namprd12.prod.outlook.com (2603:10b6:207:4d::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.776.11; Mon, 21 May 2018 15:52:42 +0000 Cc: brijesh.singh@amd.com, Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH] KVM: X86: prevent integer overflows in KVM_MEMORY_ENCRYPT_REG_REGION To: Dan Carpenter , Joerg Roedel References: <20180519060135.GA4991@mwanda> From: Brijesh Singh Message-ID: Date: Mon, 21 May 2018 10:52:33 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180519060135.GA4991@mwanda> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN1PR12CA0072.namprd12.prod.outlook.com (2603:10b6:802:20::43) To BL0PR12MB2449.namprd12.prod.outlook.com (2603:10b6:207:4d::31) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:BL0PR12MB2449; X-Microsoft-Exchange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kxdVJD8DFKwBGvtxxyH0ymEgtlMhRtEZG0AbS8z+1JuusJ5x1HkZRER0qTNhLuloibgsf3qMegDH3On7mkY/7wMdGn5gtjP9DMD1TEMbiXDJGKtH8Thw0SEAWKZaCrWePbFA5JOxwHOsBCakmGt9Ik5SXVlJYsEStGutjqmRGN5BByWlgFI9QSPENZqkutjTM8xsuXk4P31w+O4hUQ541dwD17rHhHph0+OchWkTQdTVe/+3RVsYRNFGqKRmb3MT9Ec6NhSVMHpKyPHismhTZO7uNQ/Ww9ST0RUnNpmxPD+uU09Uxmy0vzdTr+iH/UBM+q6rWCCPHLZmKxptj8gFcIkEPDQssoe8VZOWqG34UmxpksCsx+mja;4:SCX8eIc2zIK1z4CYYXaA/JvWwBWkG6J01oEFAt2d3uj8L3FYIMjEjhwXlaHNmfnoTQN5dAMYK9cGJP5dZd4Pq+E1xb2UQyP7lkimNRn5IKvge9hryN4oC4rQywdtw3cFHDJSUyIkzzZ0E64jkF31Qk5E5gpySzu3SluY+H1TT7E5ckG3Jy5OPr1BhUt9qJqBCjIHsHpCaz8dNH5dvL3o0q+XydarJhvzj4td3mNuhsmy7+Un5wOsrvNqYBmyzZQyxoXUmKzKikjxRvN1uOj02B1hIJ5VKZIt5XViEGfNf1NLpxd3FbLFI5Uyvg0Lu9McluBFZ9LpDICYoRAC3QEJqQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(146099531331640); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3231254)(944501410)(52105095)(3002001)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(20161123560045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011)(7699016);SRVR:BL0PR12MB2449;BCL:0;PCL:0;RULEID:;SRVR:BL0PR12MB2449; X-Forefront-PRVS: 06793E740F X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(346002)(396003)(366004)(39860400002)(376002)(39380400002)(199004)(189003)(110136005)(50466002)(956004)(58126008)(476003)(25786009)(97736004)(486006)(86362001)(31696002)(53546011)(54906003)(3846002)(65956001)(66066001)(65806001)(6246003)(305945005)(5660300001)(81156014)(2906002)(8676002)(2616005)(81166006)(47776003)(7416002)(186003)(7736002)(16526019)(64126003)(65826007)(44832011)(53936002)(6116002)(316002)(36756003)(77096007)(26005)(230700001)(16576012)(6486002)(68736007)(229853002)(106356001)(386003)(31686004)(23676004)(59450400001)(52116002)(2486003)(52146003)(478600001)(446003)(4326008)(6666003)(105586002)(11346002)(8936002)(76176011)(67846002);DIR:OUT;SFP:1101;SCL:1;SRVR:BL0PR12MB2449;H:[10.236.136.62];FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTDBQUjEyTUIyNDQ5OzIzOkdRMEJUR0drSjlTc0hBK2s2NnEzRVBwWUxr?= =?utf-8?B?dGd0ZWwza3RHQVJsaGNXbWdyTUowdVA2ZExldFNjYnVZR2dmeEdNUlBSWjQx?= =?utf-8?B?ekpsVHU1Smw0SmVvWnBGb1dPNk5acHJ0S05KaGR4c25NZjZJVy9CWFJZSm5J?= =?utf-8?B?T2dDdEdDY2lnUHQzNWUxanBlNFhvcEdEQmNUdnNXcTJtdFNkRTlMZ1RHanRv?= =?utf-8?B?TlV0K1VEUHpEN0ZhVUNBV3JaeUgvaC9XOGVNalYzYmRMYStiMjE4YXF1cURO?= =?utf-8?B?SDFZU0drUnNCOXhzanJqSXdhMHBjVitGWDg4Sno0Q29NTEczb1EzMEFJdmJu?= =?utf-8?B?dlRZcFd4dFpTYUU5eGY5bHdCYzRYaGJ2RE9kL2FQYnhRUTZkb2RqUGpoOTlR?= =?utf-8?B?dTBrSmR6W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usco/acoZlis3Yza3u/aoE7dl9/4zQwde1GRc/UDrP9QLilW2z1DY44vGWVEjyZFVU2ss1BlsSQtvaq97LuPu1jJdRdGUS9/;20:wPFvRvsXJUzOE4o6Qa5je53YUYf1Q9UE7XIeObM9lDkKojgZt+pAVsKor1SnAIldnvoaXICxSmFMDZPwhFQcevQbMqCRgLK6cDb3xelfLiFdDpSFIKHsWYAo9eA+JYN+fM2ZhsPX3txUsvwVSwTK5KZG3jUq2u0e/iZyfqUWZqidwTgQQ9xiFYSdwAEkCikxRwCwc5NsifiZQGpqF/gpMXeMgI86sfaoXS3PSvaZeYk8blxre8IJxxE4AI8Kva1Q X-MS-Office365-Filtering-Correlation-Id: 19241b38-0e2c-45d5-689b-08d5bf32e3c2 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2018 15:52:42.4806 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 19241b38-0e2c-45d5-689b-08d5bf32e3c2 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB2449 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Dan, On 05/19/2018 01:01 AM, Dan Carpenter wrote: > This is a fix from reviewing the code, but it looks like it might be > able to lead to an Oops. It affects 32bit systems. > Please note that SEV is not available on 32bit systems. > The KVM_MEMORY_ENCRYPT_REG_REGION ioctl uses a u64 for range->addr and > range->size but the high 32 bits would be truncated away on a 32 bit > system. This is harmless but it's also harmless to prevent it. > > Then in sev_pin_memory() the "uaddr + ulen" calculation can wrap around. > The wrap around can happen on 32 bit or 64 bit systems, but I was only > able to figure out a problem for 32 bit systems. We would pick a number > which results in "npages" being zero. The sev_pin_memory() would then > return ZERO_SIZE_PTR without allocating anything. > > I made it illegal to call sev_pin_memory() with "ulen" set to zero. > Hopefully, that doesn't cause any problems. I think this should be fine. I also changed the type of > "first" and "last" to long, just for cosmetic reasons. Otherwise on a > 64 bit system you're saving "uaddr >> 12" in an int and it truncates the > high 20 bits away. The math works in the current code so far as I can > see but it's just weird. > This change looks good. thanks > Signed-off-by: Dan Carpenter Reviewed-by: Brijesh Singh > --- > Again, this is a static checker fix. The most risky parts of this > patch are blocking "ulen == 0" and changing the types of "first" and > "last". I felt like those changes made the math easier to understand > > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c > index 220e5a89465a..de21d5c5168b 100644 > --- a/arch/x86/kvm/svm.c > +++ b/arch/x86/kvm/svm.c > @@ -1762,7 +1762,10 @@ static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr, > unsigned long npages, npinned, size; > unsigned long locked, lock_limit; > struct page **pages; > - int first, last; > + unsigned long first, last; > + > + if (ulen == 0 || uaddr + ulen < uaddr) > + return NULL; > > /* Calculate number of pages. */ > first = (uaddr & PAGE_MASK) >> PAGE_SHIFT; > @@ -6925,6 +6928,9 @@ static int svm_register_enc_region(struct kvm *kvm, > if (!sev_guest(kvm)) > return -ENOTTY; > > + if (range->addr > ULONG_MAX || range->size > ULONG_MAX) > + return -EINVAL; > + > region = kzalloc(sizeof(*region), GFP_KERNEL); > if (!region) > return -ENOMEM; >