* [PATCH 0/6] tty_audit: random cleanups
@ 2023-06-21 10:16 Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 1/6] tty_audit: use TASK_COMM_LEN for task comm Jiri Slaby (SUSE)
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Jiri Slaby (SUSE) @ 2023-06-21 10:16 UTC (permalink / raw)
To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)
These are random clean up patches which I came up with while doing more
invasive cleanup over the tty layer (to be sent later).
Jiri Slaby (SUSE) (6):
tty_audit: use TASK_COMM_LEN for task comm
tty_audit: use kzalloc() in tty_audit_buf_alloc()
tty_audit: invert the condition in tty_audit_log()
tty_audit: make icanon a bool
tty_audit: make tty pointers in exposed functions const
tty_audit: make data of tty_audit_log() const
drivers/tty/tty.h | 11 ++++++-----
drivers/tty/tty_audit.c | 43 +++++++++++++++++++++--------------------
2 files changed, 28 insertions(+), 26 deletions(-)
--
2.41.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/6] tty_audit: use TASK_COMM_LEN for task comm
2023-06-21 10:16 [PATCH 0/6] tty_audit: random cleanups Jiri Slaby (SUSE)
@ 2023-06-21 10:16 ` Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 2/6] tty_audit: use kzalloc() in tty_audit_buf_alloc() Jiri Slaby (SUSE)
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Jiri Slaby (SUSE) @ 2023-06-21 10:16 UTC (permalink / raw)
To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)
This is the preferred way of declaring an array for get_task_comm().
Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
drivers/tty/tty_audit.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c
index ca7afd7b2716..b98b1aef5f6f 100644
--- a/drivers/tty/tty_audit.c
+++ b/drivers/tty/tty_audit.c
@@ -69,7 +69,7 @@ static void tty_audit_log(const char *description, dev_t dev,
ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_TTY);
if (ab) {
- char name[sizeof(current->comm)];
+ char name[TASK_COMM_LEN];
audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u major=%d"
" minor=%d comm=", description, pid, uid,
--
2.41.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/6] tty_audit: use kzalloc() in tty_audit_buf_alloc()
2023-06-21 10:16 [PATCH 0/6] tty_audit: random cleanups Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 1/6] tty_audit: use TASK_COMM_LEN for task comm Jiri Slaby (SUSE)
@ 2023-06-21 10:16 ` Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 3/6] tty_audit: invert the condition in tty_audit_log() Jiri Slaby (SUSE)
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Jiri Slaby (SUSE) @ 2023-06-21 10:16 UTC (permalink / raw)
To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)
tty_audit_buf_alloc() manually erases most of the entries after
kmalloc(). So use kzalloc() and remove the manual sets to zero.
That way, we are sure that we do not omit anything.
Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
drivers/tty/tty_audit.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c
index b98b1aef5f6f..43f34465b9df 100644
--- a/drivers/tty/tty_audit.c
+++ b/drivers/tty/tty_audit.c
@@ -33,16 +33,16 @@ static struct tty_audit_buf *tty_audit_buf_alloc(void)
{
struct tty_audit_buf *buf;
- buf = kmalloc(sizeof(*buf), GFP_KERNEL);
+ buf = kzalloc(sizeof(*buf), GFP_KERNEL);
if (!buf)
goto err;
+
buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
if (!buf->data)
goto err_buf;
+
mutex_init(&buf->mutex);
- buf->dev = MKDEV(0, 0);
- buf->icanon = 0;
- buf->valid = 0;
+
return buf;
err_buf:
--
2.41.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/6] tty_audit: invert the condition in tty_audit_log()
2023-06-21 10:16 [PATCH 0/6] tty_audit: random cleanups Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 1/6] tty_audit: use TASK_COMM_LEN for task comm Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 2/6] tty_audit: use kzalloc() in tty_audit_buf_alloc() Jiri Slaby (SUSE)
@ 2023-06-21 10:16 ` Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 4/6] tty_audit: make icanon a bool Jiri Slaby (SUSE)
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Jiri Slaby (SUSE) @ 2023-06-21 10:16 UTC (permalink / raw)
To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)
If we cannot obtain an audit buffer in tty_audit_log(), simply return
from the function. Apart this is mostly preferred in the kernel, it
allows to merge the split audit string while still keeping it readable.
Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
drivers/tty/tty_audit.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c
index 43f34465b9df..c6c27acad2ad 100644
--- a/drivers/tty/tty_audit.c
+++ b/drivers/tty/tty_audit.c
@@ -66,20 +66,20 @@ static void tty_audit_log(const char *description, dev_t dev,
uid_t uid = from_kuid(&init_user_ns, task_uid(current));
uid_t loginuid = from_kuid(&init_user_ns, audit_get_loginuid(current));
unsigned int sessionid = audit_get_sessionid(current);
+ char name[TASK_COMM_LEN];
ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_TTY);
- if (ab) {
- char name[TASK_COMM_LEN];
-
- audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u major=%d"
- " minor=%d comm=", description, pid, uid,
- loginuid, sessionid, MAJOR(dev), MINOR(dev));
- get_task_comm(name, current);
- audit_log_untrustedstring(ab, name);
- audit_log_format(ab, " data=");
- audit_log_n_hex(ab, data, size);
- audit_log_end(ab);
- }
+ if (!ab)
+ return;
+
+ audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u major=%d minor=%d comm=",
+ description, pid, uid, loginuid, sessionid,
+ MAJOR(dev), MINOR(dev));
+ get_task_comm(name, current);
+ audit_log_untrustedstring(ab, name);
+ audit_log_format(ab, " data=");
+ audit_log_n_hex(ab, data, size);
+ audit_log_end(ab);
}
/*
--
2.41.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/6] tty_audit: make icanon a bool
2023-06-21 10:16 [PATCH 0/6] tty_audit: random cleanups Jiri Slaby (SUSE)
` (2 preceding siblings ...)
2023-06-21 10:16 ` [PATCH 3/6] tty_audit: invert the condition in tty_audit_log() Jiri Slaby (SUSE)
@ 2023-06-21 10:16 ` Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 5/6] tty_audit: make tty pointers in exposed functions const Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 6/6] tty_audit: make data of tty_audit_log() const Jiri Slaby (SUSE)
5 siblings, 0 replies; 7+ messages in thread
From: Jiri Slaby (SUSE) @ 2023-06-21 10:16 UTC (permalink / raw)
To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)
Use bool for tty_audit_buf::icanon in favor of ugly bitfields. And get
rid of "!!" as that is completely unnecessary.
Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
drivers/tty/tty_audit.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c
index c6c27acad2ad..6cf8b63368ee 100644
--- a/drivers/tty/tty_audit.c
+++ b/drivers/tty/tty_audit.c
@@ -15,7 +15,7 @@
struct tty_audit_buf {
struct mutex mutex; /* Protects all data below */
dev_t dev; /* The TTY which the data is from */
- unsigned icanon:1;
+ bool icanon;
size_t valid;
unsigned char *data; /* Allocated size N_TTY_BUF_SIZE */
};
@@ -202,8 +202,8 @@ static struct tty_audit_buf *tty_audit_buf_get(void)
void tty_audit_add_data(struct tty_struct *tty, const void *data, size_t size)
{
struct tty_audit_buf *buf;
- unsigned int icanon = !!L_ICANON(tty);
unsigned int audit_tty;
+ bool icanon = L_ICANON(tty);
dev_t dev;
audit_tty = READ_ONCE(current->signal->audit_tty);
--
2.41.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/6] tty_audit: make tty pointers in exposed functions const
2023-06-21 10:16 [PATCH 0/6] tty_audit: random cleanups Jiri Slaby (SUSE)
` (3 preceding siblings ...)
2023-06-21 10:16 ` [PATCH 4/6] tty_audit: make icanon a bool Jiri Slaby (SUSE)
@ 2023-06-21 10:16 ` Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 6/6] tty_audit: make data of tty_audit_log() const Jiri Slaby (SUSE)
5 siblings, 0 replies; 7+ messages in thread
From: Jiri Slaby (SUSE) @ 2023-06-21 10:16 UTC (permalink / raw)
To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)
Both tty_audit_add_data() and tty_audit_tiocsti() need only to read from
the tty struct, so make the tty parameters of them both const. This
aids the compiler a bit.
Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
drivers/tty/tty.h | 11 ++++++-----
drivers/tty/tty_audit.c | 5 +++--
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/tty/tty.h b/drivers/tty/tty.h
index 1e0d80e98d26..89769a1f1f97 100644
--- a/drivers/tty/tty.h
+++ b/drivers/tty/tty.h
@@ -99,14 +99,15 @@ extern int tty_ldisc_autoload;
/* tty_audit.c */
#ifdef CONFIG_AUDIT
-void tty_audit_add_data(struct tty_struct *tty, const void *data, size_t size);
-void tty_audit_tiocsti(struct tty_struct *tty, char ch);
+void tty_audit_add_data(const struct tty_struct *tty, const void *data,
+ size_t size);
+void tty_audit_tiocsti(const struct tty_struct *tty, char ch);
#else
-static inline void tty_audit_add_data(struct tty_struct *tty, const void *data,
- size_t size)
+static inline void tty_audit_add_data(const struct tty_struct *tty,
+ const void *data, size_t size)
{
}
-static inline void tty_audit_tiocsti(struct tty_struct *tty, char ch)
+static inline void tty_audit_tiocsti(const struct tty_struct *tty, char ch)
{
}
#endif
diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c
index 6cf8b63368ee..5cbe28ac1763 100644
--- a/drivers/tty/tty_audit.c
+++ b/drivers/tty/tty_audit.c
@@ -134,7 +134,7 @@ void tty_audit_fork(struct signal_struct *sig)
/*
* tty_audit_tiocsti - Log TIOCSTI
*/
-void tty_audit_tiocsti(struct tty_struct *tty, char ch)
+void tty_audit_tiocsti(const struct tty_struct *tty, char ch)
{
dev_t dev;
@@ -199,7 +199,8 @@ static struct tty_audit_buf *tty_audit_buf_get(void)
*
* Audit @data of @size from @tty, if necessary.
*/
-void tty_audit_add_data(struct tty_struct *tty, const void *data, size_t size)
+void tty_audit_add_data(const struct tty_struct *tty, const void *data,
+ size_t size)
{
struct tty_audit_buf *buf;
unsigned int audit_tty;
--
2.41.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 6/6] tty_audit: make data of tty_audit_log() const
2023-06-21 10:16 [PATCH 0/6] tty_audit: random cleanups Jiri Slaby (SUSE)
` (4 preceding siblings ...)
2023-06-21 10:16 ` [PATCH 5/6] tty_audit: make tty pointers in exposed functions const Jiri Slaby (SUSE)
@ 2023-06-21 10:16 ` Jiri Slaby (SUSE)
5 siblings, 0 replies; 7+ messages in thread
From: Jiri Slaby (SUSE) @ 2023-06-21 10:16 UTC (permalink / raw)
To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)
'data' are only read (passed down to audit_log_n_hex()), so they can be
const -- the same what is expected in audit_log_n_hex(). Only a minor
cleanup to be consistent.
Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
drivers/tty/tty_audit.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c
index 5cbe28ac1763..24d010589379 100644
--- a/drivers/tty/tty_audit.c
+++ b/drivers/tty/tty_audit.c
@@ -59,7 +59,7 @@ static void tty_audit_buf_free(struct tty_audit_buf *buf)
}
static void tty_audit_log(const char *description, dev_t dev,
- unsigned char *data, size_t size)
+ const unsigned char *data, size_t size)
{
struct audit_buffer *ab;
pid_t pid = task_pid_nr(current);
--
2.41.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-06-21 10:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-21 10:16 [PATCH 0/6] tty_audit: random cleanups Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 1/6] tty_audit: use TASK_COMM_LEN for task comm Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 2/6] tty_audit: use kzalloc() in tty_audit_buf_alloc() Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 3/6] tty_audit: invert the condition in tty_audit_log() Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 4/6] tty_audit: make icanon a bool Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 5/6] tty_audit: make tty pointers in exposed functions const Jiri Slaby (SUSE)
2023-06-21 10:16 ` [PATCH 6/6] tty_audit: make data of tty_audit_log() const Jiri Slaby (SUSE)
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).