From patchwork Sun Mar 2 14:32:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13997835 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D72CC1E5B6D for ; Sun, 2 Mar 2025 14:34:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740926060; cv=none; b=OVXBSVPUBY1Xn8sE6PhTC3JmoIIgOM6d/dSbZDQjCyzillVYOpKM5bTsUMcq+N/0LhccZuJ3zJYDeDrSxU2zsxgIFKdLmZY7PZmhY69i9/mL5o6HOYJVkugPx6gNw8GCcD5PnSf6v2Pg2548h/cceHnlpKvnBhSNYn/IE1evuio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740926060; c=relaxed/simple; bh=uvSR+nHkOyddC0QdPQ72//WOuIk64mxGFFY2EA8HABQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o/B3r6r+MX4Mf3OqJkAwgxXpAhTnuidFb4eXG6mEsiKdxacCuiUgl6djtOQjsE6hugTqc+PRSHTEKMUa2RcT4KbydnKCamoUA6NxfVQeN/OI6pHK4AfytQpxTF+mqcACWXkCNASkmPYyjIWnqAd44h12XKYDIuRASZRze79TWLQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gg+p4nEQ; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gg+p4nEQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740926057; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rlJT47zLkSfn9zom7PdH4akIw1D+Y3HK6R7VYjb50+Q=; b=gg+p4nEQg6p4Uxu5biPj52LCquPCDLluDSuifewZ0MqYz8WXymH6UAW9/PI/k7Qzv30YmM c400Gb3IcoGZMqd1I3yGb88bO9TfaCWoH5yyX+H0mmDGjYC4L36HfCeFZn6ceBfc2X9X4a r4UJcsZmVO2ng1GPBkUAwTiDP7OOV1I= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-189-cKQuFv4DNUKVRzrAAVuWDg-1; Sun, 02 Mar 2025 09:34:14 -0500 X-MC-Unique: cKQuFv4DNUKVRzrAAVuWDg-1 X-Mimecast-MFC-AGG-ID: cKQuFv4DNUKVRzrAAVuWDg_1740926053 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AF5351954B1C; Sun, 2 Mar 2025 14:34:13 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.49]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2799019560AB; Sun, 2 Mar 2025 14:34:08 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v7 7/8] vhost: Add check for inherit_owner status Date: Sun, 2 Mar 2025 22:32:09 +0800 Message-ID: <20250302143259.1221569-8-lulu@redhat.com> In-Reply-To: <20250302143259.1221569-1-lulu@redhat.com> References: <20250302143259.1221569-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 The VHOST_NEW_WORKER requires the inherit_owner setting to be true. So we need to add a check for this. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index ff930c2e5b78..fb0c7fb43f78 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -1018,6 +1018,13 @@ long vhost_worker_ioctl(struct vhost_dev *dev, unsigned int ioctl, switch (ioctl) { /* dev worker ioctls */ case VHOST_NEW_WORKER: + /* + * vhost_tasks will account for worker threads under the parent's + * NPROC value but kthreads do not. To avoid userspace overflowing + * the system with worker threads inherit_owner must be true. + */ + if (!dev->inherit_owner) + return -EFAULT; ret = vhost_new_worker(dev, &state); if (!ret && copy_to_user(argp, &state, sizeof(state))) ret = -EFAULT;