Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5933515ybi; Wed, 12 Jun 2019 10:57:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqy77XUfPhdhn+dHknwJ7gJ2QYMMFzKxEJ3CwuCVv8//SHVfe7S5/7z4TbTb7mt9eslU5FKW X-Received: by 2002:a17:90a:6544:: with SMTP id f4mr438687pjs.17.1560362270477; Wed, 12 Jun 2019 10:57:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560362270; cv=none; d=google.com; s=arc-20160816; b=S7TF0cb1ynClBO3HRnmtIbbcGD0Ki6M2Qw6l+0XeNVfLmVzLwvFOSrpS9kTxPrPL2l Vso1Oro/Pwq+lnz1eI/9LlFJEGkoZHqnM7YQvdw6f7SoBlgOpUE4XYHV1beon1oqKwI/ Yc1iSuEZvFYautn6RtT9g9PmhumAeOmYwdsqgmWAxldluS7ZvaJHdGncJvnPRY+Vjh/U PC6jZBJZ8PTqB+ieCg1Iim0OoZiBbPWlGq72KcAzl7fwuB/bCBUM2RXh2holjXIuEL5k GGJDUfrpjiqZyh++IkttMdkxPj4EWAVgo66nszT9kZNliNiGsyQ9u2AihMYkr0E2eK/f 445g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=S7gYL9MQAqJJl42POKnYTZhA1fNy6NXQksgxdieePNA=; b=lteMJy7nssyENhLDo+2fUXJONp9TfFg45BFcOeFkN9g1qRUpNAWMqAfyZGB6njjnwo IDq1ba6tAyF1t/KH6+9oxRnOhvCTPzK40q/DiYJXgTD/FP4NWbqRZVdro/4Ncab9dlxQ Z5+lAfKl0B2znmR1NyvnKTmKqf4pikJaJjH5PQTsVWJdQTOq3P/t+WsZYoxuR2p3s4NG 7WoTQ4wVfR2t17eIRUE5v9z6t/aix0owyz9zsVpRN8A399PdWJ2iJTQR2NKCTEi/H9V9 6ooQL2rl7sUYLbszODOVy2Q0zUjE35SGj17qrMNiB1UvN56rzp8cXVkBxkOJSi2W72xT 3QxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LWspt71x; 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 v4si386847pgr.475.2019.06.12.10.57.35; Wed, 12 Jun 2019 10:57:50 -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=@gmail.com header.s=20161025 header.b=LWspt71x; 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 S1729161AbfFLNPS (ORCPT + 99 others); Wed, 12 Jun 2019 09:15:18 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:55177 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727102AbfFLNPS (ORCPT ); Wed, 12 Jun 2019 09:15:18 -0400 Received: by mail-wm1-f66.google.com with SMTP id g135so6546641wme.4 for ; Wed, 12 Jun 2019 06:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=S7gYL9MQAqJJl42POKnYTZhA1fNy6NXQksgxdieePNA=; b=LWspt71xGTH7IU6YaesxzKNTXMxJrT5V08RvFUpfFnryMaqw+T/Db3y6fqI2+Naid6 310c3UzFccv9bwithR8Oo9kjjfngvUMiW7vOs3NNcunBkW7ZCq0YDBbBuPoO+OUiOsYu zB33EA4oa2t3FlBFBg2RvzGoro0GsAd0ufZQJqcghPef7E9Ja+0VrMYmPEBsuCVHYbq3 wyfkzdp3BQtVpE97oWNSR5cz/CsLfkNr6xi7RYwnPaGrkt9TskRD9+XS4eTqHcEZFNGN 0tZylGo5SuJQG6D06xk79TGAF2dwvxQmdBHfpjCd0lO8ZK0RnRn+jrdzJCsWZAsz2Tyr UYDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=S7gYL9MQAqJJl42POKnYTZhA1fNy6NXQksgxdieePNA=; b=VEXGcoReWCp63cY/XbIEPlxx1DVRyhIzgfgc3EKjpyJljUM0bcqTSB8pRyE29gFbLG d2R5n5TaKFrWCnwpqsCtlNLgLwYrSX12k1z7idOI5NjxVJoXBn83QAlNeMQ+CpNLOe7x 9ybHdyItSfmyzW/DRnvyR4b6LGJWqN1xolykUHdUDJNunbTh5283dXHJQMX89kBlKIQF Zjgsyd+ZtXfRag4B9EPf0KEXok1SJWzYpJnHHGQIOfSbjTyVFjmVZGsVoO13Wkb9avQi /UAddSV/QOWH9L/lC1TWqEWcwFN5LUtFpUzmINBA593T0Z6HLWD7x0qzx50+d4THw+sX XCOg== X-Gm-Message-State: APjAAAWQNqWKqthJjBjKchyTVd60TpVkaUx3yThQ3t1HifwtwoTeiOuW zer+cW8+Cg/lfGwOmvSa8BQ= X-Received: by 2002:a1c:ef10:: with SMTP id n16mr20120978wmh.134.1560345316503; Wed, 12 Jun 2019 06:15:16 -0700 (PDT) Received: from zhanggen-UX430UQ ([108.61.173.19]) by smtp.gmail.com with ESMTPSA id c4sm4640654wmf.43.2019.06.12.06.15.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jun 2019 06:15:15 -0700 (PDT) Date: Wed, 12 Jun 2019 21:15:06 +0800 From: Gen Zhang To: gregkh@linuxfoundation.org, nico@fluxnic.net, kilobyte@angband.pl, textshell@uchuujin.de, mpatocka@redhat.com, daniel.vetter@ffwll.ch Cc: linux-kernel@vger.kernel.org Subject: [PATCH v4] vt: fix a missing-check bug in con_init() Message-ID: <20190612131506.GA3526@zhanggen-UX430UQ> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In function con_init(), the pointer variable vc_cons[currcons].d, vc and vc->vc_screenbuf is allocated by kzalloc(). However, kzalloc() returns NULL when fails. Therefore, we should check the return value and handle the error. Signed-off-by: Gen Zhang --- diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 5c0ca1c..dc40e29 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -3357,10 +3357,14 @@ static int __init con_init(void) for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) { vc_cons[currcons].d = vc = kzalloc(sizeof(struct vc_data), GFP_NOWAIT); + if (!vc) + goto vc_err; INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); tty_port_init(&vc->port); visual_init(vc, currcons, 1); vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_NOWAIT); + if (!vc->vc_screenbuf) + goto vc_screenbuf_err; vc_init(vc, vc->vc_rows, vc->vc_cols, currcons || !vc->vc_sw->con_save_screen); } @@ -3382,6 +3386,16 @@ static int __init con_init(void) register_console(&vt_console_driver); #endif return 0; +vc_err: + while (currcons > 0) { + currcons--; + kfree(vc_cons[currcons].d->vc_screenbuf); +vc_screenbuf_err: + kfree(vc_cons[currcons].d); + vc_cons[currcons].d = NULL; + } + console_unlock(); + return -ENOMEM; } console_initcall(con_init);