Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2126034ioo; Mon, 23 May 2022 10:37:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziEKQyFo5tm3qdILs3hh8RJNKVjWiX5lHwruNbsuoVrUGrEURojrb1Xd0DgBXZnoxqhXYX X-Received: by 2002:a62:194a:0:b0:518:9c0b:3130 with SMTP id 71-20020a62194a000000b005189c0b3130mr6661384pfz.19.1653327463877; Mon, 23 May 2022 10:37:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653327463; cv=none; d=google.com; s=arc-20160816; b=LM2mGJ99ZjUK5eL54BQcyI94U2D9H0JhcazBfd7mgW3ZIY/ff+fuU5OLJNJ48kU4kS feVQIrEDYGW/83yUioxKDEvsizhW8aq4fqkNYvL2lphHXtfhPJyi7u8TtPqcakk8NSUT Lyw0pCvQFRC3EekBnj+2aflByRSsegv5KZZNZeBtihoexugW6YUOByKR12cFUEVt72+y 5opOl9pXzZb4OyjEv98xU5h/xzEtQQch6St2vCeZl3od2mRmxmZJFHgrm3+kgpZYCeBm YP0uLAImgKaPs4roaSIwN4I3ShevY7ry+h13t4wAsE1EtfZg4FgNJwjnto+xER6gRr0l TFEw== 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=TnLjlT2UuhC8Tg2Yf0aiTH2jCPzhIgefIvWrAEGkSfs=; b=wSGSr7J5iHYwIHYtBwVIWuI4woGDtipnwHQGKknhnjj6pPCWRIBCOrVNsUPN68jNx1 hPZynXlhCmbgnk0/9hfNzMPOhhTuczfyWqU+Hqqcs8UEGcbXMVJ6+V4zOAQaOV5UJMa9 oQQ4M8Cz88kVf357dZB2Y2K+azLamueYt2ohYv6aLKr5TlFOt7eKvHAy6F2g+rvzRGkV 4tIW3MRY1IPLLR52R1fBYubgPPWv1rKhgbcuKmeCur452mOg+dHY7tX2yLvHdBC6QEfX 1kExv0gcCHlvlQyr4vpc+bcbFuCg5875sBeeF/DBLzfKz32fBf/0FaVwiFnGiitNuYm2 cy0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gCBUAc64; 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 b2-20020a056a00114200b004fafa481427si16793325pfm.91.2022.05.23.10.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 10:37:43 -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=gCBUAc64; 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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D4A38B863; Mon, 23 May 2022 10:36:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241275AbiEWRfD (ORCPT + 99 others); Mon, 23 May 2022 13:35:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240648AbiEWRZI (ORCPT ); Mon, 23 May 2022 13:25:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48CDB3EA89; Mon, 23 May 2022 10:12: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 ams.source.kernel.org (Postfix) with ESMTPS id 34BCEB8120F; Mon, 23 May 2022 17:11:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9495AC385A9; Mon, 23 May 2022 17:11:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653325902; bh=AuNJiLT2mmTuKkv5FyUijn+gb+NPPAPZlGfZWgzy4Bo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gCBUAc646cHqWnD/71RO5rqnn2VDcnVmRvnJxHmsai0OYiQ7zm8CPOGrte5D8E6LA eubvNEVumIwhF7vuaASMmZwbbBHf2iXJIvxsadQsaVbOMpbROB8jkag9oIEO1E26FX tgabjBaZSWa1g106kdgST1RONFy5hNSPAy7aD6J8= 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 5.4 06/68] Input: add bounds checking to input_set_capability() Date: Mon, 23 May 2022 19:04:33 +0200 Message-Id: <20220523165803.609691673@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165802.500642349@linuxfoundation.org> References: <20220523165802.500642349@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 e2eb9b9b8363..0e16a9980c6a 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -47,6 +47,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) { @@ -1978,6 +1989,14 @@ EXPORT_SYMBOL(input_get_timestamp); */ 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