Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp701680ybe; Thu, 19 Sep 2019 02:21:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0wkjV+1gPQA7jBl6CAfBTojcBhBtsv4ayiNxSKO9XGOs7v0o/A0gq7IvXBd2zyq4+x3hM X-Received: by 2002:a50:d51b:: with SMTP id u27mr14786304edi.249.1568884909025; Thu, 19 Sep 2019 02:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568884909; cv=none; d=google.com; s=arc-20160816; b=nJHkZgzbMvGg3bqCEvPfZ4qMbo9sbI17nFUnK/KpbVtiEVKZOymn3jVSReABAojgjV 6ohppkAgGFcLDrW8XSyK1bm3WeK+JIaK9Eh6itph3xo8Lj84Zu+e6bXfV37NJ3vvHkep QGP7s85jR2oOMM39AP/ZvBB9H3p4UpOuYH978MPgNSZHL8hJOEpIvk5JCj5/icoHecc4 EDZ30wUbkOUENf2zxwwwBA2cYhHd0epnV6iV+F8TCzV9WAF4igSl7BOmmzWFn0ZD/HbR NB1UUqVphMWEJDpkSYmw6PbsqBvHsN7GWKpmZUYg2Umajr2ThNSjkeDoS5IuNT9zbVSI 00ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=al6Pw1iZ5ncawPD+qean/R5PSeUd1FzfxAmQAFZj1EI=; b=pJpXCzN+32RCQ9IKNqkSpOnjnESlZI/uk18Kbnv58eocRy6ppdKmaVrMDQNJ5n7gTi ygoGakFLypQ4EvquzczJAR8zVDei++Hj4KBV9eYJ6ChxnVDCbe2z698l1Vhuj8uV3ZLS VYVAlX1qGG99hLkAgdzqAO+02N9ESIboImw+ooXiR+dYs7dxzuqSvYRDnWQgH3Cyg6W4 GqPNEPMgpkMRFUOoB5lA0MxQTpSzig+tWbmsF8YRhjRwK/C4WpYEuRXoVh+7mgR/xFgL oCuyr/TmWJyPjeyOmf24hjckq5TJ39jW7uH9gOIaYAhdOPVk6XldG+D+UigYNo27oLUk HMAg== ARC-Authentication-Results: i=1; mx.google.com; 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 d12si4011151ejj.369.2019.09.19.02.21.26; Thu, 19 Sep 2019 02:21:49 -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; 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 S2388793AbfISJSb (ORCPT + 99 others); Thu, 19 Sep 2019 05:18:31 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:55016 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387757AbfISJSb (ORCPT ); Thu, 19 Sep 2019 05:18:31 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id AC69EA8542200CA7C669; Thu, 19 Sep 2019 17:18:29 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.439.0; Thu, 19 Sep 2019 17:18:20 +0800 From: Xiaoming Ni To: , , CC: , , , , , , , , , Subject: [PATCH] tty:vt: Add check the return value of kzalloc to avoid oops Date: Thu, 19 Sep 2019 17:18:15 +0800 Message-ID: <1568884695-56789-1-git-send-email-nixiaoming@huawei.com> X-Mailer: git-send-email 1.8.5.6 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.189.174] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using kzalloc() to allocate memory in function con_init(), but not checking the return value, there is a risk of null pointer references oops. Signed-off-by: Xiaoming Ni --- drivers/tty/vt/vt.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 34aa39d..db83e52 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -3357,15 +3357,33 @@ 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 (unlikely(!vc)) { + pr_warn("%s:failed to allocate memory for the %u vc\n", + __func__, currcons); + break; + } 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 (unlikely(!vc->vc_screenbuf)) { + pr_warn("%s:failed to allocate memory for the %u vc_screenbuf\n", + __func__, currcons); + visual_deinit(vc); + tty_port_destroy(&vc->port); + kfree(vc); + vc_cons[currcons].d = NULL; + break; + } vc_init(vc, vc->vc_rows, vc->vc_cols, currcons || !vc->vc_sw->con_save_screen); } currcons = fg_console = 0; master_display_fg = vc = vc_cons[currcons].d; + if (unlikely(!vc)) { + console_unlock(); + return 0; + } set_origin(vc); save_screen(vc); gotoxy(vc, vc->vc_x, vc->vc_y); -- 1.8.5.6