Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp876667imj; Fri, 15 Feb 2019 08:14:50 -0800 (PST) X-Google-Smtp-Source: AHgI3IYtCAK5dDirQO1No0rSrUJKx7nYSjHPNe70qDVree4j42Lz5w9ipOCG4SXuy6ONNTiBa/8m X-Received: by 2002:aa7:80c8:: with SMTP id a8mr10493707pfn.27.1550247290347; Fri, 15 Feb 2019 08:14:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550247290; cv=none; d=google.com; s=arc-20160816; b=ip+vq3VDMTxUbzD/12ZwLTklMLiukL0AAXMH4Wj25v52qdwh3H/hg+XB8rZiTd5Ydo itmgNnsV4mWKFu06JreiDYtMptWzdyPnErx46OdCHO0lrPFqlAtntc277DEgHmIADCmB QD6zFTzFDFcUFt6SQDy8VRRqW3yNVG5ScZ8a37Eq1sqKJFEPVlSgZFoPU1oIcIE8MEW0 QuAi9a2W9YUW8U71oHz1ydcZZWc+7LbkNDKwswfeUvlKoRROwt3w6CR7kzUJywJP2PI5 pr9I3Cqj3y/CIV3IPUHdfhjqIOAUdLBa7t87isWf9HUf25PzCfUUhb/bMbz6xRO+QIJF Bqhw== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Ub+02h/K5AUUGJKO7hIeNp6LOFzOw9WcvmBmDb8mbBY=; b=NSTRthK4S/+Pjx5sGsGHl0KdHX4eaIJO4YCosXe26F+pa83wr+qoSJI2qeMLg0lDJi HTjM4PM2BDojBv0C2x7Xc2wIMdPP/AZg2gicKEdkBOMPw/Kt7oe6cWPrT2z0hQkA3yH0 yW7bFs692OPbj401YHU/m+fuJlDedQ2eqXVkiqJM76zQ5mjcVt8QJXj/7uoYyDs80WBz XqZQk4MtZkAYP76kF6k3oo2BDbZLBGw70Twa+NgHgudBriP4y6D8GUppmJzdnly9eBoJ 8f4rqXYSIDFII8lgBR43+pJtEmbwzItypoAClYlpTNwOQJvl3uxsAjSw7bxq+z6slPFG PMWA== 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 x7si5895643pfe.257.2019.02.15.08.14.34; Fri, 15 Feb 2019 08:14:50 -0800 (PST) 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 S2406096AbfBOM2X (ORCPT + 99 others); Fri, 15 Feb 2019 07:28:23 -0500 Received: from mout.gmx.net ([212.227.17.22]:54925 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406082AbfBOM2W (ORCPT ); Fri, 15 Feb 2019 07:28:22 -0500 Received: from localhost.localdomain ([218.18.229.179]) by mail.gmx.com (mrgmx103 [212.227.17.174]) with ESMTPSA (Nemesis) id 0M7Y9j-1hFAQe167L-00xKFG; Fri, 15 Feb 2019 13:28:20 +0100 From: Chengguang Xu To: gregkh@linuxfoundation.org Cc: viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, Chengguang Xu Subject: [PATCH v2 2/4] chardev: add a check for given minor range Date: Fri, 15 Feb 2019 20:27:12 +0800 Message-Id: <20190215122714.28842-2-cgxu519@gmx.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190215122714.28842-1-cgxu519@gmx.com> References: <20190215122714.28842-1-cgxu519@gmx.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Provags-ID: V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ZwQmMdX8Q5UpTJVEutMsUke+V+EAiKFp8tgiKDRnx9wud vnxdK4L8ONJMYl94hpKJVh/5oi4PzVsKfppVYlxL2Nhc7ei6wh1LALHNrsVaAJd8qxl+R/997 zBTbQl1pq9vWp0hOAMiopC7HNP43aOAtSu51Z78AEWmaS5IkviOmQp16YC7Qs+ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org register_chrdev_region() carefully checks minor range before calling __register_chrdev_region() but there is another path from alloc_chrdev_region() which does not check the range properly. So add a check for given minor range in __register_chrdev_region(). Signed-off-by: Chengguang Xu --- v1->v2: - Split fix and cleanup patches. - Remove printing minor range in chrdev_show(). fs/char_dev.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/char_dev.c b/fs/char_dev.c index 8a63cfa29005..6803e98414f1 100644 --- a/fs/char_dev.c +++ b/fs/char_dev.c @@ -104,6 +104,12 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor, int ret = 0; int i; + if (minorct > MINORMASK + 1 - baseminor) { + pr_err("CHRDEV \"%s\" minor range requested (%u-%u) is out of range of maximum range (%u-%u) for a single major\n", + name, baseminor, baseminor + minorct - 1, 0, MINORMASK); + return ERR_PTR(-EINVAL); + } + cd = kzalloc(sizeof(struct char_device_struct), GFP_KERNEL); if (cd == NULL) return ERR_PTR(-ENOMEM); -- 2.20.1