Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp959421ybb; Sat, 28 Mar 2020 14:34:03 -0700 (PDT) X-Google-Smtp-Source: ADFU+vshIlv00e5aKuSwWoRLVgJ5AUloREe12I1VpepbB2FrgL0avZ/wH1M+eiHHsaGgKbEEQkCk X-Received: by 2002:aca:4986:: with SMTP id w128mr3254562oia.46.1585431243602; Sat, 28 Mar 2020 14:34:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585431243; cv=none; d=google.com; s=arc-20160816; b=smN+EMaf18KoLlJfXhr4Q3Za4mmkjZv1l+vb04xG0B/PtxMzP6Qxjw0RHSK+0sOdym albJ8ha2m8fr3EVRo4vlpUXP1kOA2S9edvpJbhs9FbnXqevOmbI/UDL2gme4kGf+ngj4 r70b0Tm8pQzVzeR8d2hHrWxBzAWKB9d8IsBuvZfjQZyUVQtxlSf3CbfJajjMaFLnHCqA UjSSJ1CDz9cXfQapdsh9npecBaEu8EW8mhca7GY0MahphR2pX/MngndHNuB+tIjp8Pvr oaSvLCht4geOhOLak0uMtOi6rS06pZF9IkcTjA6cU9WBRNmH52lEKYmkOoIC8Xfjh1g5 iL1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature:dkim-signature; bh=b08+ACMRd0Ds8qEXYoDlU+PFuETjWg7Rod3YfbGZWPE=; b=OgyiEzCs4oQdlPw+rJdcnyL2vmi2g3DGz19HtXZv8EIDZ0olRhAP+ihDqhT//A+2oe mnuLehAn2a8occWPuLJ0ZB6VegObmtABRTOnha+/+avgwFx0k59NpJscT54aw9OmLi48 zxFKKW6FuB2BU17N3K1OFhu1FDaKmehyZEeOLIuCBTV089DX/jk7Se5DCWsAscok4RtS AXwib/58hgSVH8gmHfL+W2u7/c3PuqT/XDmHPJ5NBKkJcP4EVGQ42A6R04pVn8VVu3Rc uG7ZK2bTJCO+evhOkIj6ng0OZFqRtu/0eZrv3jdEXuE1oEIJnXqU8R5gg8Fgjcu709No ByOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pobox.com header.s=sasl header.b=E3o+qHGz; dkim=temperror (no key for signature) header.i=@fluxnic.net header.s=2016-12.pbsmtp header.b=yH8DcDUo; 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 l21si2865846otd.63.2020.03.28.14.33.51; Sat, 28 Mar 2020 14:34:03 -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=@pobox.com header.s=sasl header.b=E3o+qHGz; dkim=temperror (no key for signature) header.i=@fluxnic.net header.s=2016-12.pbsmtp header.b=yH8DcDUo; 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 S1727718AbgC1Vcu (ORCPT + 99 others); Sat, 28 Mar 2020 17:32:50 -0400 Received: from pb-smtp20.pobox.com ([173.228.157.52]:63114 "EHLO pb-smtp20.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726604AbgC1Vcu (ORCPT ); Sat, 28 Mar 2020 17:32:50 -0400 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 365FDC1CA3; Sat, 28 Mar 2020 17:32:48 -0400 (EDT) (envelope-from nico@fluxnic.net) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=date:from:to :cc:subject:message-id:mime-version:content-type; s=sasl; bh=tuv 2YoU2aL/2c/u/7jXp1zqbclA=; b=E3o+qHGz8/UGzrLdSBc4UdXQWZAInqosNDD nOSJ66aD+4VeWLOLC03WXeVZFZ0gOwCjNMKx+GJuo6hlt4jXeurcRJl93g8zJHl7 CAZkYvIzrjOUmiJ7x/EOJhYcb+0tepAw8Jx3WouQN8UxSNKLrTBg9NCrOCo2AShH QhtJAttM= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 2C468C1CA2; Sat, 28 Mar 2020 17:32:48 -0400 (EDT) (envelope-from nico@fluxnic.net) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=fluxnic.net; h=date:from:to:cc:subject:message-id:mime-version:content-type; s=2016-12.pbsmtp; bh=t4YwzAUHQeJQ27J5HRnM1y/AWnEpgYbN1AeSv1YdeuA=; b=yH8DcDUoYmDzjtD1P2XAigNE7y7BVD5VE4e1C+C9ii2z1uknM88c/7P2UftIoJLKvps8hYGn7TvHW5sa3NuudidCp7YmKzO5n3lTnsHMHiaXa08z2ZvuzVc15h+9lQqZltWNQI+Yk95r1K/WDYeOkQ2CM7Jj9mGksmTk8FOtuHs= Received: from yoda.home (unknown [24.203.50.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 0B6A4C1CA1; Sat, 28 Mar 2020 17:32:45 -0400 (EDT) (envelope-from nico@fluxnic.net) Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTPSA id 161A82DA0174; Sat, 28 Mar 2020 17:32:43 -0400 (EDT) Date: Sat, 28 Mar 2020 17:32:42 -0400 (EDT) From: Nicolas Pitre To: gregkh@linuxfoundation.org cc: Adam Borowski , Chen Wandun , jslaby@suse.com, daniel.vetter@ffwll.ch, sam@ravnborg.org, b.zolnierkie@samsung.com, lukas@wunner.de, ghalat@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH] vt: don't hardcode the mem allocation upper bound Message-ID: User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Pobox-Relay-ID: A99919B0-713B-11EA-9914-B0405B776F7B-78420484!pb-smtp20.pobox.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code in vc_do_resize() bounds the memory allocation size to avoid exceeding MAX_ORDER down the kzalloc() call chain and generating a runtime warning triggerable from user space. However, not only is it unwise to use a literal value here, but MAX_ORDER may also be configurable based on CONFIG_FORCE_MAX_ZONEORDER. Let's use KMALLOC_MAX_SIZE instead. Note that prior commit bb1107f7c605 ("mm, slab: make sure that KMALLOC_MAX_SIZE will fit into MAX_ORDER") the KMALLOC_MAX_SIZE value could not be relied upon. Signed-off-by: Nicolas Pitre Cc: # v4.10+ diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 15d2769805..37c5f21490 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -1193,7 +1193,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 > (4 << 20)) + if (new_screen_size > KMALLOC_MAX_SIZE) return -EINVAL; newscreen = kzalloc(new_screen_size, GFP_USER); if (!newscreen)