Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3985053pxb; Tue, 25 Jan 2022 00:41:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJztDky7jOg2AfL/a8me1gaS4CslJLVr+sSHAk8qgZdN00F8Q7Qx7NXxi1Ouwt7vaxung8Bi X-Received: by 2002:a17:90b:4a12:: with SMTP id kk18mr2339798pjb.227.1643100109607; Tue, 25 Jan 2022 00:41:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643100109; cv=none; d=google.com; s=arc-20160816; b=ATiR+5OBePxX9WDjz6LD4AGZvyAkWO0ngwy+2oikutRubtA0JYEqjKDlJYfMwJ9PFU mGlk/bcNCroltg5+W8EylJj5qkYuSi5m+NS4pRIx970/9tMLaMsIzq0F505ZGAu0zrZ9 DCZRD8y2s5V6VoNLTKhMR8bBwO7IdH6cbxo3nmSfRb9IDfj4oEPwMQhRNilSx/o8uMYh fNWq6+hAN+8L8qd8K6Fc4MPSGLdpNKf6aMhb4S9SANcjJawDJ9OxD1GZ6Faw4Xgey0oX 4nKHxsCIjZtBQMGYptkNgsmMG7UwhviNN+sjAB0ZIsJ+7A3YUJIC+Fug+cOAAI4vQYCA XRFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:user-agent:from :references:in-reply-to:mime-version:dkim-signature; bh=T4rF0hLY7ipw4hc6cLAFZLFsJmiutz6BweB8Dz29VfE=; b=qjADrPMC4vA2Ls9/HZlUH7yqlw2Kw3etPhxXMEIPgkVvIU+QwLMFH9hNRC5PjFTtKH Bq4LwdxW6wLuSt0zREhTXfhEdeBHYgyc6l7CW4fZhCAVpVAc0ggDntESBftAeCGFY+DN klhk+Xb0z8Uz+rwyLuDpBEPLZRqPaDl5F2C60IO5qN1lk+96388XN9UoOaWle/Z78L/Y p3dkjGB8sI7q5BJ0KFIwUEoh1cRWIFnvH41rU5Ozzsevbe7JZPn6UE4llvZ7s062UOqH xjkiaZAV+i8rmyYGftSVWdIxJAcjHCAVntjWBgBmG++jj02A424QqGAVmhHf/HUnhhv8 gU1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mvEF6fOK; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 135si6469929pgc.430.2022.01.25.00.41.37; Tue, 25 Jan 2022 00:41:49 -0800 (PST) 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=@chromium.org header.s=google header.b=mvEF6fOK; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1318804AbiAYDHL (ORCPT + 99 others); Mon, 24 Jan 2022 22:07:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S3416559AbiAYCES (ORCPT ); Mon, 24 Jan 2022 21:04:18 -0500 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEFB0C055A83 for ; Mon, 24 Jan 2022 17:55:59 -0800 (PST) Received: by mail-oi1-x22f.google.com with SMTP id e81so28488901oia.6 for ; Mon, 24 Jan 2022 17:55:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:in-reply-to:references:from:user-agent:date:message-id :subject:to:cc; bh=T4rF0hLY7ipw4hc6cLAFZLFsJmiutz6BweB8Dz29VfE=; b=mvEF6fOKLUpg42CVbbypm40M0/3KmMchADzb3NMDmLowUcZqsdQ9ybGgFg0NFGWzwh b9WHGpDfddcXAyDpMpRpB5KzlYxFPoJ4xXSMLdA5smZ6UkM91INnKst7AlTuayeQvzbs Uxx0n2Jukd4i1d5M70kWyTYutk/S9Qa+S1XOk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:in-reply-to:references:from :user-agent:date:message-id:subject:to:cc; bh=T4rF0hLY7ipw4hc6cLAFZLFsJmiutz6BweB8Dz29VfE=; b=BpAZLHnhaCTMYFvEShodUYhqniuSStUE2trWCHwgz03HC3Yn4Hsoq5tUyiA1A0j5gZ h3RxZikgjP7ll5gvBCj87roLiklDokkRQuUvJezaTt4+LN0evWKCPs40Nri8qXEM820V WteBUJR9eO2es6PI2gd2mxUmV/41HF1rB+mqwFnx6rYZwIjnh/yNW1nuSNXnZzUOh0jY mdKIAYjII7IXBt216/g/viJtSk5ksDE5yp8Pa3djcYq8oNqU+4qb8eUOiLQ2vFTOQFOL N+CtqOHmyRYh2xpmKr23C2naORa0PZZyk4ozIM9TUAVM47r4VHamiiq159eUvqBpGJs2 E++A== X-Gm-Message-State: AOAM531jJg5obZNmf0aD6Oe8tYuoLv1qqj/+3zP38aTL6jFWUg1skVD7 As8r/NOXCVHdIhK8jP1hPmQFIDQ+WTxAwkWSK5eTUg== X-Received: by 2002:a05:6808:252:: with SMTP id m18mr1234653oie.164.1643075759011; Mon, 24 Jan 2022 17:55:59 -0800 (PST) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Mon, 24 Jan 2022 17:55:58 -0800 MIME-Version: 1.0 In-Reply-To: References: <20220120204132.17875-1-quic_amelende@quicinc.com> <20220120204132.17875-4-quic_amelende@quicinc.com> From: Stephen Boyd User-Agent: alot/0.10 Date: Mon, 24 Jan 2022 17:55:58 -0800 Message-ID: Subject: Re: [PATCH 3/3] input: misc: pm8941-pwrkey: avoid potential null pointer dereference To: Bjorn Andersson Cc: Anjelique Melendez , dmitry.torokhov@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, collinsd@codeaurora.org, skakit@codeaurora.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Bjorn Andersson (2022-01-24 14:26:34) > On Thu 20 Jan 20:18 PST 2022, Stephen Boyd wrote: > > > Quoting Anjelique Melendez (2022-01-20 16:25:26) > > > > > > On 1/20/2022 3:01 PM, Bjorn Andersson wrote: > > > > On Thu 20 Jan 12:41 PST 2022, Anjelique Melendez wrote: > > > > > > > >> From: David Collins > > > >> > > > >> Add a null check for the pwrkey->data pointer after it is assigned > > > >> in pm8941_pwrkey_probe(). This avoids a potential null pointer > > > >> dereference when pwrkey->data->has_pon_pbs is accessed later in > > > >> the probe function. > > > >> > > > >> Change-Id: I589c4851e544d79a1863fd110b32a0b45ac03caf > > > >> Signed-off-by: David Collins > > > >> Signed-off-by: Anjelique Melendez > > > >> --- > > > >> drivers/input/misc/pm8941-pwrkey.c | 4 ++++ > > > >> 1 file changed, 4 insertions(+) > > > >> > > > >> diff --git a/drivers/input/misc/pm8941-pwrkey.c b/drivers/input/misc/pm8941-pwrkey.c > > > >> index 0ce00736e695..ac08ed025802 100644 > > > >> --- a/drivers/input/misc/pm8941-pwrkey.c > > > >> +++ b/drivers/input/misc/pm8941-pwrkey.c > > > >> @@ -263,6 +263,10 @@ static int pm8941_pwrkey_probe(struct platform_device *pdev) > > > >> > > > >> pwrkey->dev = &pdev->dev; > > > >> pwrkey->data = of_device_get_match_data(&pdev->dev); > > > >> + if (!pwrkey->data) { > > > > The only way this can happen is if you add a new compatible and forget > > > > to specify data and when that happens you will get a print in the log > > > > somewhere, which once you realize that you don't have your pwrkey you > > > > might be able to find among all the other prints. > > > > > > > > If you instead don't NULL check this pointer you will get a large splat > > > > in the log, with callstack and all, immediately hinting you that > > > > pwrkey->data is NULL. > > > > > > > > > > > > In other words, there's already a print, a much larger print and I don't > > > > think there's value in handling this mistake gracefully. > > > > > > > > Regards, > > > > Bjorn > > > > > > > > > We would like to the null pointer check in place to avoid static analysis > > > > > > warnings that can be easily fixed. > > > > > > > Many drivers check that their device_get_match_data() returns a valid > > pointer. I'd like to see that API used in addition to checking the > > return value for NULL so that we can keep the static analysis tools > > happy. Yes it's an impossible case assuming the driver writer didn't > > mess up but it shuts SA up and we don't really have a better solution > > to tell tools that device_get_match_data() can't return NULL. > > I'm not saying that device_get_match_data() can't return NULL, Indeed, I wasn't implying that you were saying that. > I'm > saying that in the very specific cases that it would return NULL it's > useful to have a kernel panic - as that's a much faster way to figure > out that something is wrong. I see it as more annoying, but maybe that's my workflow? When my kernel oopses I have to go back to a recovery kernel, which takes me a few more seconds to "repair" my device. If the driver only failed to probe then I'd probably be able to boot far enough to get networking and more easily replace my kernel with a working device. And I'd have userspace access so I could poke around and figure out why the driver failed to probe. Now obviously a big stacktrace would be helpful to know that it's the power key driver that's busted, but it's not like we're calling some internal API here. We're trying to probe a driver and if that oopses because the driver writer failed at their job then it's bad on them for writing a bad patch but also annoying for the integrator who has to deal with the mess they created. I'd rather have a half working system here vs. a totally broken one.