Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp2294008rwj; Sun, 30 Oct 2022 15:04:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6xv0qVgMicMLFPcOuPo8Aa2cnswCOqKdoHlLoCfBma8NKkamaX4B308wH3OMvQ5oaKFVYV X-Received: by 2002:a05:6a00:234d:b0:561:ec04:e77e with SMTP id j13-20020a056a00234d00b00561ec04e77emr11486041pfj.14.1667167479125; Sun, 30 Oct 2022 15:04:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667167479; cv=none; d=google.com; s=arc-20160816; b=0kG1GsvAN5PNMjQgFmvlMm9dHvRXbhCAPkN+0XQSySlS77xy1eRwV/6rzNzpsaJg05 ij1hpfwarB/YA9ZwlcVAYzLggnaZYFxI3ilNvpi+bGwF7W1PAi4bO2y6ygs6qsRLdEF/ 69JykqqI+WfHEogrIxWs/nsiN/zwz1L2nojqDVixSHG4uudChvXlh4WMBAjinUAHiN4e zE6gkM98PpXYS+P8+JT6o3WEXeSOrTgiWiwBYDzzfDMDwJZNaL0dO4yTkICNOL19IHzh /ugGcRApXWvKJe3AYXIiNMky7+5ID83UlC+pPEcXt3SJi/prJr3PN7m7ia5xvUj6ChxZ xk8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=T2Hzb+xxyKnPzMsKtR+WvmF1ywGYO4tzf59V+gc/0/s=; b=PN0DgAJeQf5LdNA/9NwzVfOtYf4vL9U0gAV8+9kkNMPEWEo1F2/w3n0jELW9hjSyit oIIN9dZCaI1tp2y/eReJSz/dPsjOMnLkWo5QXNVI+ldWbj+8tj05REgau2ZZKeKdfbe4 YwuGGbzDuQQyH4jHiKxnJoafNTlayh4UdNHuoPK4cul09zWQ3EMSM/4ZplQk0dMcLYh/ p5JZ17LHHaLspzZfXz4scfOeW9SpsGmVs4Z/fMpnHssiFRxp43VpkZoYk9a190YcLvnu yCjvptQg2zT9T8C/k0cXxHeidGVHAg35p27O6Kg1o5NBmD3Zb+CCUbOE85ZRneQp3ZGq ztAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=4SbYyN02; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m8-20020a170902bb8800b00183243c7a2dsi6035226pls.406.2022.10.30.15.04.27; Sun, 30 Oct 2022 15:04:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=4SbYyN02; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229980AbiJ3WCo (ORCPT + 99 others); Sun, 30 Oct 2022 18:02:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229932AbiJ3WCU (ORCPT ); Sun, 30 Oct 2022 18:02:20 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5448DB1DE for ; Sun, 30 Oct 2022 15:02:13 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id f193so9252165pgc.0 for ; Sun, 30 Oct 2022 15:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T2Hzb+xxyKnPzMsKtR+WvmF1ywGYO4tzf59V+gc/0/s=; b=4SbYyN02zU3+59sahg+YLvVvWkSd64+1XsaqdsPV7wLhPizJiL1ZOSfFWLEXqALNYa 6W6QeSVCcOzhNwakNJ4zPTTE1Kep4cZIA88KTO2RA+MLTQn/knPn/uclsfs5FWpp2r6X MBwpK2jSIc9AuGhnLLcYN95HkF+kptFd0w5wvA/YtE9N5+9YKHf7bcTuPECr48LAKx0C 7ea3GPXX5Pek4eIhJCfGxGLaMzcEtWvp/NBeUf5cfL4o2WKF375Mdt8o3+ozsisYNfV4 LlCBO/tvvMnw7IofiBWylGe7Pp676nxsruegSlfD1fNjwlCGunhC8UcSHHnfzrI6bgv5 Dicw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T2Hzb+xxyKnPzMsKtR+WvmF1ywGYO4tzf59V+gc/0/s=; b=0HMQqce5lNVSMDniMIjgmltkvIFhDsj7pHLN+NcFoR4FWrQ5VTH2DyEFe1o/Q5b3ur pZdHBsumE0IbQfmQWNBYH9AnAuDGYRaLlHh/4Hb3gbbS5uBpJ14Fg8zLuaxjMLWl6Je5 NA6PDtcB617csaVSN6WwB35svFmADxYGnPh0CRXRlQnME7efSOIDqAHLYXkAx6akJPdS 54+sNseVi53T+ngeGnFsYsHwuwR+6UKGxTn22VuggYt6L+dZ5ikWcJwV9hKR5fHFz5rT XIXPYoNpPZs1kmfYtnem8lFmoLe+oup45rCCqj84HO9oT6i7uH1jQEuRCYLeJM0vjNuM yDxQ== X-Gm-Message-State: ACrzQf0rgctVSvTJkJLL+GxN4B/FykwJ7piRX5SQ/q78hF/sxClJjNgX B6TbrUOmihhQsNp9A62UH5u4xLaEiWQRqwJN X-Received: by 2002:a63:f103:0:b0:439:398f:80f8 with SMTP id f3-20020a63f103000000b00439398f80f8mr9698925pgi.494.1667167332660; Sun, 30 Oct 2022 15:02:12 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id y3-20020aa79e03000000b0056d73ef41fdsm562852pfq.75.2022.10.30.15.02.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 15:02:12 -0700 (PDT) From: Jens Axboe To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 5/6] eventpoll: move file checking earlier for epoll_ctl() Date: Sun, 30 Oct 2022 16:02:02 -0600 Message-Id: <20221030220203.31210-6-axboe@kernel.dk> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221030220203.31210-1-axboe@kernel.dk> References: <20221030220203.31210-1-axboe@kernel.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This just cleans up the checking a bit, in preparation for a change that will need access to 'ep' earlier. Signed-off-by: Jens Axboe --- fs/eventpoll.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 0994f2eb6adc..962d897bbfc6 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -2111,6 +2111,20 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, if (!f.file) goto error_return; + /* + * We have to check that the file structure underneath the file + * descriptor the user passed to us _is_ an eventpoll file. + */ + error = -EINVAL; + if (!is_file_epoll(f.file)) + goto error_fput; + + /* + * At this point it is safe to assume that the "private_data" contains + * our own data structure. + */ + ep = f.file->private_data; + /* Get the "struct file *" for the target file */ tf = fdget(fd); if (!tf.file) @@ -2126,12 +2140,10 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, ep_take_care_of_epollwakeup(epds); /* - * We have to check that the file structure underneath the file descriptor - * the user passed to us _is_ an eventpoll file. And also we do not permit - * adding an epoll file descriptor inside itself. + * We do not permit adding an epoll file descriptor inside itself. */ error = -EINVAL; - if (f.file == tf.file || !is_file_epoll(f.file)) + if (f.file == tf.file) goto error_tgt_fput; /* @@ -2147,12 +2159,6 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, goto error_tgt_fput; } - /* - * At this point it is safe to assume that the "private_data" contains - * our own data structure. - */ - ep = f.file->private_data; - /* * When we insert an epoll file descriptor inside another epoll file * descriptor, there is the chance of creating closed loops, which are -- 2.35.1