Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp462849ybt; Fri, 10 Jul 2020 04:33:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxakGtUrbEUlwe18FYHbPjf7/ggfUSy5VK3m+QUofSxLU/msNq5vdIAufnyl2TxU0P/vYF0 X-Received: by 2002:a17:906:f98e:: with SMTP id li14mr60327461ejb.174.1594380784258; Fri, 10 Jul 2020 04:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594380784; cv=none; d=google.com; s=arc-20160816; b=S3AqHrvSREuoQEOS63eO5yy9RzxGKK+QoTyWnHHKVwrPJvRuc5Tdskr+j/D0bjix/V TbwXbClOlhXYHqhWGJ78Wu5IbBcJ84kfGOdJQAZwqp2wcJjPirpZVR1VTQkXoCAuRk/P 4STl+Ryl4ChKG2whur3wbaHTXsGteSFeO2XAVAuInkjh5bsO7VFyFuYyDQxI7eCvSW/i ORTAxa759Fz9VE+nmDYCRdGSAXQXz522WXuuQoslBTWg0ohQe5bg+Jph5F8eVq2FtKs8 Qj53Iq6WDgHQtvt6OPHbm6C+L1OaOXxn3wRyHFc2kpf53N5GiXb7Sb2C0NMj3+WV84PQ dLqA== 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:from:references:cc:to:subject; bh=Y/Cmfq48TRw85DTDAORzgUIDwcUYRvogKcUbQ+Z1nek=; b=Q5n56FaxQF9TTon/brP3hw9psmjgQ1X20xA2CYqdNoaC8r1YNR6yIdswlYCrtvqVKt OFCcrgVgEUz8MS4aLbebFZ94gC6tdqTc14mqEOwV2ttG5YRarkv13Th5Svk7ejlQbrUy ic439IMgbJSe8a789Ef4MB/7g9HCLWutme3OFHEfQwbw3mbmzY/lG3YVZR7pr+txD2lK 3+N7yicPX46twBKr9R+uCr2O0Ar6S4EJ4tV/2xGrW2XuJakbt9VxFx4dO8vOH6zJpLpg NigPyUldR7DnJSEhq9jX6SES0ceHu03CTTSBvtMj90WikShnseV47W78eRsPW1oAwWO8 lWMQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k21si4072983eds.345.2020.07.10.04.32.41; Fri, 10 Jul 2020 04:33:04 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728024AbgGJLcD (ORCPT + 99 others); Fri, 10 Jul 2020 07:32:03 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:62577 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727943AbgGJLcC (ORCPT ); Fri, 10 Jul 2020 07:32:02 -0400 Received: from fsav110.sakura.ne.jp (fsav110.sakura.ne.jp [27.133.134.237]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 06ABVlOt059266; Fri, 10 Jul 2020 20:31:47 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav110.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav110.sakura.ne.jp); Fri, 10 Jul 2020 20:31:47 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav110.sakura.ne.jp) Received: from [192.168.1.9] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 06ABVl9i059263 (version=TLSv1.2 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 10 Jul 2020 20:31:47 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Subject: Re: [PATCH] vt: Reject zero-sized screen buffer size. To: Greg Kroah-Hartman Cc: Jiri Slaby , Dmitry Vyukov , linux-kernel@vger.kernel.org, syzbot References: <20200710055329.3759-1-penguin-kernel@I-love.SAKURA.ne.jp> <20200710105500.GA1232395@kroah.com> From: Tetsuo Handa Message-ID: <7adf8aee-9bdd-8184-6cbe-291357677edd@i-love.sakura.ne.jp> Date: Fri, 10 Jul 2020 20:31:42 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200710105500.GA1232395@kroah.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/07/10 19:55, Greg Kroah-Hartman wrote: >> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c >> index 48a8199f7845..8497e9206607 100644 >> --- a/drivers/tty/vt/vt.c >> +++ b/drivers/tty/vt/vt.c >> @@ -1126,7 +1126,7 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */ >> con_set_default_unimap(vc); >> >> vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_KERNEL); >> - if (!vc->vc_screenbuf) >> + if (ZERO_OR_NULL_PTR(vc->vc_screenbuf)) > > No, let's check this before we do kzalloc() please, that's just an odd > way of doing an allocation we shouldn't have had to do. OK. I can change to + if (vc->vc_screenbuf_size > KMALLOC_MAX_SIZE || !vc->vc_screenbuf_size) + goto err_free; vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_KERNEL); if (!vc->vc_screenbuf) goto err_free; like vc_do_resize() does. But I'm currently waiting for syzbot to test this patch, for I don't have an environment for reproducing this problem. > >> goto err_free; >> >> /* If no drivers have overridden us and the user didn't pass a >> @@ -1212,7 +1212,7 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc, >> if (new_cols == vc->vc_cols && new_rows == vc->vc_rows) >> return 0; >> >> - if (new_screen_size > KMALLOC_MAX_SIZE) >> + if (new_screen_size > KMALLOC_MAX_SIZE || !new_screen_size) >> return -EINVAL; >> newscreen = kzalloc(new_screen_size, GFP_USER); >> if (!newscreen) >> @@ -3393,6 +3393,7 @@ static int __init con_init(void) >> INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); >> tty_port_init(&vc->port); >> visual_init(vc, currcons, 1); >> + /* Assuming vc->vc_screenbuf_size is sane here, for this is __init code. */ > > Shouldn't we also check this here, or before we get here, too? This is an __init function. Can we somehow pass column=0 or row=0 ? > > Just checking the values and rejecting that as a valid screen size > should be sufficient. Hmm, where are we checking that column * row does not exceed UINT_MAX, given that "struct vc_data"->vc_{cols,rows,screenbuf_size} are "unsigned int" and we do vc->vc_size_row = vc->vc_cols << 1; vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row; in visual_init() ? Don't we need to reject earlier?