diff options
author | David Herrmann <dh.herrmann@googlemail.com> | 2012-10-18 13:28:10 +0200 |
---|---|---|
committer | David Herrmann <dh.herrmann@googlemail.com> | 2012-10-18 13:28:10 +0200 |
commit | 18b0011d55b37c437844331e2d48834988ce73a5 (patch) | |
tree | 527dfea523cd92de55f2f61737212db908bdd221 /src/kmscon_seat.c | |
parent | ebce60a86aade8aa4dfd73b3d2fc87924d92ec78 (diff) |
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>
Diffstat (limited to 'src/kmscon_seat.c')
-rw-r--r-- | src/kmscon_seat.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/kmscon_seat.c b/src/kmscon_seat.c index 077acea..2178226 100644 --- a/src/kmscon_seat.c +++ b/src/kmscon_seat.c @@ -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); } |