Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3964102pxb; Mon, 4 Oct 2021 13:51:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5KlXGm0MOzYt7RFJQGVb+q4ZCtVMGdoJxzLnT9rTQpMvZba1JN+7KfEAq0aKwfjuiEnOh X-Received: by 2002:a05:6402:1e88:: with SMTP id f8mr20544504edf.126.1633380683566; Mon, 04 Oct 2021 13:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633380683; cv=none; d=google.com; s=arc-20160816; b=h+7coA9sgCNonOgEarIcwY++Jrw2Ev8sbTuzI/wRv70uGJNFOqT9qkKps5/QfpPj5G 6fkaxbUHcBhxiMDb3OlRDB190V6XDkOGb3JJO0mo92xBCRpcIRPMKNLxoBtT5LvJMWua vuz1pRyPd+IisnaIxo/2pqVtI6QlMcEFDJ2IIX0HCqSwzUNuMZl0MoYXvgXf/7cNhRSP a73m2tmmJ30NsQbYS3+F1YBad+ZzW78vclaJFLLSvpuElpVzLhyIZgjE/0h60HLiDmio je/ATEfSboYEGZXc3KOeOKUMsZFsrvRvMIJ4vNK25TPaJ2yt96J/Z6ilh3JjGxR42/yJ z7mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6JvTcg3Z7LUjjQWfd47/4z22JMZGl5J4Z7iZc+nNUto=; b=N2Ll1SFM/ZXNmBF4idwGSWGov7CG+JzRoQWyGTtjZ+MR9w5v+rUI4IbYz7rM1LknQd /ISl+GUDWTx9NeEzkFJ5PRoksLV2zLzOf7OZ/SzEMNnp4cCPUK6PvDtLa/W+ukboXe9t ESqVpSdAn0nT0+QC1hFxZNPqp+nwK+2Go3iAg6S4JjzOuxtu1eq5hoFkFlsLPXpIDw3H HFDxMshMskrOdINT41HW35YCcOBhk+quT8QLgEqN3Fc6XT8vm/7ON3s0mNW/sCQ1SMOS Fl8ektXtPJgUPOha4m0XyfWnoivz1cWTlyLj/964YCBeAC9gL3EsDV6WIX3tjAvLgl5H jhbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pWfKAbRl; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q3si19391241edw.140.2021.10.04.13.50.59; Mon, 04 Oct 2021 13:51:23 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pWfKAbRl; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237787AbhJDNlI (ORCPT + 99 others); Mon, 4 Oct 2021 09:41:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:53358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238079AbhJDNjC (ORCPT ); Mon, 4 Oct 2021 09:39:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3E2DA6323A; Mon, 4 Oct 2021 13:18:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353486; bh=623FplseSe4mF/o7DtESWhLIbFvpBnAtd8YcM7CFvTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pWfKAbRlSmIV8884cSXSEYiT7l7iWQbX6CMqBDbyYaQc1uC15SU03JsELMlzFaS64 zKtg4JiUfwlZyUeVo9asDzzyAbEaK6uhiaYluaDspbmjTCHmquk6cJG3e133Zd1vhD wXuQx6PlTFZMlmatJln5LFReq1ORWe2xNklzp8CU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Samuel Iglesias Gonsalvez , Johan Hovold Subject: [PATCH 5.14 148/172] ipack: ipoctal: fix stack information leak Date: Mon, 4 Oct 2021 14:53:18 +0200 Message-Id: <20211004125049.744454878@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johan Hovold commit a89936cce87d60766a75732a9e7e25c51164f47c upstream. The tty driver name is used also after registering the driver and must specifically not be allocated on the stack to avoid leaking information to user space (or triggering an oops). Drivers should not try to encode topology information in the tty device name but this one snuck in through staging without anyone noticing and another driver has since copied this malpractice. Fixing the ABI is a separate issue, but this at least plugs the security hole. Fixes: ba4dc61fe8c5 ("Staging: ipack: add support for IP-OCTAL mezzanine board") Cc: stable@vger.kernel.org # 3.5 Acked-by: Samuel Iglesias Gonsalvez Signed-off-by: Johan Hovold Link: https://lore.kernel.org/r/20210917114622.5412-2-johan@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/ipack/devices/ipoctal.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) --- a/drivers/ipack/devices/ipoctal.c +++ b/drivers/ipack/devices/ipoctal.c @@ -264,7 +264,6 @@ static int ipoctal_inst_slot(struct ipoc int res; int i; struct tty_driver *tty; - char name[20]; struct ipoctal_channel *channel; struct ipack_region *region; void __iomem *addr; @@ -355,8 +354,11 @@ static int ipoctal_inst_slot(struct ipoc /* Fill struct tty_driver with ipoctal data */ tty->owner = THIS_MODULE; tty->driver_name = KBUILD_MODNAME; - sprintf(name, KBUILD_MODNAME ".%d.%d.", bus_nr, slot); - tty->name = name; + tty->name = kasprintf(GFP_KERNEL, KBUILD_MODNAME ".%d.%d.", bus_nr, slot); + if (!tty->name) { + res = -ENOMEM; + goto err_put_driver; + } tty->major = 0; tty->minor_start = 0; @@ -372,8 +374,7 @@ static int ipoctal_inst_slot(struct ipoc res = tty_register_driver(tty); if (res) { dev_err(&ipoctal->dev->dev, "Can't register tty driver.\n"); - put_tty_driver(tty); - return res; + goto err_free_name; } /* Save struct tty_driver for use it when uninstalling the device */ @@ -410,6 +411,13 @@ static int ipoctal_inst_slot(struct ipoc ipoctal_irq_handler, ipoctal); return 0; + +err_free_name: + kfree(tty->name); +err_put_driver: + put_tty_driver(tty); + + return res; } static inline int ipoctal_copy_write_buffer(struct ipoctal_channel *channel, @@ -697,6 +705,7 @@ static void __ipoctal_remove(struct ipoc } tty_unregister_driver(ipoctal->tty_drv); + kfree(ipoctal->tty_drv->name); put_tty_driver(ipoctal->tty_drv); kfree(ipoctal); }