[PATCH 03/11] RAS/CEC: Fix pfn insertion

From: Borislav Petkov
Date: Thu May 09 2019 - 14:11:40 EST


From: Borislav Petkov <bp@xxxxxxx>

When inserting random PFNs for debugging the CEC through
(debugfs)/ras/cec/pfn, depending on the return value of pfn_set(),
multiple values get inserted per a single write.

That is because simple_attr_write() interprets a retval of 0 as
success and claims the whole input. However, pfn_set() returns the
cec_add_elem() value, which, if > 0 and smaller than the whole input
length, makes glibc continue issuing the write syscall until there's
input left:

pfn_set
simple_attr_write
debugfs_attr_write
full_proxy_write
vfs_write
ksys_write
do_syscall_64
entry_SYSCALL_64_after_hwframe

leading to those repeated calls.

Return 0 to fix that.

Rename u64_get() to pfn_get() while at it.

Signed-off-by: Borislav Petkov <bp@xxxxxxx>
Cc: Tony Luck <tony.luck@xxxxxxxxx>
Cc: linux-edac <linux-edac@xxxxxxxxxxxxxxx>
---
drivers/ras/cec.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/ras/cec.c b/drivers/ras/cec.c
index 673f8a128397..1275907ff21c 100644
--- a/drivers/ras/cec.c
+++ b/drivers/ras/cec.c
@@ -358,7 +358,7 @@ int cec_add_elem(u64 pfn)
return ret;
}

-static int u64_get(void *data, u64 *val)
+static int pfn_get(void *data, u64 *val)
{
*val = *(u64 *)data;

@@ -369,10 +369,12 @@ static int pfn_set(void *data, u64 val)
{
*(u64 *)data = val;

- return cec_add_elem(val);
+ cec_add_elem(val);
+
+ return 0;
}

-DEFINE_DEBUGFS_ATTRIBUTE(pfn_ops, u64_get, pfn_set, "0x%llx\n");
+DEFINE_DEBUGFS_ATTRIBUTE(pfn_ops, pfn_get, pfn_set, "0x%llx\n");

static int decay_interval_set(void *data, u64 val)
{
@@ -389,7 +391,7 @@ static int decay_interval_set(void *data, u64 val)
cec_mod_work(decay_interval);
return 0;
}
-DEFINE_DEBUGFS_ATTRIBUTE(decay_interval_ops, u64_get, decay_interval_set, "%lld\n");
+DEFINE_DEBUGFS_ATTRIBUTE(decay_interval_ops, pfn_get, decay_interval_set, "%lld\n");

static int count_threshold_set(void *data, u64 val)
{
@@ -402,7 +404,7 @@ static int count_threshold_set(void *data, u64 val)

return 0;
}
-DEFINE_DEBUGFS_ATTRIBUTE(count_threshold_ops, u64_get, count_threshold_set, "%lld\n");
+DEFINE_DEBUGFS_ATTRIBUTE(count_threshold_ops, pfn_get, count_threshold_set, "%lld\n");

static int array_dump(struct seq_file *m, void *v)
{
--
2.21.0