On Wed, Jun 28, 2017 at 9:13 PM, Li Kun <hw.likun@xxxxxxxxxx> wrote:An immature idea,can we set the count to INT_MAX/2 when we detect and kill the offending process,
å 2017/5/31 5:39, Kees Cook åé:Ah yes, thanks for the catch. Yeah, that test is expecting both
+bool ex_handler_refcount(const struct exception_table_entry *fixup,Should it be like this to indicate that the refcount is wapped from
+ struct pt_regs *regs, int trapnr)
+{
+ int reset;
+
+ /*
+ * If we crossed from INT_MAX to INT_MIN, the OF flag (result
+ * wrapped around) and the SF flag (result is negative) will be
+ * set. In this case, reset to INT_MAX in an attempt to leave the
+ * refcount usable. Otherwise, we've landed here due to producing
+ * a negative result from either decrementing zero or operating on
+ * a negative value. In this case things are badly broken, so we
+ * we saturate to INT_MIN / 2.
+ */
+ if (regs->flags & (X86_EFLAGS_OF | X86_EFLAGS_SF))
+ reset = INT_MAX;
INT_MAX to INT_MIN ?
if (regs->flags & (X86_EFLAGS_OF | X86_EFLAGS_SF)
== (X86_EFLAGS_OF | X86_EFLAGS_SF))
reset = INT_MAX;
condition flags to be set.
I'm still on the fence about the best way to deal with the bad states.
I've been pondering just strictly using a saturation value (INT_MIN /
2), which should offer the same system state protection (except for
the inherent resource leak), but that means there isn't really a good
way to kill an offending process (since after saturation ALL processes
will look like violators). It can be argued that killing the process
doesn't actually provide any benefit since the system is still safe,
though.
Thanks for looking at this!+ else
+ reset = INT_MIN / 2;
+ *(int *)regs->cx = reset;
-Kees