Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp8174945rwl; Tue, 10 Jan 2023 09:56:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXsdgd/Vu4Ln5M+0AfjnsXoImHGhoZB5UG+0HEpis7iybNOxRCBQ6PbIc+V1xR6DXLFkjkSf X-Received: by 2002:a05:6a21:3d1c:b0:b6:b9f:7e62 with SMTP id bi28-20020a056a213d1c00b000b60b9f7e62mr4029211pzc.17.1673373378658; Tue, 10 Jan 2023 09:56:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673373378; cv=none; d=google.com; s=arc-20160816; b=N6RGmAF90usEIwqZpMfz/6WrXrpOcKGX/SBEuuhOGhKF6ewv/dIM+xo+gMCCswraL/ YTqo7qXdJvCo5xWPgPWd0cxZWRcKKbJ6cPKcKrJloImxy114Zc26I0eLV37QDrHmYr0h ayrTknD/JzYSZImWJvla3xL+lEkiqoA8ukqzXvq0L/xwE0ymOwoK7Nc+QRICef+0Y3w/ 6XIexEpvahe430pIQVDhl+oxlZIoW2m3hCITa6FdUwQKFDv++6EMkUL5T3wvCvT+MH3o oxr3i6GgQauodU1O0tjGRlaQ+VA0uVeJ0Ta1v+t/+A69vsKwHYupCZ0sCgvZGAFar5HB HjjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=BiD9HDtY677v73zD/DAwV3gxXKXHJJtF5vodMznouXI=; b=EPH1MwcLPXMu/9hexW52XDmnqpE+pzH+PEZbVkFVm/GiHTWy0UP/hVrdWT9REdyf5l iT9OOtIPsH0Jt4QXu0yQXdxxA0Klucf1S3qZDYUwwfq/5LR2gDwas9VryM8K+iS9HGMs Zsr9KHe5LwA0IvUzoKTIwUdFC5881UV1Yq9vk9OSsj9misebqLbAeyHVhOkVSQKzX/69 +KUqRY+3JKC0Wczn1U8ZkL+tT/eCBG3805TQmiFPXI1kSzd2cls1p7LMP4FxaWvzPFDa W3x5aLUEYi4UCfGGQyP6RNNBVTc1CDGDq21SJl+6WsRYcLf9t4iOWz1YgAunSIW3REml Plng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=LtCcapEf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p14-20020a63740e000000b0049457cea998si12761525pgc.410.2023.01.10.09.56.12; Tue, 10 Jan 2023 09:56:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=LtCcapEf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232645AbjAJRWC (ORCPT + 53 others); Tue, 10 Jan 2023 12:22:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233797AbjAJRVj (ORCPT ); Tue, 10 Jan 2023 12:21:39 -0500 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 653272F7A7 for ; Tue, 10 Jan 2023 09:21:04 -0800 (PST) Received: by mail-lf1-x12a.google.com with SMTP id m6so19526430lfj.11 for ; Tue, 10 Jan 2023 09:21:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=BiD9HDtY677v73zD/DAwV3gxXKXHJJtF5vodMznouXI=; b=LtCcapEfaq7jnw+0fGg77tKfZIsc0Ia1/E/mVPvdvIeEfaUDocpq2qs66q6GPOw+JK Pxve+JFGST72umFROmdvgPrsqTgozMzdSDcaFCaoI1HgN98eGnYmPwCErho77OzrCd0l DLNCw3XmItwejeHB5US7WEj8eASOgmF6/aqG0U7Ua0YD0Moww9aHxy4rjyUyEuGrLljV HW2zTdvTCyJ57N8jf8aGm4sEhw5g2bqc3PYf41lorsBz2Vn69tLFRehGj5nuHhYxNFGF dfwiulkdAaoKjGof+vEdw0VtFxBzi3L3diD4231k+0gVkLoVA8PLU6bBwlDNdQGnujjB vMUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BiD9HDtY677v73zD/DAwV3gxXKXHJJtF5vodMznouXI=; b=YhFFySa2JQYbgpFbp+hOvCZMl/Ce+qpPa5HzQ3wzv6aXvsdYX/4oJLeNMxghT0p45J StwF0MWu4W55OrIJk0IlPDGFoarTYlcK9viMyHhmqo7If3XPQFLhKeoaifWcuRxZM/Cf smcrnb6+91e9VuNOAKrgyatjN8lSgaaTiyK2DVm7w0veyy4LRtUAwq/3mX8R39laA5xh a4GjNruzDzLfh3f1re+YCl/Qn8rk+/OBBiat1uPDgBnOSzqVuI8Z9Mcvceg5dJGJ9fZc D367KAC6aJf5Yz/0Ne3qBsIywOHIvRXXFe2/qEq1lgm+I/RE987X+DzFT8ig+iiQqtpA BM+Q== X-Gm-Message-State: AFqh2kpJwDVoCqeyBGdGQxqc60xYz/jrwISeo9zp1HbwpA9Yj39blNLe RpObu1knyVS91ZCx+zCh7GkQPaQQF6jvk0cB/SI8qQ== X-Received: by 2002:a05:6512:22d6:b0:4cb:3ff7:f24a with SMTP id g22-20020a05651222d600b004cb3ff7f24amr1538148lfu.409.1673371262485; Tue, 10 Jan 2023 09:21:02 -0800 (PST) MIME-Version: 1.0 References: <20230109160808.3618132-1-pgonda@google.com> <74745684-785e-71b2-288e-91fbcf1b555b@amd.com> In-Reply-To: From: Peter Gonda Date: Tue, 10 Jan 2023 10:20:50 -0700 Message-ID: Subject: Re: [PATCH] KVM: sev: Fix int overflow in send|recieve_update_data ioctls To: Tom Lendacky Cc: kvm@vger.kernel.org, Andy Nguyen , David Rientjes , Paolo Bonzini , Sean Christopherson , stable@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 10, 2023 at 10:16 AM Tom Lendacky wrote: > > On 1/10/23 10:44, Peter Gonda wrote: > >>> > >>> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c > >>> index 273cba809328..9451de72f917 100644 > >>> --- a/arch/x86/kvm/svm/sev.c > >>> +++ b/arch/x86/kvm/svm/sev.c > >>> @@ -1294,7 +1294,7 @@ static int sev_send_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) > >>> > >>> /* Check if we are crossing the page boundary */ > >>> offset = params.guest_uaddr & (PAGE_SIZE - 1); > >>> - if ((params.guest_len + offset > PAGE_SIZE)) > >>> + if (params.guest_len > PAGE_SIZE || (params.guest_len + offset > PAGE_SIZE)) > >> > >> I see the original if statement had double parentheses, which looks > >> strange. Should this if (and the one below) be: > >> > >> if (params.guest_len > PAGE_SIZE || (params.guest_len + offset) > PAGE_SIZE) > > > > Isn't the order of operations here: '+' and then '>'. So is the patch > > correct and matches the old conditional? I am fine adding additional > > But what was the purpose of them in the old conditional? They weren't > necessary. > > But, yes, that order of operations is correct and those are both before > '||'. So the extra parentheses around the second condition check are still > strange then, right? > > Given that, then: > > if (params.guest_len > PAGE_SIZE || params.guest_len + offset > PAGE_SIZE) > > > () for clarity though. > > I do like the look and clarity of the parentheses around the addition. Sounds good to me. I'll update the V2 in a couple days to wait for any other comments. > > Thanks, > Tom