Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1702591ybg; Wed, 29 Jul 2020 23:47:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZW2EoIShEEs+zLM/B93cZOkCeRdwuDZbmhiai3F7PWySmB6inCpbyPvX+FpvJdwxD/5xM X-Received: by 2002:a17:906:4685:: with SMTP id a5mr1220947ejr.46.1596091630677; Wed, 29 Jul 2020 23:47:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596091630; cv=none; d=google.com; s=arc-20160816; b=F1vOdrYcqHSFiWjv6rpkCOndDKBO0pJfRZbLg0T7AFVBRsB10I1JG0JP/1tA5RwjOc ozwg8CKFJ43HTYwW0pCmxIbxtCit8SoLhNxYx9EEXOvF0fJSSe56aSfGnqPUEuhe2Ybm VBXKiyCMEjB3fePWCu1sDho1u3ulnKHKaLGJBoVsgvfLNSFU1zG3+s28+A9hGj+HzaxS 5Z/HXkv9lCWYVhjPeO/tozLIFk7SC5QPsJFXlW19H9ZrLOJW5obnclT9x78vdHXw4/xV kYY2IgVLJGwN7Z8XKufOqgjLMyPby0qcu2U7bD0u8PoAC0cSibDSIyeMPoi9H7NtfzJ4 v3MQ== 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:from:references:cc:to:subject; bh=VvW/5770zwdEjP0loB0rGyzZeqTV1S8hvb/EOvhH5ns=; b=Ao5BwJimPcCaAChRTLl96ysh3lw5t0Q4t8sP1zW9qtT9Cj7ktUU0jASbqxnyTf6ARa nGdDJxjpgsY0Pf0Vu9WHarZgATJzS1vnWpVJTKhRn+Bmi2/xDBGjlVlVyCpQDVJtgt7l z1ywW4i65BUVNb0OCJjUF2XxhPmPhud9MyyVc9nysGs30sXZBEaxmdJLeFIobmke3w33 2uNxQHuzMa2ikpTN/nYbD0WfYRkAc/U1oCXx9DLaLMNo7d0c+jf4p5242/PfBmPi/NRu Ufo419cPg3ibtKF7KWmTRn80rVuBLDtZHnpN5UMffXoQXrEESm8lGg5DYBCMwQQysxqS trJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 89si2772238edr.415.2020.07.29.23.46.48; Wed, 29 Jul 2020 23:47:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728597AbgG3Gqh (ORCPT + 99 others); Thu, 30 Jul 2020 02:46:37 -0400 Received: from mail-ej1-f66.google.com ([209.85.218.66]:37500 "EHLO mail-ej1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725892AbgG3Gqh (ORCPT ); Thu, 30 Jul 2020 02:46:37 -0400 Received: by mail-ej1-f66.google.com with SMTP id qc22so12042345ejb.4; Wed, 29 Jul 2020 23:46:34 -0700 (PDT) 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:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=VvW/5770zwdEjP0loB0rGyzZeqTV1S8hvb/EOvhH5ns=; b=K8Ncut16Dy74iSG9N70LUm44js+zJp+txfKEKYYwBqHjgkUThhfCo3imov/f3AP8n3 +PoPDNORyU1WjCVCglgLVI7YwyfwCJ+ZtOQD6Xb/+KtWs3DPF3gqEsIncCTwMR//wALO 9FkiRljCU+X5smUasRL9m0fX9olSSKFzBwCJbg8x1Dj+nPICgp8DnfntODVd8ifdWj0q Qq7SNzh6/bXwSiMMGeKd+7GRsdhesXKK1nQ6CjJfzLFkBb8KtQiB1VPW1RxJ2m783qAk FLFkHFmcwbuEEcZBKZreLppkqGNBYfBa5AYWe35r+fMbLYfqe+ldRC9u379CantMyDOI DsSQ== X-Gm-Message-State: AOAM532XgSQUXyIUpjNBQW4scL7okC61NV5uHvVWINrKMqVLXQOuleSv DdUaJZ10lssrvG/IAxI3poYxsWdy X-Received: by 2002:a17:907:94c9:: with SMTP id dn9mr1149368ejc.355.1596091593696; Wed, 29 Jul 2020 23:46:33 -0700 (PDT) Received: from ?IPv6:2a0b:e7c0:0:107::49? ([2a0b:e7c0:0:107::49]) by smtp.gmail.com with ESMTPSA id t25sm4480562ejc.34.2020.07.29.23.46.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jul 2020 23:46:32 -0700 (PDT) Subject: Re: [PATCH] vgacon: fix out of bounds write to the scrollback buffer To: =?UTF-8?B?5byg5LqR5rW3?= , Solar Designer Cc: b.zolnierkie@samsung.com, Yang Yingliang , Kyungtae Kim , Linus Torvalds , Greg KH , "Srivatsa S. Bhat" , Anthony Liguori , xiao.zhang@windriver.com, DRI devel , Linux Fbdev development list , Linux kernel mailing list References: <20200729130710.GA13262@openwall.com> From: Jiri Slaby Autocrypt: addr=jslaby@suse.cz; prefer-encrypt=mutual; keydata= mQINBE6S54YBEACzzjLwDUbU5elY4GTg/NdotjA0jyyJtYI86wdKraekbNE0bC4zV+ryvH4j rrcDwGs6tFVrAHvdHeIdI07s1iIx5R/ndcHwt4fvI8CL5PzPmn5J+h0WERR5rFprRh6axhOk rSD5CwQl19fm4AJCS6A9GJtOoiLpWn2/IbogPc71jQVrupZYYx51rAaHZ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mlipAI5JBgE+5g9UOT4i69OmP/is3a/dHlFZ3 qjNk1EEGyvioeycJhla0RjakKw5PoETbypxsBTXk5EyrSdD/I2Hez9YGW/RcI/WC8Y4Z/7FS ITZhASwaCOzy/vX2yC6iTx4AMFt+a6Z6uH/xGE8pG5NbGtd02r+m7SfuEDoG3Hs1iMGecPyV XxCVvSV6dwRQFc0UOZ1a6ywwCWfGOYqFnJvfSbUiCMV8bfRSWhnNQYLIuSv/nckyi8CzCYIg c21cfBvnwiSfWLZTTj1oWyj5a0PPgGOdgGoIvVjYXul3yXYeYOqbYjiC5t99JpEeIFupxIGV ciMk6t3pDrq7n7Vi/faqT+c4vnjazJi0UMfYnnAzYBa9+NkfW0w5W9Uy7kW/v7SffH/2yFiK 9HKkJqkN9xYEYaxtfl5pelF8idoxMZpTvCZY7jhnl2IemZCBMs6s338wS12Qro5WEAxV6cjD VSdmcD5l9plhKGLmgVNCTe8DPv81oDn9s0cIRLg9wNnDtj8aIiH8lBHwfUkpn32iv0uMV6Ae sLxhDWfOR4N+wu1gzXWgLel4drkCJcuYK5IL1qaZDcuGR8RPo3jbFO7Y Message-ID: <659f8dcf-7802-1ca1-1372-eb7fefd4d8f4@kernel.org> Date: Thu, 30 Jul 2020 08:46:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=gbk 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, OTOH, you should have CCed all the (public) lists. On 30. 07. 20, 4:50, ???ƺ? wrote: > Zhang Xiao points out that the check should use > instead of >=, > otherwise the last line will be skip. > I agree with that, so I modify the patch. > Could you please verify that it is still correct and sufficient? IMO, yes, correct -- I was thinking about this yesterday too. Just an example: hypothetically, if we had: size_row = 1 tail = 29 size = 30 data[29] would be the last accessible member. Writing to data + tail (as "29 + 1 > 30" doesn't hold, so the modified check would pass), i.e. data[29] is still OK. So yes, > is OK, >= would waste space and would be actually incorrect. > BTW, Zhang Xiao also points out that the check after the memcpy can be > remove. > I also think that was right, but vgacon_scrollback_cur->tail may keep > the value vgacon_scrollback_cur->size in some case. That is not a > problem in vgacon_scrollback_update because of the check before the > memcpy. However, that may break some other code which assumes that > vgacon_scrollback_cur->tail won't be vgacon_scrollback_cur->size. I do > not know if there are such code, and if it is the code actually should > check it too. But I still not remove the check in the patch to make sure > it won't breaks other code. As I wrote about this yesterday: === I am also not sure the test I was pointing out on the top of this message would be of any use after the change. But maybe leave the code rest in peace. === I would let it as is in this particular code. Especially because vgacon_scrolldelta takes ->tail into consideration and I was too lazy to study the code there. But if you are willing to study the code there and confirm the check is superfluous, feel free to remove it. Perhaps in a separate patch. I was actually testing with the check removed and didn't hit any issue (which means, in fact, exactly nothing). > From ad143ede24ff4e61292cc9c96000100aacd97259 Mon Sep 17 00:00:00 2001 > From: Yunhai Zhang > Date: Tue, 28 Jul 2020 09:58:03 +0800 > Subject: [PATCH] Fix for missing check in vgacon scrollback handling > > vgacon_scrollback_update() always left enbough room in the scrollback "leaves enough" > buffer for the next call, but if the console size changed that room > might not actually be enough, and so we need to re-check. Also, could you add reasoning why you are adding the check to the loop and not outside (for instance, use your reasoning with numbers or CSI M as an example). Could you add a sample output here, something like I had: === This leads to random crashes or KASAN reports like: BUG: KASAN: slab-out-of-bounds in vgacon_scroll+0x57a/0x8ed === It's then easier to google for when this happens to someone who runs non-patched kernels. > This fixes CVE-2020-14331. > > Reported-and-debugged-by: ???ƺ? > Reported-and-debugged-by: Yang Yingliang > Reported-by: Kyungtae Kim > Fixes: 15bdab959c9b ([PATCH] vgacon: Add support for soft scrollback) > Cc: Linus Torvalds > Cc: Greg KH > Cc: Solar Designer > Cc: "Srivatsa S. Bhat" > Cc: Anthony Liguori > Cc: Yang Yingliang > Cc: Bartlomiej Zolnierkiewicz Oh, and we should: Cc: stable@vger.kernel.org > Signed-off-by: Yunhai Zhang > --- > drivers/video/console/vgacon.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c > index 998b0de1812f..37b5711cd958 100644 > --- a/drivers/video/console/vgacon.c > +++ b/drivers/video/console/vgacon.c > @@ -251,6 +251,10 @@ static void vgacon_scrollback_update(struct vc_data *c, int t, int count) > p = (void *) (c->vc_origin + t * c->vc_size_row); > > while (count--) { > + if ((vgacon_scrollback_cur->tail + c->vc_size_row) > > + vgacon_scrollback_cur->size) > + vgacon_scrollback_cur->tail = 0; > + > scr_memcpyw(vgacon_scrollback_cur->data + > vgacon_scrollback_cur->tail, > p, c->vc_size_row); thanks, -- js suse labs