From 2f593094f0c4f828fd81a3b052ee426135135694 Mon Sep 17 00:00:00 2001 From: jsm Date: Sun, 12 Sep 1999 09:02:20 +0000 Subject: Security improvements for games (largely from or inspired by OpenBSD). Games which run setgid from dm, but don't need to, should drop their privileges at startup. Games which have a scorefile should open it at startup, then drop all privileges leaving just the open writable file descriptor. If the game can invoke subprocesses, this should be made close-on-exec. Games with scorefiles should make sure they do not get a file descriptor < 3. (Otherwise, they could get confused and corrupt the scorefile when using stdin, stdout or stderr.) Some old setuid revokes from the days of setuid games change into gid revokes. --- canfield/canfield/canfield.c | 10 ++++++++-- canfield/cfscores/cfscores.c | 7 +++++-- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'canfield') diff --git a/canfield/canfield/canfield.c b/canfield/canfield/canfield.c index f13e1eb9..854bf2eb 100644 --- a/canfield/canfield/canfield.c +++ b/canfield/canfield/canfield.c @@ -1,4 +1,4 @@ -/* $NetBSD: canfield.c,v 1.14 1999/09/09 17:30:19 jsm Exp $ */ +/* $NetBSD: canfield.c,v 1.15 1999/09/12 09:02:20 jsm Exp $ */ /* * Copyright (c) 1980, 1993 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\ #if 0 static char sccsid[] = "@(#)canfield.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: canfield.c,v 1.14 1999/09/09 17:30:19 jsm Exp $"); +__RCSID("$NetBSD: canfield.c,v 1.15 1999/09/12 09:02:20 jsm Exp $"); #endif #endif /* not lint */ @@ -1683,8 +1683,14 @@ initall() if (uid < 0) uid = 0; dbfd = open(_PATH_SCORE, O_RDWR); + + /* Revoke setgid privileges */ + setregid(getgid(), getgid()); + if (dbfd < 0) return; + if (dbfd < 3) + exit(1); i = lseek(dbfd, uid * sizeof(struct betinfo), SEEK_SET); if (i < 0) { close(dbfd); diff --git a/canfield/cfscores/cfscores.c b/canfield/cfscores/cfscores.c index 84216877..b4a291b5 100644 --- a/canfield/cfscores/cfscores.c +++ b/canfield/cfscores/cfscores.c @@ -1,4 +1,4 @@ -/* $NetBSD: cfscores.c,v 1.7 1999/09/08 21:17:46 jsm Exp $ */ +/* $NetBSD: cfscores.c,v 1.8 1999/09/12 09:02:20 jsm Exp $ */ /* * Copyright (c) 1983, 1993 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\ #if 0 static char sccsid[] = "@(#)cfscores.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: cfscores.c,v 1.7 1999/09/08 21:17:46 jsm Exp $"); +__RCSID("$NetBSD: cfscores.c,v 1.8 1999/09/12 09:02:20 jsm Exp $"); #endif #endif /* not lint */ @@ -79,6 +79,9 @@ main(argc, argv) struct passwd *pw; int uid; + /* Revoke setgid privileges */ + setregid(getgid(), getgid()); + if (argc > 2) { printf("Usage: cfscores [user]\n"); exit(1); -- cgit v1.2.3-56-ge451