F01 : le debut du mouvement ne s'execute plus sur le thread reseau
Injection apres PacketUtils.ensureRunningOnSameThread (INVOKE, shift AFTER) au lieu de HEAD ; garde isSameThread dans Garde. Test de bytecode MixinsThreadTest (rouge avant), 101 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
c45ec6df7b
révision
f69348b08b
5 fichiers modifiés
+196
-1
Aucun fichier ne correspond à votre recherche
@@ -0,0 +1,31 @@
|
||||
# Corrections de l'audit (version 0.3.0)
|
||||
|
||||
Mis à jour après chaque faille. Reprise : partir de la première ligne « à faire » du tableau.
|
||||
Règles : tout reste en OBSERVE par défaut, aucun bannissement, rien de poussé ni déployé.
|
||||
Tests : `src/test/java/com/gastinelgarde/core/AuditFaillesTest.java` (preuves de l'audit, assertions inversées
|
||||
une fois la faille corrigée) et `src/test/java/com/gastinelgarde/MixinsThreadTest.java` (bytecode des mixins).
|
||||
Base avant corrections : 98 tests verts.
|
||||
|
||||
| Faille | État | Commit | Tests | Reste à faire |
|
||||
|---|---|---|---|---|
|
||||
| F01 thread réseau | corrigée | voir `git log --grep F01` | `MixinsThreadTest` (2, rouges avant), `AuditFaillesTest.F01_*` ; 101 verts | essai en jeu n° 1 (aucune ligne `timer` en marchant) |
|
||||
| F04 riptide tenu | à faire | | | |
|
||||
| F05 grâce téléportation | à faire | | | |
|
||||
| F06 grâce dégâts | à faire | | | |
|
||||
| F07 ping | à faire | | | |
|
||||
| F08 vol aveugle | à faire | | | |
|
||||
| F02 timer inondation | à faire | | | |
|
||||
| F12 cadence saturée | à faire | | | |
|
||||
| F13 cibles saturées | à faire | | | |
|
||||
| F20 véhicules | à faire | | | |
|
||||
| F11 rotation silencieuse | à faire | | | |
|
||||
| F19, F22, F25 | essais en jeu seulement | | | `audit/ESSAIS-EN-JEU.md` |
|
||||
| Version 0.3.0, jar, README, script | à faire | | | |
|
||||
|
||||
## Détail
|
||||
|
||||
### F01
|
||||
- `MovePacketMixin.gastinelgarde$avantMouvement` : `@At(value="INVOKE", target=PacketUtils.ensureRunningOnSameThread(Packet;PacketListener;ServerLevel)V, shift=AFTER)` au lieu de `HEAD`. Cible vérifiée par `javap -c` sur `neoforge-21.1.234-merged.jar` : un seul appel dans `handleMovePlayer`, à l'offset 9 (première instruction). Mixin l'applique (`MixinsAppliquesTest`, `defaultRequire=1`).
|
||||
- Les autres injections dans `handleMovePlayer` (`TAIL`, `@ModifyArg doCheckFallDamage`, `@ModifyConstant 100/300`) sont après l'appel : jamais exécutées sur le thread réseau. `getMaximumFlyingTicks` et `teleport` ne sont pas des `handle*`.
|
||||
- Garde supplémentaire : `Garde.surThreadServeur` (sortie si `!server.isSameThread()`) dans `avantMouvement`, `apresMouvement`, `noterTeleport`, `auSolPourChute`.
|
||||
- Test de règle générale : aucun injecteur sur une méthode `handle*` en `HEAD` (pour les mixins futurs, F20).
|
||||
@@ -148,6 +148,7 @@ public final class Garde {
|
||||
// --- Faits collectés ---
|
||||
|
||||
public static void noterTeleport(ServerPlayer p) {
|
||||
if (!surThreadServeur(p)) return;
|
||||
marques(p.getUUID()).teleportTick = p.server.getTickCount();
|
||||
}
|
||||
|
||||
@@ -180,6 +181,11 @@ public final class Garde {
|
||||
else ALERTES_COUPEES.add(id);
|
||||
}
|
||||
|
||||
/** L'état du mod n'est pas thread-safe : seul le thread du serveur y touche (F01). */
|
||||
static boolean surThreadServeur(ServerPlayer p) {
|
||||
return p.server == null || p.server.isSameThread();
|
||||
}
|
||||
|
||||
private static Marques marques(UUID id) {
|
||||
return MARQUES.computeIfAbsent(id, k -> new Marques());
|
||||
}
|
||||
@@ -313,6 +319,7 @@ public final class Garde {
|
||||
|
||||
/** Début du traitement d'un paquet de mouvement : contrôle du débit. */
|
||||
public static void avantMouvement(ServerPlayer p) {
|
||||
if (!surThreadServeur(p)) return; // F01 : jamais depuis le thread réseau (le mixin l'évite déjà)
|
||||
if (estExempteManuellement(p.getUUID())) return;
|
||||
EtatJoueur etat = etat(p, false);
|
||||
List<Verdict> v = MOTEUR.paquetMouvement(p.getUUID(), System.currentTimeMillis(), etat);
|
||||
@@ -322,6 +329,7 @@ public final class Garde {
|
||||
|
||||
/** Fin du traitement d'un paquet accepté : mémorise la position valide et trace. */
|
||||
public static void apresMouvement(ServerPlayer p) {
|
||||
if (!surThreadServeur(p)) return;
|
||||
int tick = p.server.getTickCount();
|
||||
Marques m = marques(p.getUUID());
|
||||
boolean solServeur = auSolServeur(p);
|
||||
@@ -375,6 +383,7 @@ public final class Garde {
|
||||
*/
|
||||
public static boolean auSolPourChute(ServerPlayer p, boolean auSolClient) {
|
||||
if (!auSolClient) return false;
|
||||
if (!surThreadServeur(p)) return auSolClient;
|
||||
if (CONFIG.mode(Controle.NO_FALL) != Mode.ENFORCE) return auSolClient;
|
||||
if (estExempteManuellement(p.getUUID())) return auSolClient;
|
||||
return MOTEUR.auSolPourDegatsDeChute(etat(p, true), auSolClient, auSolServeur(p));
|
||||
|
||||
@@ -13,13 +13,22 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
/**
|
||||
* Observe les paquets de mouvement et les téléportations. Aucune modification du comportement vanilla : on
|
||||
* lit seulement (début : débit des paquets ; fin : position acceptée ; teleport : marque de grâce).
|
||||
*
|
||||
* Règle (F01) : rien n'est injecté avant ensureRunningOnSameThread dans une méthode handle* (MixinsThreadTest).
|
||||
*/
|
||||
@Mixin(ServerGamePacketListenerImpl.class)
|
||||
public abstract class MovePacketMixin {
|
||||
|
||||
@Shadow public ServerPlayer player;
|
||||
|
||||
@Inject(method = "handleMovePlayer", at = @At("HEAD"))
|
||||
// Jamais HEAD (F01) : la première instruction de handleMovePlayer, ensureRunningOnSameThread, replanifie le
|
||||
// paquet sur le thread serveur et lève une exception quand on est sur le thread réseau. Injecté juste après,
|
||||
// on ne s'exécute qu'une fois, sur le thread serveur (cible unique dans la méthode, vérifié par javap sur
|
||||
// NeoForge 21.1.234).
|
||||
@Inject(method = "handleMovePlayer",
|
||||
at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/network/protocol/PacketUtils;ensureRunningOnSameThread(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketListener;Lnet/minecraft/server/level/ServerLevel;)V",
|
||||
shift = At.Shift.AFTER))
|
||||
private void gastinelgarde$avantMouvement(net.minecraft.network.protocol.game.ServerboundMovePlayerPacket packet,
|
||||
CallbackInfo ci) {
|
||||
if (player != null) Garde.avantMouvement(player);
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.gastinelgarde;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
/**
|
||||
* F01 (audit 2026-10-14) : une méthode handle* de ServerGamePacketListenerImpl commence par
|
||||
* PacketUtils.ensureRunningOnSameThread. Sur le thread réseau, cet appel replanifie le paquet puis lève une
|
||||
* exception : tout ce qui est injecté AVANT s'exécute donc deux fois (Netty puis serveur).
|
||||
*
|
||||
* On lit le bytecode du mixin (ASM) : charger la classe d'un mixin directement est interdit par Mixin.
|
||||
*/
|
||||
class MixinsThreadTest {
|
||||
|
||||
static final String ENSURE = "Lnet/minecraft/network/protocol/PacketUtils;ensureRunningOnSameThread("
|
||||
+ "Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketListener;"
|
||||
+ "Lnet/minecraft/server/level/ServerLevel;)V";
|
||||
|
||||
record Injection(String methode, String annotation, List<String> cibles, AnnotationNode at) { }
|
||||
|
||||
static ClassNode lire(String classe) throws Exception {
|
||||
try (InputStream in = MixinsThreadTest.class.getClassLoader()
|
||||
.getResourceAsStream(classe.replace('.', '/') + ".class")) {
|
||||
assertNotNull(in, classe);
|
||||
ClassNode n = new ClassNode();
|
||||
new ClassReader(in).accept(n, ClassReader.SKIP_CODE);
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static Object valeur(AnnotationNode a, String nom) {
|
||||
if (a == null || a.values == null) return null;
|
||||
for (int i = 0; i + 1 < a.values.size(); i += 2) {
|
||||
if (nom.equals(a.values.get(i))) return a.values.get(i + 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static List<Injection> injections(ClassNode n) {
|
||||
List<Injection> sortie = new ArrayList<>();
|
||||
for (MethodNode m : n.methods) {
|
||||
List<AnnotationNode> toutes = new ArrayList<>();
|
||||
if (m.visibleAnnotations != null) toutes.addAll(m.visibleAnnotations);
|
||||
if (m.invisibleAnnotations != null) toutes.addAll(m.invisibleAnnotations);
|
||||
for (AnnotationNode a : toutes) {
|
||||
if (!a.desc.startsWith("Lorg/spongepowered/asm/mixin/injection/")) continue;
|
||||
Object cibles = valeur(a, "method");
|
||||
Object at = valeur(a, "at");
|
||||
if (at instanceof List<?> l) at = l.isEmpty() ? null : l.get(0);
|
||||
sortie.add(new Injection(m.name, a.desc, cibles == null ? List.of() : (List<String>) cibles,
|
||||
(AnnotationNode) at));
|
||||
}
|
||||
}
|
||||
return sortie;
|
||||
}
|
||||
|
||||
static boolean visePaquet(Injection i) {
|
||||
return i.cibles().stream().anyMatch(c -> c.startsWith("handle"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void F01_aucune_injection_HEAD_dans_un_handle() throws Exception {
|
||||
for (String classe : new String[] {"com.gastinelgarde.mixin.MovePacketMixin", "com.gastinelgarde.mixin.RiptideMoveMixin"}) {
|
||||
for (Injection i : injections(lire(classe))) {
|
||||
if (!visePaquet(i) || i.at() == null) continue;
|
||||
assertFalse("HEAD".equals(valeur(i.at(), "value")),
|
||||
classe + "." + i.methode() + " : HEAD d'un handle* = exécuté aussi sur le thread réseau");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void F01_debut_du_mouvement_apres_ensureRunningOnSameThread() throws Exception {
|
||||
Injection avant = injections(lire("com.gastinelgarde.mixin.MovePacketMixin")).stream()
|
||||
.filter(i -> i.methode().equals("gastinelgarde$avantMouvement")).findFirst().orElseThrow();
|
||||
assertEquals("INVOKE", valeur(avant.at(), "value"));
|
||||
assertEquals(ENSURE, valeur(avant.at(), "target"));
|
||||
Object shift = valeur(avant.at(), "shift");
|
||||
assertTrue(shift instanceof String[] s && s.length == 2 && "AFTER".equals(s[1]), "shift = AFTER");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.gastinelgarde.core;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Preuves de l'audit 2026-10-14 (audit/tests-proposes/AuditFaillesTest.java), intégrées une par une avec la
|
||||
* correction de chaque faille : les assertions « BYPASS » et « FAUX_POSITIF » ont été inversées une fois la
|
||||
* faille corrigée. Chaque test porte l'identifiant de la faille (audit/02-failles-detection.md).
|
||||
*/
|
||||
class AuditFaillesTest {
|
||||
|
||||
private final GardeConfig cfg = new GardeConfig();
|
||||
private final Moteur moteur = new Moteur(cfg);
|
||||
private final UUID j = UUID.randomUUID();
|
||||
|
||||
static EtatMouvement mv(double dxz, double dy, int ticks, boolean solServeur, boolean sprint) {
|
||||
return new EtatMouvement(dxz, dy, ticks, solServeur, solServeur, sprint, false, false, 0, 0, false, false);
|
||||
}
|
||||
|
||||
static boolean contient(List<Verdict> v, Controle c) {
|
||||
return v.stream().anyMatch(x -> x.controle() == c);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- F01
|
||||
/**
|
||||
* Ce que coûtait le HEAD du mixin exécuté sur les deux threads : un joueur honnête vu à 40 paquets/s. La
|
||||
* correction (injection après ensureRunningOnSameThread) est vérifiée sur le bytecode : MixinsThreadTest.
|
||||
*/
|
||||
@Test
|
||||
void F01_un_paquet_compte_une_fois_est_honnete_deux_fois_faux_positif() {
|
||||
boolean simple = false;
|
||||
UUID a = UUID.randomUUID();
|
||||
for (long t = 0; t < 10_000; t += 50) {
|
||||
if (contient(moteur.paquetMouvement(a, t, EtatJoueur.normal()), Controle.TIMER)) simple = true;
|
||||
}
|
||||
assertFalse(simple, "20 paquets/s comptés une fois : aucune infraction");
|
||||
|
||||
boolean double_ = false;
|
||||
UUID b = UUID.randomUUID();
|
||||
for (long t = 0; t < 10_000; t += 50) {
|
||||
moteur.paquetMouvement(b, t, EtatJoueur.normal());
|
||||
if (contient(moteur.paquetMouvement(b, t + 1, EtatJoueur.normal()), Controle.TIMER)) double_ = true;
|
||||
}
|
||||
assertTrue(double_, "20 paquets/s comptés deux fois = 40/s : c'est pourquoi le mixin ne doit compter qu'une fois");
|
||||
}
|
||||
}
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur