Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4922784imu; Tue, 8 Jan 2019 08:30:31 -0800 (PST) X-Google-Smtp-Source: ALg8bN7qFyFo7rNsmIucX3Au73MC+9lM4+NLcNn2tZD1dlXN8ywo/JW6bmmHhqnWhvYR7sFd9tb+ X-Received: by 2002:a63:2d46:: with SMTP id t67mr2140553pgt.140.1546965031889; Tue, 08 Jan 2019 08:30:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546965031; cv=none; d=google.com; s=arc-20160816; b=tLDOLbOIBh2N7DlYPM44PsNP983vopC/wI6qnEyEsIY8YcRbDU6xEtbeaEuOBnIgAO Y9vHlA5p9kv0OWjqzmlEPyKREov4k4lMIWOabqmgBgsoMOQ8tiebF0tX5SLaZ8pLwL48 rynXNitV8XUb9w9ju4E/9KyjKGhV/zOMstTkRR8Q3f7MwXKR4wZV0735jwykG/HNAFWR BTw+ZrLDcASJU7qlSphgg4+vzCU8PrxUfS1fQEI6tRY4qNGNQXAdFqW74kzw9LBXN39X 5cE72WYIh7exhLLTFFfO+wJdX4dFuZuGy+Ief7IKbvUEkKNKwxAe+TYklIfGSsN14XTx 2tdw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :dkim-signature; bh=qWRbL3N32mSE6w4dNJPwmsnCu5CZYMQLMJ8ea9T1CAI=; b=z0sEJnuBK8HwXzK9jGb2M/ftVOOGZPNpWAyx3IiHaPRoWEkeTTVoE3iDS27T/oxNvA 1r5ourys++X5IeH+tVVwXKW4Iw4LcF3mpTHKzKynOpG8pWllbJw/t1yZ0qmR9p20cnLS eMcvn+7Csx1piTR85Ksh2zNv+91dcdu3xs1Y/CLdevTW2fg2C2YdVexULj37338lItFJ ARohe9gnDlKnnpqp7D//dRXKtmy/HF1iKEJeIafrxmFBNv52gF+OWc6nJojCD7BFNxEB 4Xnw0JxVFV0fQE7/38wJ0iUVvRlRALm+2+UVv5TciKS4l/2d5wYHAAGiqHXGFeSAvrkm jMPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YHjwHpO9; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l17si72225236pfd.236.2019.01.08.08.30.16; Tue, 08 Jan 2019 08:30:31 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=YHjwHpO9; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729508AbfAHQ2M (ORCPT + 99 others); Tue, 8 Jan 2019 11:28:12 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:34739 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729218AbfAHQ2L (ORCPT ); Tue, 8 Jan 2019 11:28:11 -0500 Received: by mail-ed1-f68.google.com with SMTP id b3so4845673ede.1; Tue, 08 Jan 2019 08:28:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qWRbL3N32mSE6w4dNJPwmsnCu5CZYMQLMJ8ea9T1CAI=; b=YHjwHpO9rP7gC2YmJ7aHZkgAx4paxCZ9zZC2UwhIjiCnF6f44nTKb92BTf8TNRACtM xwuH8GFJ0+fRUCe/ZrjrLm/CpYATKR4TZainCrc2vhb9WIM+uCJLuPqYFQhLqM1b4E7s cMlNhB0g6eGkzOFiVnPQYbBs4f5XCp3mRW2FQ4QpzT7YfoW6uzDA//2OIu18lJmhISCf 2h7R9t/zKZgn6L2GGT4NEE1mA/IuEwSt9EGG53gQhxSWq+hNFT59+pgiLpxPO7+wxDa7 6bS+FolkjNF++OQbZFbQ7gcxSCWrQ9L52+RWPZWNPu0TXQoRdLL7VD1taFQckYUKlmTa 3LwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=qWRbL3N32mSE6w4dNJPwmsnCu5CZYMQLMJ8ea9T1CAI=; b=qTevw6x7uEmiyTFnVtmTJt1DzwRJTLONQTFD9LclALHJku3OhQisYd80iabtC18+5B dZ6Vnu93ByNS8gQGK1dXbnI7lw9o3gayLOQLvOuxVPbU4446ywoKAxkiaslvRjbz2mZ4 FEqH66550zEPFBAJoEkq3PqoAfHTzFPyBwQrbmSYj6owf4+sJwb3RRv899V/Q8goNG93 HW/8r1SuDe8umQehgDbm/Kh72/olncCHUYKUClhvbTVchwrbCTaJJSz7zanYx1hp3EVo l1dFCQfnN/EjRHdG4buqDUMkfGWp89AFG36FkrwnzELuvVoSIx2JQcUuYK0Q3dM6xgCM 0v6g== X-Gm-Message-State: AJcUukdJZ0ogEI+0QsrZW6yjKsQ2xsll+AVvsDaSIrOn4/J6KPmovRDX u8zp47rVzQ1SaIbLxdzqhUk= X-Received: by 2002:a17:906:cd2:: with SMTP id l18-v6mr2390658ejh.97.1546964888289; Tue, 08 Jan 2019 08:28:08 -0800 (PST) Received: from [192.168.0.61] (xd520f268.cust.hiper.dk. [213.32.242.104]) by smtp.gmail.com with ESMTPSA id j8sm120853ede.55.2019.01.08.08.28.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Jan 2019 08:28:07 -0800 (PST) Subject: Re: [PATCH] KVM: validate userspace input in kvm_clear_dirty_log_protect() To: Paolo Bonzini , rkrcmar@redhat.com, kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, syzkaller@googlegroups.com References: <20190102172937.28741-1-tomasbortoli@gmail.com> <99de332c-d4e3-0628-8ad1-982032e67690@redhat.com> From: Tomas Bortoli Openpgp: preference=signencrypt Autocrypt: addr=tomasbortoli@gmail.com; prefer-encrypt=mutual; keydata= mQINBFpCTZMBEADNZ1+Ibh0Z4pgGRcd1aOUMbe/YfHktmajjcoTnKmZZunjoUVAl8waeLITd BC2c8i1wHzHcnthrmb1izs5XlG6PZnl8n5tjysSNbwggzS1NcEK1qgn5VjNlHQ5aRMUwCC51 kicBiNmlQk2UuzzWwdheRGnaf+O1MNhC0GBeEDKQAL5obOU92pzflv6wWNACr+lHxdnpyies mOnRMjH16NjuTkrGbEmJe+MKp0qbjvR3R/dmFC1wczniRMQmV5w3MZ/N9wRappE+Atc1fOM+ wP7AWNuPvrKg4bN5uqKZLDFH7OFpxvjgVdWM40n0cQfqElWY9as+228Sltdd1XyHtUWRF2VW O1l5L0kX0+7+B5k/fpLhXqD3Z7DK7wRXpXmY59pofk7aFdcN97ZK+r6R7mqrwX4W9IpsPhkT kUyg3/Dx/khBZlJKFoUP325/hoH684bSiPEBroel9alB7gTq2ueoFwy6R3q5CMUw3D+CZWHA 3xllu46TRQ/Vt2g0cIHQNPoye2OWYFJ6kSEvaLpymjNDJ9ph2EuHegonDfOaYSq34ic2BcdB JkCgXRLP5K7KtRNJqqR+DM8xByeGmQv9yp6S97el+SiM9R53RhHawJZGz0EPl+2Q6+5mgh3u wXOlkmGrrSrlB8lc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RchVVfm7UWgLAy11pV3xM4wMSJOuqVMOz jYpWKYxDTpvsZ0ginUUY993Gb8k/CxjABEMUGVHhQPZ0OzjHIKS6cTzN6ue8bB+CGOLCaQp1 C0NRT5Tn9zpLxtf5nBExFd/zVENY5vAV2ZbKQdemO54O7j6B9DSgVRrm83GCZxbL4d+qTYBF 3tSCWw/6SG1F3q9gR9QrSC2YRjCmhijUVEh6FhZwB58TNZ1sEEttrps8TDa5tUd9 Message-ID: <8418f6c8-0fc8-e22c-c39a-bfcaee7471e2@gmail.com> Date: Tue, 8 Jan 2019 17:28:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <99de332c-d4e3-0628-8ad1-982032e67690@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Paolo, On 1/7/19 11:42 PM, Paolo Bonzini wrote: > On 02/01/19 18:29, Tomas Bortoli wrote: >> n = kvm_dirty_bitmap_bytes(memslot); >> + >> + if (n << 3 < log->num_pages || log->first_page > log->num_pages) >> + return -EINVAL; >> + > > This should be > > if (log->first_page > memslot->npages || > log->num_pages > memslot->npages - log->first_page) > return -EINVAL; > > i.e. the comparison should check the last page in the range, not the > number of pages. In addition, using "n" is unnecessary since we do have > the memslot. I'll do the changes myself if you prefer, but an ack would > be nice. > > Yeah, I agree. Thanks for the reply and sure you can do the changes, np :) Tomas