kmscon: add --session-max parameter
This parameter allows to limit the maximum number of sessions to a sane limit. Otherwise, a user could DOS a systemd by opening as many session as they want. This can be set to 0 to drop that limit, however, this is not recommended. Instead, if you want an ability to add more sessions than that limit, you should implement a flag to register_session() that overwrites the limit. This can then be used by a safe way to register new sessions. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
ebce60a86a
commit
18b0011d55
@ -120,6 +120,9 @@ static void print_help()
|
||||
"\t --grab-terminal-new <grab> [<Ctrl><Alt>Return]\n"
|
||||
"\t Create new terminal session\n"
|
||||
"\n"
|
||||
"Session Options:\n"
|
||||
"\t --session-max <max> [50] Maximum number of sessions\n"
|
||||
"\n"
|
||||
"Font Options:\n"
|
||||
"\t --font-engine <engine> [pango]\n"
|
||||
"\t Font engine\n"
|
||||
@ -298,6 +301,7 @@ struct conf_option options[] = {
|
||||
CONF_OPTION_UINT(0, "font-size", NULL, &kmscon_conf.font_size, 12),
|
||||
CONF_OPTION_STRING(0, "font-name", NULL, &kmscon_conf.font_name, "monospace"),
|
||||
CONF_OPTION_UINT(0, "font-dpi", NULL, &kmscon_conf.font_ppi, 96),
|
||||
CONF_OPTION_UINT(0, "session-max", NULL, &kmscon_conf.session_max, 50),
|
||||
CONF_OPTION_STRING_LIST(0, "seats", aftercheck_seats, &kmscon_conf.seats, def_seats),
|
||||
};
|
||||
|
||||
|
@ -94,6 +94,9 @@ struct kmscon_conf_t {
|
||||
char **seats;
|
||||
bool all_seats;
|
||||
|
||||
/* sessions */
|
||||
unsigned int session_max;
|
||||
|
||||
/* font engine */
|
||||
char *font_engine;
|
||||
/* font size */
|
||||
|
@ -73,6 +73,7 @@ struct kmscon_seat {
|
||||
struct uterm_vt *vt;
|
||||
struct shl_dlist displays;
|
||||
|
||||
size_t session_count;
|
||||
struct shl_dlist sessions;
|
||||
struct kmscon_session *cur_sess;
|
||||
struct kmscon_session *dummy;
|
||||
@ -560,6 +561,13 @@ int kmscon_seat_register_session(struct kmscon_seat *seat,
|
||||
if (!seat || !out)
|
||||
return -EINVAL;
|
||||
|
||||
if (kmscon_conf.session_max &&
|
||||
seat->session_count >= kmscon_conf.session_max) {
|
||||
log_warning("maximum number of sessions reached (%d), dropping new session",
|
||||
kmscon_conf.session_max);
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
|
||||
sess = malloc(sizeof(*sess));
|
||||
if (!sess) {
|
||||
log_error("cannot allocate memory for new session on seat %s",
|
||||
@ -576,6 +584,7 @@ int kmscon_seat_register_session(struct kmscon_seat *seat,
|
||||
sess->data = data;
|
||||
|
||||
shl_dlist_link_tail(&seat->sessions, &sess->list);
|
||||
++seat->session_count;
|
||||
*out = sess;
|
||||
|
||||
shl_dlist_for_each(iter, &seat->displays) {
|
||||
@ -612,6 +621,7 @@ void kmscon_session_unregister(struct kmscon_session *sess)
|
||||
|
||||
session_deactivate(sess);
|
||||
shl_dlist_unlink(&sess->list);
|
||||
--sess->seat->session_count;
|
||||
sess->seat = NULL;
|
||||
session_call(sess, KMSCON_SESSION_UNREGISTER, NULL);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user