Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2104745ioo; Mon, 23 May 2022 10:09:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXRTEomm7jSuDadHhM0vYv0dgGji2e7c/Grx1h/3abud0i1N2iEwZ2I7p/M2wHVvjXf+lf X-Received: by 2002:a17:90b:1e53:b0:1df:c858:7c5d with SMTP id pi19-20020a17090b1e5300b001dfc8587c5dmr26833441pjb.203.1653325771535; Mon, 23 May 2022 10:09:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653325771; cv=none; d=google.com; s=arc-20160816; b=pls1l77fSjOQSanW31f8amfCSEE6fHFPOgMqT/9pYixmnRruQi3xDDhfgl5zdKNaBQ 3VfUGHLsQzIKEWQo+KpZWPoJGeqYjfKApjzisPyw4T90Iafc8nYnfXilyi7NPRblc3Um 9IuJgiYRhPRnM/GxNtyJNServd0vQwOOubo9J+f89KOzc9JhbzW6JWC6VaCS/oSs7vmw oj4pEpGfV1TZBEd2TSJVt0ZTotMKkgj1UliRd7qqFJqe+4OcDUZrpEvR+Hl6dEUTgY9y fPpRw+CNzCrLwT/SqxiKBg3PlrTJWrZQaCaS9k8Pb3DdNFyBmuZolYIi/2qYW1MlGct9 FzpA== 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=jnRTRqPQtdS2EdRYNnnLGlOxKxmF3GtLPPXBsYlMEaM=; b=qGCBYIAM+YdlL1/NxBPCDkRtpPsxEGAqU6ShIJNqR7H0EgTSOtwY1rzM16Ljs8BF/m tRudBDErt1avdBJl2z8G5imMz0Sw+9MeIBv7gDUbJG4P4CyHZHSqNblSTPtXrrR4i67W F0/d8BRRjABxMHMPigfhdjJyuqgetBmFbYCmKhwDi29JEr3ExtJEzkiGHPvZ2Pmwy5xg OaboTn+TT5NTsxNmqhoEKC6Qg7vqYqjoQzlgGlckp7V5gKQePK0jyRn2qwEZKlpI5qcY nmVDpQEA7GUA6JghRctr0an0HfmmlNa66dE76/3fMrFcXYC8cXK5dhvOEM+N8/FaRocr +/MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HRFMVZkC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i15-20020a170902cf0f00b0015872db9713si12976934plg.131.2022.05.23.10.09.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 10:09:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HRFMVZkC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 183736B674; Mon, 23 May 2022 10:09:18 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239586AbiEWRIZ (ORCPT + 99 others); Mon, 23 May 2022 13:08:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239395AbiEWRHv (ORCPT ); Mon, 23 May 2022 13:07:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50D6A3EA89; Mon, 23 May 2022 10:07:46 -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 C7C99614CC; Mon, 23 May 2022 17:07:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88197C34115; Mon, 23 May 2022 17:07:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653325665; bh=jQ6gt1z8OySJGiK/cfPqJsZiYOhXdGYEOqmvy11hhfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HRFMVZkCj3v4uDJ1SBQP3h9Zp405bOukOwUPY94j04jPRLYGpzv+gGuJwyAqR/s8Q zYbMyReHa8+d24xc+tIXdZE4kGkYyx47eO2SQwKjRFBaJkNmnXOc19o5/EiPMuP2oY i4A2bGGn88JEyUDb8dFdYvDH4/k/GRmEV+pSKmDY= 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.14 03/33] Input: add bounds checking to input_set_capability() Date: Mon, 23 May 2022 19:04:52 +0200 Message-Id: <20220523165747.639182565@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165746.957506211@linuxfoundation.org> References: <20220523165746.957506211@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 cadb368be8ef..f9f3d6261dc5 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