From owner-freebsd-hackers@freebsd.org Mon Feb 1 05:13:08 2016 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 30A44A901F4 for ; Mon, 1 Feb 2016 05:13:08 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C03CE1649; Mon, 1 Feb 2016 05:13:07 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-wm0-x242.google.com with SMTP id 128so7385718wmz.3; Sun, 31 Jan 2016 21:13:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=DfztBr18ciYGbYcV9W/qr/f2a5CAhkFVKolSovxnLTc=; b=TzS+6YE3MXOXAqAfqr6kXWn2QmlktfhvqG4yByXKqQRY+feCQWioXD0KbvF6/b2jlk Amop4DUdjw76S8hCsSofC1cCOukDrfrMHxA1HCZbF11xY6i2hDJRKBKn+mxLfJHjjChv fwrpITwgYg52lac8VM5/PGXTR4gn/NAwiIFndpqjD8/ve7zphjtDb44zv69PgK02GNow q0ayf1Yy9OzbfMpOzBjC6xFsAusppM56jirY2oMmobZ74IBkvWeBipaEk3q483SGN82j ufH5aDK1Sriq6jugtupozVbzh0SSZe1Cp+cP8e/cumisx2rXekOSexo8uJQnOLbn4jMN dIQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=DfztBr18ciYGbYcV9W/qr/f2a5CAhkFVKolSovxnLTc=; b=TfRmQ+s5sD1FHJaGdK8MkB53Q393wlw5ichXtBkKuYm5OlTy49c4IZyZ7W2xyQaXVe uWFtrErJtcNvBX7cYPJhvczxiOteJIelSMPyjuBxv10Z4swbG5/uplWQlxlZSE0UYV1g cfWnOg53tkiGfy2zlNTn2xO/+mQfCdFXSEDlOnzy9dh+YUJWsxt5TQIAbvn3W4srkmxJ 3ITZWrsb1AmtmjFQp8Wi708tR0PeZNwTk2HDh/gUHUDpkSjQgDlMvE4jN58HzOEWUn93 oLjzmhMcjXFuBK+fmtJABltqIIq40o9sDpYDwcnjxDX8VvKxmyVLis/fRnXWVtvVC6gP bb4A== X-Gm-Message-State: AG10YORWlaiy8Y/ov+tyzvmDcYAn7Jys11m8fjSfNCQN+8V54HUbEsjm+16UJcQAze7G/Q== X-Received: by 10.194.201.134 with SMTP id ka6mr20467056wjc.116.1454303586215; Sun, 31 Jan 2016 21:13:06 -0800 (PST) Received: from mguzik.localdomain (ip-62-245-66-110.net.upcbroadband.cz. [62.245.66.110]) by smtp.gmail.com with ESMTPSA id x6sm27239437wje.38.2016.01.31.21.13.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Jan 2016 21:13:05 -0800 (PST) From: Mateusz Guzik To: freebsd-hackers@freebsd.org Cc: kib@freebsd.org, Mateusz Guzik Subject: [PATCH 0/2] plug fork use-after-free Date: Mon, 1 Feb 2016 06:13:02 +0100 Message-Id: <1454303584-20941-1-git-send-email-mjguzik@gmail.com> X-Mailer: git-send-email 2.4.3 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Feb 2016 05:13:08 -0000 From: Mateusz Guzik Quit some time ago I reported a problem with fork and provided a half-assed patch, see: https://lists.freebsd.org/pipermail/freebsd-hackers/2014-October/046212.html Now I got around to fixing the problem in a less hackish manner. Note that despite the new process possibly immediatley exiting and being waited on, returning its (possibly now reused PID) is fine - that's the pid it possibly saw by other means and in worst case the process is racing with itself. To reiterate, as it is, the code has use-after-free in procdesc and racct handling. The first patch is a small cleanup to reduce the number of arguments to fork1, which was getting out of hand. I don't feel strongly about the name of the structure used in there. Mateusz Guzik (2): fork: move procdesc-related parameters into a dedicated struct fork: plug a use after free of the returned process pointer sys/compat/cloudabi/cloudabi_proc.c | 11 ++-- sys/compat/linux/linux_fork.c | 6 +- sys/kern/init_main.c | 2 +- sys/kern/kern_fork.c | 125 ++++++++++++++++++++---------------- sys/kern/kern_kthread.c | 2 +- sys/sys/proc.h | 5 +- sys/sys/procdesc.h | 6 ++ 7 files changed, 91 insertions(+), 66 deletions(-) -- 2.7.0