Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2110216ioo; Mon, 23 May 2022 10:15:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEI8/jVV4dfA5LEnBFN3T9vixYYc8TyC41xyuqaKUZX921L9TLg+y5jRblIWqPTn617+5v X-Received: by 2002:a17:902:7fc2:b0:153:3c90:17b9 with SMTP id t2-20020a1709027fc200b001533c9017b9mr23841713plb.61.1653326147296; Mon, 23 May 2022 10:15:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653326147; cv=none; d=google.com; s=arc-20160816; b=f1Sk0CsDDcytbPnBA3OrWLMXV3phOvLPFe7J8I1psQH7enMItOQNUe3msgjtb4WJnG fARPzkuugC7lUnbhYc439JlyuXMMXqDVtt9AbPTHVaH4dIwYHPN1C4UcXCHeXV5piaOq HqQiu0QDkWMZ2szOCu3TnnqWJV2IHDq++2nglgDcREw6RZWK0vFa+CdJqYKie+W+Pf37 U+z0NGt3kKUOaRFeBkpiFtwTwsAd0fcoupOluxyztPAC43usqU5somNw+xW9DLBC/tBx rhw6AbzR6jPZwu1eShngyjI3I2zjziMkM601Z+nJ4Q8KOlc9e7wclhq3U3+7/JRg4X/5 sOfA== 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=cGgx2SOAQEcWr1rd9eP3tJDVvDS6ikNrQNzG6t1FTsI=; b=sqO2Qclb+aQJi7kFNpOr0n3TkLKD6m3btKYzlcc+0M1IfMAc0KVbEkdfm83yAZXEso fPIPBHRDJb9WRZKcwVGFKR8Dft+UejYQgSvxuSfmP5PhCLE5gMD96aJKe4nwgW2RMfWE 3eWyUBFA0srIQzd64VbvgfM05OsSQ5HmHQrekj4p3IrzBxGorbl+tQ6J5N+aq0xhrL8h USYYArTuvjDxCqJFpuvf1YgzWd45ipN3K3reDcMYutaPCoakZXGqvt+Lup58oI489j5O 6LO0r/nNSNumZRVFDv8wI10wjY8k6YZM5JSXmtsHtyGpbA29nVMCG0gkjD/ACCO4OZJD u/JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DuogWZft; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x15-20020a63b34f000000b003a007b8c222si11560036pgt.505.2022.05.23.10.15.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 10:15:47 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DuogWZft; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 322A0193C5; Mon, 23 May 2022 10:15:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240054AbiEWROl (ORCPT + 99 others); Mon, 23 May 2022 13:14:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240482AbiEWRM3 (ORCPT ); Mon, 23 May 2022 13:12:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1849583AB; Mon, 23 May 2022 10:11:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ABF29614EB; Mon, 23 May 2022 17:09:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91CFBC34115; Mon, 23 May 2022 17:09:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653325786; bh=4rBaSOrIJjKLFiIam8gz65RXThh97E5diUSE/kUbUD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DuogWZftBiuZAFqxiVk4hXngnMU431IQq3vTdL4hKfndcL3DXqB4C1UgvLEEIodP/ CRGyCHE8TnGLNJdDRtmxv7M+Lv9SwUUE1eybSoXFFIqoodzem8K9s6ExjbEI+NT5+V N4u1NKEmo0kySmNG0fYcJvH4Ky5FKABE52r5/mx8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Tomasz=20Mo=C5=84?= , Jeff LaBundy , Dmitry Torokhov , Sasha Levin Subject: [PATCH 4.19 03/44] Input: add bounds checking to input_set_capability() Date: Mon, 23 May 2022 19:04:47 +0200 Message-Id: <20220523165754.069303666@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165752.797318097@linuxfoundation.org> References: <20220523165752.797318097@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jeff LaBundy [ Upstream commit 409353cbe9fe48f6bc196114c442b1cff05a39bc ] Update input_set_capability() to prevent kernel panic in case the event code exceeds the bitmap for the given event type. Suggested-by: Tomasz Moń Signed-off-by: Jeff LaBundy Reviewed-by: Tomasz Moń Link: https://lore.kernel.org/r/20220320032537.545250-1-jeff@labundy.com Signed-off-by: Dmitry Torokhov Signed-off-by: Sasha Levin --- drivers/input/input.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/input/input.c b/drivers/input/input.c index a0d90022fcf7..dcbf53b5b2bc 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -50,6 +50,17 @@ static DEFINE_MUTEX(input_mutex); static const struct input_value input_value_sync = { EV_SYN, SYN_REPORT, 1 }; +static const unsigned int input_max_code[EV_CNT] = { + [EV_KEY] = KEY_MAX, + [EV_REL] = REL_MAX, + [EV_ABS] = ABS_MAX, + [EV_MSC] = MSC_MAX, + [EV_SW] = SW_MAX, + [EV_LED] = LED_MAX, + [EV_SND] = SND_MAX, + [EV_FF] = FF_MAX, +}; + static inline int is_event_supported(unsigned int code, unsigned long *bm, unsigned int max) { @@ -1915,6 +1926,14 @@ EXPORT_SYMBOL(input_free_device); */ void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code) { + if (type < EV_CNT && input_max_code[type] && + code > input_max_code[type]) { + pr_err("%s: invalid code %u for type %u\n", __func__, code, + type); + dump_stack(); + return; + } + switch (type) { case EV_KEY: __set_bit(code, dev->keybit); -- 2.35.1