Skip to content

8344446: Remove security manager dependency from module jdk.sctp #22225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpChannelImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -30,8 +30,6 @@
import java.net.InetSocketAddress;
import java.io.FileDescriptor;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.Set;
import java.util.HashSet;
@@ -194,11 +192,6 @@ public SctpChannel bind(SocketAddress local) throws IOException {
SctpNet.throwAlreadyBoundException();
InetSocketAddress isa = (local == null) ?
new InetSocketAddress(0) : Net.checkAddress(local);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkListen(isa.getPort());
}
Net.bind(fd, isa.getAddress(), isa.getPort());
InetSocketAddress boundIsa = Net.localAddress(fd);
port = boundIsa.getPort();
@@ -364,11 +357,6 @@ public boolean connect(SocketAddress endpoint) throws IOException {
synchronized (sendLock) {
ensureOpenAndUnconnected();
InetSocketAddress isa = Net.checkAddress(endpoint);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkConnect(isa.getAddress().getHostAddress(),
isa.getPort());
synchronized (blockingLock()) {
int n = 0;
try {
@@ -1094,16 +1082,10 @@ static native int send0(int fd, long address, int length,
loadSctpLibrary();
}

@SuppressWarnings({"removal", "restricted"})
@SuppressWarnings("restricted")
private static void loadSctpLibrary() {
IOUtil.load(); /* loads nio & net native libraries */
AccessController.doPrivileged(
new PrivilegedAction<>() {
public Void run() {
System.loadLibrary("sctp");
return null;
}
});
System.loadLibrary("sctp");
initIDs();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -149,10 +149,6 @@ public SctpMultiChannel bind(SocketAddress local, int backlog)
InetSocketAddress isa = (local == null) ?
new InetSocketAddress(0) : Net.checkAddress(local);

@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkListen(isa.getPort());
Net.bind(fd, isa.getAddress(), isa.getPort());

InetSocketAddress boundIsa = Net.localAddress(fd);
@@ -508,21 +504,6 @@ public <T> MessageInfo receive(ByteBuffer buffer,
resultContainer.getMessageInfo();
info.setAssociation(lookupAssociation(info.
associationID()));
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
InetSocketAddress isa = (InetSocketAddress)info.address();
if (!addressMap.containsKey(isa)) {
/* must be a new association */
try {
sm.checkAccept(isa.getAddress().getHostAddress(),
isa.getPort());
} catch (SecurityException se) {
buffer.clear();
throw se;
}
}
}

assert info.association() != null;
return info;
@@ -805,12 +786,6 @@ public int send(ByteBuffer buffer, MessageInfo messageInfo)
checkStreamNumber(association, messageInfo.streamNumber());
assocId = association.associationID();

} else { /* must be new association */
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkConnect(addr.getAddress().getHostAddress(),
addr.getPort());
}
} else {
throw new AssertionError(
45 changes: 5 additions & 40 deletions src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpNet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -32,8 +32,6 @@
import java.nio.channels.AlreadyBoundException;
import java.util.Set;
import java.util.HashSet;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.net.util.IPAddressUtil;
import sun.nio.ch.IOUtil;
import sun.nio.ch.Net;
@@ -91,41 +89,14 @@ static Set<SocketAddress> getLocalAddresses(int fd)
SocketAddress[] saa = getLocalAddresses0(fd);

if (saa != null) {
set = getRevealedLocalAddressSet(saa);
set = new HashSet<>(saa.length);
for (SocketAddress sa : saa)
set.add(sa);
}

return set;
}

private static Set<SocketAddress> getRevealedLocalAddressSet(
SocketAddress[] saa)
{
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
Set<SocketAddress> set = new HashSet<>(saa.length);
for (SocketAddress sa : saa) {
set.add(getRevealedLocalAddress(sa, sm));
}
return set;
}

private static SocketAddress getRevealedLocalAddress(SocketAddress sa,
@SuppressWarnings("removal") SecurityManager sm)
{
if (sm == null || sa == null)
return sa;
InetSocketAddress ia = (InetSocketAddress)sa;
try{
sm.checkConnect(ia.getAddress().getHostAddress(), -1);
// Security check passed
} catch (SecurityException e) {
// Return loopback address
return new InetSocketAddress(InetAddress.getLoopbackAddress(),
ia.getPort());
}
return sa;
}

static Set<SocketAddress> getRemoteAddresses(int fd, int assocId)
throws IOException {
Set<SocketAddress> set = null;
@@ -336,13 +307,7 @@ static native void setInitMsgOption0(int fd, int arg1, int arg2)
@SuppressWarnings({"removal", "restricted"})
private static void loadSctpLibrary() {
IOUtil.load(); // loads nio & net native libraries
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("sctp");
return null;
}
});
System.loadLibrary("sctp");
init();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -109,10 +109,6 @@ public SctpServerChannel bind(SocketAddress local, int backlog)

InetSocketAddress isa = (local == null) ?
new InetSocketAddress(0) : Net.checkAddress(local);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkListen(isa.getPort());
Net.bind(fd, isa.getAddress(), isa.getPort());

InetSocketAddress boundIsa = Net.localAddress(fd);
@@ -217,7 +213,6 @@ public SctpChannel accept() throws IOException {
throw new ClosedChannelException();
if (!isBound())
throw new NotYetBoundException();
SctpChannel sc = null;

int n = 0;
FileDescriptor newfd = new FileDescriptor();
@@ -244,16 +239,7 @@ public SctpChannel accept() throws IOException {
return null;

IOUtil.configureBlocking(newfd, true);
InetSocketAddress isa = isaa[0];
sc = new SctpChannelImpl(provider(), newfd);

@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkAccept(isa.getAddress().getHostAddress(),
isa.getPort());

return sc;
return new SctpChannelImpl(provider(), newfd);
}
}