Thread (14 messages) 14 messages, 4 authors, 2021-08-16

Re: [PATCH 1/1] NAX LSM: Add initial support support

flat view

From: THOBY Simon <hidden>
Date: 2021-08-13 07:47:51
Also in: linux-security-module

Hi Igor,

On 8/12/21 10:24 PM, Igor Zhbanov wrote:
Hi Simon,

ср, 28 июл. 2021 г. в 13:19, THOBY Simon [off-list ref]:
quoted
Nit: considering that allowed_caps_hex is only used in this function, and that it represents a small amount of
stack space, couldn't you define it directly in the function?
quoted
+             len = strlen(allowed_caps_hex);
It is also used as sysctl parameter input buffer in nax_sysctl_table[]
for "allowed_caps" parameter.
Yes, what I meant was that maybe you could just declare it at the beginning of the function,
and not use it at all in the sysctl table. Because as I see it, you only use allowed_caps_hex in the sysctl
table to copy the string to that temporary (variable), and its use is limited to that one function.

Instead of:

+		if ((error = proc_dostring(table, write, buffer, lenp, ppos)))
+			return error;

You could probably get away with something like:
quoted hunk ↗ jump to hunk
+static int
+nax_dostring(struct ctl_table *table, int write, void *buffer,
+             size_t *lenp, loff_t *ppos)
+{
+ 	int error;
+	char allowed_caps_hex[ALLOWED_CAPS_HEX_LEN + 1];
[...]
+	len = strlen(allowed_caps_hex);
+	if (len > ALLOWED_CAPS_HEX_LEN)
+		return -EINVAL;
+	strncpy(allowed_caps_hex, buffer, ALLOWED_CAPS_HEX_LEN + 1);

I have to admit that having nearly no kernel development experience, I'm not
sure there is any guidance on the matter (maybe there is even guidance that recommend
preferring what your original patch does to what I suggested) but I think it is
unnecessary to have a variable accessible to the whole file but being used to hold (small)
temporary data for a single function.
In any case, I would appreciate comments for other reviewers if what I'm saying is completely
wrong, so as to not mislead you in doing adverse changes.

 
Thanks,
Simon
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help