From: Lyude Paul <lyude@redhat.com>
To: Xiaomeng Tong <xiam0nd.tong@gmail.com>,
bskeggs@redhat.com, kherbst@redhat.com, airlied@linux.ie,
daniel@ffwll.ch
Cc: martin.peres@free.fr, dri-devel@lists.freedesktop.org,
nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] clk: base: fix an incorrect NULL check on list iterator
Date: Mon, 04 Apr 2022 17:23:17 -0400 [thread overview]
Message-ID: <74509d19d84b879b624fa9f40bc8186fd09e750a.camel@redhat.com> (raw)
In-Reply-To: <20220327075824.11806-1-xiam0nd.tong@gmail.com>
This should probably be prefixed with the title "drm/nouveau/clk:", but I can
fix that before pushing it.
Reviewed-by: Lyude Paul <lyude@redhat.com>
Will push it to the appropriate repository shortly
On Sun, 2022-03-27 at 15:58 +0800, Xiaomeng Tong wrote:
> The bug is here:
> if (nvkm_cstate_valid(clk, cstate, max_volt, clk->temp))
> return cstate;
>
> The list iterator value 'cstate' will *always* be set and non-NULL
> by list_for_each_entry_from_reverse(), so it is incorrect to assume
> that the iterator value will be unchanged if the list is empty or no
> element is found (In fact, it will be a bogus pointer to an invalid
> structure object containing the HEAD). Also it missed a NULL check
> at callsite and may lead to invalid memory access after that.
>
> To fix this bug, just return 'encoder' when found, otherwise return
> NULL. And add the NULL check.
>
> Cc: stable@vger.kernel.org
> Fixes: 1f7f3d91ad38a ("drm/nouveau/clk: Respect voltage limits in
> nvkm_cstate_prog")
> Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
> ---
> drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c
> b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c
> index 57199be082fd..c2b5cc5f97ed 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c
> @@ -135,10 +135,10 @@ nvkm_cstate_find_best(struct nvkm_clk *clk, struct
> nvkm_pstate *pstate,
>
> list_for_each_entry_from_reverse(cstate, &pstate->list, head) {
> if (nvkm_cstate_valid(clk, cstate, max_volt, clk->temp))
> - break;
> + return cstate;
> }
>
> - return cstate;
> + return NULL;
> }
>
> static struct nvkm_cstate *
> @@ -169,6 +169,8 @@ nvkm_cstate_prog(struct nvkm_clk *clk, struct
> nvkm_pstate *pstate, int cstatei)
> if (!list_empty(&pstate->list)) {
> cstate = nvkm_cstate_get(clk, pstate, cstatei);
> cstate = nvkm_cstate_find_best(clk, pstate, cstate);
> + if (!cstate)
> + return -EINVAL;
> } else {
> cstate = &pstate->base;
> }
--
Cheers,
Lyude Paul (she/her)
Software Engineer at Red Hat
prev parent reply other threads:[~2022-04-04 22:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-27 7:58 Xiaomeng Tong
2022-04-04 21:23 ` Lyude Paul [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=74509d19d84b879b624fa9f40bc8186fd09e750a.camel@redhat.com \
--to=lyude@redhat.com \
--cc=airlied@linux.ie \
--cc=bskeggs@redhat.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=kherbst@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.peres@free.fr \
--cc=nouveau@lists.freedesktop.org \
--cc=stable@vger.kernel.org \
--cc=xiam0nd.tong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®