linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/resctrl: Fix rdt_find_domain() return value checks
@ 2018-11-28 18:20 Reinette Chatre
  2018-12-10 19:13 ` Borislav Petkov
  0 siblings, 1 reply; 5+ messages in thread
From: Reinette Chatre @ 2018-11-28 18:20 UTC (permalink / raw)
  To: tglx, fenghua.yu, bp, tony.luck
  Cc: jithu.joseph, mingo, hpa, x86, linux-kernel, Reinette Chatre

rdt_find_domain() may return an ERR_PTR(), NULL, or a pointer to struct
rdt_domain. It is thus required that the return value be checked for the
possibility of an ERR_PTR as well as NULL.

In a few instances the return value of rdt_find_domain() is just checked
for NULL - fix these to include a check of ERR_PTR.

Fixes: d89b7379015f ("x86/intel_rdt/cqm: Add mon_data")
Fixes: 521348b011d6 ("x86/intel_rdt: Introduce utility to obtain CDP peer")
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
---
Dear Maintainers,

Two original commits are fixed here. d89b7379015f can be found in v4.14 and
521348b011d6 starting in v4.20. I am unsure whether this is appropriate for
stable since it is not fixing an issue reported by users. This issue was
discovered during code inspection.

Thank you

Reinette


 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index 6f7adb3be01e..3b5de7d54307 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -538,7 +538,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 
 	r = &rdt_resources_all[resid];
 	d = rdt_find_domain(r, domid, NULL);
-	if (!d) {
+	if (IS_ERR_OR_NULL(d)) {
 		ret = -ENOENT;
 		goto out;
 	}
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 1c7827d142e7..715c6697b07d 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -1029,7 +1029,7 @@ static int rdt_cdp_peer_get(struct rdt_resource *r, struct rdt_domain *d,
 	 * peer RDT CDP resource. Hence the WARN.
 	 */
 	_d_cdp = rdt_find_domain(_r_cdp, d->id, NULL);
-	if (WARN_ON(!_d_cdp)) {
+	if (WARN_ON(IS_ERR_OR_NULL(_d_cdp))) {
 		_r_cdp = NULL;
 		ret = -EINVAL;
 	}
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86/resctrl: Fix rdt_find_domain() return value checks
  2018-11-28 18:20 [PATCH] x86/resctrl: Fix rdt_find_domain() return value checks Reinette Chatre
@ 2018-12-10 19:13 ` Borislav Petkov
  2018-12-10 20:42   ` Reinette Chatre
  0 siblings, 1 reply; 5+ messages in thread
From: Borislav Petkov @ 2018-12-10 19:13 UTC (permalink / raw)
  To: Reinette Chatre
  Cc: tglx, fenghua.yu, tony.luck, jithu.joseph, mingo, hpa, x86, linux-kernel

On Wed, Nov 28, 2018 at 10:20:27AM -0800, Reinette Chatre wrote:
> rdt_find_domain() may return an ERR_PTR(), NULL, or a pointer to struct
> rdt_domain. It is thus required that the return value be checked for the
> possibility of an ERR_PTR as well as NULL.

Well, it returns ERR_PTR(id) but code which uses ERR_PTR passes in an -E
value, for example ERR_PTR(-EINVAL) or so, and not an id.

And that might work now if id fits within that MAX_ERRNO range - I'm
looking at include/linux/err.h - but that's still fragile.

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86/resctrl: Fix rdt_find_domain() return value checks
  2018-12-10 19:13 ` Borislav Petkov
@ 2018-12-10 20:42   ` Reinette Chatre
  2018-12-10 21:04     ` Borislav Petkov
  0 siblings, 1 reply; 5+ messages in thread
From: Reinette Chatre @ 2018-12-10 20:42 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: tglx, fenghua.yu, tony.luck, jithu.joseph, mingo, hpa, x86, linux-kernel

Hi Boris,

On 12/10/2018 11:13 AM, Borislav Petkov wrote:
> On Wed, Nov 28, 2018 at 10:20:27AM -0800, Reinette Chatre wrote:
>> rdt_find_domain() may return an ERR_PTR(), NULL, or a pointer to struct
>> rdt_domain. It is thus required that the return value be checked for the
>> possibility of an ERR_PTR as well as NULL.
> 
> Well, it returns ERR_PTR(id) but code which uses ERR_PTR passes in an -E
> value, for example ERR_PTR(-EINVAL) or so, and not an id.
> 
> And that might work now if id fits within that MAX_ERRNO range - I'm
> looking at include/linux/err.h - but that's still fragile.
> 

Thank you for catching this.

It does seem as though things work at this time since rdt_find_domain()
contains:

if (id < 0)
        return ERR_PTR(id);

and from what I can tell the only possible negative value of id is -1.

As you note, this is fragile. Additionally the error, if intending to
use -E values, does not reflect the error (since -1 would mean EPERM).

Would you be ok if the above is changed to

if (id < 0)
        return ERR_PTR(-ENOENT);

as part of this patch?

Looking at rdtgroup_mondata_show() is does seem as though ENOENT is the
actual intended error value, although ENODEV could perhaps also be
considered since such a result reflects that a particular cache instance
could not be found.

Thank you!

Reinette


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86/resctrl: Fix rdt_find_domain() return value checks
  2018-12-10 20:42   ` Reinette Chatre
@ 2018-12-10 21:04     ` Borislav Petkov
  2018-12-10 21:42       ` Reinette Chatre
  0 siblings, 1 reply; 5+ messages in thread
From: Borislav Petkov @ 2018-12-10 21:04 UTC (permalink / raw)
  To: Reinette Chatre
  Cc: tglx, fenghua.yu, tony.luck, jithu.joseph, mingo, hpa, x86, linux-kernel

On Mon, Dec 10, 2018 at 12:42:14PM -0800, Reinette Chatre wrote:
> Would you be ok if the above is changed to
> 
> if (id < 0)
>         return ERR_PTR(-ENOENT);
> 
> as part of this patch?

Yap.

> Looking at rdtgroup_mondata_show() is does seem as though ENOENT is the
> actual intended error value,

#define ENOENT           2      /* No such file or directory */

> although ENODEV could perhaps also be considered since such a result
> reflects that a particular cache instance could not be found.

#define ENODEV          19      /* No such device */

Yeah, they both kinda look ok to me and in the end of the day, the thing
that matters most is pinpointing the place in the code which causes the
error.

And looking at that particular part:

        r = &rdt_resources_all[resid];
        d = rdt_find_domain(r, domid, NULL);
        if (!d) {
                ret = -ENOENT;
                goto out;
        }

You *could* put in there something like:

	seq_printf(m, "Cannot find a domain for resource ID: %d\n", domid);

and this way it is perfectly clear which error path it is.

:-)

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86/resctrl: Fix rdt_find_domain() return value checks
  2018-12-10 21:04     ` Borislav Petkov
@ 2018-12-10 21:42       ` Reinette Chatre
  0 siblings, 0 replies; 5+ messages in thread
From: Reinette Chatre @ 2018-12-10 21:42 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: tglx, fenghua.yu, tony.luck, jithu.joseph, mingo, hpa, x86, linux-kernel

Hi Boris,

On 12/10/2018 1:04 PM, Borislav Petkov wrote:
> On Mon, Dec 10, 2018 at 12:42:14PM -0800, Reinette Chatre wrote:
>> Would you be ok if the above is changed to
>>
>> if (id < 0)
>>         return ERR_PTR(-ENOENT);
>>
>> as part of this patch?
> 
> Yap.
> 
>> Looking at rdtgroup_mondata_show() is does seem as though ENOENT is the
>> actual intended error value,
> 
> #define ENOENT           2      /* No such file or directory */
> 
>> although ENODEV could perhaps also be considered since such a result
>> reflects that a particular cache instance could not be found.
> 
> #define ENODEV          19      /* No such device */
> 
> Yeah, they both kinda look ok to me and in the end of the day, the thing
> that matters most is pinpointing the place in the code which causes the
> error.

Thank you for the sanity check. I think ENODEV may reflect the issue
better and will do so in the next version. This would not affect the
current code (quoted below) that subsequently translates the error to
ENOENT.

> And looking at that particular part:
> 
>         r = &rdt_resources_all[resid];
>         d = rdt_find_domain(r, domid, NULL);
>         if (!d) {
>                 ret = -ENOENT;
>                 goto out;
>         }
> 
> You *could* put in there something like:
> 
> 	seq_printf(m, "Cannot find a domain for resource ID: %d\n", domid);
> 
> and this way it is perfectly clear which error path it is.
> 
> :-)
> 

From what I understand this scenario should never happen - at the time
knowledge of the resource instance is removed then these mondata files
referring to it will be removed also. Even so, I'd prefer not to make
any user visible changes without a specific requirement or need to do
so. In this case ENOENT is the only error code returned during this user
space interaction so from what I can tell it is currently clear which
error path it is.

Reinette

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-12-10 21:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-28 18:20 [PATCH] x86/resctrl: Fix rdt_find_domain() return value checks Reinette Chatre
2018-12-10 19:13 ` Borislav Petkov
2018-12-10 20:42   ` Reinette Chatre
2018-12-10 21:04     ` Borislav Petkov
2018-12-10 21:42       ` Reinette Chatre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).