From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BE4B9CD5BC9 for ; Mon, 25 May 2026 09:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1779699826; h=to : date : message-id : in-reply-to : references : mime-version : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : content-type : content-transfer-encoding : sender : from; bh=CG1SkIguDc2vC2FszV3PFhImVEALLeeV9MuFfbskY7M=; b=Fp60hLgZct+OtC5dPWSbYsuIGnFY1ob/JwDdZfwRIk/lQLA8sVAUb4VFFZ8kQXuTDiCm3 AITqfOTPSXN4YGEK3oZzSH9UkcNAuV7BmuUiE0kPuez7n2M5U6yy1H0CiHpyOQ2DqFlv9IR fhJfVjKOgMdBvk49UAt5ak0yj97y+Kw= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 719B53E52C9 for ; Mon, 25 May 2026 11:03:46 +0200 (CEST) Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id B8B153E528C for ; Mon, 25 May 2026 11:02:44 +0200 (CEST) Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 2992A14002C5 for ; Mon, 25 May 2026 11:02:44 +0200 (CEST) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-459bf19e87bso5406187f8f.1 for ; Mon, 25 May 2026 02:02:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1779699763; x=1780304563; darn=lists.linux.it; 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=6V/UBVWUFMR2LfmvQfKUf92ueBgrNa6FCCJJuRZDfKs=; b=Rp4fia1/QizvGTlm43pVJl+fIKp7fMdnxT89KGQorkOZrLEBKezBb89sSnMarOexaP wRE6deePxhad7WsaMaUY6tU38oEXV1zj3JOsZhrOpsR7KLKTZ1ayUN8y6KIqLrY/pRoi +cQBnkCWJuYPsVRMZ+OrxmtEauUgGVxTAhE/GPcOyoxuCAarNSuk5qrAKcmiTnZa/Qb2 LQ/Dz8U1Md43oyB6eTCddorreDDagbIHNsj+SB/x0lrK7yCYqdqDvdYo9jqUKacaqp+Q NyArsfcmx55QWV8crgliga1pAr0ch44IiGV5s+MO2KAUZ/8A8zMQQzTqmFX78oIueR5f MVcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779699763; x=1780304563; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6V/UBVWUFMR2LfmvQfKUf92ueBgrNa6FCCJJuRZDfKs=; b=k7/S7dtA0OasTZtFTISYMpIjJuPDiWl+TfLhqBWKh9Lf5oCnK/85eTLv58Eo10f/39 npJhNx9JPLUDvQ4rsI/hoZDq//v/KWuYV7J0G4lBefcLni/jUmE8C/Z1b6nR5IfzYVBh ylE9pVTiYQobICAku7w83nfXwJwlnCgblVSAfQs/+eDnVBXwfPHMejdy3tQ/nRmJfByp nwY5bEARIwYfx8LIEM7CnH4EA3QTkCt6gpGg9J7GfJWcuhoZI8E2uwUbbXExvNWS6yYm h4BDqW0VkGKYCukp1vi/AKJ9QcxxagUjdp9f8pGgeQJrucdq41vegl86R8ploSw95U3L oKYw== X-Gm-Message-State: AOJu0YwMA9wniSmZ5xPR108ZPwmfCJs24uc7u+snsqiaRqItZ+7eg5bx 6DZucZKq05WLpGwNaaobCdI9kp6WphJtRMXsYQfV29nvUH5Nndi8TOn1R8O+JtAZHax9ZxZWNtE Ojzg= X-Gm-Gg: Acq92OGucfBANx/LrQ8XWdeJNn+duxAhkG2kClwp0T329LTKlIGA0rMVySIQvpALtJh BQ05nXhg0U6Zg4zjWo+gcrT2cz3MhAip3Yof9iDDDhn0OMXUpTS83OGZ4d0I0G7UuH/AJqDxGL4 ZG5tFuNr6IYHeRky89MI8FEzxMuOyjPlLLhlcXqDtpiDnXOsgvKOiUO6Bv14VndB4V0ADZTZR9H HerU16FvSY3j+cD5rT+/X4YLT3Iswoygwx4UccnM+R7P619OJb8INdkxRJrT1FrC271RQ0PhdTo RqTM1SKRc3/O1EYkyjW2TlCAHxvEtBnf0buKcJsD/iajYstFRCjca7uqXYTbWoZNnmNSzRCIccC nJAwhPhn00zlBPsKuP5b4RwnGXJPhK1lKFaxbm6qrOnUoZ1CqulHk/iOPRcgWJvIlgLpaD3BpXh qpL+YtMRXssTk= X-Received: by 2002:a05:600c:4510:b0:490:3d2e:b67d with SMTP id 5b1f17b1804b1-490428eb9aamr205953465e9.30.1779699763268; Mon, 25 May 2026 02:02:43 -0700 (PDT) Received: from localhost ([2a07:de40:b240:0:2ad6:ed42:2ad6:ed42]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-4904178e5bfsm83878515e9.2.2026.05.25.02.02.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2026 02:02:42 -0700 (PDT) To: ltp@lists.linux.it Date: Mon, 25 May 2026 09:02:21 +0000 Message-ID: <20260525090228.11895-3-wegao@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260525090228.11895-1-wegao@suse.com> References: <20240514045110.85640-1-xuyang2018.jy@fujitsu.com> <20260525090228.11895-1-wegao@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 1.0.9 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v3 2/2] connect01: Add negative tests X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Wei Gao via ltp Reply-To: Wei Gao Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ltp-bounces+ltp=archiver.kernel.org@lists.linux.it Sender: "ltp" Add negative cases for connect(), when errno is EPROTOTYPE or EACCES. Signed-off-by: Wei Gao --- testcases/kernel/syscalls/connect/connect01.c | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/testcases/kernel/syscalls/connect/connect01.c b/testcases/kernel/syscalls/connect/connect01.c index 923c4be81..078569c48 100644 --- a/testcases/kernel/syscalls/connect/connect01.c +++ b/testcases/kernel/syscalls/connect/connect01.c @@ -11,20 +11,29 @@ #include #include #include +#include #include +#include #include "tst_test.h" #include "lapi/syscalls.h" +#define SOCK_FILE "sock_file" + static int fd_invalid = -1; static int fd_socket; static int fd_null; static int fd_connected; static int fd_server; +static int fd_unix_dgram; +static int fd_unix_stream; +static int fd_unix_server; static struct sockaddr_in sock1; static struct sockaddr_in sock2; static struct sockaddr_in sock3; +static struct sockaddr_un sock4; static void *bad_addr; +static struct passwd *pw; static pid_t pid; @@ -49,6 +58,10 @@ static struct test_case_t { "connect on a socket found no one listening on remote address"}, {&fd_socket, &sock3, sizeof(sock3), EAFNOSUPPORT, "address doesn't have the correct address family in sa_family"}, + {&fd_unix_dgram, &sock4, sizeof(sock4), EPROTOTYPE, + "socket type does not support the protocol"}, + {&fd_unix_stream, &sock4, sizeof(sock4), EACCES, + "write permission is denied on the socket file"}, }; static int sys_connect(int sockfd, const struct sockaddr *addr, @@ -103,6 +116,18 @@ static void setup(void) sock3.sin_family = 47; sock3.sin_port = 0; sock3.sin_addr.s_addr = htonl(0x0AFFFEFD); + + sock4.sun_family = AF_UNIX; + strncpy(sock4.sun_path, SOCK_FILE, sizeof(sock4.sun_path)); + + fd_unix_server = SAFE_SOCKET(AF_UNIX, SOCK_STREAM, 0); + SAFE_BIND(fd_unix_server, (struct sockaddr *)&sock4, sizeof(sock4)); + SAFE_LISTEN(fd_unix_server, 5); + + fd_unix_dgram = SAFE_SOCKET(AF_UNIX, SOCK_DGRAM, 0); + fd_unix_stream = SAFE_SOCKET(AF_UNIX, SOCK_STREAM, 0); + + pw = SAFE_GETPWNAM("nobody"); } static void cleanup(void) @@ -113,6 +138,12 @@ static void cleanup(void) SAFE_CLOSE(fd_null); if (fd_connected > 0) SAFE_CLOSE(fd_connected); + if (fd_unix_dgram > 0) + SAFE_CLOSE(fd_unix_dgram); + if (fd_unix_stream > 0) + SAFE_CLOSE(fd_unix_stream); + if (fd_unix_server > 0) + SAFE_CLOSE(fd_unix_server); if (pid > 0) { SAFE_KILL(pid, SIGKILL); @@ -125,8 +156,17 @@ static void verify_connect(unsigned int i) struct test_case_t *tc = &tcases[i]; void *addr = tc->addr ? tc->addr : bad_addr; - TST_EXP_FAIL(sys_connect(*tc->fd, addr, tc->salen), - tc->exp_errno, "%s", tc->desc); + if (tc->exp_errno == EACCES) { + if (!SAFE_FORK()) { + SAFE_SETUID(pw->pw_uid); + TST_EXP_FAIL(sys_connect(*tc->fd, addr, tc->salen), + tc->exp_errno, "%s", tc->desc); + exit(0); + } + } else { + TST_EXP_FAIL(sys_connect(*tc->fd, addr, tc->salen), + tc->exp_errno, "%s", tc->desc); + } } static struct tst_test test = { @@ -135,4 +175,6 @@ static struct tst_test test = { .tcnt = ARRAY_SIZE(tcases), .test = verify_connect, .forks_child = 1, + .needs_root = 1, + .needs_tmpdir = 1, }; -- 2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp